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

Go to the source code of this file.

Classes

struct  BrakeSystemControl
 

Enumerations

enum  BrakeSystemStatus {
  BRAKES_OK , PRESSURE_UNDER_LIMIT , PRESSURE_OVER_LIMIT , PRESSURE_SENSOR_ERROR ,
  TEMPERATURE_OVER_LIMIT , TEMPERATURE_SENSOR_ERROR
}
 

Functions

void initBrakeSystemControl (BrakeSystemControl *bsc, int hz, int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, int fbp_channel, int rbp_channel, int temp_channel, int light_port)
 Initializes the Braking System with initial settings. More...
 
int startBrakeSystemControl (BrakeSystemControl *bsc)
 Starts the Brake System Controller. More...
 
int updateBrakeSystemControl (ControllerSystem *controller)
 Updates the Brake System Controller. More...
 
void setSensorReadings (BrakeSystemControl *bsc)
 Updates BrakeSystemStatus with current sensor data. More...
 
void activateBrakeLight (BrakeSystemControl *bsc)
 Checks whether the line pressure is higher than the activation point specified by the user. More...
 
void inHeavyBreaking (BrakeSystemControl *bsc)
 Checks whether the line pressure is higher than the activation point specified by the user. More...
 
BrakeSystemStatus checkSensorLimits (BrakeSystemControl *bsc)
 Checks if the brake system is within the defined limits and desired ranges. More...
 
int brakeSafteyCheck (void *bsc)
 Checks the saftey of the braking system. More...
 
void setFrontPressure (BrakeSystemControl *bsc, float pressure)
 
void setRearPressure (BrakeSystemControl *bsc, float pressure)
 
void setTemperature (BrakeSystemControl *bsc, float temperature)
 

Enumeration Type Documentation

◆ BrakeSystemStatus

Enumerator
BRAKES_OK 
PRESSURE_UNDER_LIMIT 
PRESSURE_OVER_LIMIT 
PRESSURE_SENSOR_ERROR 
TEMPERATURE_OVER_LIMIT 
TEMPERATURE_SENSOR_ERROR 

Definition at line 9 of file BrakeSystemControl.h.

Function Documentation

◆ activateBrakeLight()

void activateBrakeLight ( BrakeSystemControl bsc)

Checks whether the line pressure is higher than the activation point specified by the user.

Parameters
bscA pointer to the BrakeControl structure.

Definition at line 71 of file BrakeSystemControl.c.

71 {
72 if (getBrakePressure(bsc -> frontPressure) > bsc -> brakeLightActivationPoint
73 || getBrakePressure(bsc -> rearPressure) > bsc -> brakeLightActivationPoint){
74 if (bsc->brakeLightBlink < 8) {bsc->brakeLightBlink++;}
75 if (bsc->brakeLightBlink%2 == 0) {
76 bsc -> brakeLightActive = 1;
77 return;
78 }
79 } else {
80 bsc -> brakeLightBlink = 0;
81 }
82 bsc -> brakeLightActive = 0;
83 return;
84}
float getBrakePressure(BrakePressure *bp)
Gets the current brake pressure.
Definition: BrakePressure.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ brakeSafteyCheck()

int brakeSafteyCheck ( void *  bsc)

Checks the saftey of the braking system.

Parameters
bscA pointer to the BrakeControl structure.

◆ checkSensorLimits()

BrakeSystemStatus checkSensorLimits ( BrakeSystemControl bsc)

Checks if the brake system is within the defined limits and desired ranges.

Parameters
bscA pointer to the BrakeControl structure.

Definition at line 95 of file BrakeSystemControl.c.

95 {
96 float front = getBrakePressure(bsc -> frontPressure);
97 float rear = getBrakePressure(bsc -> rearPressure);
98 float temp = getTemperatureFahrenheit(bsc -> temperature);
99
100 if (front > bsc -> maxPressure || rear > bsc -> maxPressure){
101 return PRESSURE_OVER_LIMIT;
102 }
103 else if (front < bsc -> minPressure || rear < bsc -> minPressure){
105 }
106 else if (temp > bsc -> maxTemperatureAllowed){
108 }
109 else if (temp < 0){
111 } else {
112 return BRAKES_OK;
113 }
114}
double getTemperatureFahrenheit(Temperature *temp)
Gets the current temperature in Fahrenheit.
Definition: Temperature.c:19
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inHeavyBreaking()

void inHeavyBreaking ( BrakeSystemControl bsc)

Checks whether the line pressure is higher than the activation point specified by the user.

Parameters
bscA pointer to the BrakeControl structure.

Definition at line 86 of file BrakeSystemControl.c.

86 {
87 if (getBrakePressure(bsc -> frontPressure) > bsc -> heavyBrakingActivationPoint || getBrakePressure(bsc -> rearPressure) > bsc -> heavyBrakingActivationPoint){
88 bsc -> heavyBraking = 1;
89 return;
90 }
91 bsc -> heavyBraking = 0;
92 return;
93}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initBrakeSystemControl()

void initBrakeSystemControl ( BrakeSystemControl bsc,
int  hz,
int  maxTemp,
int  brakeLightActivationPoint,
int  heavyBrakingActivationPoint,
int  fbp_channel,
int  rbp_channel,
int  temp_channel,
int  light_port 
)

Initializes the Braking System with initial settings.

Parameters
bscA pointer to the BrakeControl structure.
hzRate at which the sensorors are called (in hz).
maxTempThe maximum temperature limit set for the system (in farenheight).
brakeLightActivationPointAt what voltage the brake light will activate.
heavyBrakingActivationPointAt what voltage the system recognises "heavy braking".
fbp_channelThe channel number for the front brake pressure sensor
rbp_channelThe channel number for the rear brake pressure sensor
temp_channelThe channel number for the temperature sensor
light_portThe port number for the brake light

Definition at line 7 of file BrakeSystemControl.c.

7 {
8 initControllerSystem(&bsc-> base, "Brake System Control", hz, c_BRAKES, updateBrakeSystemControl, bsc);
9 static BrakePressure frontPressure, rearPressure;
10 static Temperature temperature;
11 static DigitalOutput brakeLight;
12
13 bsc->frontPressure = &frontPressure;
14 bsc->rearPressure = &rearPressure;
15 initBrakePressure(bsc -> frontPressure, hz, fbp_channel);
16 initBrakePressure(bsc -> rearPressure, hz, rbp_channel);
17
18 bsc->temperature = &temperature;
19 initTemperature(bsc -> temperature, hz, temp_channel);
20
21 bsc->brakeLight = &brakeLight;
22 initDigitalOutput(bsc -> brakeLight, "Brake Light", hz, light_port);
23
24 bsc -> maxTemperatureAllowed = maxTemp;
25 bsc -> minPressure = 0;
26 bsc -> maxPressure = 2000;
27 bsc -> brakeLightActivationPoint = brakeLightActivationPoint;
28 bsc -> brakeLightActive = 0;
29 bsc -> brakeLightBlink = 0;
30 bsc -> heavyBrakingActivationPoint = heavyBrakingActivationPoint;
31 bsc -> heavyBraking = 0;
32 bsc -> status = BRAKES_OK;
33}
void initBrakePressure(BrakePressure *bp, int hz, int channel)
Initializes the BrakePressure sensor with the given frequency and channel.
Definition: BrakePressure.c:11
int updateBrakeSystemControl(ControllerSystem *controller)
Updates the Brake System Controller.
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_BRAKES
void initDigitalOutput(DigitalOutput *digitaloutput, const char *name, int hz, int port)
Initializes a digital output with the given parameters.
Definition: DigitalOutput.c:4
void initTemperature(Temperature *temp, int hz, int channel)
Initializes the Temperature sensor with the given frequency and channel.
Definition: Temperature.c:3
BrakePressure * rearPressure
Temperature * temperature
BrakePressure * frontPressure
DigitalOutput * brakeLight
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFrontPressure()

void setFrontPressure ( BrakeSystemControl bsc,
float  pressure 
)

Definition at line 118 of file BrakeSystemControl.c.

118 {
119 bsc -> frontPressure -> pressure = pressure;
120 inHeavyBreaking(bsc);
122}
void activateBrakeLight(BrakeSystemControl *bsc)
Checks whether the line pressure is higher than the activation point specified by the user.
void inHeavyBreaking(BrakeSystemControl *bsc)
Checks whether the line pressure is higher than the activation point specified by the user.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRearPressure()

void setRearPressure ( BrakeSystemControl bsc,
float  pressure 
)

Definition at line 124 of file BrakeSystemControl.c.

124 {
125 bsc -> rearPressure -> pressure = pressure;
126 inHeavyBreaking(bsc);
128}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSensorReadings()

void setSensorReadings ( BrakeSystemControl bsc)

Updates BrakeSystemStatus with current sensor data.

Parameters
bscA pointer to the BrakeControl structure.

Definition at line 65 of file BrakeSystemControl.c.

65 {
69}
void updateBrakePressure(void *bp)
Updates the brake pressure data.
Definition: BrakePressure.c:21
void updateTemperature(void *temp)
Updates the Temperature data.
Definition: Temperature.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTemperature()

void setTemperature ( BrakeSystemControl bsc,
float  temperature 
)

Definition at line 130 of file BrakeSystemControl.c.

130 {
131 bsc -> temperature -> degrees = temperature;
132 inHeavyBreaking(bsc);
134}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startBrakeSystemControl()

int startBrakeSystemControl ( BrakeSystemControl bsc)

Starts the Brake System Controller.

Parameters
bscA pointer to the BrakeControl structure.

Definition at line 35 of file BrakeSystemControl.c.

35 {
36 if (bsc -> base.safety == NULL){
37 printf("Safety system not set for Brake System Control\r\n");
38 return _FAILURE;
39 }
40 else if (bsc -> base.safety(&bsc->base) == _FAILURE){
41 printf("Brake System Control Actuator is not in a safe state\r\n");
42 return _FAILURE;
43 }
44 ENABLE(bsc -> base.system);
45 bsc -> base.state = c_idle;
46 return _SUCCESS;
47}
#define _FAILURE
Definition: Common.h:6
#define _SUCCESS
Definition: Common.h:5
@ c_idle
#define ENABLE(item_)
Definition: Updateable.h:10
ControllerSystem base
Here is the caller graph for this function:

◆ updateBrakeSystemControl()

int updateBrakeSystemControl ( ControllerSystem controller)

Updates the Brake System Controller.

Parameters
controllerA pointer to the BrakeControl ControllerSystem.

Definition at line 49 of file BrakeSystemControl.c.

49 {
50 BrakeSystemControl *bsc = (BrakeSystemControl*)controller->child;
53 inHeavyBreaking(bsc);
54 bsc->base.state = c_computed;
56
57 #ifdef DEBUGn
58 printf("Brake System Control updated. Front Pressure: %f, Rear Pressure: %f, Temperature: %f\r\n", getBrakePressure(bsc -> frontPressure), getBrakePressure(bsc -> rearPressure), getTemperatureFahrenheit(bsc -> temperature));
59 printf("Brake Light Active: %d, Heavy Braking: %d\r\n", bsc -> brakeLightActive, bsc -> heavyBraking);
60 #endif
61
62 return _SUCCESS;
63}
void setSensorReadings(BrakeSystemControl *bsc)
Updates BrakeSystemStatus with current sensor data.
@ c_computed
int writeDigitalOutputData(DigitalOutput *output, int data)
Writes data to the buffer of the digital output.
Definition: DigitalOutput.c:18
ControllerState state
Here is the call graph for this function:
Here is the caller graph for this function: