1#include "../../../Inc/Outputs/DigitalOutput.h"
2#include "../../../Inc/Systems/Controller/BrakeSystemControl.h"
3#include "../../../Inc/Utils/Common.h"
4#include "../../../Inc/Sensors/AnalogSensors/BrakePressure.h"
5#include "../../../Inc/Sensors/AnalogSensors/Temperature.h"
7void initBrakeSystemControl(
BrakeSystemControl *bsc,
int hz,
int maxTemp,
int brakeLightActivationPoint,
int heavyBrakingActivationPoint,
int fbp_channel,
int rbp_channel,
int temp_channel,
int light_port){
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;
36 if (bsc -> base.safety == NULL){
37 printf(
"Safety system not set for Brake System Control\r\n");
41 printf(
"Brake System Control Actuator is not in a safe state\r\n");
44 ENABLE(bsc -> base.system);
45 bsc -> base.state =
c_idle;
59 printf(
"Brake Light Active: %d, Heavy Braking: %d\r\n", bsc -> brakeLightActive, bsc -> heavyBraking);
72 if (
getBrakePressure(bsc -> frontPressure) > bsc -> brakeLightActivationPoint
73 ||
getBrakePressure(bsc -> rearPressure) > bsc -> brakeLightActivationPoint){
76 bsc -> brakeLightActive = 1;
80 bsc -> brakeLightBlink = 0;
82 bsc -> brakeLightActive = 0;
87 if (
getBrakePressure(bsc -> frontPressure) > bsc -> heavyBrakingActivationPoint ||
getBrakePressure(bsc -> rearPressure) > bsc -> heavyBrakingActivationPoint){
88 bsc -> heavyBraking = 1;
91 bsc -> heavyBraking = 0;
100 if (front > bsc -> maxPressure || rear > bsc -> maxPressure){
103 else if (front < bsc -> minPressure || rear < bsc -> minPressure){
106 else if (temp > bsc -> maxTemperatureAllowed){
119 bsc -> frontPressure -> pressure = pressure;
125 bsc -> rearPressure -> pressure = pressure;
131 bsc -> temperature -> degrees = temperature;
float getBrakePressure(BrakePressure *bp)
Gets the current brake pressure.
void initBrakePressure(BrakePressure *bp, int hz, int channel)
Initializes the BrakePressure sensor with the given frequency and channel.
void updateBrakePressure(void *bp)
Updates the brake pressure data.
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 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.
void setTemperature(BrakeSystemControl *bsc, float temperature)
void setRearPressure(BrakeSystemControl *bsc, float pressure)
void inHeavyBreaking(BrakeSystemControl *bsc)
Checks whether the line pressure is higher than the activation point specified by the user.
void setSensorReadings(BrakeSystemControl *bsc)
Updates BrakeSystemStatus with current sensor data.
int updateBrakeSystemControl(ControllerSystem *controller)
Updates the Brake System Controller.
int startBrakeSystemControl(BrakeSystemControl *bsc)
Starts the Brake System Controller.
BrakeSystemStatus checkSensorLimits(BrakeSystemControl *bsc)
Checks if the brake system is within the defined limits and desired ranges.
@ TEMPERATURE_SENSOR_ERROR
void initControllerSystem(ControllerSystem *controller, const char *name, int hz, ControllerType type, int(*updateController)(ControllerSystem *controller), void *child)
Initializes the Controller System with initial settings.
int writeDigitalOutputData(DigitalOutput *output, int data)
Writes data to the buffer of the digital output.
void initDigitalOutput(DigitalOutput *digitaloutput, const char *name, int hz, int port)
Initializes a digital output with the given parameters.
double getTemperatureFahrenheit(Temperature *temp)
Gets the current temperature in Fahrenheit.
void initTemperature(Temperature *temp, int hz, int channel)
Initializes the Temperature sensor with the given frequency and channel.
void updateTemperature(void *temp)
Updates the Temperature data.
BrakePressure * rearPressure
Temperature * temperature
BrakePressure * frontPressure
DigitalOutput * brakeLight