A rule-based (no ML) system that compares the player's driving to nearby NPC traffic in CARLA and gives real-time popup + voice feedback, then a final driving report.
CARLA
│
├── PLAYER CAR
└── NPC CARS (driven by CARLA Traffic Manager — untouched)
│
▼
Read vehicle telemetry
│
▼
Compare player vs. nearby NPCs
│
▼
Rule engine (thresholds, no ML)
│
▼
Popup + voice feedback
│
▼
Log session data → Final driving report
| File | Responsibility |
|---|---|
carla_connection.py |
Connect to CARLA, find the player vehicle, attach sensors |
telemetry.py |
Read speed, steering, throttle, brake, position, lane offset |
npc_comparison.py |
Find nearby NPCs, compute their average speed/lane offset |
event_detector.py |
Threshold-based rules → list of event names |
feedback.py |
Popup text + offline text-to-speech (pyttsx3) |
report.py |
Builds the end-of-session score + report from the CSV log |
main.py |
Wires the whole pipeline together, runs the tick loop |
- Have a CARLA server running (
CarlaUE4.exe/./CarlaUE4.sh) with a player vehicle already spawned (ideally taggedrole_name=hero) and some NPCs spawned via the Traffic Manager. - Install dependencies:
Note: the
pip install -r requirements.txt
carlaPyPI package version must match your CARLA server version — ifpip install carladoesn't work for your version, use the.whlfile shipped inside your CARLA installation'sPythonAPIfolder instead (pip install <path-to-carla-whl>).
1. Milestone 1 — just prove telemetry + comparison works:
python main.py --print-onlyThis should print something like:
PLAYER SPEED: 62.0 km/h | NPC AVG SPEED: 49.2 km/h | LANE OFFSET: 0.62 m
EVENT: OVERSPEEDING
2. Full run — popup + voice + logging + report:
python main.py --duration 300This runs for 5 minutes, prints popups and speaks feedback (via
pyttsx3) on rule violations, logs every tick to session_log.csv, and
writes driving_report.txt with the final score at the end.
Useful flags:
--no-voice— popups only, no speech--host/--port— if CARLA isn't on127.0.0.1:2000--duration <seconds>— session length
Thresholds live in event_detector.py (DEFAULT_THRESHOLDS):
DEFAULT_THRESHOLDS = {
"overspeed_margin_kmh": 10,
"lane_departure_m": 0.5,
"harsh_brake": 0.8,
"aggressive_steer": 0.7,
}Scoring penalties live in report.py (SCORE_PENALTIES).
No ML model, no training dataset, no computer vision, no custom NPC AI —
CARLA's Traffic Manager already drives the NPCs, and all event detection
is threshold-based. If a generative component is required later, the
cleanest place to add one is inside feedback.py: keep event detection
rule-based, and only use an LLM to turn an already-detected event +
context into a more natural coaching sentence.