1#include "../../../Inc/Sensors/DigitalSensors/WheelSpeed.h"
2#include "../../../Inc/Utils/Conversions.h"
3#include "../../../Inc/Utils/TimeUtils.h"
4#include "../../../Inc/Utils/Common.h"
10#define M_PI 3.14159265358979323846
28 fprintf(stderr,
"Error: Null pointer passed to calculateSpeed\n");
42 if (numTeeth <= 0 || radius <= 0.0f || pulses <= 0 || delta <= 0.0) {
43 printf(
"Error: Invalid argument. "
44 "NumTeeth = %d, Radius = %.2f, Pulses = %d, Time Delta = %.2f\n",
45 numTeeth, radius, pulses, delta);
50 float circumference = 2 *
M_PI * radius;
51 float distancePerPulse = circumference / numTeeth;
52 float speedMetersPerSecond = (distancePerPulse * pulses) / delta;
66 printf(
"Error: Speed calculation failed\n");
float convertMpsToMph(float metersPerSecond)
void initDigitalSensor(DigitalSensor *digitalsensor, const char *name, int hz, int port, void *child)
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.
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.
int updateWheelSpeed(Updateable *updateable)
Updated the speed var in this sensor.
int(* update)(struct Updateable *self)
WHEEL_LOCATION wheel_location