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 ID | Source | Description | Variables Updated |
|---|---|---|---|
0x050 | Telemetry/IMU | Custom IMU message containing acceleration, gyro, and Euler angles. | imu_data |
0x0A0 | Front Gateway | Front wheel speeds and suspension travel. | gf_wheel_sensors |
0x0A1 | Front Gateway | Accelerator Pedal Position (APPS), Steering Angle, and R2D Button status. | gf_misc_sensors |
0x0B0 | Rear Gateway | Rear wheel speeds and suspension travel. | gr_wheel_sensors |
0x0B1 | Rear Gateway | Brake pressure, Junction Box (JB) currents, and SDC status. | gr_misc_sensors |
0x0B2 | Rear Gateway | Cooling flow rate and temperatures. | gr_liquid_sensors |
0x021 | Left Inverter | Motor temp, Inverter temp, and feedback inputs. | gil_inv_data_2 |
0x031 | Right Inverter | Motor temp, Inverter temp, and feedback inputs. | gir_inv_data_2 |
0x010 | BMS | Battery Management System errors and temperatures. Maps complex bitfields to local faults (can_ams_fault). | bms_errors_temps |
0x011 | BMS | SOC and Voltage data. | bms_soc_voltage |
0x014 | BMS | Battery Current and Discharge limits. | bms_current |
0x0D0 | Dashboard/Telemetry | Driver inputs (e.g., Recalibration requests, Motor Control Mode toggle). | dash_inputs |
0x0D1 | Dashboard/Telemetry | Slip control PID gains override. | dash_pid_tune_1 |
0x0D2 | Dashboard/Telemetry | Torque Vectoring (TV) PID gains override. | dash_pid_tune_2 |
0x0F0 | GPS | GPS speed, course, and yaw angle. | gps_angles |
Fault Handling on RX
- If the
SDCvalue in message0x0B1reads as0, acan_sdc_faultis flagged. - If the BMS reports any critical fault in message
0x010(e.g., Low Cell Voltage, Pack Too Hot), acan_ams_faultis flagged, and the physicalAMS_ERROR_Pinis 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 Index | Description | Payload Data |
|---|---|---|
0 | Inverter Commands (0x0E0) | Motor Enable/Disable state, L/R Regen percentages, L/R Speed percentages, and Calculated Vehicle Speed. |
1 | Rear Gateway Commands (0x0E5) | Signals the Rear Gateway to turn the R2D Buzzer On/Off. |
6 | UKF State (0x...) | Unscented Kalman Filter estimates for Velocity X, Side Slip, Rotation Z, and Angular Velocity Z. |
7 | UKF Acceleration (0x...) | Unscented Kalman Filter estimates for Acceleration X and Y. |
8 | TV State Debug (0x...) | Torque Vectoring state, delta moment Z (delta_Mz), and slip control state. |
9 | Slip Control Debug (0x...) | Reference slip ratios (kappa_ref) and maximum torques (tmax) for left and right wheels. |
