Principle:CARLA simulator Carla Car Following Model
Overview
The Car-Following Model in CARLA's BehaviorAgent implements a Time-To-Collision (TTC) based approach to longitudinal speed regulation when following a lead vehicle. The model adapts the ego vehicle's speed based on the distance and relative velocity to the vehicle ahead, with behavior-specific parameters (Cautious, Normal, Aggressive) defining safety margins, braking thresholds, and speed adaptation strategies.
Description
Car-following models are fundamental to traffic simulation and autonomous driving, governing how a following vehicle adjusts its speed in response to a leading vehicle. CARLA's implementation uses a simplified TTC model that:
- Computes Time-To-Collision (TTC): Estimates how many seconds until the ego vehicle would collide with the lead vehicle at the current closing rate.
- Compares TTC to safety_time: Each behavior profile defines a
safety_timethreshold. If the TTC falls below this threshold, the model triggers emergency braking.
- Adapts target speed: When the TTC is above the safety threshold but the ego vehicle is within a proximity zone, the model reduces the target speed to match or trail the lead vehicle's speed, then delegates to the PID controller for smooth deceleration.
- Behavior Profiles: Three pre-defined profiles control the aggressiveness of following:
| Parameter | Cautious | Normal | Aggressive |
|---|---|---|---|
| speed_lim_dist | 6 km/h below limit | 3 km/h below limit | 1 km/h above limit |
| safety_time | 3.0 s | 3.0 s | 3.0 s |
| min_proximity_threshold | 12.0 m | 12.0 m | 8.0 m |
| speed_decrease | 12 km/h | 10 km/h | 5 km/h |
Usage
Use the car-following model when you need to:
- Simulate realistic following behavior behind slower vehicles
- Compare how different driving personalities respond to the same traffic situation
- Implement safe longitudinal spacing without complex model-predictive control
- Study the interaction between safety margins and traffic throughput
Theoretical Basis
Time-To-Collision (TTC)
TTC is the time remaining before two vehicles collide if they maintain their current speeds and trajectories:
TTC = distance / relative_velocity
where:
distance = Euclidean distance between ego and lead vehicle (meters)
relative_velocity = ego_speed - lead_speed (m/s, positive when closing)
If the relative velocity is zero or negative (ego is slower than or matching the lead), TTC is infinite (no collision risk).
Decision Logic
The car-following manager implements a three-tier decision hierarchy:
function car_following_manager(lead_vehicle, distance):
ego_speed = get_speed(ego_vehicle) # km/h
lead_speed = get_speed(lead_vehicle) # km/h
# Convert to m/s for TTC calculation
delta_v = (ego_speed - lead_speed) / 3.6 # m/s
if delta_v > 0:
ttc = distance / delta_v # seconds
else:
ttc = infinity
# Tier 1: Emergency braking
if ttc < safety_time:
return emergency_brake()
# Tier 2: Speed adaptation (within proximity zone)
elif distance < min_proximity_threshold:
target_speed = min(
behavior.speed_decrease,
lead_speed,
behavior.max_speed
)
return pid_controller.run_step(target_speed, next_waypoint)
# Tier 3: Normal following
else:
target_speed = min(
behavior.max_speed,
ego_speed - behavior.speed_decrease
)
return pid_controller.run_step(target_speed, next_waypoint)
Relationship to Classical Models
CARLA's TTC-based model is a simplified variant of the Intelligent Driver Model (IDM) by Treiber et al. (2000). While IDM uses continuous acceleration functions, CARLA's model uses discrete decision tiers. Both share the core principle: maintain a safe time gap to the lead vehicle and adjust speed proportionally to the closing rate.
The key differences from IDM are:
- Discrete vs. continuous: CARLA uses threshold-based decisions rather than a smooth acceleration function
- Behavior profiles: CARLA parameterizes aggression via named profiles rather than continuous parameter spaces
- Emergency braking: CARLA applies a hard brake override when TTC is critical, rather than a smooth deceleration curve
Safety Analysis
The minimum safe following distance at steady state is:
d_safe = ego_speed * safety_time / 3.6 (meters)
For example, at 50 km/h with safety_time = 3.0s:
d_safe = 50 * 3.0 / 3.6 = 41.7 m
This conservative spacing ensures that even with typical braking distances, the ego vehicle has sufficient room to stop.