9#define GEAR_RATIO 18.75
13#define WHEEL_DISTANCE 0.212
15#define COUNTS_PER_REV 256
17#define POLLING_PERIOD 10ms
21#define M_PI 3.14159265358979323846264338327950288
Encoder class with helper functions, derived from QEI.
Definition: encoder.h:28
void m_calculateSpeed(const double &time_elapsed)
Calculate the velocity of the wheel.
static double getAverageVelocity(const Encoder &right_encoder, const Encoder &left_encoder)
Get average of linear velocity between two wheels.
static double getAverageAngular(const Encoder &right_encoder, const Encoder &left_encoder)
Get average of angular velocity between two wheels.
double getDistance() const
Get total distance travelled.
Timer m_t
Timer for high-precision clocking.
Definition: encoder.h:49
double getPPS() const
Get current pulses per unit second (PPS).
volatile int m_pulse_counter
Counter for total pulses from start.
Definition: encoder.h:40
static constexpr double FULL_ROTATION_CENTER_PIVOT
Distance covered in full rotation when turning using both wheels.
Definition: encoder.h:77
volatile int m_pulse_width
Counter for pulse difference.
Definition: encoder.h:37
void resetCounter()
Reset the running sum of pulses used for getDistance().
static constexpr double FULL_ROTATION_SIDE_PIVOT
Distance covered in full rotation when turning only using one wheel.
Definition: encoder.h:72
volatile int m_end_pulse
Counter for latest pulse.
Definition: encoder.h:34
void m_stop()
Stop the timer and get current pulse.
static double getAverageDistance(const Encoder &right_encoder, const Encoder &left_encoder)
Get average of total distance between two wheels.
Timeout m_to
Timeout to interrupt every POLLING_PERIOD.
Definition: encoder.h:52
volatile int m_start_pulse
Counter for previous pulse.
Definition: encoder.h:31
int getCounter() const
Get current running sum of pulses.
volatile double m_pulse_per_sec
Pulse per unit second.
Definition: encoder.h:43
double getVelocity() const
Get current velocity.
void start()
Start the routine to measure pulses periodically.
volatile double m_velocity
Velocity.
Definition: encoder.h:46
Encoder(PinName A, PinName B)
Constructor.
static constexpr double CIRCUMFERENCE
Circumference of the wheel.
Definition: encoder.h:67
Handle reading pulses from encoder.
Definition: QEI.h:84
#define DIAMETER
Diameter of the wheel.
Definition: encoder.h:11
#define M_PI
Define M_PI on ArmC6.
Definition: encoder.h:21
#define WHEEL_DISTANCE
Distance between two wheels.
Definition: encoder.h:13