Smartcar Shield
Loading...
Searching...
No Matches
DirectionalOdometer.hpp
Go to the documentation of this file.
1
7#pragma once
8
10
15{
22 DirectionalOdometerPins(uint8_t pulsePin, uint8_t forwardWhenLowPin)
23 : pulse{ pulsePin }
24 , direction{ forwardWhenLowPin }
25 {
26 }
27
28 const uint8_t pulse; // NOLINT: It's OK for these member variables to be non-private
29 const uint8_t direction; // NOLINT
30};
31
33{
34public:
58 uint8_t pulsePin,
59 uint8_t forwardWhenLowPin,
60 InterruptCallback callback,
61 unsigned long pulsesPerMeter);
62
82 InterruptCallback callback,
83 unsigned long pulsesPerMeter);
84
85 /* Check `DirectionlessOdometer` for documentation */
86 void reset() override;
87
88 /* Check `DirectionlessOdometer` for documentation */
89 void update() override;
90
91 /* Check `Odometer` interface for documentation */
92 long getDistance() override;
93
94 /* Check `Odometer` interface for documentation */
95 float getSpeed() override;
96
97 /* Check `Odometer` interface for documentation */
98 bool providesDirection() const override;
99
110 int8_t getDirection() const;
111
112private:
113 const uint8_t mDirectionPin;
114 Runtime& mRuntime;
115 const int kPinStateWhenForward;
116 volatile unsigned long mNegativePulsesCounter{ 0 };
117 volatile int mDirectionPinState;
118};
119
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
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...
A callback to be invoked.
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
Definition Runtime.hpp:36
Helper class to represent directional odometer pins.
DirectionalOdometerPins(uint8_t pulsePin, uint8_t forwardWhenLowPin)
Construct a DirectionalOdometerPins object.