Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions
RTD.c File Reference
#include "../../../Inc/Utils/Constants.h"
#include "../../../Inc/Systems/Controller/RTD.h"
#include "../../../Inc/Systems/ControllerSystem.h"
#include "../../../Inc/Utils/Common.h"
Include dependency graph for RTD.c:

Go to the source code of this file.

Functions

void initRTD (RTD *rtd, Apps *apps, BrakeSystemControl *bsc, int hz, int buttonPort, int piezoPort)
 Initializes the RTD Actuator with initial settings. More...
 
int startRTD (RTD *rtd)
 Starts the RTD Actuator. More...
 
int updateRTD (ControllerSystem *controller)
 Updates the RTD Actuator. More...
 
int checkRTD (void *rtd)
 Checks if RTD is in ready to drive state. More...
 

Function Documentation

◆ checkRTD()

int checkRTD ( void *  rtd)

Checks if RTD is in ready to drive state.

Parameters
rtdA pointer to the RTD structure.
Returns
_SUCCESS if the RTD is ready to drive, _FAILURE otherwise.

Definition at line 77 of file RTD.c.

77 {
78 RTD* rtdPtr = (RTD*)rtd;
79 if (rtdPtr->readyToDrive == 1) {
80 printf("RTD is ready to drive\r\n");
81 return _SUCCESS;
82 }
83 return _FAILURE;
84}
#define _FAILURE
Definition: Common.h:6
#define _SUCCESS
Definition: Common.h:5
Definition: RTD.h:11
uint8_t readyToDrive
Definition: RTD.h:13

◆ initRTD()

void initRTD ( RTD rtd,
Apps apps,
BrakeSystemControl bsc,
int  hz,
int  buttonPort,
int  piezoPort 
)

Initializes the RTD Actuator with initial settings.

Parameters
rtdA pointer to the RTD structure.
hzRate at which the sensor is called (in hz).

Definition at line 6 of file RTD.c.

6 {
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}
void initButton(Button *button, const char *name, int hz, int port)
Definition: Button.c:4
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
void initDigitalOutput(DigitalOutput *digitaloutput, const char *name, int hz, int port)
Initializes a digital output with the given parameters.
Definition: DigitalOutput.c:4
int updateRTD(ControllerSystem *controller)
Updates the RTD Actuator.
Definition: RTD.c:37
Definition: Button.h:6
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
DigitalOutput * piezo
Definition: RTD.h:17
Button * button
Definition: RTD.h:16
uint8_t counter
Definition: RTD.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startRTD()

int startRTD ( RTD rtd)

Starts the RTD Actuator.

Parameters
rtdA pointer to the RTD structure.
Returns
_SUCCESS if the actuator was started, _FAILURE otherwise.

Definition at line 23 of file RTD.c.

23 {
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}
@ c_idle
#define ENABLE(item_)
Definition: Updateable.h:10
int(* safety)(struct ControllerSystem *controller)
ControllerState state
Here is the caller graph for this function:

◆ updateRTD()

int updateRTD ( ControllerSystem controller)

Updates the RTD Actuator.

Parameters
controllerA pointer to the RTD ControllerSystem.
Returns
_SUCCESS if the actuator was updated, _FAILURE otherwise.

Definition at line 37 of file RTD.c.

37 {
38 RTD* rtd = (RTD*)controller->child;
39 if (rtd->apps->base.state != c_validated || rtd->bsc->base.state != c_validated) {
40 printf("RTD: Apps or Brake System Control Actuator is not validated\r\n");
41 return _FAILURE;
42 }
43
45 printf("RTD: APPS position is too high\r\n");
46 return _FAILURE;
47 }
48
51 printf("RTD: Brake pressure is too low\r\n");
52 return _FAILURE;
53 }
54
55 if (rtd->readyToDrive == 0) {
56 rtd->readyToDrive = getButtonReading(rtd->button); // and precharged, etc.
57 }
58
59 if (rtd->readyToDrive == 1 && rtd->counter < 30) {
60 rtd->counter++;
61 // Turn on piezo
63 } else {
64 // Turn off piezo
66 }
67
68 rtd->base.state = c_computed;
69
70 #ifdef DEBUGn
71 printf("RTD updated. Ready to Drive: %d\r\n", rtd->readyToDrive);
72 #endif
73
74 return _SUCCESS;
75}
float getAppsPosition(Apps *apps)
Averages app sensors to get pedal position.
Definition: Apps.c:42
int getButtonReading(Button *button)
Definition: Button.c:8
#define MIN_BRAKE_PRESSURE
Definition: Constants.h:18
#define MAX_A_PEDAL_POSITION
Definition: Constants.h:17
@ c_computed
@ c_validated
int writeDigitalOutputData(DigitalOutput *output, int data)
Writes data to the buffer of the digital output.
Definition: DigitalOutput.c:18
ControllerSystem base
Definition: Apps.h:23
BrakePressure * rearPressure
BrakePressure * frontPressure
ControllerSystem base
Here is the call graph for this function:
Here is the caller graph for this function: