From e2a8d9e24746af55774be234a831ef8e02e6d672 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 2 Feb 2025 17:35:08 -0500 Subject: [PATCH] Pump depend on motor temp --- Core/Inc/control.h | 10 ++++++++++ Core/Inc/dti.h | 13 +++++++++++++ Core/Src/can_handler.c | 3 +++ Core/Src/control.c | 41 ++++++++++++++--------------------------- Core/Src/dti.c | 19 +++++++++++++++++++ Core/Src/main.c | 7 ++++++- 6 files changed, 65 insertions(+), 28 deletions(-) diff --git a/Core/Inc/control.h b/Core/Inc/control.h index 2e21bbb..2a1bf54 100644 --- a/Core/Inc/control.h +++ b/Core/Inc/control.h @@ -2,14 +2,24 @@ #define CONTROL_H #include "pdu.h" +#include "dti.h" #include "can.h" #define CONTROL_CANID_FANBATTBOX 0x4A1 #define CONTROL_CANID_PUMP 0x4A0 +#define TEMP_MOTOR_LIMIT 50 + extern osThreadId_t control_handle; extern const osThreadAttr_t control_attributes; +typedef struct { + pdu_t *pdu; + bool fanBattBoxState; + bool pumpState0; + bool pumpState1; +} control_args_t; + void vControl(void *param); void control_fanbattbox_record(can_msg_t args); diff --git a/Core/Inc/dti.h b/Core/Inc/dti.h index a701654..7c68cde 100644 --- a/Core/Inc/dti.h +++ b/Core/Inc/dti.h @@ -131,6 +131,19 @@ void dti_set_relative_current(int16_t relative_current); */ void dti_set_drive_enable(bool drive_enable); +/** + * @brief Record the moter temperature in the DTI + * + * @param mc Pointer to DTI struct + * @param msg CAN message containing temperature data + */ +void dti_record_motor_temp(dti_t *mc, can_msg_t msg); + +/** + * @brief gets the current motor temperature from the DTI + */ +uint16_t dti_get_motor_temp(); + /** * @brief gets the current mph from the DTI */ diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 8262b16..f389422 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -148,6 +148,9 @@ void vCanReceive(void *pv_params) case DTI_CANID_ERPM: dti_record_rpm(mc, msg); break; + case DTI_CANID_TEMPS_FAULT: + dti_record_motor_temp(mc, msg); + break; case BMS_DCL_MSG: handle_dcl_msg(); break; diff --git a/Core/Src/control.c b/Core/Src/control.c index becbc3c..45cb372 100644 --- a/Core/Src/control.c +++ b/Core/Src/control.c @@ -1,5 +1,4 @@ #include "control.h" -#include "pdu.h" osThreadId_t control_handle; const osThreadAttr_t control_attributes = { @@ -8,21 +7,22 @@ const osThreadAttr_t control_attributes = { .priority = (osPriority_t)osPriorityRealtime, }; -static int fanBattBoxState = 0; +static control_args_t *control_args; -static int pumpState0 = 0; - -static int pumpState1 = 0; - -void vControl(void *param) +void vControl(void *params) { - pdu_t *pdu = (pdu_t *)param; + control_args = (control_args_t *)params; for (;;) { - write_fan_battbox(pdu, fanBattBoxState); + write_fan_battbox(control_args->pdu, + control_args->fanBattBoxState); - write_pump_0(pdu, pumpState0); - write_pump_1(pdu, pumpState1); + write_pump_0(control_args->pdu, + control_args->pumpState0 && + dti_get_motor_temp() <= TEMP_MOTOR_LIMIT); + write_pump_1(control_args->pdu, + control_args->pumpState1 && + dti_get_motor_temp() <= TEMP_MOTOR_LIMIT); osDelay(1000); } @@ -30,24 +30,11 @@ void vControl(void *param) void control_fanbattbox_record(can_msg_t msg) { - if (msg.data[0] > 0) { - fanBattBoxState = 1; - } else { - fanBattBoxState = 0; - } + control_args->fanBattBoxState = msg.data[0] > 0; } void control_pump_record(can_msg_t msg) { - if (msg.data[0] > 0) { - pumpState0 = 1; - } else { - pumpState0 = 0; - } - - if (msg.data[1] > 0) { - pumpState1 = 1; - } else { - pumpState1 = 0; - } + control_args->pumpState0 = msg.data[0] > 0; + control_args->pumpState1 = msg.data[1] > 0; } diff --git a/Core/Src/dti.c b/Core/Src/dti.c index 3939352..7448f7e 100644 --- a/Core/Src/dti.c +++ b/Core/Src/dti.c @@ -24,6 +24,8 @@ static osMutexAttr_t dti_mutex_attributes; static uint8_t mph = 0; +static uint8_t motorTemp = 0; + dti_t *dti_init() { dti_t *mc = malloc(sizeof(dti_t)); @@ -284,6 +286,23 @@ void dti_record_rpm(dti_t *mc, can_msg_t msg) mph = dti_get_mph(mc); } +void dti_record_motor_temp(dti_t *mc, can_msg_t msg) +{ + uint16_t temp = (msg.data[0] << 8) + (msg.data[1]); + + temp /= 10; + + osMutexAcquire(*mc->mutex, osWaitForever); + mc->motor_temp = temp; + osMutexRelease(*mc->mutex); + motorTemp = temp; +} + +uint16_t dti_get_motor_temp() +{ + return motorTemp; +} + uint8_t get_mph() { return mph; diff --git a/Core/Src/main.c b/Core/Src/main.c index 23d9ff2..66231c5 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -255,7 +255,12 @@ int main(void) assert(sm_director_handle); /* Control File Thread */ - control_handle = osThreadNew(vControl, pdu, &control_attributes); + control_args_t *control_args = malloc(sizeof(control_args_t)); + control_args->pdu = pdu; + control_args->fanBattBoxState = 0; + control_args->pumpState0 = 0; + control_args->pumpState1 = 0; + control_handle = osThreadNew(vControl, control_args, &control_attributes); assert(control_handle); /* USER CODE END RTOS_THREADS */