J1939 Vehicle Simulator

Vehicle Simulator with J1939 CAN Support

Overview

The Vehicle Simulator (gva-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.

Benefits of J1939 Simulation for Message Generation

🎯 Development & Testing Advantages

  1. Hardware-Independent Development

    • Develop and test GVA applications without physical CAN hardware
    • No need for expensive vehicle ECUs or test benches
    • Parallel development across multiple teams
  2. Realistic Vehicle Behavior

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

    • Eliminates need for physical test vehicles in early development
    • Virtual CAN interface (vcan0) enables testing on any Linux workstation
    • Reduces wear and tear on physical hardware
  4. Rapid Prototyping

    • Instant feedback loop for algorithm development
    • Easy scenario creation and replay
    • Configurable message rates and data patterns
  5. Integration Testing

    • Validate J1939 gateway functionality
    • Test data flow from CAN to DDS topics
    • Verify HMI responsiveness to vehicle parameters
  6. Reproducible Testing

    • Deterministic vehicle behavior
    • Repeatable test scenarios
    • Consistent baseline for regression testing

📊 J1939 Message Support

✅ Fully Supported PGNs (Implemented in Vehicle Simulator)

The vehicle simulator actively generates the following J1939 messages over CAN and publishes them to DDS via the gateway:

PGNHexNameRateSPNsDescription
614430xF003EEC2 - Electronic Engine Controller 250ms91, 92Accelerator pedal position, engine percent load
614440xF004EEC1 - Electronic Engine Controller 1100ms190, 512, 513Engine speed (RPM), driver demand torque, actual engine torque
614450xF005ETC2 - Electronic Transmission Controller 2100ms522, 523, 524Clutch position, selected gear, current gear
614490xF009VDC2 - Vehicle Dynamic Control 2100ms1807, 1808Steering wheel angle, yaw rate
652530xFEE5HOURS - Engine Hours1s247Total engine operating hours
652560xFEE8VDS - Vehicle Direction/Speed250ms517, 519, 586Speed over ground, compass heading, course
652580xFEEAALT - Altitude1s580GPS altitude above sea level
652620xFEEEET1 - Engine Temperature 11s110, 174, 175Engine coolant temp, fuel temp, oil temp
652630xFEEFEFLP - Engine Fluid Level/Pressure500ms96, 100, 94Fuel level, oil pressure, fuel delivery pressure
652650xFEF1CCVS - Cruise Control/Vehicle Speed100ms84, 597, 598Wheel-based vehicle speed, brake switch, clutch switch
652670xFEF3VP - Vehicle Position250ms584, 585GPS latitude, longitude
652690xFEF5AMB - Ambient Conditions1s108, 171Barometric pressure, ambient air temperature
652710xFEF7VEP1 - Vehicle Electrical Power 11s167, 168, 158Battery voltage, alternator voltage, charging system voltage
652760xFEFCDD - Dash Display1s182, 183Fuel rate (L/h), instantaneous fuel economy
0xEF000xEF00PROP_A - Proprietary A (IONNIC USM)250ms-LED control for IONNIC USM ES-Key panel

Detailed SPN List (All Supported Parameters)

SPNParameter NamePGNUnitResolutionOffsetRange
84Wheel-Based Vehicle Speed65265km/h1/256 km/h00-250 km/h
91Accelerator Pedal Position61443%0.4%00-100%
92Engine Percent Load at Current Speed61443/61444%1%00-100%
94Fuel Delivery Pressure65263kPa4 kPa00-1000 kPa
96Fuel Level65263%0.4%00-100%
100Engine Oil Pressure65263kPa4 kPa00-1000 kPa
108Barometric Pressure65269kPa0.5 kPa00-125 kPa
110Engine Coolant Temperature65262°C1°C-40-40 to +210°C
158Charging System Voltage65271V0.05 V00-3212 V
167Alternator Voltage65271V0.05 V00-3212 V
168Battery Voltage65271V0.05 V00-3212 V
171Ambient Air Temperature65269°C0.03125°C-273-273 to +1735°C
174Fuel Temperature65262°C1°C-40-40 to +210°C
175Engine Oil Temperature65262°C0.03125°C-273-273 to +1735°C
182Fuel Rate65276L/h0.05 L/h00-3212 L/h
183Instantaneous Fuel Economy65276km/L1/512 km/L00-125 km/L
190Engine Speed61444RPM0.125 RPM00-8031 RPM
247Total Engine Hours65253h0.05 h00-210,554,060 h
512Driver's Demand Engine Torque61444%1%-125-125% to +125%
513Actual Engine Torque61444%1%-125-125% to +125%
517Speed Over Ground65256km/h1/256 km/h00-250 km/h
519Course Over Ground65256deg1/128 deg00-360°
522Clutch Pedal Position61445%0.4%00-100%
523Transmission Current Gear61445gear1-125-125 to +125
524Transmission Selected Gear61445gear1-125-125 to +125
580Altitude65258m0.125 m-2500-2500 to +5531 m
584Latitude65267deg10⁻⁷ deg-210-90° to +90°
585Longitude65267deg10⁻⁷ deg-210-180° to +180°
586Compass Bearing65256deg1/128 deg00-360°
597Brake Switch65265-2 bits-Off/On/Error/Not Available
598Clutch Switch65265-2 bits-Off/On/Error/Not Available
899Engine Torque Mode61444-100-15 (enumeration)
1807Steering Wheel Angle61449rad1/1024 rad-31.374-31.374 to +31.374 rad
1808Yaw Rate61449rad/s1/8192 rad/s-3.92-3.92 to +3.92 rad/s

Total: 15 PGNs, 33 SPNs actively simulated

🔲 Unsupported PGNs (Not Yet Implemented)

The following J1939 messages are not currently generated by the vehicle simulator. These represent potential future enhancements:

PGNHexNamePriorityUse CaseComplexity
614400xF000ERC1 - Electronic Retarder Controller 1LowRetarder/engine brake controlMedium
614410xF001EBC1 - Electronic Brake Controller 1HighABS, brake system statusHigh
614420xF002ETC1 - Electronic Transmission Controller 1MediumTransmission mode, shift in progressMedium
649710xFDCBVDHR - Vehicle Distance (High Resolution)HighOdometer with 5mm resolutionLow
649720xFDCCTCO1 - TachographMediumDriver card, speed from tachographLow
651320xFE6CTPMS - Tire Pressure MonitoringMediumIndividual tire pressure/temperatureMedium
652170xFEC1PTODE - PTO Drive EngagementLowPower take-off statusLow
652480xFEE0VDIST - High Resolution Vehicle DistanceHighTotal distance with 5m resolutionLow
652510xFEE3ECFG - Engine ConfigurationLowEngine make, model, serial numberLow
652520xFEE4SHUTDN - ShutdownLowEngine shutdown overrideLow
652600xFEECVI - Vehicle IdentificationMediumFull VIN transmission (partial impl)Low
652790xFEFFCCVS1 - Cruise Control/Vehicle Speed 1MediumEnhanced cruise control dataLow
650980xFE4AEBC2 - Electronic Brake Controller 2HighIndividual wheel brake statusHigh
650990xFE4BEBC3 - Electronic Brake Controller 3MediumBrake lining wearMedium
651100xFE56IC1 - Inlet/Exhaust Conditions 1LowIntake manifold pressure/tempMedium
651720xFE84RQST - RequestLowRequest specific PGN from ECUMedium
652260xFECAAT1I - Aftertreatment 1 Intake GasLowDiesel particulate filter inletLow
652270xFECBAT1O - Aftertreatment 1 Outlet GasLowDPF outlet, NOx sensorLow
652470xFEDFEFL/P2 - Engine Fluid Level/Pressure 2LowAdditional fluid pressuresLow
652660xFEF2LFE - Fuel EconomyMediumAverage/trip fuel economyLow
652700xFEF6TD - TurbochargerLowBoost pressure, turbine speedMedium
652720xFEF8VEP2 - Vehicle Electrical Power 2LowAdditional electrical busesLow

Why These Are Not Implemented

ReasonAffected PGNsCount
Not relevant to basic vehicle simERC1, PTODE, SHUTDN, ECFG, AT1I, AT1O, TD7
Requires tire physics modelTPMS1
Requires ABS/brake modelEBC1, EBC2, EBC33
Requires advanced transmissionETC11
Low priority / cosmeticVI (VIN), VDHR, VDIST, TCO1, LFE5
Requires exhaust/emissions modelIC1, AT1I, AT1O3
Protocol-level (not vehicle data)RQST1
Duplicate/enhanced versionsCCVS1, EFL/P2, VEP23

Total: 22 unsupported PGNs

🛠️ Technical Features

  • OpenDRIVE Road Network Support: Follow realistic road geometry
  • Automatic Transmission Simulation: Gear changes based on speed and throttle
  • Physics-Based Dynamics: Acceleration, braking, steering with realistic constraints
  • DDS Integration: Direct publishing to J1939 Automotive PSM topics
  • Qt6 GUI: Real-time visualization and manual control

J1939 to DDS Gateway Architecture

The following sequence diagram illustrates the complete data flow from J1939 CAN bus messages through the gateway to DDS subscribers:

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) Sim->>CAN: Send PGN 61445
(ETC2: Transmission) Note over CAN,Decoder: CAN Reception Phase CAN->>Reader: Read CAN frame (29-bit ID) Reader->>Reader: Validate frame Reader->>Decoder: emit canFrameReceived() Note over Decoder,Gateway: J1939 Decode Phase Decoder->>Decoder: Extract PGN from CAN ID
(bits 24-8) Decoder->>Decoder: Extract source address
(bits 7-0) Decoder->>Decoder: Extract priority
(bits 28-26) Decoder->>Decoder: Decode SPNs from payload
(bit position, scale, offset) Decoder->>Gateway: emit j1939MessageDecoded() Note over Gateway,DDS: DDS Publishing Phase Gateway->>Gateway: Create C_Parameter_Group_Definition
(if first time) Gateway->>DDS: Publish PGN definition loop For each SPN in message Gateway->>Gateway: Create C_Parameter message
(sourceID, PGN, SPN, value) Gateway->>Gateway: Set metadata
(timestamp, status) Gateway->>DDS: Publish parameter end Note over DDS,HMI: Consumption Phase DDS->>HMI: onSampleReceived()
(C_Parameter) HMI->>HMI: Update speedometer HMI->>HMI: Update tachometer HMI->>HMI: Update gear indicator Note over Gateway: Status Reporting (1 Hz) Gateway->>Gateway: Update data source status Gateway->>DDS: Publish C_Data_Source
(gateway health)

Sequence Diagram Explanation

1. Message Generation Phase

  • Vehicle Simulator calculates realistic vehicle parameters based on driver inputs and physics
  • Encodes parameters into J1939 CAN frames with proper PGN/SPN structure
  • Transmits to virtual CAN interface (vcan0)

2. CAN Reception Phase

  • SocketCanReader Qt thread continuously reads from CAN interface
  • Validates CAN frame format (29-bit extended ID)
  • Emits Qt signal with raw frame data

3. J1939 Decode Phase

  • J1939Decoder extracts protocol information from CAN ID:
    • PGN: Parameter Group Number (identifies message type)
    • Source Address: ECU identifier (0-253)
    • Priority: Message urgency (0=highest, 7=lowest)
  • Decodes data payload into individual SPNs using configuration:
    • Bit position and length
    • Scale factor and offset
    • Engineering units

4. DDS Publishing Phase

  • Gateway publishes C_Parameter_Group_Definition (PGN metadata) on first occurrence
  • For each SPN in the message:
    • Creates C_Parameter message with value and status
    • Adds timestamp and source identification
    • Publishes to DDS topic
  • Periodic status updates (1 Hz) publish gateway health

5. Consumption Phase

  • GVA applications (HMI, LDMX) subscribe to J1939 DDS topics
  • Receive parameter updates via DDS middleware
  • Update UI elements (speedometer, tachometer, gear display)

Protocol Details

J1939 CAN ID Structure (29-bit)

Bits 28-26: Priority (0-7)
Bit  25:    Reserved
Bit  24:    Data Page (DP)
Bits 23-16: PDU Format (PF)
Bits 15-8:  PDU Specific (PS) - group extension or destination
Bits 7-0:   Source Address (SA)

PGN = (DP << 16) | (PF << 8) | (PS if PF >= 240 else 0)

Example CAN Frame Decoding

CAN ID: 0x18F00400
Binary: 00011000111100000000010000000000

Priority:  0x6 (bits 28-26) = 6 (normal priority)
Reserved:  0   (bit 25)
DP:        0   (bit 24)
PF:        0xF0 (bits 23-16) = 240 (broadcast)
PS:        0x04 (bits 15-8)  = 4 (group extension)
SA:        0x00 (bits 7-0)   = 0 (engine controller)

PGN = (0 << 16) | (240 << 8) | 4 = 61444 (EEC1 - Engine Controller 1)

Quick Start

1. Build Vehicle Simulator

cd build
cmake ..
make gva-vehicle-sim

2. Setup Virtual CAN

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

3. Start Vehicle Simulator

# GUI mode with OpenDRIVE track
./build/bin/gva-vehicle-sim \
  --domain=0 \
  --opendrive=data/opendrive/ZalaZONE_full.xodr \
  --can-interface=vcan0

# Headless mode with J1939 only
./build/bin/gva-vehicle-sim \
  --domain=0 \
  --can-interface=vcan0 \
  --headless

4. Start J1939 Gateway

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

5. Monitor with LDMX

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

Configuration

Vehicle Simulator Configuration

Create vehicle-sim-config.json:

{
  "j1939": {
    "enabled": true,
    "sourceAddress": 0,
    "gatewayResourceId": 1000,
    "updateRateHz": 10
  },
  "vehicle": {
    "maxSpeed": 120.0,
    "maxRpm": 6000,
    "gearRatios": [3.5, 2.5, 1.8, 1.3, 1.0, 0.8],
    "engineIdleRpm": 800
  }
}

J1939 Gateway Configuration

See /etc/gva/j1939-config.json for PGN/SPN definitions and scaling parameters.

Use Cases

1. HMI Development

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

2. Algorithm Testing

  • Test eco-driving algorithms with simulated fuel consumption
  • Validate predictive maintenance logic
  • Test autonomous driving decision-making

3. Integration Testing

  • Verify end-to-end data flow: CAN → DDS → Application
  • Test gateway performance under load
  • Validate data synchronization across subsystems

4. Training & Demonstration

  • Safe environment for operator training
  • Customer demonstrations without vehicle
  • Educational tool for GVA architecture

Performance Characteristics

MetricValue
CAN frame generation rateUp to 100 Hz per PGN
DDS publishing latency< 5 ms (local)
Gateway throughput> 1000 PGNs/sec
CPU usage (simulator + gateway)< 10% (4-core system)
Memory footprint~50 MB (combined)

Comparison: Physical vs. Simulated

AspectPhysical VehicleSimulator
Hardware Cost$50,000+$0 (software only)
Setup TimeHours (wiring, config)Minutes
ReproducibilityLimited (driver variability)Perfect (deterministic)
SafetyRisk of damage/injuryZero risk
Scenario ControlDifficult (weather, traffic)Complete control
Data LoggingRequires equipmentBuilt-in
Parallel TestingOne vehicle at a timeMultiple instances

Troubleshooting

Common Issues

CAN Interface Not Found

# Verify vcan0 exists
ip link show vcan0

# Recreate if needed
sudo scripts/test/j1939/setup-vcan.sh

No DDS Messages

# Check gateway is running
pgrep -a gva-j1939-gateway

# Verify domain ID matches
./build/bin/gva-j1939-gateway --domain=0
./build/bin/gva-vehicle-sim --domain=0

Gateway Not Decoding Messages

# Check CAN frames are being sent
candump vcan0

# Verify configuration file
cat /etc/gva/j1939-config.json

Reqest a demonstartion today.