Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
BrakePressure.c
Go to the documentation of this file.
1#include "../../../Inc/Sensors/AnalogSensors/BrakePressure.h"
2
3#include <stdio.h>
4
5// Constants for brake pressure calculations
6static const float kOffsetVoltage = 0.201; // Volts
7static const float kVoltsPerPSIA = 0.002;
8static const float kLowOutputSaturation = 0.35; // Output saturation for undersupplied sensor
9static const float kHighOutputSaturation = 4.65; // Output saturation for oversupplied sensor
10
11void initBrakePressure(BrakePressure* bp, int hz, int channel) {
12 initAnalogSensor(&bp->base, "BrakePressure", hz, channel);
13 bp->pressure = -1;
15}
16
18 return bp->pressure;
19}
20
21void updateBrakePressure(void* bp) {
22 BrakePressure *brakePressure = (BrakePressure *)bp;
23 float rawData = 0.0f; // This should come from sensor read function or simulation
24 printf("Implement BrakePressure Update\n");
25 brakePressure->pressure = transferFunctionBrakePressure(rawData);
26}
27
28float transferFunctionBrakePressure(float rawVal) {
29 if (rawVal < kLowOutputSaturation) {
30 printf("BrakePressure::transfer_function rawVal is too low\n");
31 return -1;
32 }
33 else if (rawVal > kHighOutputSaturation) {
34 printf("BrakePressure::transfer_function rawVal is too high\n");
35 return 2001;
36 }
37 else {
38 return ((rawVal - kOffsetVoltage) / kVoltsPerPSIA);
39 }
40}
void initAnalogSensor(AnalogSensor *analogSensor, const char *name, int hz, int channel)
Initializes an analog sensor and configures the corresponding GPIO pin.
Definition: AnalogSensor.c:44
float transferFunctionBrakePressure(float rawVal)
Converts raw brake pressure data to a meaningful pressure value.
Definition: BrakePressure.c:28
static const float kLowOutputSaturation
Definition: BrakePressure.c:8
static const float kHighOutputSaturation
Definition: BrakePressure.c:9
float getBrakePressure(BrakePressure *bp)
Gets the current brake pressure.
Definition: BrakePressure.c:17
static const float kVoltsPerPSIA
Definition: BrakePressure.c:7
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
static const float kOffsetVoltage
Definition: BrakePressure.c:6
Sensor sensor
Definition: AnalogSensor.h:28
AnalogSensor base
Definition: BrakePressure.h:7
Updateable updateable
Definition: Sensor.h:15
void(* update)(void *self)
Definition: Updateable.h:26