How havish06/sadsv works
1. This repository is a sensor-first ADAS simulator centered on a single orchestration loop. The main runtime entrypoints are main.py and run_simulator.py, which start the simulator defined in simulation/enhanced_simulator.py. The README indicates the current focus is on safety features like drowsiness detection, alcohol ignition lock, adaptive cruise control, and assisted lane changes.
2. The highest-level architectural boundary is the simulation engine in simulation/. enhanced_simulator.py appears to be the active coordinator, while simulation/simulator.py is likely a simpler/base variant. traffic_generator.py supplies surrounding traffic scenarios, so the simulator is not just rendering a scene; it is generating world state, updating actors, and evaluating safety logic continuously.
3. The world model lives in world/ and provides the physical environment: road.py, traffic_light.py, clock.py, and world.py. This layer defines the static and temporal simulation context that sensors and vehicles read from. It is the boundary between abstract ADAS logic and the road/traffic conditions being simulated.
4. Vehicle state is separated into vehicles/, with ego_vehicle.py for the controlled car and npc_vehicle.py for other traffic participants. vehicle.py is the shared abstraction. This split matters because most safety decisions are ego-centric: the ego vehicle is the one whose throttle, braking, lane changes, and overrides are controlled by the ADAS logic.
5. Sensor logic is isolated in sensors/, and this is the main perception layer of the system. It includes driver-facing and environment-facing checks: driver_monitor.py, alcohol_sensor.py, distance_sensor.py, blind_spot_sensor.py, lane_sensor.py, and collision_warning.py. These modules turn raw simulator state into safety signals such as drowsiness, intoxication lockout, safe following distance, lane availability, and collision risk.
6. Decision-making sits in decision/, which is where sensor outputs become control actions. state_machine.py is the central arbitration layer, and lane_change.py handles lane-change assist behavior. The README’s “priority-aware HUD” implies this layer also determines which safety module currently owns control, and when assist mode can override or yield to the driver.
7. The control flow is effectively: world and traffic update -> sensors evaluate ego/driver/environment -> decision state machine selects a safety response -> ego vehicle control is adjusted. Important safety behaviors called out by the README include emergency safe-stop for drowsiness, ignition lock for alcohol detection, ACC with sensor validation, and lane-change aborts when blind-spot or hazard conditions arise.
8. Human interaction is handled in input/driver_input.py. Keyboard controls toggle assist mode, enable/disable alcohol lock simulation, request lane changes, confirm maneuvers, manually change speed when assist is off, pause, reset, and exit. This layer is the boundary between operator intent and simulator autonomy.
9. Output and operator feedback are split across visualization/ and utils/audio.py. visualization/renderer.py is responsible for displaying road geometry, lane markers, safety state, and the HUD that shows module ownership. The README also mentions a live OpenCV eye-monitor window when camera mode is enabled, so the visualization layer includes a real-time driver-facing feedback path, not just static rendering.
10. Configuration and cross-cutting support are centralized in config/ and utils/. config/config.py, sim_config.py, and thresholds.py hold tunable simulation parameters and safety thresholds, which are crucial because the ADAS behavior is threshold-driven. utils/logger.py provides traceability, and utils/audio.py likely supports alerting. The assets/ directory supplies UI/media resources used by the renderer and alerts.
Main entry points: enhanced_simulator.py Enhanced sim · state_machine.py State machine · world.py World · lane_change.py Lane change
Components 27
Entrypoints
Process startup and top-level simulator launch.
- main.py · Primary launch script for the simulator.
main.py - run_simulator.py · Alternate launch script for running the simulator.
run_simulator.py
Simulation Core
Main runtime loop and traffic generation.
- Enhanced sim · Active coordinator for the ADAS simulation loop.
simulation/enhanced_simulator.py - Base sim · Simpler or legacy simulator variant.
simulation/simulator.py - Traffic gen · Builds surrounding traffic and world situations.
simulation/traffic_generator.py
Perception
Sensor and driver-state checks feeding safety logic.
- Driver monitor · Detects drowsiness and driver attention state.
sensors/driver_monitor.py - Alcohol sensor · Checks intoxication and ignition lock conditions.
sensors/alcohol_sensor.py - Distance sensor · Measures following distance for ACC and safety.
sensors/distance_sensor.py - Blind spot · Detects adjacent-lane hazards for lane changes.
sensors/blind_spot_sensor.py - Lane sensor · Tracks lane position and lane availability.
sensors/lane_sensor.py - Collision warn · Raises imminent collision risk signals.
sensors/collision_warning.py
Decision & Control
Arbitration and maneuver logic that turns signals into actions.
- State machine · Prioritizes safety modules and selects responses.
decision/state_machine.py - Lane change · Coordinates assisted lane-change behavior and aborts.
decision/lane_change.py
World & Vehicles
Simulation state for roads, time, traffic, and actors.
- World · Container for roads, lights, and simulation time.
world/world.py - Road · Lane and roadway structure used by sensors and control.
world/road.py - Signals · Traffic light state used by the simulator.
world/traffic_light.py - Clock · Advances simulation time and pacing.
world/clock.py - Vehicle · Shared vehicle abstraction.
vehicles/vehicle.py - Ego vehicle · Primary vehicle under ADAS control.
vehicles/ego_vehicle.py - NPC vehicle · Other traffic participants in the scene.
vehicles/npc_vehicle.py
I/O & Feedback
Human input, visualization, alerts, and logging.
- Driver input · Keyboard controls for assist, maneuvers, pause, and reset.
input/driver_input.py - Renderer · Draws road, actors, safety state, and HUD feedback.
visualization/renderer.py - Audio · Supports audible warnings and feedback.
utils/audio.py - Logger · Provides trace logging and diagnostics.
utils/logger.py
Configuration
Cross-cutting tuning and runtime parameters.
- Config · Central simulation parameters.
config/config.py - Sim config · Simulation-specific settings and defaults.
config/sim_config.py - Thresholds · Sensor and ADAS trigger thresholds.
config/thresholds.py
Connections 34
- main.py → Enhanced sim: starts · Launches the primary simulator runtime.
- run_simulator.py → Enhanced sim: starts · Alternative entrypoint into the same runtime.
- Enhanced sim → Traffic gen: spawns traffic · Generates surrounding vehicles and scenarios.
- Enhanced sim → World: updates world · Advances the simulated environment each loop.
- Enhanced sim → Vehicle: updates actors · Coordinates vehicle state and motion.
- Base sim → World: uses · Base simulator relies on the same environment model.
- World → Road: contains · Holds roadway and lane geometry.
- World → Signals: contains · Tracks signal state in the world.
- World → Clock: advances · Uses the clock to step simulation time.
- Vehicle → Ego vehicle: specializes · Shared vehicle abstraction for the controlled car.
- Vehicle → NPC vehicle: specializes · Shared vehicle abstraction for traffic actors.
- Enhanced sim → Driver monitor: reads · Consumes driver attention state.
- Enhanced sim → Alcohol sensor: reads · Consumes intoxication state.
- Enhanced sim → Distance sensor: reads · Consumes following-distance signals.
- Enhanced sim → Blind spot: reads · Consumes adjacent-lane hazard signals.
- Enhanced sim → Lane sensor: reads · Consumes lane position and lane availability.
- Enhanced sim → Collision warn: reads · Consumes collision-risk warnings.
- Driver monitor → State machine: signals · Feeds drowsiness and attention outcomes into arbitration.
- Alcohol sensor → State machine: signals · Feeds ignition-lock conditions into arbitration.
- Distance sensor → State machine: signals · Feeds ACC and safety distance checks.
- Blind spot → Lane change: blocks · Can veto unsafe lane changes.
- Lane sensor → Lane change: guides · Provides lane availability and alignment data.
- Collision warn → State machine: signals · Triggers emergency response paths.
- State machine → Lane change: authorizes · Selects lane-change assist when safe.
- State machine → Ego vehicle: commands · Adjusts ego control for stop, ACC, or assist.
- Lane change → Ego vehicle: steers · Applies lane-change maneuver control.
- Driver input → State machine: requests · Driver toggles assist and maneuver intent.
- Driver input → Ego vehicle: manual control · Can directly affect speed or pause-driven behavior.
- Enhanced sim → Renderer: renders · Provides world and safety state to the HUD.
- Enhanced sim → Audio: alerts · Emits warnings and safety prompts.
- Enhanced sim → Logger: logs · Records simulation and safety events.
- Enhanced sim → Config: uses · Loads core parameters.
- Enhanced sim → Sim config: uses · Loads scenario/runtime settings.
- Enhanced sim → Thresholds: uses · Uses safety trigger thresholds.