From 6a39b9eb2ffd1c4b59f3856a6a3f22779d544dcf Mon Sep 17 00:00:00 2001 From: Caio Date: Sun, 3 Aug 2025 11:11:14 -0400 Subject: [PATCH 1/9] no fans on moving --- Core/Inc/control.h | 3 ++- Core/Src/control.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Core/Inc/control.h b/Core/Inc/control.h index 466ac785..a8280848 100644 --- a/Core/Inc/control.h +++ b/Core/Inc/control.h @@ -23,7 +23,7 @@ /* Tempeature Constants for Devices */ #define PUMP_UPPER_MOTOR_TEMP 45 #define PUMP_LOWER_MOTOR_TEMP 35 -#define RADFAN_UPPER_MOTOR_TEMP 45 +#define RADFAN_UPPER_MOTOR_TEMP 65 #define RADFAN_LOWER_MOTOR_TEMP 35 #define PUMP_UPPER_CONTROLLER_TEMP 45 @@ -51,6 +51,7 @@ typedef enum { /* Holds all the information needed to determine and set the state of a device */ typedef struct { pdu_t *pdu; + dti_t *mc; control_func_t control_func; /* function to set device state */ device_type_t device_type; /* Device Type (Pump or Radfan) */ nertimer_t timer; /* Debounce Timer */ diff --git a/Core/Src/control.c b/Core/Src/control.c index 653f03bc..5f72d909 100644 --- a/Core/Src/control.c +++ b/Core/Src/control.c @@ -61,6 +61,15 @@ static void control_device(device_control_t *device, uint16_t temp) return; } + if (device->device_type == DEVICE_RADFAN0 || device->device_type == DEVICE_RADFAN1) { + if (fabs(dti_get_mph(device->mc)) <= 0.1 && temp > device->upper_temp) { + set_device_on(device); + } else if (temp < device->lower_temp) { + set_device_off(device); + } + return; + } + // set device state based on temps with debounce if (temp > device->upper_temp || temp < device->lower_temp || is_timer_active(&device->timer)) { @@ -88,6 +97,7 @@ void vControl(void *params) device_control_t pump0 = { .pdu = pdu, + .mc = mc, .control_func = write_pump_1, .upper_temp = PUMP_UPPER_MOTOR_TEMP, .lower_temp = PUMP_LOWER_MOTOR_TEMP, @@ -96,6 +106,7 @@ void vControl(void *params) device_control_t radfan0 = { .pdu = pdu, + .mc = mc, .control_func = write_radfan_2, .upper_temp = RADFAN_UPPER_MOTOR_TEMP, .lower_temp = RADFAN_LOWER_MOTOR_TEMP, @@ -104,6 +115,7 @@ void vControl(void *params) device_control_t pump1 = { .pdu = pdu, + .mc = mc, .control_func = write_pump_2, .upper_temp = PUMP_UPPER_CONTROLLER_TEMP, .lower_temp = PUMP_LOWER_CONTROLLER_TEMP, @@ -112,6 +124,7 @@ void vControl(void *params) device_control_t radfan1 = { .pdu = pdu, + .mc = mc, .control_func = write_radfan_1, .upper_temp = RADFAN_UPPER_CONTROLLER_TEMP, .lower_temp = RADFAN_LOWER_CONTROLLER_TEMP, @@ -120,6 +133,7 @@ void vControl(void *params) device_control_t fan_battbox = { .pdu = pdu, + .mc = mc, .control_func = write_fan_battbox, .upper_temp = FANBATTBOX_UPPER_TEMP, .lower_temp = FANBATTBOX_LOWER_TEMP, @@ -146,10 +160,10 @@ void vControl(void *params) // Determine device state control_device(&pump0, motor_temp); - control_device(&radfan0, motor_temp); control_device(&pump1, controller_temp); - control_device(&radfan1, controller_temp); control_device(&fan_battbox, battbox_temp); + control_device(&radfan0, motor_temp); + control_device(&radfan1, controller_temp); osDelay(1000); } From 58026c970bef05e45aa7f4166de230e2ef5b17b4 Mon Sep 17 00:00:00 2001 From: Peyton-McKee Date: Sun, 3 Aug 2025 11:21:42 -0400 Subject: [PATCH 2/9] fix temps --- Core/Inc/control.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Core/Inc/control.h b/Core/Inc/control.h index a8280848..25e50eaa 100644 --- a/Core/Inc/control.h +++ b/Core/Inc/control.h @@ -21,15 +21,15 @@ #define CONTROL_CANID_RADFAN 0x499 /* Tempeature Constants for Devices */ -#define PUMP_UPPER_MOTOR_TEMP 45 -#define PUMP_LOWER_MOTOR_TEMP 35 +#define PUMP_UPPER_MOTOR_TEMP 55 +#define PUMP_LOWER_MOTOR_TEMP 45 #define RADFAN_UPPER_MOTOR_TEMP 65 -#define RADFAN_LOWER_MOTOR_TEMP 35 +#define RADFAN_LOWER_MOTOR_TEMP 50 -#define PUMP_UPPER_CONTROLLER_TEMP 45 -#define PUMP_LOWER_CONTROLLER_TEMP 35 -#define RADFAN_UPPER_CONTROLLER_TEMP 45 -#define RADFAN_LOWER_CONTROLLER_TEMP 35 +#define PUMP_UPPER_CONTROLLER_TEMP 55 +#define PUMP_LOWER_CONTROLLER_TEMP 45 +#define RADFAN_UPPER_CONTROLLER_TEMP 65 +#define RADFAN_LOWER_CONTROLLER_TEMP 50 #define FANBATTBOX_UPPER_TEMP 50 #define FANBATTBOX_LOWER_TEMP 30 From 24aec3285b89de60169cc3efedd98caeb8a72534 Mon Sep 17 00:00:00 2001 From: Peyton-McKee Date: Sun, 3 Aug 2025 11:40:10 -0400 Subject: [PATCH 3/9] get avg bms temp --- Core/Src/bms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Src/bms.c b/Core/Src/bms.c index b4b53cd2..995a9fe2 100644 --- a/Core/Src/bms.c +++ b/Core/Src/bms.c @@ -54,7 +54,7 @@ void bms_record_battbox_temp(can_msg_t msg) { osMutexAcquire(bms.mutex, osWaitForever); bms.battbox_temp = - (msg.data[0] << 8) + - msg.data[1]; // Get "BMS/Cells/Temp_High_Value" (first two bytes of the "Cell Temperatures" CAN message) + (msg.data[0] << 8) | + msg.data[1]; // Get "BMS/Cells/Temp_Avg_Value" osMutexRelease(bms.mutex); } \ No newline at end of file From 44f20fb9abf2676f2463068d139c52fc38fd3a38 Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Sun, 3 Aug 2025 12:06:08 -0400 Subject: [PATCH 4/9] add rtds over, fix battbox --- Core/Inc/pdu.h | 2 +- Core/Src/bms.c | 4 ++-- Core/Src/can_handler.c | 12 ++++++++++-- Core/Src/main.c | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Core/Inc/pdu.h b/Core/Inc/pdu.h index 60070b91..9df0bf30 100644 --- a/Core/Inc/pdu.h +++ b/Core/Inc/pdu.h @@ -132,7 +132,7 @@ extern const osThreadAttr_t rtds_attributes; /* Misc */ #define MUTEX_TIMEOUT osWaitForever /* ms */ -#define RTDS_DURATION 1750 /* ms at 1kHz tick rate */ +#define RTDS_DURATION 30000 /* ms at 1kHz tick rate */ #define SOUND_RTDS_FLAG 1U /* Function that approximates the pump sensor temperature. Takes in resistance and outputs temperature. */ diff --git a/Core/Src/bms.c b/Core/Src/bms.c index 995a9fe2..109a0f55 100644 --- a/Core/Src/bms.c +++ b/Core/Src/bms.c @@ -54,7 +54,7 @@ void bms_record_battbox_temp(can_msg_t msg) { osMutexAcquire(bms.mutex, osWaitForever); bms.battbox_temp = - (msg.data[0] << 8) | - msg.data[1]; // Get "BMS/Cells/Temp_Avg_Value" + ((msg.data[6] << 8) | + msg.data[7]) / 100; // Get "BMS/Cells/Temp_Avg_Value" osMutexRelease(bms.mutex); } \ No newline at end of file diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 655116bf..bcd6b214 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -33,7 +33,7 @@ static uint16_t id_list_1[4] = { static uint16_t id_list_2[4] = { DIAL_CANID_IO, CONTROL_CANID_FANBATTBOX, CONTROL_CANID_PUMP, CONTROL_CANID_RADFAN }; -static uint16_t id_list_3[4] = { BMS_CANID_CELL_TEMPS, DTI_CANID_CURRENTS }; +static uint16_t id_list_3[4] = { BMS_CANID_CELL_TEMPS, DTI_CANID_CURRENTS, 0x49A }; void init_can1(CAN_HandleTypeDef *hcan) { @@ -150,8 +150,11 @@ const osThreadAttr_t can_receive_attributes = { void vCanReceive(void *pv_params) { - dti_t *mc = (dti_t *)pv_params; + control_args_t *args = (control_args_t *)pv_params; + dti_t *mc = args->mc; assert(mc); + pdu_t *pdu = args->pdu; + assert(pdu); can_msg_t msg; @@ -187,8 +190,13 @@ void vCanReceive(void *pv_params) break; case CONTROL_CANID_RADFAN: control_radfan_record(msg); + break; case DTI_CANID_CURRENTS: dti_record_currents(mc, msg); + break; + case 0x49A: + write_rtds(pdu, msg.data[0]); + break; default: break; } diff --git a/Core/Src/main.c b/Core/Src/main.c index a2fd74f5..17a8ff62 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -241,7 +241,7 @@ int main(void) assert(can_dispatch_handle); can_receive_thread = - osThreadNew(vCanReceive, mc, &can_receive_attributes); + osThreadNew(vCanReceive, control_args, &can_receive_attributes); assert(can_receive_thread); /* Control Logic */ From c6a62de4b75a88b0a9290bb0c902557f4a01b15d Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Tue, 5 Aug 2025 22:01:50 -0400 Subject: [PATCH 5/9] last push from test day --- Core/Inc/control.h | 12 ++++++------ Core/Src/control.c | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Core/Inc/control.h b/Core/Inc/control.h index 25e50eaa..a1339123 100644 --- a/Core/Inc/control.h +++ b/Core/Inc/control.h @@ -23,16 +23,16 @@ /* Tempeature Constants for Devices */ #define PUMP_UPPER_MOTOR_TEMP 55 #define PUMP_LOWER_MOTOR_TEMP 45 -#define RADFAN_UPPER_MOTOR_TEMP 65 -#define RADFAN_LOWER_MOTOR_TEMP 50 +#define RADFAN_UPPER_MOTOR_TEMP 55 +#define RADFAN_LOWER_MOTOR_TEMP 45 #define PUMP_UPPER_CONTROLLER_TEMP 55 #define PUMP_LOWER_CONTROLLER_TEMP 45 -#define RADFAN_UPPER_CONTROLLER_TEMP 65 -#define RADFAN_LOWER_CONTROLLER_TEMP 50 +#define RADFAN_UPPER_CONTROLLER_TEMP 55 +#define RADFAN_LOWER_CONTROLLER_TEMP 45 -#define FANBATTBOX_UPPER_TEMP 50 -#define FANBATTBOX_LOWER_TEMP 30 +#define FANBATTBOX_UPPER_TEMP 42 +#define FANBATTBOX_LOWER_TEMP 38 extern osThreadId_t control_handle; extern const osThreadAttr_t control_attributes; diff --git a/Core/Src/control.c b/Core/Src/control.c index 5f72d909..292b8e59 100644 --- a/Core/Src/control.c +++ b/Core/Src/control.c @@ -50,10 +50,10 @@ static void control_device(device_control_t *device, uint16_t temp) // set_device_on(device); // return; // } else - if (get_func_state() == FAULTED) { - set_device_off(device); - return; - } + // if (get_func_state() == FAULTED) { + // set_device_off(device); + // return; + // } // turn on device if calypso sent message to turn it on if (calypso_states[device->device_type]) { @@ -61,14 +61,14 @@ static void control_device(device_control_t *device, uint16_t temp) return; } - if (device->device_type == DEVICE_RADFAN0 || device->device_type == DEVICE_RADFAN1) { - if (fabs(dti_get_mph(device->mc)) <= 0.1 && temp > device->upper_temp) { - set_device_on(device); - } else if (temp < device->lower_temp) { - set_device_off(device); - } - return; - } + // if (device->device_type == DEVICE_RADFAN0 || device->device_type == DEVICE_RADFAN1) { + // if (fabs(dti_get_mph(device->mc)) <= 0.1 && temp > device->upper_temp) { + // set_device_on(device); + // } else if (temp < device->lower_temp) { + // set_device_off(device); + // } + // return; + // } // set device state based on temps with debounce if (temp > device->upper_temp || temp < device->lower_temp || From 3c4e0992021a2b4848de9a8d633b14302ce22307 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 5 Aug 2025 22:18:10 -0400 Subject: [PATCH 6/9] remove mc --- Core/Inc/control.h | 21 ++++++++++----------- Core/Src/bms.c | 5 ++--- Core/Src/control.c | 14 -------------- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/Core/Inc/control.h b/Core/Inc/control.h index a1339123..af9224dd 100644 --- a/Core/Inc/control.h +++ b/Core/Inc/control.h @@ -21,18 +21,18 @@ #define CONTROL_CANID_RADFAN 0x499 /* Tempeature Constants for Devices */ -#define PUMP_UPPER_MOTOR_TEMP 55 -#define PUMP_LOWER_MOTOR_TEMP 45 -#define RADFAN_UPPER_MOTOR_TEMP 55 -#define RADFAN_LOWER_MOTOR_TEMP 45 +#define PUMP_UPPER_MOTOR_TEMP 45 +#define PUMP_LOWER_MOTOR_TEMP 35 +#define RADFAN_UPPER_MOTOR_TEMP 65 +#define RADFAN_LOWER_MOTOR_TEMP 35 -#define PUMP_UPPER_CONTROLLER_TEMP 55 -#define PUMP_LOWER_CONTROLLER_TEMP 45 -#define RADFAN_UPPER_CONTROLLER_TEMP 55 -#define RADFAN_LOWER_CONTROLLER_TEMP 45 +#define PUMP_UPPER_CONTROLLER_TEMP 45 +#define PUMP_LOWER_CONTROLLER_TEMP 35 +#define RADFAN_UPPER_CONTROLLER_TEMP 45 +#define RADFAN_LOWER_CONTROLLER_TEMP 35 -#define FANBATTBOX_UPPER_TEMP 42 -#define FANBATTBOX_LOWER_TEMP 38 +#define FANBATTBOX_UPPER_TEMP 50 +#define FANBATTBOX_LOWER_TEMP 30 extern osThreadId_t control_handle; extern const osThreadAttr_t control_attributes; @@ -51,7 +51,6 @@ typedef enum { /* Holds all the information needed to determine and set the state of a device */ typedef struct { pdu_t *pdu; - dti_t *mc; control_func_t control_func; /* function to set device state */ device_type_t device_type; /* Device Type (Pump or Radfan) */ nertimer_t timer; /* Debounce Timer */ diff --git a/Core/Src/bms.c b/Core/Src/bms.c index 109a0f55..ec550ed3 100644 --- a/Core/Src/bms.c +++ b/Core/Src/bms.c @@ -53,8 +53,7 @@ osStatus_t bms_get_battbox_temp(uint16_t *temp) void bms_record_battbox_temp(can_msg_t msg) { osMutexAcquire(bms.mutex, osWaitForever); - bms.battbox_temp = - ((msg.data[6] << 8) | - msg.data[7]) / 100; // Get "BMS/Cells/Temp_Avg_Value" + bms.battbox_temp = ((msg.data[6] << 8) | msg.data[7]) / + 100; // Get "BMS/Cells/Temp_Avg_Value" osMutexRelease(bms.mutex); } \ No newline at end of file diff --git a/Core/Src/control.c b/Core/Src/control.c index 292b8e59..68adb474 100644 --- a/Core/Src/control.c +++ b/Core/Src/control.c @@ -61,15 +61,6 @@ static void control_device(device_control_t *device, uint16_t temp) return; } - // if (device->device_type == DEVICE_RADFAN0 || device->device_type == DEVICE_RADFAN1) { - // if (fabs(dti_get_mph(device->mc)) <= 0.1 && temp > device->upper_temp) { - // set_device_on(device); - // } else if (temp < device->lower_temp) { - // set_device_off(device); - // } - // return; - // } - // set device state based on temps with debounce if (temp > device->upper_temp || temp < device->lower_temp || is_timer_active(&device->timer)) { @@ -97,7 +88,6 @@ void vControl(void *params) device_control_t pump0 = { .pdu = pdu, - .mc = mc, .control_func = write_pump_1, .upper_temp = PUMP_UPPER_MOTOR_TEMP, .lower_temp = PUMP_LOWER_MOTOR_TEMP, @@ -106,7 +96,6 @@ void vControl(void *params) device_control_t radfan0 = { .pdu = pdu, - .mc = mc, .control_func = write_radfan_2, .upper_temp = RADFAN_UPPER_MOTOR_TEMP, .lower_temp = RADFAN_LOWER_MOTOR_TEMP, @@ -115,7 +104,6 @@ void vControl(void *params) device_control_t pump1 = { .pdu = pdu, - .mc = mc, .control_func = write_pump_2, .upper_temp = PUMP_UPPER_CONTROLLER_TEMP, .lower_temp = PUMP_LOWER_CONTROLLER_TEMP, @@ -124,7 +112,6 @@ void vControl(void *params) device_control_t radfan1 = { .pdu = pdu, - .mc = mc, .control_func = write_radfan_1, .upper_temp = RADFAN_UPPER_CONTROLLER_TEMP, .lower_temp = RADFAN_LOWER_CONTROLLER_TEMP, @@ -133,7 +120,6 @@ void vControl(void *params) device_control_t fan_battbox = { .pdu = pdu, - .mc = mc, .control_func = write_fan_battbox, .upper_temp = FANBATTBOX_UPPER_TEMP, .lower_temp = FANBATTBOX_LOWER_TEMP, From 386cb8c7701f4bf679b01e5a5d66acdeadc1245e Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 5 Aug 2025 22:26:34 -0400 Subject: [PATCH 7/9] fmt --- Core/Inc/control.h | 4 ++-- Core/Src/control.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/Inc/control.h b/Core/Inc/control.h index af9224dd..c2832e72 100644 --- a/Core/Inc/control.h +++ b/Core/Inc/control.h @@ -24,14 +24,14 @@ #define PUMP_UPPER_MOTOR_TEMP 45 #define PUMP_LOWER_MOTOR_TEMP 35 #define RADFAN_UPPER_MOTOR_TEMP 65 -#define RADFAN_LOWER_MOTOR_TEMP 35 +#define RADFAN_LOWER_MOTOR_TEMP 35 #define PUMP_UPPER_CONTROLLER_TEMP 45 #define PUMP_LOWER_CONTROLLER_TEMP 35 #define RADFAN_UPPER_CONTROLLER_TEMP 45 #define RADFAN_LOWER_CONTROLLER_TEMP 35 -#define FANBATTBOX_UPPER_TEMP 50 +#define FANBATTBOX_UPPER_TEMP 50 #define FANBATTBOX_LOWER_TEMP 30 extern osThreadId_t control_handle; diff --git a/Core/Src/control.c b/Core/Src/control.c index 68adb474..d2ff3926 100644 --- a/Core/Src/control.c +++ b/Core/Src/control.c @@ -50,10 +50,10 @@ static void control_device(device_control_t *device, uint16_t temp) // set_device_on(device); // return; // } else - // if (get_func_state() == FAULTED) { - // set_device_off(device); - // return; - // } + if (get_func_state() == FAULTED) { + set_device_off(device); + return; + } // turn on device if calypso sent message to turn it on if (calypso_states[device->device_type]) { From 7de201e72d5e818ca943da58bd04b60d44a1f422 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 5 Aug 2025 22:27:40 -0400 Subject: [PATCH 8/9] fmt --- Core/Src/control.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Src/control.c b/Core/Src/control.c index d2ff3926..93455d4b 100644 --- a/Core/Src/control.c +++ b/Core/Src/control.c @@ -51,8 +51,8 @@ static void control_device(device_control_t *device, uint16_t temp) // return; // } else if (get_func_state() == FAULTED) { - set_device_off(device); - return; + set_device_off(device); + return; } // turn on device if calypso sent message to turn it on From e465f515b8f3a66a6b1dc1d7f1a9e8cb41bfda9b Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 5 Aug 2025 22:29:12 -0400 Subject: [PATCH 9/9] plz pass fmt --- Core/Src/can_handler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index bcd6b214..2641654c 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -33,7 +33,8 @@ static uint16_t id_list_1[4] = { static uint16_t id_list_2[4] = { DIAL_CANID_IO, CONTROL_CANID_FANBATTBOX, CONTROL_CANID_PUMP, CONTROL_CANID_RADFAN }; -static uint16_t id_list_3[4] = { BMS_CANID_CELL_TEMPS, DTI_CANID_CURRENTS, 0x49A }; +static uint16_t id_list_3[4] = { BMS_CANID_CELL_TEMPS, DTI_CANID_CURRENTS, + 0x49A }; void init_can1(CAN_HandleTypeDef *hcan) {