suboptimumg.track.utils#

suboptimumg.track.utils.calculate_cumulative_distances(x_m, y_m)[source]#

Calculates cumulative distances along a path defined by x, y coordinates.

Parameters:
  • x_m (NDArray[float64]) – Array of x coordinates in meters

  • y_m (NDArray[float64]) – Array of y coordinates in meters

Returns:

(track_length, cumulative_distances) - Total track length and array of cumulative distances

Return type:

Tuple[float, NDArray[float64]]

suboptimumg.track.utils.calculate_menger_curvature(x_m, y_m, cumulative_dist, dist, sample_dist)[source]#

Calculates curvature at a given distance using the Menger curvature formula. Uses three points: one at dist-sample_dist, one at dist, and one at dist+sample_dist.

Parameters:
  • x_m (NDArray[float64]) – Array of x coordinates in meters

  • y_m (NDArray[float64]) – Array of y coordinates in meters

  • cumulative_dist (NDArray[float64]) – Array of cumulative distances

  • dist (float) – Distance along track to calculate curvature

  • sample_dist (float) – Distance to sample before/after the point

Returns:

(curvature, radius) - Curvature (1/m) and radius of curvature (m)

Return type:

Tuple[float, float]

suboptimumg.track.utils.calculate_radii(x_m, y_m, cumulative_dist, sample_dist)[source]#

Calculates the radius of curvature at each point in a track.

Parameters:
  • x_m (NDArray[float64]) – Array of x coordinates in meters

  • y_m (NDArray[float64]) – Array of y coordinates in meters

  • cumulative_dist (NDArray[float64]) – Array of cumulative distances

  • sample_dist (float) – Distance to sample for Menger curvature calculation

Returns:

An array containing the Radius of Curvature at each point

Return type:

npt.NDArray[float64]

suboptimumg.track.utils.corners_to_cartesian(corners, distance_step, start_angle_deg=0.0)[source]#

Converts a list of corners (radius, length) into absolute cartesian coordinates (x, y) and creates ArcData objects for visualization.

This function simulates driving through each corner, starting from the origin (0, 0) with an initial heading angle, and tracks the path by computing arc geometry.

Parameters:
  • corners (List[List]) – List of corners specified as [radius (m), length (steps)] where length is the number of discrete steps (not meters)

  • distance_step (float) – The distance in meters represented by each step

  • start_angle_deg (float, optional) – Initial heading angle in degrees (default: 0)

Returns:

(x_m, y_m, arcs) - Arrays of x and y coordinates in meters, and list of ArcData objects

Return type:

Tuple[NDArray[float64], NDArray[float64], List[ArcData]]

suboptimumg.track.utils.get_2d_rotation_matrix(alpha)[source]#

Returns a 2D rotation matrix for a given angle alpha (in radians).

Parameters:

alpha (float) – Rotation angle in radians

Returns:

2x2 rotation matrix

Return type:

NDArray[float64]

suboptimumg.track.utils.scale_and_discretize_corner_lengths(corners, ratio)[source]#

Scales each corner length (corner[i][1]) by ratio and rounds to nearest integer. Used to convert corner length (meters) to number of simulation steps (unitless).

Parameters:
  • corners (List[List]) – List of corners specified as [radius (m), length (decimeters)]

  • ratio (float) – The scaling to apply, before rounding.

Returns:

Same list of corners with lengths scaled, represented as [radius (m), steps]

Return type:

List[List]

suboptimumg.track.utils.smooth_and_normalize_corner_radii(corners)[source]#

Takes the absolute value of all corner radii. Scales radius of small corners (r <= 10) by a factor of ((20 - r) / 10)^1.2

Parameters:

corners (List[List]) – List of corners specified as [radius (m), length (decimeters)]

Returns:

The same corners, but with cleaned radii

Return type:

List[List]

Notes

Currently used for Mich 2023 AutoX and Endurance tracks. Subject to review.

suboptimumg.track.utils.unroll_corners_into_track(corners, distance_step)[source]#

Unrolls the compressed corner list into discrete chunks.

Parameters:
  • corners (List[List[int]]) – List of corners specified as [radius (m), length (decimeters)]

  • distance_step (float) – Length of each step in the simulation

Returns:

(dx, radius, cumulative_dist)

Return type:

Tuple[npt.NDArray[float64], npt.NDArray[float64], npt.NDArray[float64]]