Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions | Variables
BrakePressure.c File Reference
#include "../../../Inc/Sensors/AnalogSensors/BrakePressure.h"
#include "../../../Inc/Utils/MessageFormat.h"
#include "../../../Inc/Utils/Telemetry.h"
#include <stdio.h>
Include dependency graph for BrakePressure.c:

Go to the source code of this file.

Functions

void initBrakePressure (BrakePressure *bp, int hz, int channel, char *name)
 Initializes the BrakePressure sensor with the given frequency and channel. More...
 
float getBrakePressure (BrakePressure *bp)
 Gets the current brake pressure. More...
 
void updateBrakePressure (void *bp)
 Updates the brake pressure data. More...
 
float transferFunctionBrakePressure (float rawVal)
 Converts raw brake pressure data to a meaningful pressure value. More...
 

Variables

static const float kOffsetVoltage = 0.5
 
static const float kVoltsPerPSIA = 0.002
 
static const float kLowOutputSaturation = 0.45
 
static const float kHighOutputSaturation = 4.65
 

Function Documentation

◆ getBrakePressure()

float getBrakePressure ( BrakePressure bp)

Gets the current brake pressure.

Parameters
bpPointer to the BrakePressure structure to query.
Returns
The current brake pressure.

Definition at line 23 of file BrakePressure.c.

23 {
24 return bp->pressure;
25}
Here is the caller graph for this function:

◆ initBrakePressure()

void initBrakePressure ( BrakePressure bp,
int  hz,
int  channel,
char *  name 
)

Initializes the BrakePressure sensor with the given frequency and channel.

Parameters
bpPointer to the BrakePressure structure to initialize.
hzThe frequency in Hertz at which the sensor operates.
channelThe analog channel the sensor is connected to.
nameThe name of the sensor (default is "BrakePressure").

Definition at line 13 of file BrakePressure.c.

13 {
14 initAnalogSensor(&bp->base, name, hz, channel, bp);
15 bp->pressure = -1;
17
18 // Setup telemetry signals
19 bp->telem_raw = registerTelemetrySignal(name, TELEMETRY_SENSOR, UNIT_VOLTS, 1000/hz, 0.4f, 4.7f);
20 bp->telem_psi = registerTelemetrySignal(name, TELEMETRY_SENSOR, UNIT_PSI, 1000/hz, 0.0f, 2000.0f);
21}
void initAnalogSensor(AnalogSensor *analogSensor, const char *name, int hz, int channel, void *child)
Initializes an analog sensor and configures the corresponding GPIO pin.
Definition: AnalogSensor.c:42
void updateBrakePressure(void *bp)
Updates the brake pressure data.
Definition: BrakePressure.c:27
@ TELEMETRY_SENSOR
Definition: Telemetry.h:9
TelemetrySignal * registerTelemetrySignal(const char *name, TelemetryType type, UnitId unit_id, uint32_t expected_rate_ms, float custom_min, float custom_max)
Definition: Telemetry.c:23
@ UNIT_PSI
Definition: Units.h:49
@ UNIT_VOLTS
Definition: Units.h:45
Sensor sensor
Definition: AnalogSensor.h:23
TelemetrySignal * telem_raw
Definition: BrakePressure.h:10
AnalogSensor base
Definition: BrakePressure.h:8
TelemetrySignal * telem_psi
Definition: BrakePressure.h:11
Updateable updateable
Definition: Sensor.h:15
int(* update)(struct Updateable *self)
Definition: Updateable.h:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transferFunctionBrakePressure()

float transferFunctionBrakePressure ( float  rawVal)

Converts raw brake pressure data to a meaningful pressure value.

Parameters
rawValThe raw data from the brake pressure sensor.
Returns
The converted brake pressure value.

Definition at line 46 of file BrakePressure.c.

46 {
47 if (rawVal < kLowOutputSaturation) {
48 return -1;
49 }
50 else if (rawVal > kHighOutputSaturation) {
51 return 2001;
52 }
53 else {
54 return ((rawVal - kOffsetVoltage) / kVoltsPerPSIA);
55 }
56}
static const float kLowOutputSaturation
Definition: BrakePressure.c:10
static const float kHighOutputSaturation
Definition: BrakePressure.c:11
static const float kVoltsPerPSIA
Definition: BrakePressure.c:9
static const float kOffsetVoltage
Definition: BrakePressure.c:8
Here is the caller graph for this function:

◆ updateBrakePressure()

void updateBrakePressure ( void *  bp)

Updates the brake pressure data.

Parameters
bpPointer to the BrakePressure structure to update.

Definition at line 27 of file BrakePressure.c.

27 {
28 BrakePressure *brakePressure = (BrakePressure *)bp;
29 float rawData = getAnalogSensorData(&brakePressure->base);
30
31 // Send Telemetry float
32 sendTelemetryValue(brakePressure->telem_raw, rawData);
33
34 brakePressure->pressure = transferFunctionBrakePressure(rawData);
35 if (brakePressure->pressure == -1) {
37 "Brake pressure reading below sensor minimum (%.3f V)", rawData);
38 } else if (brakePressure->pressure == 2001) {
40 "Brake pressure reading above sensor maximum (%.3f V)", rawData);
41 }
42
43 sendTelemetryValue(brakePressure->telem_psi, brakePressure->pressure);
44}
float getAnalogSensorData(AnalogSensor *sensor)
Retrieves analog sensor data for a specific channel.
Definition: AnalogSensor.c:89
float transferFunctionBrakePressure(float rawVal)
Converts raw brake pressure data to a meaningful pressure value.
Definition: BrakePressure.c:46
@ MSG_WARNING
Definition: MessageFormat.h:12
void sendMessage(const char *sender, MessageType type, const char *format,...)
Definition: MessageFormat.c:5
void sendTelemetryValue(TelemetrySignal *signal, float value)
Definition: Telemetry.c:59
char name[MAX_NAME_LENGTH]
Definition: Updateable.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kHighOutputSaturation

const float kHighOutputSaturation = 4.65
static

Definition at line 11 of file BrakePressure.c.

◆ kLowOutputSaturation

const float kLowOutputSaturation = 0.45
static

Definition at line 10 of file BrakePressure.c.

◆ kOffsetVoltage

const float kOffsetVoltage = 0.5
static

Definition at line 8 of file BrakePressure.c.

◆ kVoltsPerPSIA

const float kVoltsPerPSIA = 0.002
static

Definition at line 9 of file BrakePressure.c.