From ccdc70af8299663909f010f7a2191bf27e0eb227 Mon Sep 17 00:00:00 2001 From: Aditya Anand <90068582+AdityaAsGithub@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:23:47 -0400 Subject: [PATCH] Bug/anand89/main sdc ws (#117) * Changes from testing * Can Change * Uncomment apps, final changes --------- Co-authored-by: AdityaAsGithub --- common/daq/can_config.json | 44 ++++++++ common/daq/per_dbc.dbc | 32 ++++++ common/phal_F4_F7/can/can.c | 3 + common/phal_F4_F7/can/can.h | 1 + common/phal_F4_F7/usart/usart.c | 2 +- source/a_box/main.c | 19 +++- source/dashboard/can/can_parse.h | 34 ++++++ source/dashboard/lcd/lcd.c | 102 +++++++++--------- source/dashboard/main.c | 55 +++++++++- source/dashboard/pedals/pedals.c | 28 ++--- source/l4_testing/can/can_parse.h | 8 +- source/main_module/can/can_parse.h | 35 ++++++ source/main_module/car/car.c | 17 ++- source/main_module/car/car.h | 1 + source/main_module/main.c | 51 ++++++++- .../main_module/wheel_speeds/wheel_speeds.h | 9 +- 16 files changed, 356 insertions(+), 85 deletions(-) diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 0a3796e3..635f8bef 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -55,6 +55,28 @@ "msg_id_override": "0x7C0", "is_normal":true }, + { + "msg_name": "load_sensor_readings", + "msg_desc": "Load Sensor readings from left and right", + "signals": [ + {"sig_name": "left_load_sensor", "type": "float", "unit": "N"}, + {"sig_name": "right_load_sensor", "type": "float", "unit": "N"} + ], + "msg_period": 15, + "msg_hlp": 4, + "msg_pgn": 1000 + }, + { + "msg_name": "shock_rear", + "msg_desc": "Load Sensor readings from left and right", + "signals": [ + {"sig_name": "left_shock", "type": "uint16_t", "unit": "mm"}, + {"sig_name": "right_shock", "type": "uint16_t", "unit": "mm"} + ], + "msg_period": 15, + "msg_hlp": 4, + "msg_pgn": 1020 + }, { "msg_name": "mcu_status", "msg_desc": "performance metrics of MCU", @@ -624,6 +646,28 @@ "msg_hlp":4, "msg_pgn":10 }, + { + "msg_name": "shock_front", + "msg_desc": "Load Sensor readings from left and right", + "signals": [ + {"sig_name": "left_shock", "type": "uint16_t", "unit": "mm"}, + {"sig_name": "right_shock", "type": "uint16_t", "unit": "mm"} + ], + "msg_period": 15, + "msg_hlp": 4, + "msg_pgn": 1015 + }, + { + "msg_name": "load_sensor_readings_dash", + "msg_desc": "Load Sensor readings from left and right", + "signals": [ + {"sig_name": "left_load_sensor", "type": "float", "unit": "N"}, + {"sig_name": "right_load_sensor", "type": "float", "unit": "N"} + ], + "msg_period": 15, + "msg_hlp": 4, + "msg_pgn": 1010 + }, { "msg_name": "cooling_driver_request", "msg_desc": "Cooling Pump/Fan requests from Dash LCD", diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 99e313fb..2db353fe 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -55,6 +55,14 @@ BO_ 1984 LWS_Config: 2 Main_Module SG_ Reserved_1 : 3|5@1+ (1,0) [0|0] "" Vector__XXX SG_ CCW : 0|3@1+ (1,0) [0|0] "" Vector__XXX +BO_ 2415983105 load_sensor_readings: 8 Main_Module + SG_ right_load_sensor : 32|32@1- (1,0) [0|0] "N" Vector__XXX + SG_ left_load_sensor : 0|32@1- (1,0) [0|0] "N" Vector__XXX + +BO_ 2415984385 shock_rear: 4 Main_Module + SG_ right_shock : 16|16@1+ (1,0) [0|0] "mm" Vector__XXX + SG_ left_shock : 0|16@1+ (1,0) [0|0] "mm" Vector__XXX + BO_ 2415925633 mcu_status: 4 Main_Module SG_ sched_error : 24|8@1+ (1,0) [0|0] "" Vector__XXX SG_ background_use : 16|8@1+ (1,0) [0|0] "" Vector__XXX @@ -327,6 +335,14 @@ BO_ 2415919749 raw_throttle_brake: 8 Dashboard SG_ throttle_right : 12|12@1+ (0.02442,0) [0|0] "%" Vector__XXX SG_ throttle : 0|12@1+ (0.02442,0) [0|0] "%" Vector__XXX +BO_ 2415984069 shock_front: 4 Dashboard + SG_ right_shock : 16|16@1+ (1,0) [0|0] "mm" Vector__XXX + SG_ left_shock : 0|16@1+ (1,0) [0|0] "mm" Vector__XXX + +BO_ 2415983749 load_sensor_readings_dash: 8 Dashboard + SG_ right_load_sensor : 32|32@1- (1,0) [0|0] "N" Vector__XXX + SG_ left_load_sensor : 0|32@1- (1,0) [0|0] "N" Vector__XXX + BO_ 2348810949 cooling_driver_request: 5 Dashboard SG_ batt_fan : 32|8@1+ (1,0) [0|100] "%" Vector__XXX SG_ batt_pump2 : 24|8@1+ (1,0) [0|0] "" Vector__XXX @@ -631,6 +647,12 @@ CM_ BO_ 1984 "Steering sensor configuration"; CM_ SG_ 1984 Reserved_2 ""; CM_ SG_ 1984 Reserved_1 ""; CM_ SG_ 1984 CCW ""; +CM_ BO_ 2415983105 "Load Sensor readings from left and right"; +CM_ SG_ 2415983105 right_load_sensor ""; +CM_ SG_ 2415983105 left_load_sensor ""; +CM_ BO_ 2415984385 "Load Sensor readings from left and right"; +CM_ SG_ 2415984385 right_shock ""; +CM_ SG_ 2415984385 left_shock ""; CM_ BO_ 2415925633 "performance metrics of MCU"; CM_ SG_ 2415925633 sched_error "PSCHED Error Flags (bit #) 0 - N/A @@ -864,6 +886,12 @@ CM_ SG_ 2415919749 brake_right ""; CM_ SG_ 2415919749 brake ""; CM_ SG_ 2415919749 throttle_right ""; CM_ SG_ 2415919749 throttle ""; +CM_ BO_ 2415984069 "Load Sensor readings from left and right"; +CM_ SG_ 2415984069 right_shock ""; +CM_ SG_ 2415984069 left_shock ""; +CM_ BO_ 2415983749 "Load Sensor readings from left and right"; +CM_ SG_ 2415983749 right_load_sensor ""; +CM_ SG_ 2415983749 left_load_sensor ""; CM_ BO_ 2348810949 "Cooling Pump/Fan requests from Dash LCD"; CM_ SG_ 2348810949 batt_fan ""; CM_ SG_ 2348810949 batt_pump2 ""; @@ -1084,6 +1112,10 @@ VAL_ 2415925569 rear_left_motor_link 0 "disconnected" 1 "attempting" 2 "verifyin VAL_ 2415925569 rear_left_motor 0 "disconnected" 1 "connected" 2 "config" 3 "error" ; VAL_ 2347693088 car_state 0 "ready2go" 1 "flipped" 2 "flying" 3 "lightspeed" ; VAL_ 2347693089 car_state2 0 "ready2go" 1 "flipped" 2 "flying" 3 "lightspeed" ; +SIG_VALTYPE_ 2415983105 left_load_sensor : 1; +SIG_VALTYPE_ 2415983105 right_load_sensor : 1; +SIG_VALTYPE_ 2415983749 left_load_sensor : 1; +SIG_VALTYPE_ 2415983749 right_load_sensor : 1; SIG_VALTYPE_ 2348810751 left_speed : 1; SIG_VALTYPE_ 2348810751 right_speed : 1; SIG_VALTYPE_ 2483028349 test_sig5_3 : 1; diff --git a/common/phal_F4_F7/can/can.c b/common/phal_F4_F7/can/can.c index a4d609a9..37785398 100644 --- a/common/phal_F4_F7/can/can.c +++ b/common/phal_F4_F7/can/can.c @@ -87,6 +87,9 @@ bool PHAL_initCAN(CAN_TypeDef* bus, bool test_mode, uint32_t bit_rate) case 24000000: bus->BTR = PHAL_CAN_24MHz_250k; break; + case 36000000: + bus->BTR = PHAL_CAN_36MHz_250k; + break; default: return false; } diff --git a/common/phal_F4_F7/can/can.h b/common/phal_F4_F7/can/can.h index 2ba11293..5b5b6f2c 100644 --- a/common/phal_F4_F7/can/can.h +++ b/common/phal_F4_F7/can/can.h @@ -37,6 +37,7 @@ #define PHAL_CAN_16MHz_250k (0x003a0003) // sample point = 75% #define PHAL_CAN_24MHz_250k (0x003a0005) // sample point = 75% +#define PHAL_CAN_36MHz_250k (0x003a0008) // sample point = 75% typedef struct { diff --git a/common/phal_F4_F7/usart/usart.c b/common/phal_F4_F7/usart/usart.c index 138cbcc5..771fccac 100644 --- a/common/phal_F4_F7/usart/usart.c +++ b/common/phal_F4_F7/usart/usart.c @@ -114,7 +114,7 @@ bool PHAL_initUSART(usart_init_t* handle, const uint32_t fck) // // Set CR3 parameters handle->periph->CR3 |= handle->obsample << USART_CR3_ONEBIT_Pos; - handle->periph->CR3 |= USART_CR3_EIE; + // handle->periph->CR3 |= USART_CR3_EIE; // Enable peripheral for use handle->periph->CR1 |= USART_CR1_UE; diff --git a/source/a_box/main.c b/source/a_box/main.c index 82113fe7..67eaa4cf 100644 --- a/source/a_box/main.c +++ b/source/a_box/main.c @@ -150,8 +150,7 @@ int main (void) // PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, 1); - if (1 != PHAL_initCAN(CAN1, false, 250000)) - PHAL_FaultHandler(); + // for (uint16_t dimitri_is_not_better_than_me = 0; dimitri_is_not_better_than_me < 1000; dimitri_is_not_better_than_me++) // { @@ -212,7 +211,7 @@ int main (void) void preflightChecks(void) { static uint16_t state; - + uint8_t charger_speed_def = 0; switch (state++) { @@ -222,6 +221,20 @@ void preflightChecks(void) case 1: initFaultLibrary(FAULT_NODE_NAME, &q_tx_can1_s[0], ID_FAULT_SYNC_A_BOX); break; + case 700: + charger_speed_def = PHAL_readGPIO(BMS_CHARGE_ENABLE_Port, BMS_CHARGE_ENABLE_Pin); + uint8_t speed_2 = PHAL_readGPIO(BMS_CHARGER_SAFETY_Port, BMS_CHARGER_SAFETY_Pin); + if (charger_speed_def) + { + if (1 != PHAL_initCAN(CAN1, false, 250000)) + PHAL_FaultHandler(); + } + else + { + if (1 != PHAL_initCAN(CAN1, false, 500000)) + PHAL_FaultHandler(); + } + break; default: if (state > 750) { diff --git a/source/dashboard/can/can_parse.h b/source/dashboard/can/can_parse.h index 34b0b858..6309dc9a 100644 --- a/source/dashboard/can/can_parse.h +++ b/source/dashboard/can/can_parse.h @@ -19,9 +19,19 @@ // Make this match the node name within the can_config.json #define NODE_NAME "Dashboard" +// Used to represent a float as 32 bits +typedef union { + float f; + uint32_t u; +} FloatConvert_t; +#define FLOAT_TO_UINT32(float_) (((FloatConvert_t) float_).u) +#define UINT32_TO_FLOAT(uint32_) (((FloatConvert_t) ((uint32_t) uint32_)).f) + // Message ID definitions /* BEGIN AUTO ID DEFS */ #define ID_RAW_THROTTLE_BRAKE 0x10000285 +#define ID_SHOCK_FRONT 0x1000fdc5 +#define ID_LOAD_SENSOR_READINGS_DASH 0x1000fc85 #define ID_COOLING_DRIVER_REQUEST 0xc0002c5 #define ID_FILT_THROTTLE_BRAKE 0x4000245 #define ID_START_BUTTON 0x4000005 @@ -58,6 +68,8 @@ // Message DLC definitions /* BEGIN AUTO DLC DEFS */ #define DLC_RAW_THROTTLE_BRAKE 8 +#define DLC_SHOCK_FRONT 4 +#define DLC_LOAD_SENSOR_READINGS_DASH 8 #define DLC_COOLING_DRIVER_REQUEST 5 #define DLC_FILT_THROTTLE_BRAKE 3 #define DLC_START_BUTTON 1 @@ -103,6 +115,20 @@ data_a->raw_throttle_brake.brake_pot = brake_pot_;\ canTxSendToBack(&msg);\ } while(0) +#define SEND_SHOCK_FRONT(left_shock_, right_shock_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_SHOCK_FRONT, .DLC=DLC_SHOCK_FRONT, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->shock_front.left_shock = left_shock_;\ + data_a->shock_front.right_shock = right_shock_;\ + canTxSendToBack(&msg);\ + } while(0) +#define SEND_LOAD_SENSOR_READINGS_DASH(left_load_sensor_, right_load_sensor_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_LOAD_SENSOR_READINGS_DASH, .DLC=DLC_LOAD_SENSOR_READINGS_DASH, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->load_sensor_readings_dash.left_load_sensor = FLOAT_TO_UINT32(left_load_sensor_);\ + data_a->load_sensor_readings_dash.right_load_sensor = FLOAT_TO_UINT32(right_load_sensor_);\ + canTxSendToBack(&msg);\ + } while(0) #define SEND_COOLING_DRIVER_REQUEST(dt_pump_, dt_fan_, batt_pump_, batt_pump2_, batt_fan_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_COOLING_DRIVER_REQUEST, .DLC=DLC_COOLING_DRIVER_REQUEST, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ @@ -220,6 +246,14 @@ typedef union { uint64_t brake_right: 12; uint64_t brake_pot: 12; } raw_throttle_brake; + struct { + uint64_t left_shock: 16; + uint64_t right_shock: 16; + } shock_front; + struct { + uint64_t left_load_sensor: 32; + uint64_t right_load_sensor: 32; + } load_sensor_readings_dash; struct { uint64_t dt_pump: 8; uint64_t dt_fan: 8; diff --git a/source/dashboard/lcd/lcd.c b/source/dashboard/lcd/lcd.c index db0acbe0..985cbbeb 100644 --- a/source/dashboard/lcd/lcd.c +++ b/source/dashboard/lcd/lcd.c @@ -16,13 +16,13 @@ char *errorText; // Pointer to data to display for the Erro extern uint16_t filtered_pedals; // Global from pedals module for throttle display extern q_handle_t q_tx_can; // Global queue for CAN tx extern q_handle_t q_fault_history; // Global queue from fault library for fault history -volatile settings_t settings; // Data for the settings page -volatile tv_settings_t tv_settings; // Data for the tvsettings page +volatile settings_t settings; // Data for the settings page +volatile tv_settings_t tv_settings; // Data for the tvsettings page volatile driver_config_t driver_config; // Data for the driver page extern lcd_t lcd_data; uint8_t fault_time_displayed; // Amount of units of time that the fault has been shown to the driver -// Call initially to ensure the LCD is initialized to the proper value - +// Call initially to ensure the LCD is initialized to the proper value - // should be replaced with the struct prev page stuff eventually bool zeroEncoder(volatile int8_t* start_pos) { @@ -42,7 +42,7 @@ bool zeroEncoder(volatile int8_t* start_pos) // Preflight will be shown on power on, then reset to RACE void initLCD() { curr_page = PAGE_RACE; - prev_page = PAGE_PREFLIGHT; + prev_page = PAGE_PREFLIGHT; errorText = 0; settings = (settings_t) {0, 0, 0, 0, 0, 0, 0, 0}; sendFirsthalf = true; @@ -62,7 +62,7 @@ void updatePage() { return; } - // Parsed value represents: + // Parsed value represents: char parsed_value[3] = "\0"; // Parse the page that was passed into the function @@ -130,7 +130,7 @@ void updatePage() { // Establish hover position tv_settings.curr_hover = TV_INTENSITY_HOVER; - + // Set background colors set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_HOVER_BG); set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); @@ -138,10 +138,10 @@ void updatePage() { set_value(TV_ENABLE_OP, NXT_BACKGROUND_COLOR, TV_BG); // Set displayed data - set_value(TV_INTENSITY_FLT, NXT_VALUE, tv_settings.tv_intensity_val); - set_value(TV_PROPORTION_FLT, NXT_VALUE, tv_settings.tv_p_val); - set_text(TV_DEAD_TXT, NXT_TEXT, int_to_char(tv_settings.tv_deadband_val, parsed_value)); - bzero(parsed_value, 3); + set_value(TV_INTENSITY_FLT, NXT_VALUE, tv_settings.tv_intensity_val); + set_value(TV_PROPORTION_FLT, NXT_VALUE, tv_settings.tv_p_val); + set_text(TV_DEAD_TXT, NXT_TEXT, int_to_char(tv_settings.tv_deadband_val, parsed_value)); + bzero(parsed_value, 3); set_value(TV_ENABLE_OP, NXT_VALUE, tv_settings.tv_enable_selected); break; @@ -158,7 +158,7 @@ void updatePage() { set_text(ERR_TXT, NXT_TEXT, errorText); break; case PAGE_RACE: - prev_page = PAGE_RACE; + prev_page = PAGE_RACE; set_page(RACE_STRING); break; case PAGE_DATA: @@ -176,9 +176,9 @@ void updatePage() { set_value(DT_FAN_VAL, NXT_FONT_COLOR, SETTINGS_BAR_BG); // Set color for t8 (background of bar?) set_text(DT_FAN_VAL, NXT_TEXT, int_to_char(settings.d_fan_val, parsed_value)); // Set fan value for t8 bzero(parsed_value, 3); // Clear our char buffer - - // Set drivetrain pump selector color - if (settings.d_pump_selected) { + + // Set drivetrain pump selector color + if (settings.d_pump_selected) { set_value(DT_PUMP_OP, NXT_FONT_COLOR, SETTINGS_UV_SELECT); } else { @@ -212,7 +212,7 @@ void updatePage() { // Set battery fan bar, text, color set_value(B_FAN1_BAR, NXT_VALUE, settings.b_fan_val); set_text(B_FAN1_VAL, NXT_TEXT, int_to_char(settings.b_fan_val, parsed_value)); - bzero(parsed_value, 3); + bzero(parsed_value, 3); set_value(B_FAN1_VAL, NXT_FONT_COLOR, SETTINGS_BAR_BG); break; @@ -322,14 +322,14 @@ void moveUp() { tv_settings.tv_intensity_val = (tv_settings.tv_intensity_val + 1) % 100; // Update the page items - set_value(TV_INTENSITY_FLT, NXT_VALUE, tv_settings.tv_intensity_val); + set_value(TV_INTENSITY_FLT, NXT_VALUE, tv_settings.tv_intensity_val); } else if (tv_settings.curr_hover == TV_INTENSITY_HOVER) { // Wrap around to enable tv_settings.curr_hover = TV_ENABLE_HOVER; - // Update the background + // Update the background set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_DEAD_TXT, NXT_BACKGROUND_COLOR, TV_BG); @@ -341,7 +341,7 @@ void moveUp() { tv_settings.tv_p_val = (tv_settings.tv_p_val + 1) % 100; // Update the page items - set_value(TV_PROPORTION_FLT, NXT_VALUE, tv_settings.tv_p_val); + set_value(TV_PROPORTION_FLT, NXT_VALUE, tv_settings.tv_p_val); } else if (tv_settings.curr_hover == TV_P_HOVER) @@ -359,10 +359,10 @@ void moveUp() { { // Increase the deadband value tv_settings.tv_deadband_val = (tv_settings.tv_deadband_val + 1) % 30; - + // Update the page items - set_text(TV_DEAD_TXT, NXT_TEXT, int_to_char(tv_settings.tv_deadband_val, parsed_value)); - bzero(parsed_value, 3); + set_text(TV_DEAD_TXT, NXT_TEXT, int_to_char(tv_settings.tv_deadband_val, parsed_value)); + bzero(parsed_value, 3); } else if (tv_settings.curr_hover == TV_DEADBAND_HOVER) @@ -424,7 +424,7 @@ void moveUp() { settings.d_fan_val = (settings.d_fan_val == 100) ? 0 : settings.d_fan_val + 10; set_value(DT_FAN_BAR, NXT_VALUE, settings.d_fan_val); set_text(DT_FAN_VAL, NXT_TEXT, int_to_char(settings.d_fan_val, parsed_value)); - bzero(parsed_value, 3); + bzero(parsed_value, 3); set_value(DT_FAN_VAL, NXT_FONT_COLOR, BLACK); break; case FAN1_SELECT: @@ -433,7 +433,7 @@ void moveUp() { settings.b_fan_val = (settings.b_fan_val == 100) ? 0 : settings.b_fan_val + 10; set_value(B_FAN1_BAR, NXT_VALUE, settings.b_fan_val); set_text(B_FAN1_VAL, NXT_TEXT, int_to_char(settings.b_fan_val, parsed_value)); - bzero(parsed_value, 3); + bzero(parsed_value, 3); set_value(B_FAN1_VAL, NXT_FONT_COLOR, BLACK); break; } @@ -445,7 +445,7 @@ void moveUp() { // Wrap around to enable driver_config.curr_hover = DRIVER_LUKE_SELECT; driver_config.curr_select = DRIVER_LUKE_SELECT; - // Update the background + // Update the background set_value(DRIVER_DEFAULT_TXT, NXT_BACKGROUND_COLOR, TV_BG); set_value(DRIVER_TYLER_TXT, NXT_BACKGROUND_COLOR, TV_BG); set_value(DRIVER_RUHAAN_TXT, NXT_BACKGROUND_COLOR, TV_BG); @@ -499,14 +499,14 @@ void moveDown() { } // Update the page item - set_value(TV_INTENSITY_FLT, NXT_VALUE, tv_settings.tv_intensity_val); + set_value(TV_INTENSITY_FLT, NXT_VALUE, tv_settings.tv_intensity_val); } else if (tv_settings.curr_hover == TV_INTENSITY_HOVER) { // Scroll down to P tv_settings.curr_hover = TV_P_HOVER; - // Update the background + // Update the background set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_HOVER_BG); set_value(TV_DEAD_TXT, NXT_BACKGROUND_COLOR, TV_BG); @@ -525,7 +525,7 @@ void moveDown() { } // Update the page items - set_value(TV_PROPORTION_FLT, NXT_VALUE, tv_settings.tv_p_val); + set_value(TV_PROPORTION_FLT, NXT_VALUE, tv_settings.tv_p_val); } else if (tv_settings.curr_hover == TV_P_HOVER) @@ -552,8 +552,8 @@ void moveDown() { } // Update the page items - set_text(TV_DEAD_TXT, NXT_TEXT, int_to_char(tv_settings.tv_deadband_val, parsed_value)); - bzero(parsed_value, 3); + set_text(TV_DEAD_TXT, NXT_TEXT, int_to_char(tv_settings.tv_deadband_val, parsed_value)); + bzero(parsed_value, 3); } else if (tv_settings.curr_hover == TV_DEADBAND_HOVER) @@ -615,7 +615,7 @@ void moveDown() { settings.d_fan_val = (settings.d_fan_val == 0) ? 100 : settings.d_fan_val - 10; set_value(DT_FAN_BAR, NXT_VALUE, settings.d_fan_val); set_text(DT_FAN_VAL, NXT_TEXT, int_to_char(settings.d_fan_val, parsed_value)); - bzero(parsed_value, 3); + bzero(parsed_value, 3); set_value(DT_FAN_VAL, NXT_FONT_COLOR, BLACK); break; case FAN1_SELECT: @@ -624,7 +624,7 @@ void moveDown() { settings.b_fan_val = (settings.b_fan_val == 0) ? 100 : settings.b_fan_val - 10; set_value(B_FAN1_BAR, NXT_VALUE, settings.b_fan_val); set_text(B_FAN1_VAL, NXT_TEXT, int_to_char(settings.b_fan_val, parsed_value)); - bzero(parsed_value, 3); + bzero(parsed_value, 3); set_value(B_FAN1_VAL, NXT_FONT_COLOR, BLACK); break; } @@ -635,7 +635,7 @@ void moveDown() { { driver_config.curr_hover = DRIVER_TYLER_SELECT; driver_config.curr_select = DRIVER_TYLER_SELECT; - // Update the background + // Update the background set_value(DRIVER_DEFAULT_TXT, NXT_BACKGROUND_COLOR, TV_BG); set_value(DRIVER_TYLER_TXT, NXT_BACKGROUND_COLOR, TV_HOVER_BG); set_value(DRIVER_RUHAAN_TXT, NXT_BACKGROUND_COLOR, TV_BG); @@ -689,7 +689,7 @@ void selectItem() { else if (curr_page == PAGE_TVSETTINGS) { // So if we hit select on an already selected item, unselect it (switch to hover) - + if (tv_settings.curr_hover == TV_INTENSITY_HOVER) { tv_settings.curr_hover = TV_INTENSITY_SELECTED; @@ -703,7 +703,7 @@ void selectItem() { else if (tv_settings.curr_hover == TV_INTENSITY_SELECTED) { // "submit" -> CAN payload will update automatically? decide - // Think about edge case when the user leaves the page? Can they without unselecting -> no. What if fault? + // Think about edge case when the user leaves the page? Can they without unselecting -> no. What if fault? tv_settings.curr_hover = TV_INTENSITY_HOVER; set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_HOVER_BG); set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); @@ -714,7 +714,7 @@ void selectItem() { else if (tv_settings.curr_hover == TV_P_HOVER) { tv_settings.curr_hover = TV_P_SELECTED; - set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, ORANGE); + set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, ORANGE); set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_DEAD_TXT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_ENABLE_OP, NXT_BACKGROUND_COLOR, TV_BG); @@ -730,7 +730,7 @@ void selectItem() { else if (tv_settings.curr_hover == TV_DEADBAND_HOVER) { tv_settings.curr_hover = TV_DEADBAND_SELECTED; - set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); + set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_DEAD_TXT, NXT_BACKGROUND_COLOR, ORANGE); set_value(TV_ENABLE_OP, NXT_BACKGROUND_COLOR, TV_BG); @@ -738,21 +738,21 @@ void selectItem() { else if (tv_settings.curr_hover == TV_DEADBAND_SELECTED) { tv_settings.curr_hover = TV_DEADBAND_HOVER; - set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); + set_value(TV_PROPORTION_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_INTENSITY_FLT, NXT_BACKGROUND_COLOR, TV_BG); set_value(TV_DEAD_TXT, NXT_BACKGROUND_COLOR, TV_HOVER_BG); set_value(TV_ENABLE_OP, NXT_BACKGROUND_COLOR, TV_BG); } else if (tv_settings.curr_hover == TV_ENABLE_HOVER) - { + { // Don't change the curr_hover // Toggle the option tv_settings.tv_enable_selected = (tv_settings.tv_enable_selected == 0); - + // Set the option set_value(TV_ENABLE_OP, NXT_VALUE, tv_settings.tv_enable_selected); - + // Update CAN as necessary } else @@ -884,7 +884,7 @@ void updateFaultDisplay() { // Track if we alrady have this fault in the display buffer bool faultAlreadyInBuffer = false; - bool pageUpdateRequired = false; + bool pageUpdateRequired = false; bool faultWasInserted = false; // Process up to 5 faults each time for now @@ -899,7 +899,7 @@ void updateFaultDisplay() { // Iterate through fault buffer for existance of fault already for (int j = 0; j < 5; j++) { - // This should be based off of the queue item not anything else + // This should be based off of the queue item not anything else if (fault_buf[j] == next_to_check) { faultAlreadyInBuffer = true; @@ -913,17 +913,17 @@ void updateFaultDisplay() { // try all the slots for inserting the fault for (uint8_t k = 0; k < 5; k++) { - // If fault is currently not in our fault buffer, replace it if the current fault is cleared, + // If fault is currently not in our fault buffer, replace it if the current fault is cleared, // or if the new fault has higher priority if (fault_buf[cur_fault_buf_ndx] != 0xFFFF) { - if ((checkFault(fault_buf[cur_fault_buf_ndx]) == false ) || + if ((checkFault(fault_buf[cur_fault_buf_ndx]) == false ) || (faultArray[next_to_check].priority > faultArray[fault_buf[cur_fault_buf_ndx]].priority)) { fault_buf[cur_fault_buf_ndx] = next_to_check; - faultWasInserted = true; - pageUpdateRequired = true; - break; + faultWasInserted = true; + pageUpdateRequired = true; + break; } } else @@ -931,12 +931,12 @@ void updateFaultDisplay() { // Empty slot just insert fault_buf[cur_fault_buf_ndx] = next_to_check; faultWasInserted = true; - pageUpdateRequired = true; + pageUpdateRequired = true; break; } cur_fault_buf_ndx = (cur_fault_buf_ndx + 1) % 5; } - + // Put back in the queue if it wasn't processed if (false == faultWasInserted) { @@ -1043,7 +1043,7 @@ void update_data_pages() { set_text(BATT_TEMP, NXT_TEXT, "S"); } else { - set_text(BATT_TEMP, NXT_TEXT, int_to_char((can_data.max_cell_temp.max_temp / 100), parsed_value)); + set_text(BATT_TEMP, NXT_TEXT, int_to_char((can_data.max_cell_temp.max_temp / 10), parsed_value)); bzero(parsed_value, 3); } if (can_data.orion_currents_volts.stale) { @@ -1267,7 +1267,7 @@ void updateSDCDashboard() set_value(SDC_INER_STAT_TXT, NXT_BACKGROUND_COLOR, RED); } break; - + case 2: if (can_data.sdc_status.c_estop) { diff --git a/source/dashboard/main.c b/source/dashboard/main.c index 47337698..e186bc08 100644 --- a/source/dashboard/main.c +++ b/source/dashboard/main.c @@ -158,7 +158,9 @@ void enableInterrupts(); void encoder_ISR(); void pollDashboardInput(); void sendBrakeStatus(); - +void interpretLoadSensor(void); +void send_shockpots(); +float voltToForce(uint16_t load_read); // Communication queues q_handle_t q_tx_usart; @@ -205,6 +207,8 @@ int main (void){ taskCreate(pedalsPeriodic, 15); taskCreate(pollDashboardInput, 25); taskCreate(heartBeatTask, 100); + taskCreate(send_shockpots, 15); + taskCreate(interpretLoadSensor, 15); taskCreate(update_data_pages, 200); taskCreate(sendTVParameters, 4000); taskCreate(updateSDCDashboard, 500); @@ -269,6 +273,20 @@ void preflightChecks(void) { } } + +#define POT_VOLT_MAX_DIST_MM 0 +#define POT_VOLT_MIN_DIST_MM 4095 + +void send_shockpots() +{ + uint16_t shock_l = raw_adc_values.shock_left; + uint16_t shock_r = raw_adc_values.shock_right; + //Scale from raw 12bit adc to mm * 10 of linear pot travel + // shock_l = (POT_VOLT_MIN_DIST_MM * 10 - ((uint32_t) shock_l) * (POT_VOLT_MIN_DIST_MM - POT_VOLT_MAX_DIST_MM) * 10 / 4095); + // shock_r = (POT_VOLT_MIN_DIST_MM * 10 - ((uint32_t) shock_r) * (POT_VOLT_MIN_DIST_MM - POT_VOLT_MAX_DIST_MM) * 10 / 4095); + SEND_SHOCK_FRONT(shock_l, shock_r); +} + void preflightAnimation(void) { // Controls external LEDs since they are more visible when dash is in car static uint32_t time_ext; @@ -308,6 +326,41 @@ void preflightAnimation(void) { } } +#define SCALE_F = (1 + (3.4/6.6)) +float voltToForce(uint16_t load_read) { + /* + //Return in newtons + float v_out_load_l = adc_readings.load_l / 4095 * 3.3; + float v_out_load_r = adc_readings.load_r / 4095 * 3.3; + //voltage -> weight + //V_out = (V_in * R_2) / (R_1 + R_2) + //Solve for V_in + //R_1 = 3.4K + //R_2 = 6.6K + float v_in_load_l = (v_out_load_l * 10) / 6.6; + float v_in_load_r = (v_out_load_r * 10) / 6.6; + //voltage * 100 = mass + //weight (in newtons) = mass * g + float force_load_l = v_in_load_l * 100 * g; + float force_load_r = v_in_load_r * 100 * g; + */ + float g = 9.8; + // float val = ((load_read / 4095.0 * 3.3) * 10.0) + float val = ((load_read / 4095.0 * 3.3) * (1.0 + (3.4/6.6))); + // return ( val / 6.6) * 100.0 * g; + return val * 100.0 * g; +} + +void interpretLoadSensor(void) { + float force_load_l = voltToForce(raw_adc_values.load_l); + float force_load_r = voltToForce(raw_adc_values.load_r); + //send a can message w/ minimal force info + //every 15 milliseconds + SEND_LOAD_SENSOR_READINGS_DASH(force_load_l, force_load_r); + + +} + void heartBeatLED() { PHAL_toggleGPIO(HEART_LED_GPIO_Port, HEART_LED_Pin); diff --git a/source/dashboard/pedals/pedals.c b/source/dashboard/pedals/pedals.c index eaa4a121..b55a0306 100644 --- a/source/dashboard/pedals/pedals.c +++ b/source/dashboard/pedals/pedals.c @@ -6,7 +6,7 @@ pedals_t pedals = {0}; uint16_t thtl_limit = 4096; -pedal_calibration_t pedal_calibration = {.t1max=2022,.t1min=662, // WARNING: DAQ VARIABLE +pedal_calibration_t pedal_calibration = {.t1max=2022,.t1min=690, // WARNING: DAQ VARIABLE .t2max=1986,.t2min=610, // IF EEPROM ENABLED, .b1max=1490,.b1min=420, // VALUE WILL CHANGE .b2max=1240,.b2min=420, // 1400, 400 @@ -208,19 +208,19 @@ void pedalsPeriodic(void) // } // Both set at the same time - // if ((b1 >=. APPS_BRAKE_THRESHOLD && - // t1 >= APPS_THROTTLE_FAULT_THRESHOLD) || (checkFault(ID_APPS_BRAKE_FAULT) && t1 >= APPS_THROTTLE_CLEARFAULT_THRESHOLD)) - // { - // // set warning fault and treq could be 0 - // t2 = 0; - // t1 = 0; - // setFault(ID_APPS_BRAKE_FAULT, true); - // // Later - setup - // } - // else if (t1 <= APPS_THROTTLE_CLEARFAULT_THRESHOLD) - // { - // setFault(ID_APPS_BRAKE_FAULT, false); - // } + if ((b1 >= APPS_BRAKE_THRESHOLD && + t1 >= APPS_THROTTLE_FAULT_THRESHOLD) || (checkFault(ID_APPS_BRAKE_FAULT) && t1 >= APPS_THROTTLE_CLEARFAULT_THRESHOLD)) + { + // set warning fault and treq could be 0 + t2 = 0; + t1 = 0; + setFault(ID_APPS_BRAKE_FAULT, true); + // Later - setup + } + else if (t1 <= APPS_THROTTLE_CLEARFAULT_THRESHOLD) + { + setFault(ID_APPS_BRAKE_FAULT, false); + } //Fault States detected by Main Module, which will exit ready2drive // if (pedals.apps_faulted || pedals.bse_faulted || pedals.apps_brake_faulted) diff --git a/source/l4_testing/can/can_parse.h b/source/l4_testing/can/can_parse.h index fadccf62..fcb0076b 100644 --- a/source/l4_testing/can/can_parse.h +++ b/source/l4_testing/can/can_parse.h @@ -4,9 +4,9 @@ * @brief Parsing of CAN messages using auto-generated structures with bit-fields * @version 0.1 * @date 2021-09-15 - * + * * @copyright Copyright (c) 2021 - * + * */ #ifndef _CAN_PARSE_H_ #define _CAN_PARSE_H_ @@ -363,7 +363,7 @@ extern void send_fault(uint16_t id, bool latched); /** * @brief Setup queue and message filtering - * + * * @param q_rx_can RX buffer of CAN messages */ void initCANParse(q_handle_t* q_rx_can_a); @@ -377,7 +377,7 @@ void canRxUpdate(void); /** * @brief Process any rx message callbacks from the CAN Rx IRQ - * + * * @param rx rx data from message just recieved */ void canProcessRxIRQs(CanMsgTypeDef_t* rx); diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index 94f5556b..02c6d906 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -19,12 +19,23 @@ // Make this match the node name within the can_config.json #define NODE_NAME "Main_Module" + +// Used to represent a float as 32 bits +typedef union { + float f; + uint32_t u; +} FloatConvert_t; +#define FLOAT_TO_UINT32(float_) (((FloatConvert_t) float_).u) +#define UINT32_TO_FLOAT(uint32_) (((FloatConvert_t) ((uint32_t) uint32_)).f) + // Message ID definitions /* BEGIN AUTO ID DEFS */ #define ID_MAIN_HB 0xc001901 #define ID_COOLANT_TEMPS 0x10000881 #define ID_GEARBOX 0x10000901 #define ID_LWS_CONFIG 0x7c0 +#define ID_LOAD_SENSOR_READINGS 0x1000fa01 +#define ID_SHOCK_REAR 0x1000ff01 #define ID_MCU_STATUS 0x10001981 #define ID_MAIN_MODULE_CAN_STATS 0x10016301 #define ID_NUM_MC_SKIPS 0x10001b81 @@ -59,6 +70,8 @@ #define DLC_COOLANT_TEMPS 4 #define DLC_GEARBOX 2 #define DLC_LWS_CONFIG 2 +#define DLC_LOAD_SENSOR_READINGS 8 +#define DLC_SHOCK_REAR 4 #define DLC_MCU_STATUS 4 #define DLC_MAIN_MODULE_CAN_STATS 4 #define DLC_NUM_MC_SKIPS 4 @@ -120,6 +133,20 @@ data_a->LWS_Config.Reserved_2 = Reserved_2_;\ canTxSendToBack(&msg);\ } while(0) +#define SEND_LOAD_SENSOR_READINGS(left_load_sensor_, right_load_sensor_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_LOAD_SENSOR_READINGS, .DLC=DLC_LOAD_SENSOR_READINGS, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->load_sensor_readings.left_load_sensor = FLOAT_TO_UINT32(left_load_sensor_);\ + data_a->load_sensor_readings.right_load_sensor = FLOAT_TO_UINT32(right_load_sensor_);\ + canTxSendToBack(&msg);\ + } while(0) +#define SEND_SHOCK_REAR(left_shock_, right_shock_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_SHOCK_REAR, .DLC=DLC_SHOCK_REAR, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->shock_rear.left_shock = left_shock_;\ + data_a->shock_rear.right_shock = right_shock_;\ + canTxSendToBack(&msg);\ + } while(0) #define SEND_MCU_STATUS(sched_skips_, foreground_use_, background_use_, sched_error_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_MCU_STATUS, .DLC=DLC_MCU_STATUS, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ @@ -313,6 +340,14 @@ typedef union { uint64_t Reserved_1: 5; uint64_t Reserved_2: 8; } LWS_Config; + struct { + uint64_t left_load_sensor: 32; + uint64_t right_load_sensor: 32; + } load_sensor_readings; + struct { + uint64_t left_shock: 16; + uint64_t right_shock: 16; + } shock_rear; struct { uint64_t sched_skips: 8; uint64_t foreground_use: 8; diff --git a/source/main_module/car/car.c b/source/main_module/car/car.c index 97512699..ea29e339 100644 --- a/source/main_module/car/car.c +++ b/source/main_module/car/car.c @@ -35,7 +35,7 @@ bool carInit() /* Set initial states */ car = (Car_t) {0}; // Everything to zero car.state = CAR_STATE_IDLE; - car.torque_src = CAR_TORQUE_RAW; + car.torque_src = CAR_TORQUE_THROT_MAP; car.regen_enabled = false; car.sdc_close = true; // We want to initialize SDC as "good" PHAL_writeGPIO(SDC_CTRL_GPIO_Port, SDC_CTRL_Pin, car.sdc_close); @@ -427,7 +427,7 @@ void parseMCDataPeriodic(void) // shock_l = (POT_VOLT_MIN_DIST_MM * 10 - ((uint32_t) shock_l) * (POT_VOLT_MIN_DIST_MM - POT_VOLT_MAX_DIST_MM) * 10 / 4095); // shock_r = (POT_VOLT_MIN_DIST_MM * 10 - ((uint32_t) shock_r) * (POT_VOLT_MIN_DIST_MM - POT_VOLT_MAX_DIST_MM) * 10 / 4095); - //SEND_REAR_WHEEL_DATA(wheel_speeds.left_kph_x100, wheel_speeds.right_kph_x100, + // SEND_REAR_WHEEL_DATA(wheel_speeds.left_kph_x100, wheel_speeds.right_kph_x100, // shock_l, shock_r); // uint16_t l_speed = (wheel_speeds.l->rad_s / (2*PI)); // uint16_t r_speed = (wheel_speeds.l->rad_s / (2*PI)); @@ -458,6 +458,19 @@ void parseMCDataPeriodic(void) } } +#define POT_VOLT_MAX_DIST_MM 0 +#define POT_VOLT_MIN_DIST_MM 4095 + +void send_shockpots() +{ + uint16_t shock_l = adc_readings.shock_l; + uint16_t shock_r = adc_readings.shock_r; + //Scale from raw 12bit adc to mm * 10 of linear pot travel + // shock_l = (POT_VOLT_MIN_DIST_MM * 10 - ((uint32_t) shock_l) * (POT_VOLT_MIN_DIST_MM - POT_VOLT_MAX_DIST_MM) * 10 / 4095); + // shock_r = (POT_VOLT_MIN_DIST_MM * 10 - ((uint32_t) shock_r) * (POT_VOLT_MIN_DIST_MM - POT_VOLT_MAX_DIST_MM) * 10 / 4095); + SEND_SHOCK_REAR(shock_l, shock_r); +} + /** * @brief Checks faults that should prevent * the car from driving, but are okay diff --git a/source/main_module/car/car.h b/source/main_module/car/car.h index d096137a..38bf608c 100644 --- a/source/main_module/car/car.h +++ b/source/main_module/car/car.h @@ -95,6 +95,7 @@ void parseMCDataPeriodic(void); void calibrateSteeringAngle(uint8_t* success); void monitorSDCPeriodic(void); void updateSDCFaults(void); +void send_shockpots(); // SDC Node defines #define SDC_MUX_HIGH_IDX 14 diff --git a/source/main_module/main.c b/source/main_module/main.c index d64859f1..030b0241 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -186,14 +186,15 @@ extern uint32_t APB2ClockRateHz; extern uint32_t AHBClockRateHz; extern uint32_t PLLClockRateHz; -#define TargetCoreClockrateHz 16000000 +#define TargetCoreClockrateHz 144000000 ClockRateConfig_t clock_config = { - .system_source =SYSTEM_CLOCK_SRC_HSI, - .vco_output_rate_target_hz =160000000, + .system_source =SYSTEM_CLOCK_SRC_PLL, + .pll_src =PLL_SRC_HSI16, + .vco_output_rate_target_hz =288000000, .system_clock_target_hz =TargetCoreClockrateHz, .ahb_clock_target_hz =(TargetCoreClockrateHz / 1), - .apb1_clock_target_hz =(TargetCoreClockrateHz / (1)), - .apb2_clock_target_hz =(TargetCoreClockrateHz / (1)), + .apb1_clock_target_hz =(TargetCoreClockrateHz / 4), + .apb2_clock_target_hz =(TargetCoreClockrateHz / 4), }; /* Function Prototypes */ @@ -204,6 +205,8 @@ void usartTxUpdate(void); void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf); void send_fault(uint16_t, bool); extern void HardFault_Handler(); +void interpretLoadSensor(void); +float voltToForce(uint16_t load_read); q_handle_t q_tx_usart_l; q_handle_t q_tx_usart_r; @@ -237,8 +240,10 @@ int main(void){ taskCreate(monitorSDCPeriodic, 20); taskCreate(carHeartbeat, 500); taskCreate(carPeriodic, 15); + taskCreate(interpretLoadSensor, 15); taskCreate(updateSDCFaults, 300); taskCreate(heartBeatTask, 100); + taskCreate(send_shockpots, 15); taskCreate(parseMCDataPeriodic, MC_LOOP_DT); taskCreate(daqPeriodic, DAQ_UPDATE_PERIOD); // taskCreate(memFg, MEM_FG_TIME); @@ -427,6 +432,42 @@ void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf) rx_buf->last_rx_loc = new_loc % rx_buf->rx_buf_size; } + +#define SCALE_F = (1 + (3.4/6.6)) +float voltToForce(uint16_t load_read) { + /* + //Return in newtons + float v_out_load_l = adc_readings.load_l / 4095 * 3.3; + float v_out_load_r = adc_readings.load_r / 4095 * 3.3; + //voltage -> weight + //V_out = (V_in * R_2) / (R_1 + R_2) + //Solve for V_in + //R_1 = 3.4K + //R_2 = 6.6K + float v_in_load_l = (v_out_load_l * 10) / 6.6; + float v_in_load_r = (v_out_load_r * 10) / 6.6; + //voltage * 100 = mass + //weight (in newtons) = mass * g + float force_load_l = v_in_load_l * 100 * g; + float force_load_r = v_in_load_r * 100 * g; + */ + float g = 9.8; + // float val = ((load_read / 4095.0 * 3.3) * 10.0) + float val = ((load_read / 4095.0 * 3.3) * (1.0 + (3.4/6.6))); + // return ( val / 6.6) * 100.0 * g; + return val * 100.0 * g; +} + +void interpretLoadSensor(void) { + float force_load_l = voltToForce(adc_readings.load_l); + float force_load_r = voltToForce(adc_readings.load_r); + //send a can message w/ minimal force info + //every 15 milliseconds + SEND_LOAD_SENSOR_READINGS(force_load_l, force_load_r); + + +} + /* CAN Message Handling */ void CAN1_RX0_IRQHandler() { diff --git a/source/main_module/wheel_speeds/wheel_speeds.h b/source/main_module/wheel_speeds/wheel_speeds.h index 00a58581..9d66bb50 100644 --- a/source/main_module/wheel_speeds/wheel_speeds.h +++ b/source/main_module/wheel_speeds/wheel_speeds.h @@ -1,12 +1,12 @@ /** * @file wheel_speeds.h * @author Luke Oxley (lcoxley@purdue.edu) - * @brief + * @brief * @version 2.0 * @date 2023-01-21 - * + * * @copyright Copyright (c) 2023 - * + * */ #ifndef _WHEEL_SPEEDS_H @@ -19,10 +19,11 @@ // to determine optimal prescaler #define WS_TIM_PSC (36) +// #define WS_TIM_PSC (16) #define WS_COUNTS_PER_REV (42) #define WS_TIMEOUT_MS (300) -typedef struct { +typedef struct { uint16_t left_rad_s_x100; //!< Left wheel sped rad/s * 100 uint16_t right_rad_s_x100; //!< Right wheel speed rad/s * 100 } WheelSpeeds_t;