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@1:12f18cede014, 2018-02-15 (annotated)
- Committer:
- Weranest
- Date:
- Thu Feb 15 20:17:42 2018 +0000
- Revision:
- 1:12f18cede014
- Parent:
- 0:62e51b80d738
- Child:
- 2:7f4be54c7257
Working motor pwm complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Weranest | 1:12f18cede014 | 1 | /*#include "mbed.h" |
Weranest | 0:62e51b80d738 | 2 | #include "QEI.h" |
Weranest | 0:62e51b80d738 | 3 | #include "pins.cpp" |
Weranest | 0:62e51b80d738 | 4 | #define ENCODER_PULSE 256 //per manual |
Weranest | 0:62e51b80d738 | 5 | #define GEAR_RATIO |
Weranest | 1:12f18cede014 | 6 | #define SAMPLE_TIME 1.0f //user defined |
Weranest | 0:62e51b80d738 | 7 | #define WHEEL_DISTANCE //need to measure that |
Weranest | 0:62e51b80d738 | 8 | |
Weranest | 0:62e51b80d738 | 9 | //these lines setup the encoders for both wheels |
Weranest | 0:62e51b80d738 | 10 | QEI encoderRight(channelARight, channelBRight, channelIRight, ENCODER_PULSE); |
Weranest | 0:62e51b80d738 | 11 | QEI encoderLeft(channelALeft, channelBLeft, channelILeft, ENCODER_PULSE); |
Weranest | 0:62e51b80d738 | 12 | |
Weranest | 0:62e51b80d738 | 13 | //main wheel class, the subclasses should follow later |
Weranest | 0:62e51b80d738 | 14 | class Wheel{ |
Weranest | 0:62e51b80d738 | 15 | int currentPulses, previousPulses; |
Weranest | 0:62e51b80d738 | 16 | public: |
Weranest | 0:62e51b80d738 | 17 | float wheelVelocity(float, int){ |
Weranest | 0:62e51b80d738 | 18 | } |
Weranest | 0:62e51b80d738 | 19 | private: |
Weranest | 1:12f18cede014 | 20 | float sampleTime= SAMPLE_TIME; |
Weranest | 0:62e51b80d738 | 21 | int gearRatio = GEAR_RATIO; |
Weranest | 0:62e51b80d738 | 22 | float encoderVelocity(){ |
Weranest | 0:62e51b80d738 | 23 | return (currentEncoderTicks-previousEncoderTicks)/sampleTime; |
Weranest | 0:62e51b80d738 | 24 | } |
Weranest | 1:12f18cede014 | 25 | |
Weranest | 0:62e51b80d738 | 26 | } wheelRight, wheelLeft; |
Weranest | 0:62e51b80d738 | 27 | |
Weranest | 0:62e51b80d738 | 28 | class WheelLeft |
Weranest | 0:62e51b80d738 | 29 | |
Weranest | 0:62e51b80d738 | 30 | //call this for speed, linear and angular |
Weranest | 0:62e51b80d738 | 31 | class Buggy{ |
Weranest | 0:62e51b80d738 | 32 | public: |
Weranest | 0:62e51b80d738 | 33 | float speedLinear(float wheelVelocityRight, float wheelVelocityLeft){ |
Weranest | 0:62e51b80d738 | 34 | return (wheelVelocityRight+wheelVelocityLeft)/2; |
Weranest | 0:62e51b80d738 | 35 | } |
Weranest | 0:62e51b80d738 | 36 | float speedAngular(float wheelVelocityRight, float wheelVelocityLeft){ |
Weranest | 0:62e51b80d738 | 37 | return (wheelVelocityRight-wheelVelocityLeft)/WHEEL_DISTANCE; |
Weranest | 0:62e51b80d738 | 38 | } |
Weranest | 0:62e51b80d738 | 39 | } |
Weranest | 1:12f18cede014 | 40 | int encoderTicks(){ |
Weranest | 1:12f18cede014 | 41 | previousEncoderTicks=currentEncoderTicks; |
Weranest | 1:12f18cede014 | 42 | currentEncoderTicks= |
Weranest | 1:12f18cede014 | 43 | } |
Weranest | 0:62e51b80d738 | 44 | |
Weranest | 0:62e51b80d738 | 45 | |
Weranest | 1:12f18cede014 | 46 | */ |