Wheel control software for satellite microcontroller running the motors on the Karbor
Dependencies: mbed ros_lib_melodic
Diff: src/encoder.h
- Revision:
- 5:44b2454a5eea
- Parent:
- 3:4b6080e86761
- Child:
- 6:ed47deb76adf
--- a/src/encoder.h Mon May 31 16:47:02 2021 +0000 +++ b/src/encoder.h Tue Jun 08 15:04:33 2021 +0000 @@ -1,19 +1,16 @@ +/** + * @file encoder.h + * This class is based upon the QEI class by Aaron Berk and the encoder class I wrote during ESP in 2nd year. + * + * @author Simon Krogedal + * + * @version 0.1 + */ + #ifndef KARBOT_ENCODER_H #define KARBOT_ENCODER_H -/* Karbot encoder class - * - * This class is based upon the QEI class by Aaron Berk and the encoder class - * I wrote during ESP in 2nd year - * - * Written by Simon Krogedal - * 27/05/21 - * Team 9 4th Year project - * - * for NUCLEO-F401RE - * - */ - + #include "mbed.h" @@ -23,6 +20,24 @@ //of rotation. #define INVALID 0x3 //XORing two states where both bits have changed. +/** encoder Class + * + * Class for measeuring quadrature magnetic encoders requiring internal pullups + * + * @author Simon Krogedal + * + * Written by Simon Krogedal + * + * 27/05/2021 + * + * Team 9 4th Year project + * + * + * for NUCLEO-F401RE + * + * @version 0.2 + * + */ class encoder { private: @@ -51,23 +66,57 @@ protected: - Ticker sampler; // ticker object to sample speed - double period, enc_const; // sampling period and wheel constant - void sample_func(void); // sample function - double getClicks(void); // returns clickrate + Ticker sampler; /// ticker object to sample speed + double period, enc_const; /// sampling period and wheel constant + + /// Sample function called by ticker object + void sample_func(void); + + /** Get wheel speed + * @returns Wheel speed in clicks/second + */ + double getClicks(void); /// returns clickrate public: - // Constructor takes 3 encoder input pins, CPR, left or right bool, sampling period, and a wheel-size constant - encoder(PinName chanA, PinName chanB, int CPR, bool c, double p, double ec); + /** Create an instance + * + * @param chanA Encoder channel A pin + * @param chanB Encoder channel B pin + * @param CPR Encoder clicks per revolution + * @param c Boolean flag to invert speeds, used to correct for left and right motors + * @param p Sampling period of the wheel speed + * @note Too short samling period gives a noisy reading, too long and dynamics are lost + * @param diameter Wheel diameter + */ + encoder(PinName chanA, PinName chanB, int CPR, bool c, double p, double diameter); + + /** Get wheel speed + * @returns Wheel speed in meters/second + */ + double getSpeed(void); - double getSpeed(void); // returns wheel speed - double getDistance(void); // returns distance travelled - double tempDist(void); // returns distance travelled - void distRst(void); // resets distance - void tempRst(void); // resets distance - void start(void); // starts recording distance - void reset(void); // resets counting + /** Get distance travelled + * @returns Distance travelled in meters + */ + double getDistance(void); + + /** Get distance travelled + * @returns Distance travelled in meters since last reset + */ + double tempDist(void); + + /// Reset distance measurement + void distRst(void); + + /// Reset distance measurement + void tempRst(void); + + /// Start encoder reading + void start(void); + + /// Stop encoder reading + void reset(void); /** * Read the state of the encoder.