Go to the documentation of this file.
9 const auto kInvalidPinState = INT_MIN;
14 uint8_t forwardWhenLowPin,
16 unsigned long pulsesPerMeter)
18 , mDirectionPin{ forwardWhenLowPin }
20 , kPinStateWhenForward{ mRuntime.getLowState() }
21 , mDirectionPinState{ kInvalidPinState }
23 mRuntime.setPinDirection(mDirectionPin, mRuntime.getInputState());
29 unsigned long pulsesPerMeter)
37 mNegativePulsesCounter = 0;
52 mDirectionPinState = mRuntime.
getPinState(mDirectionPin);
62 if (mDirectionPinState != kPinStateWhenForward)
64 mNegativePulsesCounter++;
virtual int getPinState(uint8_t pin)=0
Get the pin state, equivalent of digitalRead in Arduino.
DirectionalOdometer(Runtime &runtime, uint8_t pulsePin, uint8_t forwardWhenLowPin, InterruptCallback callback, unsigned long pulsesPerMeter)
Constructs an odometer that can measure distance, speed and direction.
volatile unsigned long mPulsesCounter
A callback to be invoked. Depending on the platform different callback types may be necessary.
volatile unsigned long mDt
void reset() override
Resets the total travelled distance and speed to 0
void update() override
Conducts the distance and speed measurements.
int8_t getDirection() const
Get the direction of movement.
const unsigned long kMinimumPulseGap
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
const float mPulsesPerMeterRatio
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
Helper class to represent directional odometer pins.
virtual unsigned long currentTimeMicros()=0
Gets the amount of microseconds since the microcontroller started running, equivalent of micros in Ar...
volatile unsigned long mPreviousPulse
virtual void reset()
Resets the total travelled distance and speed to 0