Track Utilities
Track loading, coordinate transforms, and spline utilities.
Track
- class f1tenth_gym_jax.envs.track.track.Track(xs, ys, occ_map=None, resolution=1.0, ox=0.0, oy=0.0, oyaw=0.0, velxs=None, filepath=None, centerline=None, raceline=None, ss=None, psis=None, kappas=None, accxs=None, waypoints=None, s_frame_max=None)
Bases:
object- Parameters:
xs (ndarray)
ys (ndarray)
occ_map (ndarray)
resolution (float)
ox (float)
oy (float)
oyaw (float)
velxs (ndarray)
filepath (str | None)
centerline (CubicSplineND)
raceline (CubicSplineND)
ss (ndarray | None)
psis (ndarray | None)
kappas (ndarray | None)
accxs (ndarray | None)
waypoints (ndarray | None)
s_frame_max (float | None)
- psis: ndarray | None = None
- kappas: ndarray | None = None
- accxs: ndarray | None = None
- filepath: str | None
- ss: ndarray | None = None
- xs: ndarray
- ys: ndarray
- vxs: ndarray
- occ_map: ndarray
- resolution: float
- ox: float
- oy: float
- oyaw: float
- centerline: CubicSplineND
- raceline: CubicSplineND
- static from_track_name(map_name)
- Parameters:
map_name (str)
- static from_numpy(waypoints, s_frame_max, downsample_step=1)
Create an empty track reference line.
- Parameters:
filepath (pathlib.Path) – path to the raceline file
delimiter (str, optional) – delimiter used in the file, by default “;”
downsample_step (int, optional) – downsample step for waypoints, by default 1 (no downsampling)
waypoints (ndarray)
- Returns:
track – track object
- Return type:
- static from_raceline_file(filepath, delimiter=';', downsample_step=1)
Create an empty track reference line.
- Parameters:
filepath (pathlib.Path) – path to the raceline file
delimiter (str, optional) – delimiter used in the file, by default “;”
downsample_step (int, optional) – downsample step for waypoints, by default 1 (no downsampling)
- Returns:
track – track object
- Return type:
- frenet_to_cartesian(s, ey, ephi)
Convert Frenet coordinates to Cartesian coordinates.
s: distance along the raceline ey: lateral deviation ephi: heading deviation
- returns:
x: x-coordinate y: y-coordinate psi: yaw angle
- vmap_frenet_to_cartesian_jax(poses)
- frenet_to_cartesian_jax(s, ey, ephi)
Convert Frenet coordinates to Cartesian coordinates.
s: distance along the raceline ey: lateral deviation ephi: heading deviation
- returns:
x: x-coordinate y: y-coordinate psi: yaw angle
- cartesian_to_frenet(x, y, phi, s_guess=None)
Convert Cartesian coordinates to Frenet coordinates.
x: x-coordinate y: y-coordinate phi: yaw angle
- returns:
s: distance along the centerline ey: lateral deviation ephi: heading deviation
- cartesian_to_frenet_jax(x, y, phi, s_guess=None)
- vmap_cartesian_to_frenet_jax(poses)
- curvature(s)
Get the curvature at a given s.
s: distance along the raceline
- returns:
curvature
- curvature_jax(s)
Spline
Cubic Spline interpolation using scipy.interpolate Provides utilities for position, curvature, yaw, and arclength calculation
- f1tenth_gym_jax.envs.track.cubic_spline.nearest_point_on_trajectory_jax(point, trajectory)
- Return type:
tuple
- f1tenth_gym_jax.envs.track.cubic_spline.first_point_on_trajectory(point, trajectory, radius)
- Parameters:
point (Array)
trajectory (Array)
radius (float)
- class f1tenth_gym_jax.envs.track.cubic_spline.CubicSplineND(xs, ys, psis=None, ks=None, vxs=None, axs=None)
Bases:
objectCubic CubicSplineND class.
- Parameters:
xs (ndarray)
ys (ndarray)
psis (ndarray | None)
ks (ndarray | None)
vxs (ndarray | None)
axs (ndarray | None)
- s
cumulative distance along the data points.
- Type:
list
- xs
x coordinates for data points.
- Type:
np.ndarray
- ys
y coordinates for data points.
- Type:
np.ndarray
- spsi
yaw angles for data points.
- Type:
np.ndarray
- ks
curvature for data points.
- Type:
np.ndarray
- vxs
velocity for data points.
- Type:
np.ndarray
- axs
acceleration for data points.
- Type:
np.ndarray
- predict_with_spline(point, segment, state_index=0)
- predict_with_spline_jax(point, segment, state_index=0)
- predict_first_derivative_with_spline_jax(point, segment, state_index=0)
- predict_second_derivative_with_spline_jax(point, segment, state_index=0)
- find_segment_for_x(x)
- find_segment_for_x_jax(x)
- calc_position(s)
Calc position at the given s.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
x (float | None) – x position for given s.
y (float | None) – y position for given s.
- Return type:
ndarray
- calc_position_jax(s)
Calc position at the given s.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
x (float | None) – x position for given s.
y (float | None) – y position for given s.
- Return type:
ndarray
- calc_curvature(s)
Calc curvature at the given s.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
k – curvature for given s.
- Return type:
float
- calc_curvature_jax(s)
Calc curvature at the given s.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
k – curvature for given s.
- Return type:
float
- find_curvature_jax(s)
- Parameters:
s (float)
- Return type:
float | None
- find_curvature(s)
Find curvature at the given s by the segment.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
k – curvature for given s.
- Return type:
float
- calc_yaw(s)
Calc yaw angle at the given s.
- Parameters:
s (float) – distance from the start point. If s is outside the data point’s range, return None.
- Returns:
yaw – yaw angle (tangent vector) for given s.
- Return type:
float
- calc_yaw_jax(s)
- Parameters:
s (float)
- Return type:
float | None
- calc_arclength(x, y, s_guess=0.0)
Fast calculation of arclength for a given point (x, y) on the trajectory. Less accuarate and less smooth than calc_arclength but much faster. Suitable for lap counting.
- Parameters:
x (float) – x position.
y (float) – y position.
- Returns:
s (float) – distance from the start point for given x, y.
ey (float) – lateral deviation for given x, y.
- Return type:
tuple[float, float]
- calc_arclength_jax(x, y, s_guess=0.0)
- Parameters:
x (float)
y (float)
- Return type:
tuple[float, float]
- calc_arclength_slow(x, y, s_guess=0.0)
Calculate arclength for a given point (x, y) on the trajectory.
- Parameters:
x (float) – x position.
y (float) – y position.
s_guess (float) – initial guess for s.
- Returns:
s (float) – distance from the start point for given x, y.
ey (float) – lateral deviation for given x, y.
- Return type:
tuple[float, float]
- calc_velocity(s)
Calc velocity at the given s.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
v – velocity for given s.
- Return type:
float
- calc_acceleration(s)
Calc acceleration at the given s.
- Parameters:
s (float) – distance from the start point. if s is outside the data point’s range, return None.
- Returns:
a – acceleration for given s.
- Return type:
float
Map Lookup
- f1tenth_gym_jax.envs.track.utils.get_map_search_dirs()
Return map directories in lookup order without creating them.
- Return type:
tuple[Path, …]
- f1tenth_gym_jax.envs.track.utils.find_track_dir(track_name)
Find the directory of the track map corresponding to the given track name.
- Parameters:
track_name (str) – name of the track
- Returns:
path to the track map directory
- Return type:
pathlib.Path
- Raises:
FileNotFoundError – if no map directory matching the track name is found