Smartcar Shield
Public Member Functions | List of all members
DirectionalOdometer Class Reference

#include <DirectionalOdometer.hpp>

Inheritance diagram for DirectionalOdometer:
Inheritance graph
Collaboration diagram for DirectionalOdometer:
Collaboration graph

Public Member Functions

 DirectionalOdometer (Runtime &runtime, uint8_t pulsePin, uint8_t forwardWhenLowPin, InterruptCallback callback, unsigned long pulsesPerMeter)
 Constructs an odometer that can measure distance, speed and direction. More...
 
 DirectionalOdometer (Runtime &runtime, DirectionalOdometerPins pins, InterruptCallback callback, unsigned long pulsesPerMeter)
 Constructs an odometer that can measure distance, speed and direction. More...
 
void reset () override
 Resets the total travelled distance and speed to 0 More...
 
void update () override
 Conducts the distance and speed measurements. More...
 
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 providesDirection () const override
 Return whether the sensor is capable of inferring the direction of movement. More...
 
int8_t getDirection () const
 Get the direction of movement. More...
 
- Public Member Functions inherited from DirectionlessOdometer
 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...
 
- Public Member Functions inherited from Odometer
virtual ~Odometer ()=default
 

Additional Inherited Members

- Protected Attributes inherited from DirectionlessOdometer
const float mPulsesPerMeterRatio
 
volatile unsigned long mPulsesCounter { 0 }
 
volatile unsigned long mPreviousPulse { 0 }
 
volatile unsigned long mDt { 0 }
 

Detailed Description

A class to represent directional Odometers. These sensors typically expose three signals lines, as opposed to two in the directionless counterparts. Depending on the state of this third signal, the direction of movement can be inferred.

Definition at line 32 of file DirectionalOdometer.hpp.

Constructor & Destructor Documentation

◆ DirectionalOdometer() [1/2]

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.

Parameters
runtimeThe runtime environment you want to run the class for
pulsePinThe pin that receives the pulses
forwardWhenLowPinThe pin that is set to LOW when moving forward
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 short DIRECTION_PIN = 8;
unsigned long PULSES_PER_METER = 40;
ArduinoRuntime arduinoRuntime;
DirectionalOdometer odometer(arduinoRuntime,
ODOMETER_PIN,
DIRECTION_PIN,
[]() { odometer.update(); },
PULSES_PER_METER);

Definition at line 12 of file DirectionalOdometer.cpp.

◆ DirectionalOdometer() [2/2]

DirectionalOdometer::DirectionalOdometer ( Runtime runtime,
DirectionalOdometerPins  pins,
InterruptCallback  callback,
unsigned long  pulsesPerMeter 
)

Constructs an odometer that can measure distance, speed and direction.

Parameters
pinsThe DirectionalOdometerPins object with the pins of the odometer
callbackThe callback to be invoked when a pulse is received (see example)
pulsesPerMeterThe amount of odometer pulses that constitute a meter

Example:

unsigned long PULSES_PER_METER = 40;
ArduinoRuntime arduinoRuntime;
DirectionalOdometer leftOdometer(arduinoRuntime,
[]() { odometer.update(); },
PULSES_PER_METER);

Definition at line 26 of file DirectionalOdometer.cpp.

Member Function Documentation

◆ getDirection()

int8_t DirectionalOdometer::getDirection ( ) const

Get the direction of movement.

Returns
1 if travelling forward -1 if travelling backward

Example:

unsigned short direction = odometer.getDirection();

Definition at line 83 of file DirectionalOdometer.cpp.

Here is the caller graph for this function:

◆ getDistance()

long DirectionalOdometer::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 72 of file DirectionalOdometer.cpp.

Here is the call graph for this function:

◆ getSpeed()

float DirectionalOdometer::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 78 of file DirectionalOdometer.cpp.

Here is the call graph for this function:

◆ providesDirection()

bool DirectionalOdometer::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 89 of file DirectionalOdometer.cpp.

◆ reset()

void DirectionalOdometer::reset ( )
overridevirtual

Resets the total travelled distance and speed to 0

Reimplemented from DirectionlessOdometer.

Definition at line 34 of file DirectionalOdometer.cpp.

Here is the call graph for this function:

◆ update()

void STORED_IN_RAM DirectionalOdometer::update ( )
overridevirtual

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 from DirectionlessOdometer.

Definition at line 40 of file DirectionalOdometer.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
ArduinoRuntime
Definition: ArduinoRuntime.hpp:11
DirectionalOdometer
Definition: DirectionalOdometer.hpp:32
smartcarlib::pins::v2::leftOdometerPins
const DirectionalOdometerPins leftOdometerPins
Definition: Smartcar.h:54