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.
Dependencies: mbed
QEI/Encoder.h@4:208f5279143a, 2019-03-23 (annotated)
- Committer:
- mazdo25
- Date:
- Sat Mar 23 19:46:09 2019 +0000
- Revision:
- 4:208f5279143a
- Parent:
- 3:01b5e80d842d
latest working, but line following not;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mazdo25 | 3:01b5e80d842d | 1 | //works only in x2 encoding (512 counts per second) |
| mazdo25 | 3:01b5e80d842d | 2 | #include "QEI.h" |
| mazdo25 | 3:01b5e80d842d | 3 | class Encoder: public QEI { |
| mazdo25 | 3:01b5e80d842d | 4 | private: |
| mazdo25 | 3:01b5e80d842d | 5 | Timer dT; //to calculate rate of change of encoder ticks. |
| mazdo25 | 3:01b5e80d842d | 6 | int prevPulses; |
| mazdo25 | 3:01b5e80d842d | 7 | |
| mazdo25 | 3:01b5e80d842d | 8 | public: |
| mazdo25 | 3:01b5e80d842d | 9 | |
| mazdo25 | 3:01b5e80d842d | 10 | Encoder(PinName A, PinName B) : QEI(A,B,NC,256,X2_ENCODING) |
| mazdo25 | 3:01b5e80d842d | 11 | { |
| mazdo25 | 3:01b5e80d842d | 12 | prevPulses = 0; |
| mazdo25 | 3:01b5e80d842d | 13 | dT.stop(); |
| mazdo25 | 3:01b5e80d842d | 14 | |
| mazdo25 | 3:01b5e80d842d | 15 | }; |
| mazdo25 | 3:01b5e80d842d | 16 | |
| mazdo25 | 3:01b5e80d842d | 17 | float encoderTickRate() { |
| mazdo25 | 3:01b5e80d842d | 18 | int PP = prevPulses; |
| mazdo25 | 3:01b5e80d842d | 19 | int CP = QEI::getPulses(); |
| mazdo25 | 3:01b5e80d842d | 20 | float deltaT = dT.read(); |
| mazdo25 | 3:01b5e80d842d | 21 | prevPulses = CP; |
| mazdo25 | 3:01b5e80d842d | 22 | dT.reset(); |
| mazdo25 | 3:01b5e80d842d | 23 | return ((float)(CP-PP)/deltaT); |
| mazdo25 | 3:01b5e80d842d | 24 | }; |
| mazdo25 | 3:01b5e80d842d | 25 | |
| mazdo25 | 3:01b5e80d842d | 26 | void startTimer(void) |
| mazdo25 | 3:01b5e80d842d | 27 | { |
| mazdo25 | 3:01b5e80d842d | 28 | dT.start(); |
| mazdo25 | 3:01b5e80d842d | 29 | } |
| mazdo25 | 3:01b5e80d842d | 30 | |
| mazdo25 | 4:208f5279143a | 31 | }; |