Smartcar Shield
Loading...
Searching...
No Matches
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{
16public:
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
69protected:
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
76private:
77 const float mMillimetersPerPulse;
78 Runtime& mRuntime;
79 const bool kSensorAttached;
80};
81
A class to represent the common - directionless - Odometers (speed encoders) that can be used to prim...
volatile unsigned long mPulsesCounter
volatile unsigned long mPreviousPulse
bool isAttached() const override
Returns whether the sensor has been properly attached.
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
~DirectionlessOdometer() override=default
bool providesDirection() const override
Return whether the sensor is capable of inferring the direction of movement.
virtual void update()
Conducts the distance and speed measurements.
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 programmatically represent all odometers.
Definition Odometer.hpp:27
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
Definition Runtime.hpp:36