Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Functions
RTD.h File Reference
#include "Apps.h"
#include "BrakeSystemControl.h"
#include "../ControllerSystem.h"
#include "../../Outputs/DigitalOutput.h"
#include "../../Sensors/DigitalSensors/Button.h"
#include "../../Utils/Common.h"
Include dependency graph for RTD.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RTD
 

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 80 of file RTD.c.

80 {
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}
#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:6
int updateRTD(ControllerSystem *controller)
Updates the RTD Actuator.
Definition: RTD.c:37
Definition: Button.h:7
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 // 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}
float getAppsPosition(Apps *apps)
Averages app sensors to get pedal position.
Definition: Apps.c:38
int getButtonReading(Button *button)
Definition: Button.c:9
#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:17
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: