Go to the documentation of this file.
7 const int8_t kNotAnInterrupt = -1;
8 const float kMillisecondsInSecond = 1000.0;
9 const float kMillimetersInMeter = 1000.0;
17 unsigned long pulsesPerMeter)
18 : mPulsesPerMeterRatio{ pulsesPerMeter > 0 ?
static_cast<float>(pulsesPerMeter) / 100.0F
20 , mMillimetersPerPulse{ pulsesPerMeter > 0
21 ? kMillimetersInMeter /
static_cast<float>(pulsesPerMeter)
24 , kSensorAttached{ mRuntime.pinToInterrupt(pulsePin) != kNotAnInterrupt }
26 mRuntime.setPinDirection(pulsePin, mRuntime.getInputState());
27 mRuntime.setInterrupt(
static_cast<uint8_t
>(mRuntime.pinToInterrupt(pulsePin)),
29 mRuntime.getRisingEdgeMode());
41 return mDt > 0 ? kMillisecondsInSecond * mMillimetersPerPulse /
static_cast<float>(
mDt) : 0.0F;
46 return kSensorAttached;
volatile unsigned long mPulsesCounter
A callback to be invoked. Depending on the platform different callback types may be necessary.
volatile unsigned long mDt
const unsigned long kMinimumPulseGap
virtual void update()
Conducts the distance and speed measurements.
const float mPulsesPerMeterRatio
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
DirectionlessOdometer(Runtime &runtime, uint8_t pulsePin, InterruptCallback callback, unsigned long pulsesPerMeter)
Constructs an odometer that can measure distance, speed but not direction.
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
bool isAttached() const override
Returns whether the sensor has been properly attached.
virtual unsigned long currentTimeMicros()=0
Gets the amount of microseconds since the microcontroller started running, equivalent of micros in Ar...
const unsigned long kDefaultPulsesPerMeter
volatile unsigned long mPreviousPulse
virtual void reset()
Resets the total travelled distance and speed to 0
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.