How havish06/savsd works
1. What this repo is
- This is a sensor-driven ADAS simulator, centered on a single ego vehicle that is continuously monitored and assisted by multiple safety modules: drowsiness, alcohol lockout, adaptive cruise, lane-change assist, blind-spot checks, and collision warnings.
2. Top-level execution path
- main.py and run_simulator.py are the entry entrypoints.
- They assemble configuration, build the simulator, and start the main control loop that advances the world, reads sensors, applies decision logic, and renders the scene.
3. Simulation core
- The simulation/ package is the orchestration layer.
- simulator.py is the base simulation loop.
- enhanced_simulator.py adds the “sensor-first” ADAS behaviors called out in the README, including priority-aware control ownership, safe-stop override, and the enhanced HUD.
- traffic_generator.py is responsible for populating or varying surrounding traffic.
4. World model
- world/ contains the static and temporal simulation context:
- road.py models lane geometry and road boundaries.
- traffic_light.py represents signal state.
- clock.py handles simulation time.
- world.py likely ties these together into the shared state consumed by vehicles, sensors, and rendering.
- This is the common data source for the rest of the system.
5. Vehicle layer
- vehicles/ separates the controlled car from surrounding traffic:
- ego_vehicle.py is the main controlled vehicle with ADAS interventions.
- npc_vehicle.py models other traffic participants.
- vehicle.py is the shared vehicle abstraction.
- The decision layer acts primarily on the ego vehicle, while NPCs provide dynamic obstacles and lane context.
6. Sensor subsystem
- sensors/ is the main perception layer and appears to be the architectural center of the project.
- Key modules include:
- driver_monitor.py for drowsiness and eye-based driver monitoring.
- alcohol_sensor.py for ignition lock behavior.
- distance_sensor.py for adaptive cruise / headway checks.
- lane_sensor.py for lane position and lane keeping.
- blind_spot_sensor.py for lane-change safety.
- collision_warning.py for immediate hazard detection.
- These sensors read world/vehicle state and produce safety-relevant signals that feed the decision logic.
7. Decision and control arbitration
- decision/state_machine.py is the main policy layer that decides which safety module currently owns control.
- decision/lane_change.py encapsulates lane-change assist behavior, including driver confirmation and abort-on-hazard behavior.
- This layer translates raw sensor outputs into actuation decisions such as safe stop, lockout, assist engagement, or lane-change approval.
8. Driver interaction
- input/driver_input.py handles human commands such as assist toggle, lane-change request/confirm, manual speed control, pause, reset, and exit.
- The README’s key bindings show that the simulator supports both assisted and manual driving modes, with the decision layer mediating when assist is active.
9. Visualization and operator feedback
- visualization/renderer.py is the presentation layer for the simulation.
- The README indicates road boundary visualization, lane markers, and a priority-aware HUD that shows which module currently controls the vehicle.
- There is also a live OpenCV eye-monitor window when camera mode is enabled, which belongs to the driver-monitoring feedback loop.
10. Audio and logging
- utils/audio.py provides alert or warning output for safety events.
- utils/logger.py records simulation and sensor events, likely for debugging and traceability of safety interventions.
- These utilities are cross-cutting concerns used by sensors and the decision layer rather than standalone subsystems.
11. Configuration boundary
- config/ centralizes simulation parameters and thresholds:
- config.py and sim_config.py likely hold runtime constants for the environment.
- thresholds.py defines decision limits for sensor triggers and safety actions.
- This package is the main tuning point for behavior without changing the core logic.
12. Main data flow to diagram
- A useful architectural diagram should show this loop:
- Driver input + world state + NPC traffic feed the sensor layer
- Sensor outputs feed the state machine / lane-change decision logic
- Decisions update the ego vehicle
- The updated world is sent to the renderer and audio/logger
- The key boundary is between perception/sensing and control arbitration, with the simulation world acting as the shared substrate.
13. Notable architectural emphasis
- The repo is not just a simulator; it is organized around safety-module ownership of control.
- Drowsiness, alcohol lock, collision warning, and lane-change assist are treated as competing or prioritized control sources, which is why the enhanced simulator and state machine are central to the design.
Main entry points: state_machine.py State Machine · world.py World · enhanced_simulator.py Enhanced Sim · simulator.py Simulator
Components 27
Entrypoints
Startup scripts that assemble and launch the simulator.
- main.py · Primary application entrypoint.
main.py - run_simulator.py · Alternate launcher for the simulator.
run_simulator.py
Simulation Core
Main execution loop and traffic generation.
- Simulator · Base simulation loop and orchestration.
simulation/simulator.py - Enhanced Sim · Sensor-first simulator with priority-aware control ownership and HUD.
simulation/enhanced_simulator.py - Traffic Gen · Creates and varies surrounding traffic.
simulation/traffic_generator.py
World Model
Shared road, time, and signal state.
- World · Shared simulation state tying road, signals, and time together.
world/world.py - Road · Lane layout and road boundaries.
world/road.py - Clock · Simulation time and progression.
world/clock.py - Traffic Light · Traffic signal state used by the world and vehicles.
world/traffic_light.py
Vehicles
Controlled ego vehicle and surrounding traffic participants.
- Vehicle · Shared vehicle abstraction.
vehicles/vehicle.py - Ego Vehicle · Main vehicle under ADAS control and intervention.
vehicles/ego_vehicle.py - NPC Vehicle · Other traffic participants and obstacles.
vehicles/npc_vehicle.py
Sensors
Perception and safety signal generation.
- Driver Monitor · Eye-based monitoring for driver alertness.
sensors/driver_monitor.py - Alcohol Sensor · Ignition lock and alcohol detection behavior.
sensors/alcohol_sensor.py - Distance Sensor · Adaptive cruise and following-distance checks.
sensors/distance_sensor.py - Lane Sensor · Lane position and lane keeping perception.
sensors/lane_sensor.py - Blind Spot · Safety checks for adjacent-lane maneuvers.
sensors/blind_spot_sensor.py - Collision Warn · Immediate hazard detection and warning signals.
sensors/collision_warning.py
Control Arbitration
Policy and assist logic that owns control when safety modules intervene.
- State Machine · Prioritizes safety modules and selects current control owner.
decision/state_machine.py - Lane Change · Driver-confirmed lane-change assist with abort-on-hazard behavior.
decision/lane_change.py
Input & Output
Driver commands, rendering, audio, and logging.
- Driver Input · Human commands for assist, lane change, speed, pause, reset, and exit.
input/driver_input.py - Renderer · Renders the simulation scene and HUD.
visualization/renderer.py - Audio · Safety alerts and warning output.
utils/audio.py - Logger · Records simulation and sensor events.
utils/logger.py
Configuration
Runtime tuning and thresholds.
- Config · Central simulation settings.
config/config.py - Sim Config · Simulation-specific parameters.
config/sim_config.py - Thresholds · Sensor and safety trigger limits.
config/thresholds.py
Connections 38
- main.py → Config: loads · Reads runtime configuration.
- main.py → Enhanced Sim: starts · Bootstraps the ADAS simulation loop.
- run_simulator.py → Simulator: starts · Launches the base simulator.
- Enhanced Sim → Simulator: extends · Builds on the base loop.
- Simulator → World: updates · Advances shared world state each tick.
- Simulator → Traffic Gen: spawns · Populates and varies surrounding traffic.
- Simulator → Renderer: renders · Sends the current scene to the visualization layer.
- Enhanced Sim → State Machine: arbitrates · Delegates control ownership to the policy layer.
- Enhanced Sim → Audio: alerts · Emits safety warnings and notifications.
- Enhanced Sim → Logger: logs · Records events and intervention state.
- World → Road: contains · Holds lane geometry and road boundaries.
- World → Clock: tracks · Maintains simulation time.
- World → Traffic Light: contains · Stores signal state.
- World → Ego Vehicle: includes · Shared state for the controlled vehicle.
- World → NPC Vehicle: includes · Shared state for surrounding traffic.
- Ego Vehicle → Vehicle: inherits · Specializes the base vehicle model.
- NPC Vehicle → Vehicle: inherits · Specializes the base vehicle model.
- Driver Input → State Machine: requests · Human commands influence assist ownership and mode changes.
- Driver Input → Ego Vehicle: commands · Manual speed and control inputs can affect the ego vehicle.
- Driver Monitor → State Machine: signals · Drowsiness state can trigger intervention.
- Alcohol Sensor → State Machine: signals · Lockout conditions affect ignition/control.
- Distance Sensor → State Machine: signals · Headway risk informs adaptive cruise decisions.
- Lane Sensor → State Machine: signals · Lane position feeds lane keeping and assist logic.
- Blind Spot → Lane Change: checks · Adjacent-lane safety gate for lane changes.
- Collision Warn → State Machine: signals · Hazard detection can force safe stop or takeover.
- State Machine → Lane Change: delegates · Lane-change approval and abort flow.
- State Machine → Ego Vehicle: controls · Applies safe stop, lockout, or assist actions.
- Lane Change → Ego Vehicle: updates · Executes lane-change assist decisions.
- Renderer → World: reads · Visualizes the current simulation state.
- Renderer → State Machine: shows · Displays current control owner in the HUD.
- Audio → Collision Warn: reflects · Audio alerts correspond to safety warnings.
- Logger → State Machine: records · Persists arbitration and intervention events.
- Config → Sim Config: contains · Holds simulation settings.
- Config → Thresholds: contains · Defines policy thresholds and trigger limits.
- Sim Config → Enhanced Sim: configures · Shapes simulator behavior and modes.
- Thresholds → Driver Monitor: tunes · Sets drowsiness thresholds.
- Thresholds → Collision Warn: tunes · Sets hazard sensitivity.
- Thresholds → Distance Sensor: tunes · Sets headway and cruise limits.