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@3:c9df852ad9ac, 2018-02-21 (annotated)
- Committer:
- Weranest
- Date:
- Wed Feb 21 11:55:29 2018 +0000
- Revision:
- 3:c9df852ad9ac
- Parent:
- 2:7f4be54c7257
- Child:
- 4:48d390356fba
For Alston
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Weranest | 2:7f4be54c7257 | 1 | #include "mbed.h" |
Weranest | 0:62e51b80d738 | 2 | #include "QEI.h" |
Weranest | 3:c9df852ad9ac | 3 | #include "pins.h" |
Weranest | 3:c9df852ad9ac | 4 | #include "constants.h" |
Weranest | 3:c9df852ad9ac | 5 | |
Weranest | 0:62e51b80d738 | 6 | |
Weranest | 0:62e51b80d738 | 7 | //these lines setup the encoders for both wheels |
Weranest | 0:62e51b80d738 | 8 | |
Weranest | 0:62e51b80d738 | 9 | //main wheel class, the subclasses should follow later |
Weranest | 0:62e51b80d738 | 10 | class Wheel{ |
Weranest | 0:62e51b80d738 | 11 | int currentPulses, previousPulses; |
Weranest | 0:62e51b80d738 | 12 | public: |
Weranest | 3:c9df852ad9ac | 13 | float velocity(int wheelPulses){ |
Weranest | 3:c9df852ad9ac | 14 | return encoderVelocity(wheelPulses)*GEAR_RATIO; |
Weranest | 0:62e51b80d738 | 15 | } |
Weranest | 0:62e51b80d738 | 16 | private: |
Weranest | 3:c9df852ad9ac | 17 | float encoderVelocity(int encoderPulse){ |
Weranest | 3:c9df852ad9ac | 18 | wait(SAMPLE_TIME); |
Weranest | 3:c9df852ad9ac | 19 | previousPulses=currentPulses; |
Weranest | 3:c9df852ad9ac | 20 | currentPulses=encoderPulse; |
Weranest | 3:c9df852ad9ac | 21 | return (currentPulses-previousPulses)/SAMPLE_TIME; |
Weranest | 0:62e51b80d738 | 22 | } |
Weranest | 1:12f18cede014 | 23 | |
Weranest | 0:62e51b80d738 | 24 | } wheelRight, wheelLeft; |
Weranest | 0:62e51b80d738 | 25 | |
Weranest | 0:62e51b80d738 | 26 | //call this for speed, linear and angular |
Weranest | 0:62e51b80d738 | 27 | class Buggy{ |
Weranest | 0:62e51b80d738 | 28 | public: |
Weranest | 3:c9df852ad9ac | 29 | float speedLinear(int pulseRight, int pulseLeft){ |
Weranest | 3:c9df852ad9ac | 30 | return (wheelRight.velocity(pulseRight)+wheelLeft.velocity(pulseLeft))/2; |
Weranest | 0:62e51b80d738 | 31 | } |
Weranest | 3:c9df852ad9ac | 32 | float speedAngular(int pulseRight, int pulseLeft){ |
Weranest | 3:c9df852ad9ac | 33 | return (wheelRight.velocity(pulseRight)-wheelLeft.velocity(pulseLeft))/WHEEL_DISTANCE; |
Weranest | 0:62e51b80d738 | 34 | } |
Weranest | 2:7f4be54c7257 | 35 | }buggy; |