[WIP] SDC screen

This hasn't really been tested yet and sometimes looks weird.
This commit is contained in:
2023-09-30 10:11:42 +02:00
parent 61656942f9
commit 698c6a24c4
26 changed files with 784 additions and 156 deletions

View File

@ -110,6 +110,9 @@ typedef struct {
Mission active_mission;
int sdc_closed;
int pdu_sdc_active;
int imd_ok;
int sdcl_state[3];
R2DProgress r2d_progress;
struct {
@ -172,6 +175,7 @@ typedef struct {
uint32_t last_jetson_msg;
uint32_t last_epsc_msg;
int as_ok;
float desired_angle;
float measured_angle;
float desired_speed;

View File

@ -15,6 +15,8 @@
#define CAN_ID_AMS_SLAVE_PANIC 0x9
#define CAN_ID_AMS_STATUS 0xA
#define CAN_ID_AMS_ERROR 0xC
#define CAN_ID_SDCL_TX 0x10
#define CAN_ID_PDU_RESPONSE 0xC9
#define CAN_ID_JETSON_TX 0xE1
#define CAN_ID_ABX_DRIVER 0x101
#define CAN_ID_ABX_TIMINGS 0x102
@ -36,6 +38,11 @@
#define CAN_ID_SHUNT_VOLTAGE2 0x523
#define CAN_AMS_STATUS_VOLTAGE_FACTOR 1e-4
#define CAN_AMS_STATUS_TEMP_FACTOR 0.0625
#define CAN_SDCL_STATE_1_MASK (1 << 1)
#define CAN_SDCL_STATE_2_MASK (1 << 2)
#define CAN_SDCL_STATE_3_MASK (1 << 3)
#define CAN_PDU_RESPONSE_SDC_TX_MASK (1 << 4)
#define CAN_JETSON_TX_AS_OK_MASK (1 << 1)
#define CAN_JETSON_TX_ANGLE_FACTOR 0.00784314f
#define CAN_JETSON_TX_SPEED_FACTOR (0.2 * 3.6)
#define CAN_ABX_DRIVER_SPEED_FACTOR (0.2 * 3.6)
@ -53,6 +60,8 @@ void vehicle_thread_entry(ULONG hfdcan_addr) {
ftcan_add_filter(CAN_ID_AMS_SLAVE_PANIC, 0x7FF);
ftcan_add_filter(CAN_ID_AMS_STATUS, 0x7FF);
ftcan_add_filter(CAN_ID_AMS_ERROR, 0x7FF);
ftcan_add_filter(CAN_ID_SDCL_TX, 0x7FF);
ftcan_add_filter(CAN_ID_PDU_RESPONSE, 0x7FF);
ftcan_add_filter(CAN_ID_JETSON_TX, 0x7FF);
ftcan_add_filter(CAN_ID_ABX_DRIVER, 0x7FF);
ftcan_add_filter(CAN_ID_ABX_TIMINGS, 0x7FF);
@ -119,16 +128,26 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR;
vehicle_state.max_cell_temp =
ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR;
vehicle_state.imd_ok = (data[6] >> 7);
// TODO: Separate temperatures for left and right side of battery
vehicle_state.temps.bat_l = vehicle_state.max_cell_temp;
vehicle_state.temps.bat_r = vehicle_state.max_cell_temp;
break;
case CAN_ID_SDCL_TX:
vehicle_state.sdcl_state[0] = data[0] & CAN_SDCL_STATE_1_MASK;
vehicle_state.sdcl_state[1] = data[0] & CAN_SDCL_STATE_2_MASK;
vehicle_state.sdcl_state[2] = data[0] & CAN_SDCL_STATE_3_MASK;
break;
case CAN_ID_PDU_RESPONSE:
vehicle_state.pdu_sdc_active = data[0] & CAN_PDU_RESPONSE_SDC_TX_MASK;
break;
case CAN_ID_AMS_ERROR:
vehicle_state.last_ams_error.kind = data[0];
vehicle_state.last_ams_error.arg = data[1];
break;
case CAN_ID_JETSON_TX:
vehicle_state.last_jetson_msg = HAL_GetTick();
vehicle_state.as_ok = data[0] & CAN_JETSON_TX_AS_OK_MASK;
vehicle_state.desired_speed =
((int8_t)data[1]) * CAN_JETSON_TX_SPEED_FACTOR;
vehicle_state.desired_angle =

View File

@ -1,6 +1,6 @@
#include "vehicle_state.h"
VehicleState vehicle_state = {0};
VehicleState vehicle_state;
const char *inichkstate_str(IniChkState state) {
switch (vehicle_state.ini_chk_state) {