1#include "../../../Inc/Sensors/DigitalSensors/WheelSpeed.h"
2#include "../../../Inc/Utils/Conversions.h"
3#include "../../../Inc/Utils/TimeUtils.h"
9#define M_PI 3.14159265358979323846
27 fprintf(stderr,
"Error: Null pointer passed to calculateSpeed\n");
41 if (numTeeth <= 0 || radius <= 0.0f || pulses <= 0 || delta <= 0.0) {
42 printf(
"Error: Invalid argument. "
43 "NumTeeth = %d, Radius = %.2f, Pulses = %d, Time Delta = %.2f\n",
44 numTeeth, radius, pulses, delta);
49 float circumference = 2 *
M_PI * radius;
50 float distancePerPulse = circumference / numTeeth;
51 float speedMetersPerSecond = (distancePerPulse * pulses) / delta;
float convertMpsToMph(float metersPerSecond)
void initDigitalSensor(DigitalSensor *digitalsensor, const char *name, int hz, int port)
Initializes a digital sensor with the given parameters.
double measureInterval(double lastIntervalTime)
Measures the time interval since the last recorded time.
double getCurrentTime()
Retrieves the current time in seconds.
void setTimeInterval(WheelSpeed *ws, float interval)
Set time interval.
void updateWheelSpeed(void *ws)
Updated the speed var in this sensor.
float calculateSpeed(WheelSpeed *ws)
Translates data to speed in mph.
void addPulse(WheelSpeed *ws, int num)
Add pulses to sensor;.
void initWheelSpeed(WheelSpeed *ws, int hz, int port, float radius, int numTeeth, WHEEL_LOCATION location)
Initialization function for a wheel speed sensor.
void(* update)(void *self)
WHEEL_LOCATION wheel_location