EEEN21000
GROUP 30 Line Following Buggy
|
Encoder class with helper functions, derived from QEI. More...
#include <encoder.h>
Public Member Functions | |
Encoder (PinName A, PinName B) | |
Constructor. More... | |
void | start () |
Start the routine to measure pulses periodically. More... | |
int | getCounter () const |
Get current running sum of pulses. More... | |
void | resetCounter () |
Reset the running sum of pulses used for getDistance(). More... | |
double | getVelocity () const |
Get current velocity. More... | |
double | getDistance () const |
Get total distance travelled. More... | |
double | getPPS () const |
Get current pulses per unit second (PPS). More... | |
Public Member Functions inherited from QEI | |
QEI (PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding=X2_ENCODING) | |
Constructor. More... | |
void | reset (void) |
Reset the encoder. More... | |
int | getCurrentState (void) |
Read the state of the encoder. More... | |
int | getInvalidCount (void) |
Read the number of invalid counts. More... | |
int | getPulses (void) |
Read the number of pulses recorded by the encoder. More... | |
int | getRevolutions (void) |
Read the number of revolutions recorded by the encoder on the index channel. More... | |
void | setPulses (int newCount) |
Set the current pulse count in case you want to init it. More... | |
void | setRevolutions (int newRevs) |
Set the current revolution count in case you want to init it. More... | |
Static Public Member Functions | |
static double | getAverageAngular (const Encoder &right_encoder, const Encoder &left_encoder) |
Get average of angular velocity between two wheels. More... | |
static double | getAverageVelocity (const Encoder &right_encoder, const Encoder &left_encoder) |
Get average of linear velocity between two wheels. More... | |
static double | getAverageDistance (const Encoder &right_encoder, const Encoder &left_encoder) |
Get average of total distance between two wheels. More... | |
Static Public Attributes | |
static constexpr double | CIRCUMFERENCE = DIAMETER * M_PI |
Circumference of the wheel. More... | |
static constexpr double | FULL_ROTATION_SIDE_PIVOT = 2.0 * M_PI * WHEEL_DISTANCE |
Distance covered in full rotation when turning only using one wheel. More... | |
static constexpr double | FULL_ROTATION_CENTER_PIVOT = M_PI * WHEEL_DISTANCE |
Distance covered in full rotation when turning using both wheels. More... | |
Private Member Functions | |
void | m_calculateSpeed (const double &time_elapsed) |
Calculate the velocity of the wheel. More... | |
void | m_stop () |
Stop the timer and get current pulse. More... | |
Private Attributes | |
volatile int | m_start_pulse |
Counter for previous pulse. More... | |
volatile int | m_end_pulse |
Counter for latest pulse. More... | |
volatile int | m_pulse_width |
Counter for pulse difference. More... | |
volatile int | m_pulse_counter |
Counter for total pulses from start. More... | |
volatile double | m_pulse_per_sec |
Pulse per unit second. More... | |
volatile double | m_velocity |
Velocity. More... | |
Timer | m_t |
Timer for high-precision clocking. More... | |
Timeout | m_to |
Timeout to interrupt every POLLING_PERIOD. More... | |
Additional Inherited Members | |
Public Types inherited from QEI | |
enum | Encoding { X2_ENCODING , X4_ENCODING } |
typedef enum QEI::Encoding | Encoding |
Encoder class with helper functions, derived from QEI.
This class call a function periodically to measure the speed of wheel. It features return values in terms of pulse per second, distance, and velocity.
Encoder::Encoder | ( | PinName | A, |
PinName | B | ||
) |
void Encoder::start | ( | ) |
Start the routine to measure pulses periodically.
Start timer and get current pulse. Timeout for every POLLING_PERIOD.
int Encoder::getCounter | ( | ) | const |
Get current running sum of pulses.
void Encoder::resetCounter | ( | ) |
Reset the running sum of pulses used for getDistance().
double Encoder::getVelocity | ( | ) | const |
Get current velocity.
double Encoder::getDistance | ( | ) | const |
Get total distance travelled.
The distance can be calculated from known values of COUNTS_PER_REV and CIRCUMFERENCE which is defined by \(distance = \frac{pulse\ counter\ \cdot\ cirmcumference}{2\ \cdot\ CPR}\\\)
double Encoder::getPPS | ( | ) | const |
Get current pulses per unit second (PPS).
|
static |
Get average of linear velocity between two wheels.
+ve indicates forward direction. -ve indicates reverse direction.
right_encoder | Right Wheel encoder. |
left_encoder | Left Wheel encoder. |
|
static |
Get average of total distance between two wheels.
+ve indicates forward direction. -ve indicates reverse direction.
right_encoder | Right Wheel encoder. |
left_encoder | Left Wheel encoder. |
|
private |
Calculate the velocity of the wheel.
The velocity can be calculated from known values of COUNTS_PER_REV CPR and CIRCUMFERENCE which is defined by \(velocity = \frac{pulse\ width\ \cdot\ cirmcumference}{2\ \cdot\ CPR \ \cdot \ time}\\\)
time_elapsed | The elapsed time between two pulse count. |
|
private |
Stop the timer and get current pulse.
|
private |
Counter for previous pulse.
|
private |
Counter for latest pulse.
|
private |
Counter for pulse difference.
|
private |
Counter for total pulses from start.
|
private |
Pulse per unit second.
|
private |
Velocity.
|
private |
Timer for high-precision clocking.
|
private |
Timeout to interrupt every POLLING_PERIOD.
Circumference of the wheel.
|
staticconstexpr |
Distance covered in full rotation when turning only using one wheel.
|
staticconstexpr |
Distance covered in full rotation when turning using both wheels.