Smartcar Shield
Public Member Functions | Protected Attributes | List of all members
DirectionlessOdometer Class Reference

#include <DirectionlessOdometer.hpp>

Inheritance diagram for DirectionlessOdometer:
Inheritance graph
Collaboration diagram for DirectionlessOdometer:
Collaboration graph

Public Member Functions

 DirectionlessOdometer (Runtime &runtime, uint8_t pulsePin, InterruptCallback callback, unsigned long pulsesPerMeter)
 Constructs an odometer that can measure distance, speed but not direction. More...
 
 ~DirectionlessOdometer () override=default
 
long getDistance () override
 Returns the travelled distance in centimeters where sign can indicate direction if there is hardware support. More...
 
float getSpeed () override
 Returns the current speed in meters/sec where sign can indicate direction if there is hardware support. More...
 
bool isAttached () const override
 Returns whether the sensor has been properly attached. More...
 
bool providesDirection () const override
 Return whether the sensor is capable of inferring the direction of movement. More...
 
virtual void reset ()
 Resets the total travelled distance and speed to 0 More...
 
virtual void update ()
 Conducts the distance and speed measurements. More...
 
- Public Member Functions inherited from Odometer
virtual ~Odometer ()=default
 

Protected Attributes

const float mPulsesPerMeterRatio
 
volatile unsigned long mPulsesCounter { 0 }
 
volatile unsigned long mPreviousPulse { 0 }
 
volatile unsigned long mDt { 0 }
 

Detailed Description

A class to represent the common - directionless - Odometers (speed encoders) that can be used to primarily measure the travelled distance of the car as well as its speed.

Definition at line 14 of file DirectionlessOdometer.hpp.

Constructor & Destructor Documentation

◆ DirectionlessOdometer()

DirectionlessOdometer::DirectionlessOdometer ( Runtime runtime,
uint8_t  pulsePin,
InterruptCallback  callback,
unsigned long  pulsesPerMeter 
)

Constructs an odometer that can measure distance, speed but not direction.

Parameters
runtimeThe runtime environment you want to run the class for
pulsePinThe pin that receives the pulses
callbackThe callback to be invoked when a pulse is received (see example)
pulsesPerMeterThe amount of odometer pulses that constitute a meter

Example:

unsigned short ODOMETER_PIN = 32;
unsigned long PULSES_PER_METER = 110;
ArduinoRuntime arduinoRuntime;
DirectionlessOdometer odometer(arduinoRuntime,
ODOMETER_PIN,
[]() { odometer.update(); },
PULSES_PER_METER);

Definition at line 14 of file DirectionlessOdometer.cpp.

◆ ~DirectionlessOdometer()

DirectionlessOdometer::~DirectionlessOdometer ( )
overridedefault

Member Function Documentation

◆ getDistance()

long DirectionlessOdometer::getDistance ( )
overridevirtual

Returns the travelled distance in centimeters where sign can indicate direction if there is hardware support.

Returns
The travelled distance in centimeters

Example:

unsigned long travelledDistance = odometer.getDistance();

Implements Odometer.

Definition at line 32 of file DirectionlessOdometer.cpp.

Here is the caller graph for this function:

◆ getSpeed()

float DirectionlessOdometer::getSpeed ( )
overridevirtual

Returns the current speed in meters/sec where sign can indicate direction if there is hardware support.

Returns
The speed in meters/sec

Example:

float speed = odometer.getSpeed();

Implements Odometer.

Definition at line 37 of file DirectionlessOdometer.cpp.

Here is the caller graph for this function:

◆ isAttached()

bool DirectionlessOdometer::isAttached ( ) const
overridevirtual

Returns whether the sensor has been properly attached.

Returns
True if Odometer::attach has been successfully run, false otherwise Example:
bool hasAttachBeenRun = odometer.isAttached();

Implements Odometer.

Definition at line 44 of file DirectionlessOdometer.cpp.

◆ providesDirection()

bool DirectionlessOdometer::providesDirection ( ) const
overridevirtual

Return whether the sensor is capable of inferring the direction of movement.

Returns
true if the sensor supports direction readings otherwise false

Example:

bool directional = odometer.providesDirection();

Implements Odometer.

Definition at line 77 of file DirectionlessOdometer.cpp.

◆ reset()

void DirectionlessOdometer::reset ( )
virtual

Resets the total travelled distance and speed to 0

Reimplemented in DirectionalOdometer.

Definition at line 49 of file DirectionlessOdometer.cpp.

Here is the caller graph for this function:

◆ update()

void STORED_IN_RAM DirectionlessOdometer::update ( )
virtual

Conducts the distance and speed measurements.

Updates the current dt with the time difference between the last two pulses and increases the pulse counter. Do not call it directly in your sketch! Instead, pass it in a lambda to the constructor.

Reimplemented in DirectionalOdometer.

Definition at line 56 of file DirectionlessOdometer.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ mDt

volatile unsigned long DirectionlessOdometer::mDt { 0 }
protected

Definition at line 74 of file DirectionlessOdometer.hpp.

◆ mPreviousPulse

volatile unsigned long DirectionlessOdometer::mPreviousPulse { 0 }
protected

Definition at line 73 of file DirectionlessOdometer.hpp.

◆ mPulsesCounter

volatile unsigned long DirectionlessOdometer::mPulsesCounter { 0 }
protected

Definition at line 72 of file DirectionlessOdometer.hpp.

◆ mPulsesPerMeterRatio

const float DirectionlessOdometer::mPulsesPerMeterRatio
protected

Definition at line 71 of file DirectionlessOdometer.hpp.


The documentation for this class was generated from the following files:
DirectionlessOdometer
Definition: DirectionlessOdometer.hpp:14
ArduinoRuntime
Definition: ArduinoRuntime.hpp:11