Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
encoderBase.cpp
- Committer:
- Weranest
- Date:
- 2018-02-22
- Revision:
- 4:48d390356fba
- Parent:
- 3:c9df852ad9ac
File content as of revision 4:48d390356fba:
#include "mbed.h" #include "QEI.h" #include "pins.h" #include "constants.cpp" //these lines setup the encoders for both wheels //main wheel class, the subclasses should follow later class Wheel{ int currentPulses, previousPulses; public: float velocity(int wheelPulses){ return encoderVelocity(wheelPulses)*GEAR_RATIO; } private: float encoderVelocity(int encoderPulse){ wait(SAMPLE_TIME); previousPulses=currentPulses; currentPulses=encoderPulse; return (currentPulses-previousPulses)/SAMPLE_TIME; } } wheelRight, wheelLeft; //call this for speed, linear and angular class Buggy{ public: float speedLinear(int pulseRight, int pulseLeft){ return (wheelRight.velocity(pulseRight)+wheelLeft.velocity(pulseLeft))/2; } float speedAngular(int pulseRight, int pulseLeft){ return (wheelRight.velocity(pulseRight)-wheelLeft.velocity(pulseLeft))/WHEEL_DISTANCE; } }buggy; //temp functions to get the encoder speed int encoderVelocityLeft(){ return wheelLeft.velocity(encoderLeft.getPulses()); } int encoderVelocityRight(){ return wheelRight.velocity(encoderRight.getPulses()); }