Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
TorquePolice.c
Go to the documentation of this file.
1#include "../../../Inc/Systems/Monitor/TorquePolice.h"
2#include "../../../Inc/Utils/Common.h"
3
4// Make new TorquePolice MonitorSystem
5void initTorquePolice(TorquePolice* tp, TorqueControl *tc, BrakeSystemControl *bsc, RTD* rtd, int hz, float maxTorque) {
7 tp->maxAllowedTorque = maxTorque;
8 tp->status = TORQUE_OK;
9 tp->torqueControl = tc;
10 tp->brakeSystemControl = bsc;
11 tp->rtd = rtd;
12}
13
14// Start the TorquePolice MonitorSystem
16 if (tp->base.runMonitor == NULL) {
17 printf("Monitor function not set for TorquePolice\n");
18 return _FAILURE;
19 }
20 ENABLE(tp->base.system);
21 return _SUCCESS;
22}
23
24// Check the TorquePolice MonitorSystem
25int checkTorquePolice(void* tp) {
26 TorquePolice* tpPtr = (TorquePolice*)tp;
27 TorqueControl* tc = tpPtr->torqueControl;
29 RTD* rtd = tpPtr->rtd;
30
31 if (rtd->readyToDrive == 0) {
32 tpPtr->status = TORQUE_RTD;
33 tc->desiredTorque = 0;
34 #ifdef DEBUGn
35 printf("RTD is not ready to drive, reducing torque to zero\r\n");
36 #endif
37 return _FAILURE;
38 }
39 if (tc->desiredTorque > tpPtr->maxAllowedTorque) {
41 return _FAILURE;
42 } else if (tc->status == TORQUE_SENSOR_ERROR) {
44 return _FAILURE;
45 }
46
47 if (bsc->base.state=c_validated && bsc->heavyBraking == 1) {
49 printf("Brake System is in heavy braking, reducing torque to zero\r\n");
50 tc->desiredTorque = 0;
51 // Brake fight, reduce torque to zero. Not a system failure, but a safety measure.
52 // Thus, return _SUCCESS.s
53 return _SUCCESS;
54 }
55
57 tpPtr->status = TORQUE_LOW;
58 printf("Desired torque (%f) is too low, reducing to zero\r\n", tc->desiredTorque);
59 tc->desiredTorque = 0;
60 } else {
61 tpPtr->status = TORQUE_OK;
62 }
63
64 #ifdef DEBUGn
65 printf("Actual Torque: %f\r\n", tc->desiredTorque);
66 #endif
67 return _SUCCESS;
68}
#define TORQUE_LOW_MARGIN
#define _FAILURE
Definition: Common.h:6
#define _SUCCESS
Definition: Common.h:5
@ c_validated
void initMonitorSystem(MonitorSystem *monitor, const char *name, int hz, MonitorType type, FaultType fault, int(*runMonitor)(void *self))
Initializes the Monitor System with initial settings.
Definition: MonitorSystem.c:3
@ m_TORQUE
Definition: MonitorSystem.h:11
@ VEHICLE_SHUTDOWN
Definition: MonitorSystem.h:23
@ TORQUE_OK
Definition: TorqueControl.h:9
@ TORQUE_LOW
Definition: TorqueControl.h:11
@ TORQUE_SENSOR_ERROR
Definition: TorqueControl.h:14
@ TORQUE_OVER_LIMIT
Definition: TorqueControl.h:12
@ TORQUE_BRAKE_FIGHT
Definition: TorqueControl.h:15
@ TORQUE_RTD
Definition: TorqueControl.h:10
int checkTorquePolice(void *tp)
Definition: TorquePolice.c:25
void initTorquePolice(TorquePolice *tp, TorqueControl *tc, BrakeSystemControl *bsc, RTD *rtd, int hz, float maxTorque)
Definition: TorquePolice.c:5
int startTorquePolice(TorquePolice *tp)
Definition: TorquePolice.c:15
#define ENABLE(item_)
Definition: Updateable.h:10
ControllerSystem base
ControllerState state
int(* runMonitor)(void *self)
Definition: MonitorSystem.h:30
Definition: RTD.h:11
uint8_t readyToDrive
Definition: RTD.h:13
TorqueStatus status
Definition: TorqueControl.h:23
float desiredTorque
Definition: TorqueControl.h:21
float maxAllowedTorque
Definition: TorquePolice.h:13
BrakeSystemControl * brakeSystemControl
Definition: TorquePolice.h:16
TorqueControl * torqueControl
Definition: TorquePolice.h:15
MonitorSystem base
Definition: TorquePolice.h:12
TorqueStatus status
Definition: TorquePolice.h:14