Smartcar Shield
DirectionlessOdometer.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <stdint.h> // NOLINT(modernize-deprecated-headers)
10 
11 #include "../../../runtime/Runtime.hpp"
12 #include "../Odometer.hpp"
13 
15 {
16 public:
37  uint8_t pulsePin,
38  InterruptCallback callback,
39  unsigned long pulsesPerMeter);
40 
41  ~DirectionlessOdometer() override = default;
42 
43  /* Check `Odometer` interface for documentation */
44  long getDistance() override;
45 
46  /* Check `Odometer` interface for documentation */
47  float getSpeed() override;
48 
49  /* Check `Odometer` interface for documentation */
50  bool isAttached() const override;
51 
52  /* Check `Odometer` interface for documentation */
53  bool providesDirection() const override;
54 
58  virtual void reset();
59 
67  virtual void update();
68 
69 protected:
70  const float
71  mPulsesPerMeterRatio; // NOLINT: Refactor this so protected variables are not necessary
72  volatile unsigned long mPulsesCounter{ 0 }; // NOLINT
73  volatile unsigned long mPreviousPulse{ 0 }; // NOLINT
74  volatile unsigned long mDt{ 0 }; // NOLINT
75 
76 private:
77  const float mMillimetersPerPulse;
78  Runtime& mRuntime;
79  const bool kSensorAttached;
80 };
81 
DirectionlessOdometer::mPulsesCounter
volatile unsigned long mPulsesCounter
Definition: DirectionlessOdometer.hpp:72
DirectionlessOdometer
Definition: DirectionlessOdometer.hpp:14
InterruptCallback
A callback to be invoked. Depending on the platform different callback types may be necessary.
DirectionlessOdometer::mDt
volatile unsigned long mDt
Definition: DirectionlessOdometer.hpp:74
Odometer
Definition: Odometer.hpp:26
DirectionlessOdometer::~DirectionlessOdometer
~DirectionlessOdometer() override=default
Runtime
Definition: Runtime.hpp:35
DirectionlessOdometer::update
virtual void update()
Conducts the distance and speed measurements.
Definition: DirectionlessOdometer.cpp:56
DirectionlessOdometer::mPulsesPerMeterRatio
const float mPulsesPerMeterRatio
Definition: DirectionlessOdometer.hpp:71
DirectionlessOdometer::getDistance
long getDistance() override
Returns the travelled distance in centimeters where sign can indicate direction if there is hardware ...
Definition: DirectionlessOdometer.cpp:32
DirectionlessOdometer::DirectionlessOdometer
DirectionlessOdometer(Runtime &runtime, uint8_t pulsePin, InterruptCallback callback, unsigned long pulsesPerMeter)
Constructs an odometer that can measure distance, speed but not direction.
Definition: DirectionlessOdometer.cpp:14
DirectionlessOdometer::getSpeed
float getSpeed() override
Returns the current speed in meters/sec where sign can indicate direction if there is hardware suppor...
Definition: DirectionlessOdometer.cpp:37
DirectionlessOdometer::isAttached
bool isAttached() const override
Returns whether the sensor has been properly attached.
Definition: DirectionlessOdometer.cpp:44
DirectionlessOdometer::mPreviousPulse
volatile unsigned long mPreviousPulse
Definition: DirectionlessOdometer.hpp:73
DirectionlessOdometer::reset
virtual void reset()
Resets the total travelled distance and speed to 0
Definition: DirectionlessOdometer.cpp:49
DirectionlessOdometer::providesDirection
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.
Definition: DirectionlessOdometer.cpp:77