Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
BrakeSystemControl.c
Go to the documentation of this file.
1#include "../../../Inc/Systems/Controller/BrakeSystemControl.h"
2#include "../../../Inc/Utils/Common.h"
3#include "../../../Inc/Sensors/AnalogSensors/BrakePressure.h"
4#include "../../../Inc/Sensors/AnalogSensors/Temperature.h"
5
6void initBrakeSystemControl(BrakeSystemControl *bsc, int hz, int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, int fbp_channel, int rbp_channel, int temp_channel){
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}
21
22void setSensorReadings(BrakeSystemControl *bsc, float frontPressure, float rearPressure, float temperature){
23 updateBrakePressure(bsc -> frontPressure);
24 updateBrakePressure(bsc -> rearPressure);
25 updateTemperature(bsc -> temperature);
26}
27
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}
36
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}
45
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}
64
65int brakeSafteyCheck(void* bsc){
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}
77
78//The following functions below are for testing functionality and should not be used elsewhere
79
80void setFrontPressure(BrakeSystemControl *bsc, float pressure){
81 bsc -> frontPressure -> pressure = pressure;
82}
83
84void setRearPressure(BrakeSystemControl *bsc, float pressure){
85 bsc -> rearPressure -> pressure = pressure;
86}
87
88void setTemperature(BrakeSystemControl *bsc, float temperature){
89 bsc -> temperature -> degrees = temperature;
90}
float getBrakePressure(BrakePressure *bp)
Gets the current brake pressure.
Definition: BrakePressure.c:17
void initBrakePressure(BrakePressure *bp, int hz, int channel)
Initializes the BrakePressure sensor with the given frequency and channel.
Definition: BrakePressure.c:11
void updateBrakePressure(void *bp)
Updates the brake pressure data.
Definition: BrakePressure.c:21
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.
void activateBrakeLight(BrakeSystemControl *bsc)
Checks whether the line pressure is higher than the activation point specified by the user.
void setFrontPressure(BrakeSystemControl *bsc, float pressure)
void setSensorReadings(BrakeSystemControl *bsc, float frontPressure, float rearPressure, float temperature)
Updates BrakeSystemStatus with current sensor data.
void setTemperature(BrakeSystemControl *bsc, float temperature)
void setRearPressure(BrakeSystemControl *bsc, float pressure)
int brakeSafteyCheck(void *bsc)
Checks the saftey of the braking system.
void inHeavyBreaking(BrakeSystemControl *bsc)
Checks whether the line pressure is higher than the activation point specified by the user.
BrakeSystemStatus checkSensorLimits(BrakeSystemControl *bsc)
Checks if the brake system is within the defined limits and desired ranges.
BrakeSystemStatus
@ TEMPERATURE_OVER_LIMIT
@ PRESSURE_UNDER_LIMIT
@ TEMPERATURE_SENSOR_ERROR
@ BRAKES_OK
@ PRESSURE_OVER_LIMIT
#define FAILURE
Definition: Common.h:6
#define SUCCESS
Definition: Common.h:5
@ c_BRAKES
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type)
Initializes the Controller System with initial settings.
double getTemperatureFahrenheit(Temperature *temp)
Gets the current temperature in Fahrenheit.
Definition: Temperature.c:19
void initTemperature(Temperature *temp, int hz, int channel)
Initializes the Temperature sensor with the given frequency and channel.
Definition: Temperature.c:3
void updateTemperature(void *temp)
Updates the Temperature data.
Definition: Temperature.c:9
BrakeSystemStatus status
ControllerSystem base