Vehicle Simulator with J1939 CAN Support

Overview

The Vehicle Simulator (gva-qt6-vehicle-sim) is a comprehensive testing and development tool for the GVA (Generic Vehicle Architecture) platform. It provides realistic vehicle dynamics simulation with integrated J1939 CAN bus message generation, enabling hardware-in-the-loop testing without requiring physical vehicle hardware.

Vehicle Simulator Third Person View

Quick Start

1. Build the Simulator

cd /home/newman/repos/ldm/build
cmake ..
make gva-qt6-vehicle-sim -j $(nproc)

2. Setup Virtual CAN Interface

# Load kernel module
sudo modprobe vcan

# Create and activate vcan0
sudo ip link add dev vcan0 type vcan
sudo ip link set vcan0 up

# Verify interface
ip link show vcan0

Or use the provided script:

sudo scripts/test/j1939/setup-vcan.sh

3. Launch with Map

./build/bin/gva-qt6-vehicle-sim \
  --domain=0 \
  --map=data/opendrive/ZalaZONE_full.xodr

4. Start J1939 Gateway (Optional)

Bridge CAN to DDS for monitoring:

./build/bin/gva-j1939-gateway \
  --domain=0 \
  --interface=vcan0

5. Monitor with LDMX

./build/bin/ldmx
# Navigate to J1939 tab to see live parameters

Benefits of J1939 Simulation

🎯 Development & Testing Advantages

  1. Hardware-Independent Development
  2. Develop and test GVA applications without physical CAN hardware
  3. No need for expensive vehicle ECUs or test benches
  4. Parallel development across multiple teams

  5. Realistic Vehicle Behavior

  6. Generates authentic J1939 Parameter Group Numbers (PGNs) and Suspect Parameter Numbers (SPNs)
  7. Simulates realistic vehicle dynamics (speed, RPM, gear changes, braking)
  8. Provides time-synchronized sensor data

  9. Cost Reduction

  10. Eliminates need for physical test vehicles in early development
  11. Virtual CAN interface (vcan0) enables testing on any Linux workstation
  12. Reduces wear and tear on physical hardware

  13. Rapid Prototyping

  14. Instant feedback loop for algorithm development
  15. Easy scenario creation and replay
  16. Configurable message rates and data patterns

  17. Integration Testing

  18. Validate J1939 gateway functionality
  19. Test data flow from CAN to DDS topics
  20. Verify HMI responsiveness to vehicle parameters

  21. Reproducible Testing

  22. Deterministic vehicle behavior
  23. Repeatable test scenarios
  24. Consistent baseline for regression testing

J1939 Message Support

✅ Fully Supported PGNs (15 Active)

The vehicle simulator actively generates the following J1939 messages over CAN:

PGN Hex Name Rate Key Parameters
61443 0xF003 EEC2 - Electronic Engine Controller 2 50ms Accelerator pedal, engine load
61444 0xF004 EEC1 - Electronic Engine Controller 1 100ms Engine speed (RPM), torque
61445 0xF005 ETC2 - Electronic Transmission Controller 2 100ms Gear selection, clutch position
61449 0xF009 VDC2 - Vehicle Dynamic Control 2 100ms Steering angle, yaw rate
65253 0xFEE5 HOURS - Engine Hours 1s Total engine operating hours
65256 0xFEE8 VDS - Vehicle Direction/Speed 250ms Heading, speed over ground
65258 0xFEEA ALT - Altitude 1s GPS altitude
65262 0xFEEE ET1 - Engine Temperature 1 1s Coolant, fuel, oil temperature
65263 0xFEEF EFLP - Engine Fluid Level/Pressure 500ms Fuel level, oil pressure
65265 0xFEF1 CCVS - Cruise Control/Vehicle Speed 100ms Wheel speed, brake/clutch switches
65267 0xFEF3 VP - Vehicle Position 250ms GPS latitude/longitude
65269 0xFEF5 AMB - Ambient Conditions 1s Air temperature, pressure
65271 0xFEF7 VEP1 - Vehicle Electrical Power 1 1s Battery/alternator voltage
65276 0xFEFC DD - Dash Display 1s Fuel rate, economy
0xEF00 0xEF00 PROP_A - Proprietary A (IONNIC USM) 250ms LED control for panels

Total: 33 SPNs (Suspect Parameter Numbers) actively simulated

Detailed SPN List

SPN Parameter Name PGN Unit Range
84 Wheel-Based Vehicle Speed 65265 km/h 0-250 km/h
91 Accelerator Pedal Position 61443 % 0-100%
92 Engine Percent Load 61443/61444 % 0-100%
94 Fuel Delivery Pressure 65263 kPa 0-1000 kPa
96 Fuel Level 65263 % 0-100%
100 Engine Oil Pressure 65263 kPa 0-1000 kPa
108 Barometric Pressure 65269 kPa 0-125 kPa
110 Engine Coolant Temperature 65262 °C -40 to +210°C
158 Charging System Voltage 65271 V 0-3212 V
167 Alternator Voltage 65271 V 0-3212 V
168 Battery Voltage 65271 V 0-3212 V
171 Ambient Air Temperature 65269 °C -273 to +1735°C
174 Fuel Temperature 65262 °C -40 to +210°C
175 Engine Oil Temperature 65262 °C -273 to +1735°C
182 Fuel Rate 65276 L/h 0-3212 L/h
183 Instantaneous Fuel Economy 65276 km/L 0-125 km/L
190 Engine Speed 61444 RPM 0-8031 RPM
247 Total Engine Hours 65253 h 0-210M h
512 Driver's Demand Engine Torque 61444 % -125% to +125%
513 Actual Engine Torque 61444 % -125% to +125%
517 Speed Over Ground 65256 km/h 0-250 km/h
519 Course Over Ground 65256 deg 0-360°
522 Clutch Pedal Position 61445 % 0-100%
523 Transmission Current Gear 61445 gear -125 to +125
524 Transmission Selected Gear 61445 gear -125 to +125
580 Altitude 65258 m -2500 to +5531 m
584 Latitude 65267 deg -90° to +90°
585 Longitude 65267 deg -180° to +180°
586 Compass Bearing 65256 deg 0-360°
597 Brake Switch 65265 - Off/On/Error/Not Available
598 Clutch Switch 65265 - Off/On/Error/Not Available
899 Engine Torque Mode 61444 - 0-15 (enumeration)
1807 Steering Wheel Angle 61449 rad -31.374 to +31.374 rad
1808 Yaw Rate 61449 rad/s -3.92 to +3.92 rad/s

J1939 to DDS Gateway Architecture

sequenceDiagram participant Sim as Vehicle Simulator participant CAN as CAN Bus (vcan0) participant Reader as SocketCanReader participant Decoder as J1939Decoder participant Gateway as J1939Gateway participant DDS as DDS Topic participant HMI as GVA HMI/LDMX Note over Sim,CAN: Message Generation Phase Sim->>Sim: Calculate vehicle state
(speed, RPM, gear) Sim->>CAN: Send PGN 61444
(EEC1: Engine Speed) Sim->>CAN: Send PGN 65265
(CCVS: Vehicle Speed) Note over CAN,Gateway: CAN Reception & Decode CAN->>Reader: Read CAN frame (29-bit ID) Reader->>Decoder: emit canFrameReceived() Decoder->>Decoder: Extract PGN, SPN, values Decoder->>Gateway: emit j1939MessageDecoded() Note over Gateway,DDS: DDS Publishing Gateway->>Gateway: Create C_Parameter_Group_Definition Gateway->>DDS: Publish PGN definition loop For each SPN Gateway->>Gateway: Create C_Parameter message Gateway->>DDS: Publish parameter end Note over DDS,HMI: Consumption DDS->>HMI: onSampleReceived() HMI->>HMI: Update UI (speedometer, tachometer)

Data Flow Explanation

  1. Message Generation Phase
  2. Vehicle Simulator calculates realistic vehicle parameters based on driver inputs and physics
  3. Encodes parameters into J1939 CAN frames with proper PGN/SPN structure
  4. Transmits to virtual CAN interface (vcan0)

  5. CAN Reception Phase

  6. SocketCanReader Qt thread continuously reads from CAN interface
  7. Validates CAN frame format (29-bit extended ID)

  8. J1939 Decode Phase

  9. J1939Decoder extracts PGN, source address, priority from CAN ID
  10. Decodes SPNs using bit position, scale, offset
  11. Applies engineering units

  12. DDS Publishing Phase

  13. Gateway publishes C_Parameter_Group_Definition (PGN metadata)
  14. For each SPN: creates C_Parameter with value, timestamp, status
  15. Publishes to DDS topics

  16. Consumption Phase

  17. GVA applications subscribe to J1939 DDS topics
  18. Update UI elements (speedometer, tachometer, gear display)

Vehicle Controls

Keyboard (Default)

Key Function
W / Throttle
S / Brake
A / Steer Left
D / Steer Right
Space Clutch
Q Shift Down
E Shift Up
I Toggle Ignition
P Parking Brake
T Transfer Case (4H/4L)
C Cycle Camera
R Reset Position
F11 Toggle Fullscreen

Logitech G29 Racing Wheel

When detected, G29 automatically overrides keyboard:

  • Steering Wheel: Vehicle steering with force feedback
  • Gas Pedal: Throttle (0-100%)
  • Brake Pedal: Brake pressure (0-100%)
  • Clutch Pedal: Clutch engagement
  • Paddle Shifters: Quick up/down shift

OpenDRIVE Road Networks

Vehicle Simulator Top-Down View

ZalaZONE Proving Ground

The simulator includes the ZalaZONE proving ground (Hungary):

  • 579 roads (451 junction connecting roads)
  • 76 junctions
  • Lane-accurate positioning
  • Traffic signs & signals - Speed limits, stop signs
  • Road markings - Solid/dashed lines, crosswalks
  • GPS origin: 46.8780°N, 16.8439°E, 175m altitude

Camera Modes

Vehicle Simulator Drive Along View

Cycle through perspectives with C key:

  1. Third-Person Chase Cam - Follow vehicle from behind
  2. Top-Down Strategic View - Overhead tactical perspective
  3. Drive-Along Side View - Parallel tracking camera
  4. First-Person Driver View - Cockpit perspective (planned)

Command Line Options

gva-qt6-vehicle-sim [OPTIONS]

Options:
  -h, --help               Display help
  --version                Display version
  -d, --domain <id>        DDS domain ID (default: 0)
  -m, --map <filepath>     OpenDRIVE (.xodr) map file
  -f, --fullscreen         Start in fullscreen mode
  --device <path>          G29 input device path

Usage Examples

# Launch with ZalaZONE map
./gva-qt6-vehicle-sim --domain=0 --map=data/opendrive/ZalaZONE_full.xodr

# Fullscreen mode
./gva-qt6-vehicle-sim --fullscreen --map=data/opendrive/ZalaZONE_full.xodr

# Custom G29 device
./gva-qt6-vehicle-sim --device=/dev/input/event5

Integration Examples

1. Monitor CAN Bus

# Terminal 1: Run simulator
./gva-qt6-vehicle-sim --domain=0

# Terminal 2: Monitor CAN traffic
candump vcan0 -t A

# Output:
#  (000.123)  vcan0  18F00400   [8]  00 7D 7D 20 19 FF FF FF  # EEC1: 800 RPM
#  (000.223)  vcan0  18FEF100   [8]  FF 00 00 C0 FF FF FF FF  # CCVS: 0 km/h

2. Subscribe to DDS Parameters

// Subscribe to vehicle speed in your HMI
auto subscriber = std::make_unique<QtDdsSubscriberCParameter>(
    domainId, "J1939_Automotive__Parameter");

connect(subscriber.get(), &QtDdsSubscriberCParameter::OnSampleReceived,
    [](const P_J1939_Automotive_PSM::C_Parameter& param) {
        if (param.A_suspectParameterNumber() == 84) {  // SPN 84 = Vehicle Speed
            double speedKmh = param.A_value();
            updateSpeedometer(speedKmh);
        }
    });

3. Automated Testing

#!/bin/bash
# Start simulator in background
./gva-qt6-vehicle-sim --domain=0 --headless &
SIM_PID=$!

# Wait for initialization
sleep 2

# Start gateway
./gva-j1939-gateway --domain=0 --interface=vcan0 &
GW_PID=$!

# Run test suite
python3 scripts/test/validate_j1939_output.py

# Cleanup
kill $SIM_PID $GW_PID

Use Cases

1. HMI Development

  • Develop vehicle dashboard without physical vehicle
  • Test instrument cluster rendering
  • Validate warning/alarm thresholds

2. Algorithm Testing

  • Test eco-driving algorithms
  • Validate predictive maintenance logic
  • Test autonomous driving decision-making

3. Integration Validation

  • Verify CAN → DDS → Application flow
  • Test gateway performance under load
  • Validate subsystem synchronization

4. Training & Education

  • Safe operator training environment
  • Customer demonstrations
  • Teaching tool for GVA architecture

Performance

Metric Value
Frame Rate 60 FPS
Physics Update 60 Hz
CAN Frame Rate 10-100 Hz per PGN
DDS Latency < 5 ms (local)
CPU Usage < 10% (4-core)
Memory ~200 MB with map

Troubleshooting

Simulator Won't Start

# Check Qt6
pkg-config --modversion Qt6Core

# Verify OpenGL
glxinfo | grep "OpenGL version"

# Check libraries
ldd ./build/bin/gva-qt6-vehicle-sim

No CAN Output

# Verify vcan0
ip link show vcan0

# Recreate if needed
sudo ip link delete vcan0
sudo ip link add dev vcan0 type vcan
sudo ip link set vcan0 up

G29 Not Detected

# List input devices
ls -l /dev/input/by-id/ | grep Logitech

# Check permissions
sudo chmod 666 /dev/input/event*

# Test with evtest
sudo evtest /dev/input/event5

Low Frame Rate

  • Use smaller OpenDRIVE files
  • Disable advanced features (shadows, reflections)
  • Lower resolution (1280x720)
  • Update graphics drivers

References

  • SAE J1939 Standard: Digital Annex of Serial Control and Communications Heavy Duty Vehicle Network
  • OpenDRIVE Standard: ASAM OpenDRIVE 1.8.1
  • J1939 Automotive PSM: ldm/UK/GVA/v2/J1939_Automotive/IDL/
  • Source Code: src/qt6/gva-vehicle-sim/

Last Updated: January 31, 2026