Smartcar Shield
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 {
34 public:
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 
112 private:
113  const uint8_t mDirectionPin;
114  Runtime& mRuntime;
115  const int kPinStateWhenForward;
116  volatile unsigned long mNegativePulsesCounter{ 0 };
117  volatile int mDirectionPinState;
118 };
119 
DirectionalOdometerPins::direction
const uint8_t direction
Definition: DirectionalOdometer.hpp:29
DirectionalOdometer::DirectionalOdometer
DirectionalOdometer(Runtime &runtime, uint8_t pulsePin, uint8_t forwardWhenLowPin, InterruptCallback callback, unsigned long pulsesPerMeter)
Constructs an odometer that can measure distance, speed and direction.
Definition: DirectionalOdometer.cpp:12
DirectionlessOdometer
Definition: DirectionlessOdometer.hpp:14
InterruptCallback
A callback to be invoked. Depending on the platform different callback types may be necessary.
DirectionalOdometer::reset
void reset() override
Resets the total travelled distance and speed to 0
Definition: DirectionalOdometer.cpp:34
DirectionalOdometerPins::pulse
const uint8_t pulse
Definition: DirectionalOdometer.hpp:28
DirectionalOdometer::update
void update() override
Conducts the distance and speed measurements.
Definition: DirectionalOdometer.cpp:40
DirectionalOdometer::getDirection
int8_t getDirection() const
Get the direction of movement.
Definition: DirectionalOdometer.cpp:83
Runtime
Definition: Runtime.hpp:35
DirectionalOdometer::getDistance
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
Definition: DirectionalOdometer.cpp:72
DirectionalOdometer::providesDirection
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.
Definition: DirectionalOdometer.cpp:89
DirectionalOdometer::getSpeed
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
Definition: DirectionalOdometer.cpp:78
DirectionalOdometer
Definition: DirectionalOdometer.hpp:32
DirectionalOdometerPins
Helper class to represent directional odometer pins.
Definition: DirectionalOdometer.hpp:14
DirectionlessOdometer.hpp
DirectionalOdometerPins::DirectionalOdometerPins
DirectionalOdometerPins(uint8_t pulsePin, uint8_t forwardWhenLowPin)
Construct a DirectionalOdometerPins object.
Definition: DirectionalOdometer.hpp:22