Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DriveTwin

A Stateful Vehicle Simulation Framework

Simulate the driver. Model the vehicle. Generate telemetry.


Python Simulation Framework Automotive Systems Experimental

DriveTwin is an experimental stateful simulation framework for exploring how drivers, vehicles, environments, and telemetry can be modeled as an evolving system.


Getting Started

Requirements

  • 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.


Clone the Repository

git clone https://github.com/harisrana-dev/DriveTwin.git
cd DriveTwin

Create a Virtual Environment

Windows PowerShell

python -m venv .venv
.venv\Scripts\Activate.ps1

If PowerShell prevents script execution, the environment can also be activated using:

.venv\Scripts\activate.bat

macOS / Linux

python3 -m venv .venv
source .venv/bin/activate

Run from the Backend Directory

The Python packages are located inside the backend/ directory.

Before running any module, change into the backend directory:

cd backend

This 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>

Running the Simulation

Accelerated Digital Twin Demo

Runs a short deterministic simulation without waiting for real-time delays.

cd backend
python -m digital_twin.runtime.demo --fast --ticks 5

This executes five simulation ticks and displays a concise summary of the simulation results.


Continuous Simulation

Runs the simulation continuously with approximately one real-time tick per second.

cd backend
python -m simulation.continuous_loop

The 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.


Driving Behavior Demo

Runs a 30-tick driving behavior demonstration.

cd backend
python -m tests.demo_driving

Validation Scripts

DriveTwin currently uses executable validation scripts rather than a formal test runner.

Full Telemetry Pipeline

cd backend
python -m digital_twin.validate_full_telemetry_pipeline

Vehicle Controller Validation

cd backend
python -m tests.validate_vehicle_controller

Inspect One Simulation Tick

cd backend
python -m tests.inspect_one_tick

Inspect Ten Simulation Ticks

cd backend
python -m tests.inspect_ten_ticks

Current Test Status

The 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.ini
  • conftest.py
  • configured test runner

The existing validation scripts are intended to verify and inspect simulation behavior during active development.


What is DriveTwin?

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.


Why Stateful Simulation?

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.


Core Simulation Pipeline

1. Driver Behavior

Drivers are modeled using behavioral profiles.

Current profiles include:

  • CAUTIOUS
  • STANDARD
  • AGGRESSIVE
  • ECO_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.


2. Decision Layer

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

3. Vehicle Control

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


4. Physics Engine

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

5. Persistent 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.


6. Environment

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

Virtual Sensors & Telemetry

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

Simulation Runtime

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.


Architecture

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

Repository Structure

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

Example Simulation Flow

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

Multi-Vehicle Simulation

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.


Project Entry Points

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

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.

DriveTwin asks:

How does a simulated vehicle and driver system evolve over time?

DriveVitals asks:

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.


What DriveTwin Is β€” and Is Not

DriveTwin is:

  • 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

DriveTwin is not:

  • 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.


Design Principles

1. State Over Isolated Randomness

The current state of a vehicle should be influenced by its previous state.

State N
  +
Decision
  +
Actuation
  +
Physics
  ↓
State N + 1

2. Separation of Responsibilities

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

3. Explainability

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?

4. Modularity

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

Development Workflow

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 5

followed by:

python -m simulation.continuous_loop

Development Status

Experimental 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

Engineering Focus

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?


Build the simulated system first.

Understand the data second.

Analyze the behavior third.


DriveTwin

Stateful simulation for intelligent vehicle systems.

About

A stateful vehicle simulation framework for modeling vehicle dynamics, driver behavior, environmental conditions, and fleet operations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages