Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Accelerometer.c
Go to the documentation of this file.
1#include "../../../Inc/Sensors/AnalogSensors/Accelerometer.h"
2
3#include <stdio.h>
4
5const float kOffsetVolts = 2.5; // 2.5 V at 0 g
6const float kVoltsPerG = 0.440; // 440 mV/g
7
8void initAccelerometer(Accelerometer* accel, int channel, int hz, int muxChannel) {
9 initAnalogSensor(&accel->base, "Accelerometer", hz, channel);
10 accel->value = -1;
12}
13
15 return accel->value;
16}
17
18void updateAccelerometer(void* accel) {
19 Accelerometer *myAccel = (Accelerometer *)accel;
20 float rawData = 0.0f; // Placeholder for sensor reading
21 printf("Updating Accelerometer\n");
22 myAccel->value = transferFunctionAccelerometer(rawData);
23}
24
25float transferFunctionAccelerometer(float rawVal) {
26 return (rawVal - kOffsetVolts) / kVoltsPerG;
27}
float transferFunctionAccelerometer(float rawVal)
Converts raw accelerometer data to a meaningful value.
Definition: Accelerometer.c:25
void updateAccelerometer(void *accel)
Updates the accelerometer data.
Definition: Accelerometer.c:18
float getAccelerometerValue(Accelerometer *accel)
Gets the current value of the accelerometer.
Definition: Accelerometer.c:14
const float kOffsetVolts
Definition: Accelerometer.c:5
void initAccelerometer(Accelerometer *accel, int channel, int hz, int muxChannel)
Initializes the accelerometer with the given channel, frequency, and multiplexer channel.
Definition: Accelerometer.c:8
const float kVoltsPerG
Definition: Accelerometer.c:6
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
AnalogSensor base
Definition: Accelerometer.h:7
Sensor sensor
Definition: AnalogSensor.h:28
Updateable updateable
Definition: Sensor.h:15
void(* update)(void *self)
Definition: Updateable.h:26