API
The layers mirror the Python package: the gym environment, the simulator and its cars, then the dynamics, collision and LiDAR models.
Environment
F1Tenth.F110Env — Type
F110Env(; seed=12345, map="vegas", map_ext=".png", params=VehicleParams(), num_agents=2,
timestep=0.01, ego_idx=1, integrator=Integrator.RK4, lidar_dist=0.0)The F1TENTH gym environment, with the keyword arguments of Python's gym.make('f110_gym:f110-v0', **kwargs):
seed: seed of the LiDAR noisemap:"berlin","skirk","levine","vegas", a track from f1tenth_racetracks such as"Austin"or"Spa"(downloaded on first use; seeF1Tenth.RACETRACKS), or the path of a map yaml file without its extensionmap_ext: extension of the map image, such as".png"(built-in maps default to their own)params: aVehicleParamsor a dict with all of its keysnum_agents: number of carstimestep: physics time step in secondsego_idx: index of the ego car (1-based)integrator:Integrator.RK4orIntegrator.Eulerlidar_dist: distance from the rear axle to the LiDAR
F1Tenth.step! — Function
step!(sim::Simulator, control_inputs) -> ObservationAdvance every car one step. control_inputs is num_agents × 2: desired steering angle in column 1, desired speed in column 2.
step!(env::F110Env, action) -> (obs, reward, done, info)Advance one time step. action is num_agents × 2: desired steering angle in column 1, desired speed in column 2. reward is the time step; done is true once the ego car crashes or every car has done two laps; info.checkpoint_done[i] is true once car i has.
The returned Observation and info are overwritten by the next call.
F1Tenth.reset! — Function
reset!(car::RaceCar, pose)Put the car at rest at pose = (x, y, θ), clear its steering delay and collision flag, and restart its scan noise from seed.
reset!(sim::Simulator, poses)Put car i at row i of poses (num_agents × 3: x, y, θ).
reset!(env::F110Env, poses) -> (obs, reward, done, info)Start a new episode with car i at row i of poses (num_agents × 3: x, y, θ). As in Python, this takes one zero-input step and returns its result.
F1Tenth.render! — Function
render!(env; mode=:human)Draw the environment in a window (needs using GLMakie). Drag to pan, scroll to zoom. :human waits 5 ms per frame, as Python does; :human_fast doesn't.
F1Tenth.update_map! — Function
update_map!(env, map_path, map_ext)Switch the simulation to the map yaml at map_path with image extension map_ext. (As in Python, an open render window keeps drawing the old map.)
F1Tenth.update_params! — Function
update_params!(car::RaceCar, params)Replace the car's physical parameters (a VehicleParams or a dict).
update_params!(sim::Simulator, params; agent_idx=-1)Update car agent_idx's parameters, or every car's when agent_idx is negative.
update_params!(env, params; index=-1)Replace the vehicle parameters of car index, or of every car when index is negative. Car-to-car collisions keep the body size given at construction, as in Python.
F1Tenth.add_render_callback! — Function
add_render_callback!(env, callback)Call callback(renderer::EnvRenderer) on every render!, before drawing.
F1Tenth.Observation — Type
ObservationWhat step! and reset! return: the entries of Python's observation dict (ego_idx, scans, poses_x, poses_y, poses_theta, linear_vels_x, linear_vels_y, ang_vels_z, collisions, lap_times, lap_counts). Read them as obs.poses_x, obs[:poses_x] or obs["poses_x"].
The arrays are reused: each step overwrites them. copy(obs) keeps a snapshot.
Rendering
F1Tenth.EnvRenderer — Type
EnvRendererThe render window, passed to render callbacks. Like Python's renderer it works in renderer units (50 × meters). Callbacks may set the camera (left, right, bottom, top) and score_label, read cars[i][] (corner points of car i), poses (num_agents × 3, meters) and ego_idx, and draw on axis with GLMakie (where Python callbacks add to batch).
F1Tenth.ScoreLabel — Type
ScoreLabelThe text label in the render window, like Python's pyglet Label: set text, x, y (renderer units) from a render callback.
Simulator and cars
F1Tenth.Simulator — Type
Simulator(params, num_agents, seed; time_step=0.01, ego_idx=1,
integrator=Integrator.RK4, lidar_dist=0.0)All the cars of an environment and their interactions. Cars are numbered from 1.
F1Tenth.RaceCar — Type
RaceCar(params, seed; is_ego=false, time_step=0.01, num_beams=1080, fov=4.7,
integrator=Integrator.Euler, lidar_dist=0.0)One vehicle: dynamics, a two-step steering delay, the speed/steering controller and a LiDAR. state is (x, y, steer_angle, vel, yaw_angle, yaw_rate, slip_angle). Scan noise is drawn from scan_rng; set it to nothing for noise-free scans (as rng=None in Python).
Cars made by a Simulator share its scan simulator and beam tables, like the class attributes of Python's RaceCar.
F1Tenth.Integrator — Module
Integrator.RK4, Integrator.EulerIntegrator for the vehicle dynamics, as Python's Integrator enum.
F1Tenth.VehicleParams — Type
VehicleParams(; mu=1.0489, C_Sf=4.718, C_Sr=5.4562, lf=0.15875, lr=0.17145, h=0.074,
m=3.74, I=0.04712, s_min=-0.4189, s_max=0.4189, sv_min=-3.2, sv_max=3.2,
v_switch=7.319, a_max=9.51, v_min=-5.0, v_max=20.0, width=0.31, length=0.58)
VehicleParams(d::AbstractDict)Vehicle parameters. Same keys and defaults as the Python env's params dict:
mu: surface friction coefficientC_Sf,C_Sr: front/rear cornering stiffness coefficientslf,lr: distance from the center of gravity to the front/rear axleh: height of the center of gravitym: total mass of the vehicleI: moment of inertia of the vehicle about the z axiss_min,s_max: steering angle limitssv_min,sv_max: steering velocity limitsv_switch: velocity above which acceleration can no longer spin the wheelsa_max: maximum longitudinal accelerationv_min,v_max: longitudinal velocity limitswidth,length: car body size in meters
A dict (String or Symbol keys) must hold every key, as in Python; extra keys are ignored.
F1Tenth.update_pose! — Function
update_pose!(car, raw_steer, vel) -> scanAdvance the car one time step towards the requested steering angle and speed, then scan from the new pose. The scan is the car's own buffer, overwritten on the next call.
F1Tenth.update_scan! — Function
update_scan!(car, scan) -> scanRun the iTTC check on scan, then add the other cars to it.
F1Tenth.update_opp_poses! — Function
update_opp_poses!(car, opp_poses)Tell the car where the other cars are (a list of (x, y, θ)).
F1Tenth.check_ttc! — Function
check_ttc!(car, current_scan) -> BooliTTC check against the environment (not other cars). On a hit the car is stopped as in Python: velocity, yaw, yaw rate and slip are all zeroed.
F1Tenth.ray_cast_agents! — Function
ray_cast_agents!(car, scan) -> scanShorten scan where the other cars (at car.opp_poses) block the beams.
F1Tenth.check_collision! — Function
check_collision!(sim)GJK check between every pair of cars.
F1Tenth.set_map! — Function
set_map!(scan_sim, map_path, map_ext)Load the map yaml at map_path and its image <map_path without extension><map_ext>.
set_map!(car::RaceCar, map_path, map_ext)Set the map of the car's scan simulator (shared with its simulator's other cars).
set_map!(sim::Simulator, map_path, map_ext)Set the map used by every car's LiDAR.
Dynamics
F1Tenth.vehicle_dynamics_st — Function
vehicle_dynamics_st(x, u_init, params::VehicleParams) -> SVector{7}Dynamic single-track model. State x = (x, y, steering angle, velocity, yaw, yaw rate, slip angle), input u_init = (steering velocity, acceleration). Below 0.5 m/s it switches to the kinematic model, exactly as the Python code.
F1Tenth.vehicle_dynamics_ks — Function
vehicle_dynamics_ks(x, u_init, params::VehicleParams) -> SVector{5}Kinematic single-track model. State x = (x, y, steering angle, velocity, yaw), input u_init = (steering velocity, acceleration); inputs are clamped first.
F1Tenth.pid — Function
pid(speed, steer, current_speed, current_steer, max_sv, max_a, max_v, min_v) -> (accl, sv)The env's built-in controller: turns a target speed and steering angle into an acceleration and a steering velocity.
F1Tenth.accl_constraints — Function
accl_constraints(vel, accl, v_switch, a_max, v_min, v_max) -> Float64Clamp the requested acceleration accl to what the car can do at speed vel.
F1Tenth.steering_constraint — Function
steering_constraint(steering_angle, steering_velocity, s_min, s_max, sv_min, sv_max) -> Float64Clamp the requested steering velocity to the steering angle and rate limits.
Collisions
F1Tenth.get_vertices — Function
get_vertices(pose, length, width) -> SVector{4,SVector{2,Float64}}Corners of a car body at pose = (x, y, θ), in Python's order: rear-left, rear-right, front-right, front-left.
F1Tenth.collision — Function
collision(vertices1, vertices2) -> BoolGJK overlap test between two convex polygons, each given as a list of 2D points.
F1Tenth.collision_multiple — Function
collision_multiple(vertices) -> (collisions::Vector{Float64}, collision_idx::Vector{Int})Pairwise GJK checks over every body. collisions[i] is 1.0 when body i touches any other body; collision_idx[i] is the last body it hit, or -1.
LiDAR
F1Tenth.ScanSimulator2D — Type
ScanSimulator2D(num_beams, fov; eps=0.0001, theta_dis=2000, max_range=30.0)2D LiDAR simulator. Beam angles are looked up in a table of theta_dis angles over a full turn; call set_map! before scanning.
F1Tenth.get_scan! — Function
get_scan!(scan, sim, pose) -> scanNoise-free scan from pose = (x, y, θ) into scan (length num_beams).
F1Tenth.scan! — Function
scan!(out, sim, pose, rng; std_dev=0.01) -> out
scan(sim, pose, rng; std_dev=0.01) -> Vector{Float64}Scan from pose with N(0, std_dev) noise added to every beam, drawn from rng; rng = nothing gives a noise-free scan.
F1Tenth.get_increment — Function
get_increment(scan_sim) -> Float64Angle between neighboring beams, in radians.
F1Tenth.check_ttc — Function
check_ttc(scan, vel, scan_angles, cosines, side_distances, ttc_thresh) -> BoolInstantaneous time-to-collision check against the environment: true when any beam's iTTC is in [0, ttc_thresh). (scan_angles is unused, as in Python.)
F1Tenth.ray_cast! — Function
ray_cast!(pose, scan, scan_angles, vertices) -> scanShorten the beams of scan (taken at pose) that hit the car with corners vertices.
F1Tenth.get_range — Function
get_range(pose, beam_theta, va, vb) -> Float64Distance along the world-frame beam angle beam_theta from pose to edge va-vb.
F1Tenth.get_blocked_view_indices — Function
get_blocked_view_indices(pose, vertices, scan_angles) -> (min_index, max_index)Range of beam indices that can see the car with corners vertices.
Performance settings
F1Tenth.TRACER — Constant
F1Tenth.TRACER[] = :auto | :simd | :scalarLiDAR tracer to use. Both give identical scans; :auto (the default) picks the faster one for this CPU on first use.
F1Tenth.THREAD_AGENTS — Constant
F1Tenth.THREAD_AGENTS[] = true | falseWith more than one Julia thread, step each car on its own thread (default true). Set to false when running many simulators in parallel yourself.