9const auto kInvalidPinState = INT_MIN;
14 uint8_t forwardWhenLowPin,
16 unsigned long pulsesPerMeter)
18 , mDirectionPin{ forwardWhenLowPin }
20 , kPinStateWhenForward{ mRuntime.getLowState() }
21 , mDirectionPinState{ kInvalidPinState }
29 unsigned long pulsesPerMeter)
38 mNegativePulsesCounter = 0;
54 mDirectionPinState = mRuntime.
getPinState(mDirectionPin);
64 if (mDirectionPinState != kPinStateWhenForward)
66 mNegativePulsesCounter = mNegativePulsesCounter + 1;
77 const auto negativePulses = mNegativePulsesCounter;
91 const auto directionPinState = mDirectionPinState;
A class to represent directional Odometers.
void update() override
Conducts the distance and speed measurements.
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
int8_t getDirection() const
Get the direction of movement.
void reset() override
Resets the total travelled distance and speed to 0
DirectionalOdometer(Runtime &runtime, uint8_t pulsePin, uint8_t forwardWhenLowPin, InterruptCallback callback, unsigned long pulsesPerMeter)
Constructs an odometer that can measure distance, speed and direction.
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
A class to represent the common - directionless - Odometers (speed encoders) that can be used to prim...
volatile unsigned long mPulsesCounter
volatile unsigned long mPreviousPulse
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
virtual void reset()
Resets the total travelled distance and speed to 0
volatile unsigned long mDt
const float mPulsesPerMeterRatio
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
A callback to be invoked.
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
virtual void enableInterrupts()=0
Enable interrupts.
virtual void setPinDirection(uint8_t pin, uint8_t direction)=0
Set pin direction, equivalent of pinMode in Arduino.
virtual void disableInterrupts()=0
Disable interrupts.
virtual uint8_t getInputState() const =0
Get the runtime-specific value representing an INPUT pin state.
virtual int getPinState(uint8_t pin)=0
Get the pin state, equivalent of digitalRead in Arduino.
virtual unsigned long currentTimeMicros()=0
Gets the amount of microseconds since the microcontroller started running, equivalent of micros in Ar...
const unsigned long kMinimumPulseGap
Helper class to represent directional odometer pins.