Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Core/Inc/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
#define CONTROL_CANID_RADFAN 0x499

/* Tempeature Constants for Devices */
#define PUMP_UPPER_MOTOR_TEMP 45
#define PUMP_LOWER_MOTOR_TEMP 35
#define RADFAN_UPPER_MOTOR_TEMP 45
#define RADFAN_LOWER_MOTOR_TEMP 35
#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_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 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;
Expand All @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 2 additions & 2 deletions Core/Src/bms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[6] << 8) |
msg.data[7]) / 100; // Get "BMS/Cells/Temp_Avg_Value"
osMutexRelease(bms.mutex);
}
12 changes: 10 additions & 2 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 20 additions & 6 deletions Core/Src/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,26 @@ 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]) {
set_device_on(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 ||
is_timer_active(&device->timer)) {
Expand Down Expand Up @@ -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,
Expand All @@ -96,6 +106,7 @@ void vControl(void *params)

device_control_t radfan0 = {
.pdu = pdu,
.mc = mc,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

.control_func = write_radfan_2,
.upper_temp = RADFAN_UPPER_MOTOR_TEMP,
.lower_temp = RADFAN_LOWER_MOTOR_TEMP,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading