Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:CARLA simulator Carla Traffic Behavior Configuration

From Leeroopedia
Knowledge Sources
Domains Traffic Behavior Modeling, Simulation Configuration
Last Updated 2026-02-15 00:00 GMT

Overview

Traffic behavior configuration is the process of tuning parameters that govern how simulated NPC vehicles drive, including speed profiles, following distances, physics fidelity, and deterministic reproducibility.

Description

Once a Traffic Manager is initialized and vehicles are registered for autopilot, their driving behavior is determined by a set of configurable parameters. These parameters fall into several categories:

Speed Configuration

The speed of NPC vehicles is controlled relative to the posted speed limit of each road segment. A percentage speed difference parameter adjusts speed globally or per-vehicle:

  • A positive value (e.g., +30) means vehicles drive 30% slower than the speed limit
  • A negative value (e.g., -10) means vehicles drive 10% faster than the speed limit
  • A value of 0 means vehicles drive exactly at the speed limit

This relative approach means NPC vehicles automatically respect different speed limits across the road network (residential streets, highways, school zones).

Following Distance

The distance to leading vehicle parameter controls the minimum gap NPC vehicles maintain behind the vehicle ahead. This is a critical parameter for:

  • Realistic traffic density -- shorter distances create denser traffic
  • Safety margins -- longer distances reduce rear-end collision risk
  • Traffic flow -- the following distance affects throughput at intersections and merges

Synchronous Mode

In synchronous mode, the Traffic Manager processes all vehicle updates in lockstep with the simulation's world tick. This ensures:

  • Deterministic behavior -- the same inputs always produce the same outputs
  • No race conditions -- the TM always operates on consistent world state
  • Frame-perfect control -- no vehicle updates are skipped or doubled

Synchronous mode should always be enabled when the simulation itself is running in synchronous mode.

Hybrid Physics Mode

Hybrid physics is a performance optimization that applies full physics simulation only to vehicles within a configurable radius of the "hero" (ego) vehicle. Vehicles outside this radius are moved kinematically (teleported along their planned paths without physics calculations), dramatically reducing CPU load for large traffic populations.

  • Enabled: Vehicles far from the ego vehicle skip physics -- they still follow roads and obey traffic rules, but their movement is simplified
  • Radius: The distance threshold (in meters) that determines which vehicles get full physics
  • Benefit: Enables simulations with hundreds of vehicles without physics engine bottlenecks

Deterministic Seeding

Setting a random device seed makes the Traffic Manager's internal random number generation deterministic. With the same seed, vehicles will make the same lane-change decisions, speed variations, and gap acceptances across repeated runs, which is essential for:

  • Reproducible test scenarios
  • Regression testing of autonomous driving algorithms
  • Fair comparison of different algorithm versions

Usage

Configure traffic behavior after initializing the Traffic Manager and before (or immediately after) spawning NPC vehicles. Behavior parameters can be adjusted at any time during simulation, but changes to synchronous mode should be set before spawning vehicles.

Theoretical Basis

Car-Following Models

The Traffic Manager's following distance and speed configuration implement a simplified version of established car-following models from traffic engineering:

Intelligent Driver Model (IDM) - simplified:

    desired_gap(v, delta_v) = s0 + v * T + (v * delta_v) / (2 * sqrt(a * b))

    where:
        s0 = minimum gap (distance_to_leading_vehicle parameter)
        v  = current velocity
        T  = desired time headway
        delta_v = approach speed (speed difference to leading vehicle)
        a  = maximum acceleration
        b  = comfortable deceleration

    acceleration = a * [1 - (v / v_desired)^4 - (desired_gap / actual_gap)^2]

    where:
        v_desired = speed_limit * (1 - percentage_speed_difference / 100)

The Traffic Manager simplifies this by using a fixed following distance rather than a velocity-dependent gap, but the underlying principle of maintaining safe following distance relative to speed and closing rate is preserved.

Level of Detail (LOD) for Physics

Hybrid physics mode implements a Level of Detail (LOD) approach borrowed from computer graphics, applied to physics simulation:

Distance from Hero Physics Level Computation Cost
Within hybrid radius Full Unreal Engine physics (tire model, suspension, collision) High
Outside hybrid radius Kinematic path following (position interpolation along waypoints) Low
Very far (if culled) Minimal updates (position only, no rendering) Minimal

The transition between physics levels must be smooth to avoid visible popping. When a vehicle crosses from kinematic to full-physics mode, its velocity and heading are initialized from the kinematic state to prevent jarring transitions.

Determinism Requirements

For fully deterministic traffic simulation, several conditions must hold simultaneously:

  1. Synchronous mode enabled -- Both the world and Traffic Manager must tick in lockstep
  2. Fixed random seed -- All random decisions use the seeded generator
  3. Fixed time step -- The simulation must use a fixed delta time (not variable frame rate)
  4. Single-threaded execution order -- Or deterministic thread scheduling
Deterministic configuration:
    settings = world.get_settings()
    settings.synchronous_mode = True
    settings.fixed_delta_seconds = 0.05   # 20 FPS fixed time step
    world.apply_settings(settings)

    traffic_manager.set_synchronous_mode(True)
    traffic_manager.set_random_device_seed(42)

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment