Week 5 — Traffic Controls, Rules, and Traffic Agents
Overview
A static road network is a map; adding traffic controls and moving agents makes it a world. This week adds traffic-control semantics — lights, stop signs, crosswalks — backed by a rule engine, and populates the world with non-ego traffic vehicles that follow lanes and obey those rules with simple but believable behavior. This consolidates the traffic-control and traffic-agent weeks of the longer course: the rule engine and the agents are tightly coupled (agents query rules every tick), so building them together is natural.
The design themes are state machines (traffic lights, agent behavior modes) and clean separation between the rules (semantic, queryable) and the agents (consumers of rules). By the end the world has cycling lights, rule-respecting intersections, and traffic vehicles driving through them.
Readings
- DPV (apply): finite state machines and graph traversal. Extract: FSMs for light cycles and agent behavior; lane-graph following.
- PR: motion models. Extract: simple kinematic models for agent motion.
- Embedded AI / robotics: failsafe patterns and state machines. Extract: defensive default behavior.
- Traffic-control rules (informal): right-of-way at four-way stops, yield rules, signalized vs unsignalized intersections.
Key Concepts
Traffic controls as state machines
A traffic light is an FSM cycling green→yellow→red with per-state durations, coordinated across an intersection so conflicting movements aren’t simultaneously green. Stop signs and crosswalks are simpler stateful entities. The control state is part of the semantic world model (Week 4), queryable by agents and by the rule engine.
The rule engine
Given an agent, its lane, and nearby controls, the rule engine answers: may I proceed, must I stop, must I yield, and to whom? Encode right-of-way (four-way stop ordering, yield-to-oncoming on left turns) as explicit, testable predicates. Keeping rules separate from agents means rules can be unit-tested in isolation and reused by the ego planner (Week 9).
Traffic agents and car-following
Each agent follows its lane centerline (Week 4) at a target speed, modulated by car-following (don’t hit the vehicle ahead — a simple intelligent-driver-style model: decelerate based on gap and closing speed) and by the rule engine (stop at red, yield as required). Agent behavior is itself a small FSM: cruise, follow, stop, yield. Determinism (Week 1) must be preserved — agents step on the fixed sim tick.
Believable, not optimal
The aim is plausible traffic for testing perception/planning, not a realistic human-driver model. Simple, deterministic, rule-respecting behavior is the right scope; full behavior prediction is explicitly out.
Theory Exercises
- Design the traffic-light FSM for a four-way intersection: states, durations, and the constraint that conflicting movements are never simultaneously green.
- Specify right-of-way at a four-way stop as testable predicates over arrival order and position.
- Write a car-following rule that decelerates based on gap and closing speed; show it prevents collisions for a lead vehicle braking.
- Model agent behavior as an FSM (cruise/follow/stop/yield) and define the transition guards.
- Argue why the rule engine must be deterministic and side-effect-free for scenario reproducibility.
Implementation
Add a traffic/ module: light/stop-sign/crosswalk entities with FSMs, a rule engine with right-of-way predicates, and traffic agents that follow the lane graph with car-following plus rule compliance. Render lights/signs and moving agents in the Week 3 renderer. Unit-test the rule engine independently.
Benchmark
Traffic-control update time (tick all FSMs), rule-query latency per agent, and agent-simulation time vs agent count. Verify (in a scripted scenario) zero rule violations and zero collisions among well-behaved agents.
Expected baselines: FSM and rule updates are cheap (microseconds for a small intersection); agent simulation scales linearly with agent count; the scripted scenario shows agents correctly stopping at reds and yielding — no violations or collisions.
Connections
The rule engine is reused by the ego planner (Week 9, which must obey the same rules). Agents provide the dynamic obstacles the ego must perceive (Weeks 7–8) and plan around (Week 9). The four-way intersection is the demo target for Week 10. Determinism from Week 1 makes the whole thing reproducible.
Further Reading
- Treiber & Kesting, Traffic Flow Dynamics — the intelligent-driver model (conceptual reference).
- DPV finite-automata and graph chapters (Course 5 review).
- Game-AI references on behavior FSMs.