Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
RTD.c
Go to the documentation of this file.
1#include "../../../Inc/Utils/Constants.h"
2#include "../../../Inc/Systems/Controller/RTD.h"
3#include "../../../Inc/Systems/ControllerSystem.h"
4#include "../../../Inc/Utils/Common.h"
5
6void initRTD(RTD* rtd, Apps* apps, BrakeSystemControl* bsc, int hz, int buttonPort, int piezoPort) {
7 initControllerSystem(&rtd->base, "RTD", hz, c_RTD, updateRTD, rtd);
8 rtd->readyToDrive = 0;
9 rtd->precharged = 0;
10 rtd->counter = 0;
11
12 static Button button;
13 rtd->button = &button;
14 initButton(rtd->button, "RTD Button", hz, 0);
15
16 static DigitalOutput piezo;
17 rtd->piezo = &piezo;
18 initDigitalOutput(rtd->piezo, "Piezo", hz, piezoPort);
19 rtd->apps = apps;
20 rtd->bsc = bsc;
21}
22
23int startRTD(RTD* rtd) {
24 if (rtd->base.safety == NULL) {
25 //printf("Safety system not set for RTD\r\n");
26 return _FAILURE;
27 }
28 else if (rtd->base.safety(&rtd->base) == _FAILURE) {
29 //printf("RTD Actuator is not in a safe state\r\n");
30 return _FAILURE;
31 }
32 ENABLE(rtd->base.system);
33 rtd->base.state = c_idle;
34 return _SUCCESS;
35}
36
37int updateRTD(ControllerSystem* controller) {
38 RTD* rtd = (RTD*)controller->child;
39 // ping button to update in telemetry
41
42 if (rtd->apps->base.state != c_validated || rtd->bsc->base.state != c_validated) {
43 //printf("RTD: Apps or Brake System Control Actuator is not validated\r\n");
44 return _FAILURE;
45 }
46
48 //printf("RTD: APPS position is too high\r\n");
49 return _FAILURE;
50 }
51
54 //printf("RTD: Brake pressure is too low\r\n");
55 return _FAILURE;
56 }
57
58 if (rtd->readyToDrive == 0) {
59 rtd->readyToDrive = getButtonReading(rtd->button); // and precharged, etc.
60 }
61
62 if (rtd->readyToDrive == 1 && rtd->counter < 30) {
63 rtd->counter++;
64 // Turn on piezo
66 } else {
67 // Turn off piezo
69 }
70
71 rtd->base.state = c_computed;
72
73 #ifdef DEBUGn
74 //printf("RTD updated. Ready to Drive: %d\r\n", rtd->readyToDrive);
75 #endif
76
77 return _SUCCESS;
78}
79
80int checkRTD(void* rtd) {
81 RTD* rtdPtr = (RTD*)rtd;
82 if (rtdPtr->readyToDrive == 1) {
83 //printf("RTD is ready to drive\r\n");
84 return _SUCCESS;
85 }
86 return _FAILURE;
87}
float getAppsPosition(Apps *apps)
Averages app sensors to get pedal position.
Definition: Apps.c:38
void initButton(Button *button, const char *name, int hz, int port)
Definition: Button.c:4
int getButtonReading(Button *button)
Definition: Button.c:9
#define _FAILURE
Definition: Common.h:6
#define _SUCCESS
Definition: Common.h:5
#define MIN_BRAKE_PRESSURE
Definition: Constants.h:18
#define MAX_A_PEDAL_POSITION
Definition: Constants.h:17
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type, int(*updateController)(ControllerSystem *controller), void *child)
Initializes the Controller System with initial settings.
@ c_RTD
@ c_idle
@ c_computed
@ c_validated
int writeDigitalOutputData(DigitalOutput *output, int data)
Writes data to the buffer of the digital output.
Definition: DigitalOutput.c:17
void initDigitalOutput(DigitalOutput *digitaloutput, const char *name, int hz, int port)
Initializes a digital output with the given parameters.
Definition: DigitalOutput.c:6
int checkRTD(void *rtd)
Checks if RTD is in ready to drive state.
Definition: RTD.c:80
int startRTD(RTD *rtd)
Starts the RTD Actuator.
Definition: RTD.c:23
int updateRTD(ControllerSystem *controller)
Updates the RTD Actuator.
Definition: RTD.c:37
void initRTD(RTD *rtd, Apps *apps, BrakeSystemControl *bsc, int hz, int buttonPort, int piezoPort)
Initializes the RTD Actuator with initial settings.
Definition: RTD.c:6
#define ENABLE(item_)
Definition: Updateable.h:10
Definition: Apps.h:22
ControllerSystem base
Definition: Apps.h:23
BrakePressure * rearPressure
BrakePressure * frontPressure
ControllerSystem base
Definition: Button.h:7
int(* safety)(struct ControllerSystem *controller)
ControllerState state
Definition: RTD.h:11
BrakeSystemControl * bsc
Definition: RTD.h:19
Apps * apps
Definition: RTD.h:18
ControllerSystem base
Definition: RTD.h:12
uint8_t precharged
Definition: RTD.h:14
uint8_t readyToDrive
Definition: RTD.h:13
DigitalOutput * piezo
Definition: RTD.h:17
Button * button
Definition: RTD.h:16
uint8_t counter
Definition: RTD.h:15