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

Go to the source code of this file.

Functions

void initBrakeSystemControl (BrakeSystemControl *bsc, int hz, int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, int fbp_channel, int rbp_channel, int temp_channel)
 Initializes the Braking System with initial settings. More...
 
void setSensorReadings (BrakeSystemControl *bsc, float frontPressure, float rearPressure, float temperature)
 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)
 

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 28 of file BrakeSystemControl.c.

28 {
29 if (getBrakePressure(bsc -> frontPressure) > bsc -> brakeLightActivationPoint || getBrakePressure(bsc -> rearPressure) > bsc -> brakeLightActivationPoint){
30 bsc -> brakeLightActive = 1;
31 return;
32 }
33 bsc -> brakeLightActive = 0;
34 return;
35}
float getBrakePressure(BrakePressure *bp)
Gets the current brake pressure.
Definition: BrakePressure.c:17
Here is the call graph for this function:

◆ brakeSafteyCheck()

int brakeSafteyCheck ( void *  bsc)

Checks the saftey of the braking system.

Parameters
bscA pointer to the BrakeControl structure.

Definition at line 65 of file BrakeSystemControl.c.

65 {
67 if (bscPtr->base.num_monitors == 0){
68 printf("No monitors set for Brake System Control\n");
69 return FAILURE;
70 }
71 else if (bscPtr->status != BRAKES_OK){
72 printf("Brake System is not in a safe state\n");
73 return FAILURE;
74 }
75 return SUCCESS;
76}
@ BRAKES_OK
#define FAILURE
Definition: Common.h:6
#define SUCCESS
Definition: Common.h:5
BrakeSystemStatus status
ControllerSystem base
Here is the caller graph for this function:

◆ 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 46 of file BrakeSystemControl.c.

46 {
47 float front = getBrakePressure(bsc -> frontPressure);
48 float rear = getBrakePressure(bsc -> rearPressure);
49 float temp = getTemperatureFahrenheit(bsc -> temperature);
50
51 if (front > bsc -> maxPressure || rear > bsc -> maxPressure){
53 }
54 else if (front > bsc -> minPressure || rear > bsc -> minPressure){
56 }
57 else if (temp > bsc -> maxTemperatureAllowed){
59 }
60 else if (temp < 0){
62 }
63}
@ TEMPERATURE_OVER_LIMIT
@ PRESSURE_UNDER_LIMIT
@ TEMPERATURE_SENSOR_ERROR
@ PRESSURE_OVER_LIMIT
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 37 of file BrakeSystemControl.c.

37 {
38 if (getBrakePressure(bsc -> frontPressure) > bsc -> heavyBrakingActivationPoint || getBrakePressure(bsc -> rearPressure) > bsc -> heavyBrakingActivationPoint){
39 bsc -> heavyBraking = 1;
40 return;
41 }
42 bsc -> heavyBraking = 0;
43 return;
44}
Here is the call 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 
)

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

Definition at line 6 of file BrakeSystemControl.c.

6 {
7 initControllerSystem(&bsc-> base, "Brake System Control", hz, c_BRAKES);
8 bsc -> maxTemperatureAllowed = maxTemp;
9 initBrakePressure(bsc -> frontPressure, hz, fbp_channel);
10 initBrakePressure(bsc -> rearPressure, hz, rbp_channel);
11 bsc -> minPressure = 0;
12 bsc -> maxPressure = 2000;
13 initTemperature(bsc -> temperature, hz, temp_channel);
14 bsc -> brakeLightActivationPoint = brakeLightActivationPoint;
15 bsc -> brakeLightActive = 0;
16 bsc -> heavyBrakingActivationPoint = heavyBrakingActivationPoint;
17 bsc -> heavyBraking = 0;
18 bsc -> status = BRAKES_OK;
19 bsc -> base.safety = brakeSafteyCheck;
20}
void initBrakePressure(BrakePressure *bp, int hz, int channel)
Initializes the BrakePressure sensor with the given frequency and channel.
Definition: BrakePressure.c:11
int brakeSafteyCheck(void *bsc)
Checks the saftey of the braking system.
@ c_BRAKES
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type)
Initializes the Controller System with initial settings.
void initTemperature(Temperature *temp, int hz, int channel)
Initializes the Temperature sensor with the given frequency and channel.
Definition: Temperature.c:3
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 80 of file BrakeSystemControl.c.

80 {
81 bsc -> frontPressure -> pressure = pressure;
82}
Here is the caller graph for this function:

◆ setRearPressure()

void setRearPressure ( BrakeSystemControl bsc,
float  pressure 
)

Definition at line 84 of file BrakeSystemControl.c.

84 {
85 bsc -> rearPressure -> pressure = pressure;
86}
Here is the caller graph for this function:

◆ setSensorReadings()

void setSensorReadings ( BrakeSystemControl bsc,
float  frontPressure,
float  rearPressure,
float  temperaure 
)

Updates BrakeSystemStatus with current sensor data.

Parameters
bscA pointer to the BrakeControl structure.
frontPressureThe reading from the front brake line pressure sensor (in psi).
rearPressureThe reading from the rear brake line pressure sensor (in psi).
temperatureThe reading from the brake rotor temperature sensor (in farenheight).

Definition at line 22 of file BrakeSystemControl.c.

22 {
23 updateBrakePressure(bsc -> frontPressure);
24 updateBrakePressure(bsc -> rearPressure);
25 updateTemperature(bsc -> temperature);
26}
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:

◆ setTemperature()

void setTemperature ( BrakeSystemControl bsc,
float  temperature 
)

Definition at line 88 of file BrakeSystemControl.c.

88 {
89 bsc -> temperature -> degrees = temperature;
90}
Here is the caller graph for this function: