Skip to content

Commit

Permalink
Pump depend on motor temp
Browse files Browse the repository at this point in the history
  • Loading branch information
dnakhooda committed Feb 2, 2025
1 parent 430b120 commit e2a8d9e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
10 changes: 10 additions & 0 deletions Core/Inc/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 3 additions & 0 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 14 additions & 27 deletions Core/Src/control.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "control.h"
#include "pdu.h"

osThreadId_t control_handle;
const osThreadAttr_t control_attributes = {
Expand All @@ -8,46 +7,34 @@ 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);
}
}

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;
}
19 changes: 19 additions & 0 deletions Core/Src/dti.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit e2a8d9e

Please sign in to comment.