Simulate the driver. Model the vehicle. Generate telemetry.
DriveTwin is an experimental stateful simulation framework for exploring how drivers, vehicles, environments, and telemetry can be modeled as an evolving system.
- Python 3.10 or newer
- Git
DriveTwin currently uses only Python's standard library for its core simulation framework.
No external Python packages are required for the current simulation engine.
git clone https://github.com/harisrana-dev/DriveTwin.git
cd DriveTwinpython -m venv .venv
.venv\Scripts\Activate.ps1If PowerShell prevents script execution, the environment can also be activated using:
.venv\Scripts\activate.batpython3 -m venv .venv
source .venv/bin/activateThe Python packages are located inside the backend/ directory.
Before running any module, change into the backend directory:
cd backendThis is important because the simulation imports packages such as:
digital_twin
simulation
analytics
from the backend package root.
The standard execution pattern is therefore:
DriveTwin/
β
βββ README.md
βββ requirements.txt
βββ .gitignore
β
βββ backend/
βββ digital_twin/
βββ simulation/
βββ analytics/
βββ tests/
Then:
cd backend
python -m <module>Runs a short deterministic simulation without waiting for real-time delays.
cd backend
python -m digital_twin.runtime.demo --fast --ticks 5This executes five simulation ticks and displays a concise summary of the simulation results.
Runs the simulation continuously with approximately one real-time tick per second.
cd backend
python -m simulation.continuous_loopThe simulation creates multiple vehicles and continuously prints:
- vehicle telemetry
- speed
- RPM
- gear
- fuel level
- engine temperature
- engine load
- battery voltage
- odometer
- brake health
- tyre health
- driver behavior analytics
- vehicle health analytics
- fuel efficiency
- detected events
Press:
Ctrl+C
to stop the simulation gracefully.
Runs a 30-tick driving behavior demonstration.
cd backend
python -m tests.demo_drivingDriveTwin currently uses executable validation scripts rather than a formal test runner.
cd backend
python -m digital_twin.validate_full_telemetry_pipelinecd backend
python -m tests.validate_vehicle_controllercd backend
python -m tests.inspect_one_tickcd backend
python -m tests.inspect_ten_ticksThe project does not currently contain a formal pytest or unittest test suite.
The validation scripts inside backend/tests/ are executable Python modules that use:
if __name__ == "__main__":and can be run directly using the commands documented above.
There is currently no:
pytest.iniconftest.py- configured test runner
The existing validation scripts are intended to verify and inspect simulation behavior during active development.
DriveTwin is a Python-based simulation framework for modeling the interaction between a driver and a vehicle over time.
Instead of generating isolated random telemetry values, the simulation maintains a persistent vehicle state that evolves from one simulation tick to the next.
A simplified simulation loop looks like this:
βββββββββββββββββ
β Driver β
β Behavior β
βββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββ
β Decision β
β Intent β
βββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββ
β Vehicle β
β Actuation β
βββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββ
β Physics β
β State Evolutionβ
βββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββ
β Vehicle State β
β Speed β’ RPM β
β Fuel β’ Health β
βββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββ
β Virtual Sensorsβ
βββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββ
β Telemetry β
βββββββββββββββββ
The goal is not to reproduce the exact behavior of a specific manufacturer's ECU or vehicle.
The goal is to build a consistent, explainable, stateful environment for experimenting with automotive systems and telemetry.
A real vehicle does not become a completely different vehicle every second.
Its current state is influenced by its previous state.
For example:
Tick N
β
βββ Speed: 42 km/h
βββ RPM: 2,100
βββ Gear: 3
βββ Fuel: 78%
β
βΌ
Driver applies throttle
β
βΌ
Vehicle controller computes actuation
β
βΌ
Physics updates the vehicle
β
βΌ
Tick N + 1
β
βββ Speed: 47 km/h
βββ RPM: 2,450
βββ Gear: 3
βββ Fuel: 77.98%
This creates a continuous chain of cause and effect:
Previous State β Decision β Actuation β Physics β New State
That state can then be observed through virtual sensors and converted into telemetry.
Drivers are modeled using behavioral profiles.
Current profiles include:
CAUTIOUSSTANDARDAGGRESSIVEECO_FOCUSED
A driver profile influences the type of driving intent generated by the Decision Layer.
Driver
β
βββ Behaviour Profile
βββ Experience Level
βββ Fatigue
βββ Operational State
β
βΌ
Driving Intent
The Driver entity stores the driver's state.
The Decision Layer determines what the driver intends to do.
The Decision Layer translates the current situation into a driving intent.
It considers information such as:
- current vehicle speed
- speed limit
- driver behavior profile
- driver fatigue
- continuous driving time
- break requirements
- weather
- road conditions
The result is a structured intent such as:
ACCELERATE
DECELERATE
MAINTAIN_SPEED
BRAKE
IDLE
Conceptually:
Driver
+
Vehicle State
+
Environment
+
Trip Context
β
βΌ
ββββββββββββββββββββββββ
β Driver Behaviour β
β Engine β
ββββββββββββ¬ββββββββββββ
β
βΌ
Driver Intent
The Vehicle Controller converts a driver's intent into physical actuation.
For example:
Driver Intent
β
βΌ
ββββββββββββββββββββββββ
β Vehicle Controller β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Vehicle Actuation β
β β
β Throttle β
β Brake β
β Gear β
ββββββββββββββββββββββββ
This separates:
What the driver wants to do
from:
What the vehicle actually receives as an input
The Physics Engine applies actuation to the vehicle's current state.
It is responsible for evolving values such as:
- speed
- acceleration
- RPM
- gear
- fuel consumption
- engine temperature
- distance traveled
- engine hours
- component wear
- vehicle health
The physics model is intentionally simplified and explainable.
It is designed for simulation and experimentation rather than manufacturer-grade vehicle modeling.
Current Vehicle State
β
+
β
Actuation Input
β
+
β
Environment
β
βΌ
βββββββββββββββββββββββ
β Physics Engine β
ββββββββββββ¬βββββββββββ
β
βΌ
Updated Vehicle
State
Each simulated vehicle maintains its own operating state.
Vehicle
β
βββ Specification
β βββ Manufacturer
β βββ Model
β βββ Year
β βββ Fuel Type
β βββ Transmission
β
βββ Operating State
β βββ Speed
β βββ RPM
β βββ Gear
β βββ Fuel Level
β βββ Engine Temperature
β βββ Engine Load
β
βββ Health State
β βββ Engine Health
β βββ Brake Wear
β βββ Tyre Wear
β
βββ Lifetime State
βββ Odometer
βββ Engine Hours
The important distinction is:
Vehicle
β
βββ Owns the state
Physics Engine
β
βββ Evolves the state
The Vehicle entity itself does not decide how its speed or RPM changes.
The Physics Engine is responsible for that evolution.
The simulation can provide environmental context to the vehicle and decision system.
Current environmental dimensions include:
- weather
- road conditions
- simulation time
For example:
Same Driver
+
Same Vehicle
+
Different Environment
β
βΌ
Different Decisions
β
βΌ
Different Actuation
β
βΌ
Different Vehicle State
This allows simulation scenarios such as:
Aggressive Driver
+
Dry Road
β
βΌ
Different Result
Aggressive Driver
+
Wet Road
β
βΌ
Different Result
DriveTwin separates the internal simulation state from the data that an external system consumes.
ββββββββββββββββββββββββ
β Vehicle State β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Virtual Sensors β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Sensor Readings β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Telemetry Generator β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Telemetry Packet β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Telemetry Pipeline β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Telemetry Stream β
ββββββββββββββββββββββββ
This boundary is important.
The simulation does not need to know what consumes the data.
The generated telemetry can theoretically be consumed by:
- analytics engines
- dashboards
- databases
- anomaly detection systems
- machine learning pipelines
- fleet intelligence platforms
DriveTwin advances through discrete simulation ticks.
A tick represents a small interval of simulated time.
βββββββββββββββββββββββββββββββ
β TICK N β
ββββββββββββββββ¬βββββββββββββββ
β
βΌ
Advance Simulation Clock
β
βΌ
Update Environment
β
βΌ
Evaluate Driver State
β
βΌ
Generate Driver Intent
β
βΌ
Compute Actuation
β
βΌ
Apply Physics
β
βΌ
Update Vehicle State
β
βΌ
Read Virtual Sensors
β
βΌ
Generate Telemetry
β
βΌ
Publish Telemetry
β
βΌ
βββββββββββββββββββββββββββββββ
β TICK N + 1 β
βββββββββββββββββββββββββββββββ
The simulation runtime is responsible for coordinating the progression of the simulation.
The individual domain components remain responsible for their own behavior.
The current architecture is organized into several independent layers.
βββββββββββββββββββββββββββββββββββββββββββββββ
β Simulation Runtime β
β Clock β’ Tick Context β’ Scheduling β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Domain Entities β
β Vehicle β’ Driver β’ Trip β’ Environment β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Decision Layer β
β Driver Behavior β Driving Intent β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Control Layer β
β Intent β Vehicle Actuation β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Physics Layer β
β Actuation β Vehicle State Evolution β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Sensor Layer β
β Vehicle State β Sensor Data β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Telemetry Layer β
β Sensor Data β Telemetry Stream β
βββββββββββββββββββββββββββββββββββββββββββββββ
The project also contains supporting layers for:
- fleet management
- trip management
- driver management
- vehicle management
- maintenance
- dispatch
- events
- configuration
- reusable profiles
DriveTwin/
β
βββ README.md
βββ requirements.txt
βββ .gitignore
β
βββ backend/
β
βββ digital_twin/
β β
β βββ common/
β β βββ config/
β β βββ controller/
β β βββ decision/
β β βββ entities/
β β βββ events/
β β βββ managers/
β β βββ physics/
β β βββ profiles/
β β βββ runtime/
β β βββ sensors/
β β βββ telemetry/
β β βββ utils/
β β
β βββ validate_full_telemetry_pipeline.py
β βββ ...
β
βββ simulation/
β βββ entity_bridge.py
β βββ simulation_runner.py
β
βββ analytics/
β βββ ...
β
βββ tests/
βββ analytics/
βββ demo_driving.py
βββ inspect_one_tick.py
βββ inspect_ten_ticks.py
βββ validate_vehicle_controller.py
The core digital_twin package is organized as follows:
digital_twin/
β
βββ common/
β βββ enums.py
β βββ exceptions.py
β βββ interfaces.py
β
βββ config/
β βββ constants.py
β βββ defaults.py
β βββ simulation_config.py
β
βββ controller/
β βββ brake_controller.py
β βββ controller_limits.py
β βββ gear_logic.py
β βββ throttle_controller.py
β βββ transmission_controller.py
β βββ vehicle_actuation.py
β βββ vehicle_controller.py
β
βββ decision/
β βββ braking_policy.py
β βββ decision_context.py
β βββ driver_behaviour_engine.py
β βββ driver_intent.py
β βββ fatigue_model.py
β βββ personalities.py
β βββ speed_policy.py
β βββ throttle_policy.py
β
βββ entities/
β βββ cargo.py
β βββ driver.py
β βββ environment.py
β βββ fleet.py
β βββ route.py
β βββ shift.py
β βββ trip.py
β βββ vehicle.py
β
βββ events/
β βββ events.py
β βββ event_bus.py
β βββ event_handlers.py
β
βββ managers/
β βββ dispatch_manager.py
β βββ driver_manager.py
β βββ environment_manager.py
β βββ fleet_manager.py
β βββ maintenance_manager.py
β βββ trip_manager.py
β βββ vehicle_manager.py
β
βββ physics/
β βββ dynamics.py
β βββ fuel_model.py
β βββ kinematics.py
β βββ physics_constants.py
β βββ physics_engine.py
β βββ powertrain.py
β βββ resistance_model.py
β βββ thermal_model.py
β βββ wear_model.py
β
βββ profiles/
β βββ driver_profiles.py
β βββ fleet_profiles.py
β βββ route_profiles.py
β βββ vehicle_profiles.py
β
βββ runtime/
β βββ continuous_runtime.py
β βββ demo.py
β βββ digital_twin_runtime.py
β βββ driving_scenario.py
β βββ scheduler.py
β βββ simulation_clock.py
β βββ tick_context.py
β
βββ sensors/
β βββ pid_mapper.py
β βββ sensor_constants.py
β βββ sensor_models.py
β βββ sensor_provider.py
β βββ sensor_registry.py
β βββ virtual_sensor_provider.py
β
βββ telemetry/
β βββ telemetry_generator.py
β βββ telemetry_packet.py
β βββ telemetry_pipeline.py
β βββ telemetry_stream.py
β
βββ utils/
βββ helpers.py
βββ random_utils.py
A simplified representation of the simulation pipeline:
# 1. The driver and environment provide context
decision_context = DecisionContext(
driver=driver,
vehicle=vehicle,
environment=environment,
)
# 2. The Decision Layer produces an intent
intent = driver_behaviour_engine.decide(decision_context)
# 3. The Controller converts intent into actuation
actuation = vehicle_controller.compute_actuation(
intent=intent,
vehicle=vehicle,
)
# 4. The Physics Engine evolves the vehicle state
physics_result = physics_engine.update(
vehicle=vehicle,
actuation=actuation,
environment=environment,
)
# 5. Virtual sensors observe the resulting state
readings = sensor_provider.update_all(
vehicle,
tick_context,
)
# 6. Telemetry is generated
packet = telemetry_generator.generate(
vehicle,
readings,
tick_context,
)
# 7. The telemetry pipeline publishes the result
telemetry_pipeline.process(packet)The core idea is:
Intent
β
Actuation
β
Physics
β
Vehicle State
β
Sensors
β
Telemetry
DriveTwin can orchestrate multiple simulated vehicles.
Each vehicle maintains its own state and simulation context.
ββββββββββββββββββββββ
β Simulation Clock β
βββββββββββ¬βββββββββββ
β
βββββββββββββββββββββΌββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Vehicle 1 β β Vehicle 2 β β Vehicle 3 β
β β β β β β
β Driver β β Driver β β Driver β
β Decisions β β Decisions β β Decisions β
β Physics β β Physics β β Physics β
β Sensors β β Sensors β β Sensors β
β Telemetry β β Telemetry β β Telemetry β
ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ
β β β
βββββββββββββββββββββΌββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Telemetry Stream β
ββββββββββββββββββββββ
The current system is designed to explore how a simulation can scale from a single vehicle to a small simulated fleet.
The main executable entry points are:
| Entry Point | Command | Purpose |
|---|---|---|
| Accelerated Demo | python -m digital_twin.runtime.demo --fast --ticks 5 |
Short deterministic simulation |
| Driving Demo | python -m tests.demo_driving |
30-tick driving behavior demonstration |
| Continuous Simulation | python -m simulation.continuous_loop |
Continuous multi-vehicle simulation |
| Telemetry Validation | python -m digital_twin.validate_full_telemetry_pipeline |
Validate the telemetry pipeline |
| Controller Validation | python -m tests.validate_vehicle_controller |
Validate vehicle actuation and controller behavior |
All commands should be executed from the backend/ directory.
DriveTwin and DriveVitals are separate projects with different responsibilities.
βββββββββββββββββββββββββββββββ
β DriveTwin β
β β
β Simulated Driver β
β Simulated Vehicle β
β Environment β
β Vehicle Physics β
β Virtual Sensors β
β Telemetry Generation β
ββββββββββββββββ¬βββββββββββββββ
β
β Telemetry
βΌ
βββββββββββββββββββββββββββββββ
β DriveVitals β
β β
β Driver Analytics β
β Vehicle Analytics β
β Fleet Intelligence β
β Historical Trends β
β Insights β
β Dashboard β
βββββββββββββββββββββββββββββββ
The distinction is intentional.
How does a simulated vehicle and driver system evolve over time?
What can we learn from vehicle and driver data?
DriveTwin can therefore act as a controlled data source for testing analytics systems.
For example:
DriveTwin
β
βββ Aggressive Driver
βββ Eco Driver
βββ Wet Road
βββ Heavy Load
βββ Long Trip
β
βΌ
Telemetry
β
βΌ
DriveVitals
β
βΌ
Driver & Vehicle
Analytics
This separation allows the simulation system and the analytics system to evolve independently.
- a stateful vehicle simulation framework
- an experimental automotive software project
- a controlled environment for generating telemetry
- a way to model driver-vehicle interactions
- a platform for experimenting with simulation architecture
- a potential data source for analytics systems
- a manufacturer-grade vehicle simulator
- a replacement for an actual ECU
- a complete physical digital replica of a specific production vehicle
- a full traffic simulator
- a production fleet management platform
The purpose of the project is to create a useful abstraction of vehicle operation that is:
Stateful. Explainable. Modular. Experimentable.
The current state of a vehicle should be influenced by its previous state.
State N
+
Decision
+
Actuation
+
Physics
β
State N + 1
Different layers should have different jobs.
Driver
β decides
Controller
β translates intent into actuation
Physics
β evolves vehicle state
Sensors
β observe vehicle state
Telemetry
β transports structured data
Simulation behavior should be traceable.
When a vehicle accelerates, it should be possible to understand:
Why did the driver intend to accelerate?
β
Why was throttle applied?
β
How did physics update the vehicle?
β
How did the resulting state become telemetry?
The simulation should allow components to evolve independently.
For example:
New Driver Model
β
βΌ
Same Controller
New Physics Model
β
βΌ
Same Sensor Layer
Real Telemetry Source
β
βΌ
Same Analytics Consumer
DriveTwin is currently a standard-library-only Python project.
The recommended development workflow is:
Clone Repository
β
Create Virtual Environment
β
Activate Environment
β
cd backend
β
Run Demo
β
Inspect Simulation
β
Modify Simulation Components
β
Run Validation Scripts
A typical first run is:
python -m digital_twin.runtime.demo --fast --ticks 5followed by:
python -m simulation.continuous_loopExperimental Project β Active Development
DriveTwin is an evolving engineering and research project.
The current foundation focuses on:
- stateful vehicle simulation
- driver behavior modeling
- decision-making
- vehicle actuation
- physics-based state evolution
- virtual sensors
- telemetry generation
- multi-vehicle orchestration
Future exploration may include:
- richer vehicle dynamics
- configurable driving scenarios
- route-aware simulation
- traffic modeling
- scenario replay
- simulation recording
- what-if experimentation
- larger fleet simulations
- real-world OBD-II telemetry integration
- integration with analytics and machine learning systems
DriveTwin sits at the intersection of:
Automotive Systems
+
Software Architecture
+
Simulation
+
Telemetry
+
Digital Twin Concepts
The project explores questions such as:
How should a vehicle be represented as a persistent software entity?
How can driver decisions influence vehicle state?
How can a simulation produce structured telemetry?
How can controlled simulation scenarios support analytics development?
How can a simulated vehicle system evolve independently from the system analyzing its data?