Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/FanControlSystem #267

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions Core/Inc/control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef CONTROL_H
#define CONTROL_H

#include "pdu.h"
#include "can.h"

#define CONTROL_CANID_FANBATTBOX 0x4A1

extern osThreadId_t control_handle;
extern const osThreadAttr_t control_attributes;

void vControl(void *param);

void control_fanbattbox_record(can_msg_t args);

#endif
4 changes: 4 additions & 0 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "dti.h"
#include "fault.h"
#include "steeringio.h"
#include "control.h"

#define CAN_MSG_QUEUE_SIZE 50 /* messages */

Expand Down Expand Up @@ -153,6 +154,9 @@ void vCanReceive(void *pv_params)
case STEERING_CANID_IO:
steeringio_update(msg);
break;
case CONTROL_CANID_FANBATTBOX:
control_fanbattbox_record(msg);
break;
default:
break;
}
Expand Down
31 changes: 31 additions & 0 deletions Core/Src/control.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "control.h"
#include "pdu.h"

osThreadId_t control_handle;
const osThreadAttr_t control_attributes = {
.name = "Control",
.stack_size = 128 * 8,
.priority = (osPriority_t)osPriorityRealtime,
};

static int fanBattBoxState = 0;

void vControl(void *param)
{
pdu_t *pdu = (pdu_t *)param;

for (;;) {
write_fan_battbox(pdu, fanBattBoxState);

osDelay(1000);
}
}

void control_fanbattbox_record(can_msg_t msg)
{
if (msg.data[0] > 0) {
fanBattBoxState = 1;
} else {
fanBattBoxState = 0;
}
}
8 changes: 7 additions & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "dti.h"
#include "steeringio.h"
#include "pedals.h"
#include "control.h"
#include "monitor.h"
#include "state_machine.h"
/* USER CODE END Includes */
Expand Down Expand Up @@ -248,6 +249,11 @@ int main(void)
sm_args->mpu = mpu;
sm_director_handle = osThreadNew(vStateMachineDirector, sm_args, &sm_director_attributes);
assert(sm_director_handle);

/* Control File Thread */
control_handle = osThreadNew(vControl, pdu, &control_attributes);
dnakhooda marked this conversation as resolved.
Show resolved Hide resolved
assert(control_handle);

/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_EVENTS */
Expand Down Expand Up @@ -764,7 +770,7 @@ void StartDefaultTask(void *argument)
// refresh the external watchdog so the car doesnt fault
pet_watchdog(mpu);

/* Send NERO state data continuously */
send_git_version_message();
osDelay(500);
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Core/Src/state_machine.c \
Core/Src/bms.c \
Core/Src/pdu.c \
Core/Src/mpu.c \
Core/Src/control.c \
Core/Src/steeringio.c \
Core/Src/pedals.c \
Core/Src/cerb_utils.c \
Expand Down
Loading