Skip to content

CAN Message Handling

The CAN Message Handling module (can_comm.c) acts as the interpreter between the raw CAN bus data and the ECU's internal representations. It utilizes a ring buffer provided by the generic_can_driver.

Receiving Messages (process_can_frames)

The process_can_frames function empties the RX ring buffer, inspecting the CAN ID of each message to unpack its payload into the global can_rx_data structure.

Key Incoming Messages

CAN IDSourceDescriptionVariables Updated
0x050Telemetry/IMUCustom IMU message containing acceleration, gyro, and Euler angles.imu_data
0x0A0Front GatewayFront wheel speeds and suspension travel.gf_wheel_sensors
0x0A1Front GatewayAccelerator Pedal Position (APPS), Steering Angle, and R2D Button status.gf_misc_sensors
0x0B0Rear GatewayRear wheel speeds and suspension travel.gr_wheel_sensors
0x0B1Rear GatewayBrake pressure, Junction Box (JB) currents, and SDC status.gr_misc_sensors
0x0B2Rear GatewayCooling flow rate and temperatures.gr_liquid_sensors
0x021Left InverterMotor temp, Inverter temp, and feedback inputs.gil_inv_data_2
0x031Right InverterMotor temp, Inverter temp, and feedback inputs.gir_inv_data_2
0x010BMSBattery Management System errors and temperatures. Maps complex bitfields to local faults (can_ams_fault).bms_errors_temps
0x011BMSSOC and Voltage data.bms_soc_voltage
0x014BMSBattery Current and Discharge limits.bms_current
0x0D0Dashboard/TelemetryDriver inputs (e.g., Recalibration requests, Motor Control Mode toggle).dash_inputs
0x0D1Dashboard/TelemetrySlip control PID gains override.dash_pid_tune_1
0x0D2Dashboard/TelemetryTorque Vectoring (TV) PID gains override.dash_pid_tune_2
0x0F0GPSGPS speed, course, and yaw angle.gps_angles

Fault Handling on RX

  • If the SDC value in message 0x0B1 reads as 0, a can_sdc_fault is flagged.
  • If the BMS reports any critical fault in message 0x010 (e.g., Low Cell Voltage, Pack Too Hot), a can_ams_fault is flagged, and the physical AMS_ERROR_Pin is driven low.

Sending Messages (set_can_frames)

The set_can_frames function packs the most recent internal data into the transmit ring buffer.

Key Outgoing Messages

Transmit Buffer IndexDescriptionPayload Data
0Inverter Commands (0x0E0)Motor Enable/Disable state, L/R Regen percentages, L/R Speed percentages, and Calculated Vehicle Speed.
1Rear Gateway Commands (0x0E5)Signals the Rear Gateway to turn the R2D Buzzer On/Off.
6UKF State (0x...)Unscented Kalman Filter estimates for Velocity X, Side Slip, Rotation Z, and Angular Velocity Z.
7UKF Acceleration (0x...)Unscented Kalman Filter estimates for Acceleration X and Y.
8TV State Debug (0x...)Torque Vectoring state, delta moment Z (delta_Mz), and slip control state.
9Slip Control Debug (0x...)Reference slip ratios (kappa_ref) and maximum torques (tmax) for left and right wheels.

Released under the MIT License.