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 noise
  • map: "berlin", "skirk", "levine", "vegas", a track from f1tenth_racetracks such as "Austin" or "Spa" (downloaded on first use; see F1Tenth.RACETRACKS), or the path of a map yaml file without its extension
  • map_ext: extension of the map image, such as ".png" (built-in maps default to their own)
  • params: a VehicleParams or a dict with all of its keys
  • num_agents: number of cars
  • timestep: physics time step in seconds
  • ego_idx: index of the ego car (1-based)
  • integrator: Integrator.RK4 or Integrator.Euler
  • lidar_dist: distance from the rear axle to the LiDAR

Drive it with reset!, step! and render!.

source
F1Tenth.step! — Function
step!(sim::Simulator, control_inputs) -> Observation

Advance every car one step. control_inputs is num_agents × 2: desired steering angle in column 1, desired speed in column 2.

source
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.

source
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.

source
reset!(sim::Simulator, poses)

Put car i at row i of poses (num_agents × 3: x, y, θ).

source
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.

source
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.

source
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.)

source
F1Tenth.update_params! — Function
update_params!(car::RaceCar, params)

Replace the car's physical parameters (a VehicleParams or a dict).

source
update_params!(sim::Simulator, params; agent_idx=-1)

Update car agent_idx's parameters, or every car's when agent_idx is negative.

source
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.

source
F1Tenth.Observation — Type
Observation

What 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.

source

Rendering

F1Tenth.EnvRenderer — Type
EnvRenderer

The 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).

source
F1Tenth.ScoreLabel — Type
ScoreLabel

The text label in the render window, like Python's pyglet Label: set text, x, y (renderer units) from a render callback.

source

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.

source
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.

source
F1Tenth.Integrator — Module
Integrator.RK4, Integrator.Euler

Integrator for the vehicle dynamics, as Python's Integrator enum.

source
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 coefficient
  • C_Sf, C_Sr: front/rear cornering stiffness coefficients
  • lf, lr: distance from the center of gravity to the front/rear axle
  • h: height of the center of gravity
  • m: total mass of the vehicle
  • I: moment of inertia of the vehicle about the z axis
  • s_min, s_max: steering angle limits
  • sv_min, sv_max: steering velocity limits
  • v_switch: velocity above which acceleration can no longer spin the wheels
  • a_max: maximum longitudinal acceleration
  • v_min, v_max: longitudinal velocity limits
  • width, length: car body size in meters

A dict (String or Symbol keys) must hold every key, as in Python; extra keys are ignored.

source
F1Tenth.update_pose! — Function
update_pose!(car, raw_steer, vel) -> scan

Advance 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.

source
F1Tenth.check_ttc! — Function
check_ttc!(car, current_scan) -> Bool

iTTC 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.

source
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>.

source
set_map!(car::RaceCar, map_path, map_ext)

Set the map of the car's scan simulator (shared with its simulator's other cars).

source
set_map!(sim::Simulator, map_path, map_ext)

Set the map used by every car's LiDAR.

source

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.

source
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.

source
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.

source
F1Tenth.accl_constraints — Function
accl_constraints(vel, accl, v_switch, a_max, v_min, v_max) -> Float64

Clamp the requested acceleration accl to what the car can do at speed vel.

source
F1Tenth.steering_constraint — Function
steering_constraint(steering_angle, steering_velocity, s_min, s_max, sv_min, sv_max) -> Float64

Clamp the requested steering velocity to the steering angle and rate limits.

source

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.

source
F1Tenth.collision — Function
collision(vertices1, vertices2) -> Bool

GJK overlap test between two convex polygons, each given as a list of 2D points.

source
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.

source

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.

source
F1Tenth.get_scan! — Function
get_scan!(scan, sim, pose) -> scan

Noise-free scan from pose = (x, y, θ) into scan (length num_beams).

source
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.

source
F1Tenth.check_ttc — Function
check_ttc(scan, vel, scan_angles, cosines, side_distances, ttc_thresh) -> Bool

Instantaneous 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.)

source
F1Tenth.ray_cast! — Function
ray_cast!(pose, scan, scan_angles, vertices) -> scan

Shorten the beams of scan (taken at pose) that hit the car with corners vertices.

source
F1Tenth.get_range — Function
get_range(pose, beam_theta, va, vb) -> Float64

Distance along the world-frame beam angle beam_theta from pose to edge va-vb.

source
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.

source

Performance settings

F1Tenth.TRACER — Constant
F1Tenth.TRACER[] = :auto | :simd | :scalar

LiDAR tracer to use. Both give identical scans; :auto (the default) picks the faster one for this CPU on first use.

source
F1Tenth.THREAD_AGENTS — Constant
F1Tenth.THREAD_AGENTS[] = true | false

With more than one Julia thread, step each car on its own thread (default true). Set to false when running many simulators in parallel yourself.

source