Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
ShockPot.c
Go to the documentation of this file.
1#include "../../../Inc/Sensors/AnalogSensors/ShockPot.h"
2
3#include <math.h>
4#include <stdio.h>
5
6void initShockPot(ShockPot* shockPot, int hz, int channel, WHEEL_LOCATION location) {
7 initAnalogSensor(&shockPot->base, "ShockPot", hz, channel);
8 shockPot->distance = -1;
9 shockPot->wheel_location = location;
11}
12
13float getShockPotDistance(ShockPot* shockPot) {
14 return shockPot->distance;
15}
16
17void updateShockPot(void* shockPot) {
18 ShockPot *myShockPot = (ShockPot *)shockPot;
19 printf("Implement ShockPot::update\n");
20 float rawData = 50.0;
21 myShockPot->distance = transferFunctionShockPot(rawData);
22}
23
24float transferFunctionShockPot(float rawVal) {
25 if (rawVal < 15) {
26 printf("ShockPot::transfer_function rawValue is too low\n");
27 return -1;
28 }
29 else if (rawVal > 135) {
30 printf("ShockPot::transfer_function rawValue is too high\n");
31 return -1;
32 }
33 return 2.71965 * pow(rawVal, 0.837683) - 16.2622;
34}
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
void initShockPot(ShockPot *shockPot, int hz, int channel, WHEEL_LOCATION location)
Initializes the ShockPot sensor with the given frequency, channel, and wheel location.
Definition: ShockPot.c:6
float getShockPotDistance(ShockPot *shockPot)
Gets the current distance measured by the ShockPot.
Definition: ShockPot.c:13
void updateShockPot(void *shockPot)
Updates the ShockPot data.
Definition: ShockPot.c:17
float transferFunctionShockPot(float rawVal)
Converts raw ShockPot data to a meaningful distance value.
Definition: ShockPot.c:24
WHEEL_LOCATION
Definition: WheelLocation.h:4
Sensor sensor
Definition: AnalogSensor.h:28
Updateable updateable
Definition: Sensor.h:15
float distance
Definition: ShockPot.h:9
AnalogSensor base
Definition: ShockPot.h:8
WHEEL_LOCATION wheel_location
Definition: ShockPot.h:10
void(* update)(void *self)
Definition: Updateable.h:26