191. Traffic density watcher
The vehicle.traffic_density watcher monitors the traffic conditions in the immediate vicinity of a vehicle and emits intervals when traffic density changes across different categories. This watcher provides real-time assessment of traffic conditions in the Ego lane, left lanes, and right lanes, along with an overall traffic density indicator based on established traffic engineering standards.
191.0.1 Start condition
A new interval starts when all the following conditions are met:
- No active interval exists (
data == null) - Lane information is available
- The Ego exists in the simulator
- The Ego's speed is greater than or equal to
min_activation_speed
191.0.2 End condition
An active interval ends when any of the following conditions are met:
1. Category change (with delayed restart):
- The traffic density category changes from one level to another (e.g., from light to moderate)
- The previous interval ends immediately at the current sampling time
- The watcher prevents starting a new interval within the same clock cycle
- The new interval starts at the next clock cycle in which the conditions are met. This ensures distinct start and end timestamps and prevents overlap.
2. Invalid operating conditions (end with deferred restart):
- The Ego's speed drops below the
min_activation_speed - Lane information becomes unavailable, or lane/occupancy consistency checks fail
- The interval ends on that tick. When activation is OK again, the next interval starts on the following
w_clk(you do not need to wait forsampling_frequency).
Take note of the following rules governing interval timing, validity checks, and the use of rolling versus interval-based metrics.
- Category change ends at the sample time and opens the next interval on the next
w_clk. Invalid activation ends on any tick; the same deferred start applies when speed and lane checks pass again. - The check for invalid operating conditions runs on every clock tick, not just at sampling intervals, so intervals can end between traffic-density samples.
- Rolling window vs what you see on the closed interval: A per-lane rolling average of instantaneous spatial density (last up to
rolling_window_sizesamples) decides when the overall category changes and thus when the interval ends on category change. Reported lane/overall density and categories ondatawhen the interval closes use interval-mean occupancy: mean vehicle count per sample over the whole interval (computed with a fractional mean), converted to vehicles/km/lane. That aligns density with min/max/avg count statistics over the same interval. Sparse traffic (many zero samples, a few non-zero) can still show integer*_vehicle_count_avgas 0 while density reflects the true fractional mean. - Lane validity can use either
lane_position.laneormsp_pos_closest_lanewhen both match an occupied driving lane, to reduce one-tick glitches. - Longitudinal distance for the detection window uses route-based road distance (driving lanes only), consistent with lane-relative counting.
- Rolling density sample lists are cleared at each interval start so rolling state applies only within that interval.
191.1 Configuration parameters
The following parameters can be configured to customize the evaluator's behavior.
| Parameter | Type | Description | Default Value |
|---|---|---|---|
detection_range_forward |
length | The forward detection range is the distance from the Ego's current position to the forward detection range. | 100m |
detection_range_backward |
length | The backward detection range is the distance from the Ego's current position to the backward detection range. | 50m |
min_vehicle_speed |
speed | The minimum vehicle speed is the minimum speed at which a vehicle is considered to be moving. | 5kph |
min_activation_speed |
speed | The minimum activation speed is the minimum speed at which the watcher activates. | 5kph |
moderate_traffic_density_threshold |
float | The moderate traffic density threshold is the threshold for the moderate traffic density category. | 19.0 |
heavy_traffic_density_threshold |
float | The heavy traffic density threshold is the threshold for the heavy traffic density category. | 42.0 |
sampling_frequency |
time | The sampling frequency is the frequency at which the watcher samples the traffic density. | 2s |
rolling_window_size |
uint | The rolling window size is the size of the rolling window for the traffic density. | 5 |
light_traffic_density_threshold |
float | The light traffic density threshold is the threshold for the light traffic density category. | No default |
191.2 Metrics
The following metrics are recorded and tracked by the evaluator.
| Metric item | Unit / Type | Description |
|---|---|---|
avg_speed |
kph | Average speed of the Ego during the interval |
ego_lane_traffic_density_category |
enum (no_traffic, light, moderate, heavy, congested, not_available) |
Category from interval-mean density in the Ego lane |
left_lane_traffic_density_category |
enum (no_traffic, light, moderate, heavy, congested, not_available) |
Category from interval-mean density in the left adjacent lane |
right_lane_traffic_density_category |
enum (no_traffic, light, moderate, heavy, congested, not_available) |
Category from interval-mean density in the right adjacent lane |
ego_lane_vehicle_count_avg |
Mean number of vehicles per sample tick in the Ego lane (integer statistics; may truncate fractional averages) | |
left_lane_vehicle_count_avg |
Mean number of vehicles per sample tick in the left adjacent lane (if available); integer statistics may truncate | |
right_lane_vehicle_count_avg |
Mean number of vehicles per sample tick in the right adjacent lane (if available); integer statistics may truncate | |
ego_lane_vehicle_count_minimum |
Minimum number of vehicles detected in the Ego lane within the detection range | |
left_lane_vehicle_count_minimum |
Minimum number of vehicles detected in the left adjacent lane (if available) | |
right_lane_vehicle_count_minimum |
Minimum number of vehicles detected in the right adjacent lane (if available) | |
ego_lane_vehicle_count_maximum |
Maximum number of vehicles detected in the Ego lane within the detection range | |
left_lane_vehicle_count_maximum |
Maximum number of vehicles detected in the left adjacent lane (if available) | |
right_lane_vehicle_count_maximum |
Maximum number of vehicles detected in the right adjacent lane (if available) | |
ego_lane_density |
Spatial density in the Ego lane (vehicles/km/lane) from interval-mean count ÷ detection length | |
left_lane_density |
Spatial density in the left adjacent lane (vehicles/km/lane) from interval-mean count | |
right_lane_density |
Spatial density in the right adjacent lane (vehicles/km/lane) from interval-mean count | |
traffic_avg_density |
Mean of per-lane interval densities for lanes with positive interval-mean density (vehicles/km/lane) | |
overall_traffic_density_category |
enum (no_traffic, light, moderate, heavy, congested, not_available) |
Overall traffic density category |
total_vehicle_count |
Rounded mean total vehicles in range per sample tick over the interval (aligned with interval-mean density) | |
ego_lane_avg_speed |
kph | Mean speed of vehicles traveling in the Ego lane |
left_lane_avg_speed |
kph | Mean speed of vehicles traveling in the left adjacent lane |
right_lane_avg_speed |
kph | Mean speed of vehicles traveling in the right adjacent lane |
traffic_avg_speed |
kph | Mean speed of vehicles across all lanes |
191.3 Log and Error Messages
No error messages found.
191.4 Additional information
Custom traffic density interval watcher configuration example
extend top.main:
watcher my_traffic_density_watcher is traffic_density(
vehicle: sut.car,
detection_range_forward: 150m,
detection_range_backward: 75m,
min_vehicle_speed: 10kph,
min_activation_speed: 15kph,
light_traffic_density_threshold: 10.0,
moderate_traffic_density_threshold: 25.0,
heavy_traffic_density_threshold: 50.0,
sampling_frequency: 1s,
rolling_window_size: 3,
log_level: debug_level
)
Traffic density categories
The watcher classifies traffic density into the following five categories based on spatial density of vehicles per kilometer per lane (vehicles/km/lane).
| Category | Density Range | Description | Unit |
|---|---|---|---|
| no_traffic | 0.0 | No vehicles detected in the detection range | |
| light | < 8.0 | Sparse traffic with minimal vehicle interactions | vehicles/km/lane |
| moderate | 8.0 - 19.0 | Stable traffic flow with some vehicle interactions | vehicles/km/lane |
| heavy | 19.0 - 42.0 | Unstable traffic flow where frequent lane changes are difficult due to significant congestion | vehicles/km/lane |
| congested | > 42.0 | Very heavy traffic, near standstill conditions where breakdowns cause major delays | vehicles/km/lane |
| not_available | N/A | Lane information unavailable or invalid density calculation |