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.
Dependents: backdrive backdrive_3
encoder.h@0:4b99060621fd, 2018-06-04 (annotated)
- Committer:
- takenowa
- Date:
- Mon Jun 04 07:38:05 2018 +0000
- Revision:
- 0:4b99060621fd
- Child:
- 2:4bb7c8730d91
?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takenowa | 0:4b99060621fd | 1 | #ifndef ENCODER_H |
takenowa | 0:4b99060621fd | 2 | #define ENCODER_H |
takenowa | 0:4b99060621fd | 3 | |
takenowa | 0:4b99060621fd | 4 | #include "mbed.h" |
takenowa | 0:4b99060621fd | 5 | #include "arm_math.h" |
takenowa | 0:4b99060621fd | 6 | |
takenowa | 0:4b99060621fd | 7 | enum CH{ |
takenowa | 0:4b99060621fd | 8 | DISTANCE, |
takenowa | 0:4b99060621fd | 9 | RPM, |
takenowa | 0:4b99060621fd | 10 | VELOCITY, |
takenowa | 0:4b99060621fd | 11 | ACCELERATION, |
takenowa | 0:4b99060621fd | 12 | OMEGA, |
takenowa | 0:4b99060621fd | 13 | DELTA_DISTANCE, |
takenowa | 0:4b99060621fd | 14 | }; |
takenowa | 0:4b99060621fd | 15 | |
takenowa | 0:4b99060621fd | 16 | enum TYPE_NUMBER{ |
takenowa | 0:4b99060621fd | 17 | NORMAL, |
takenowa | 0:4b99060621fd | 18 | DELTA, |
takenowa | 0:4b99060621fd | 19 | TYPE_NUMBER, |
takenowa | 0:4b99060621fd | 20 | }; |
takenowa | 0:4b99060621fd | 21 | |
takenowa | 0:4b99060621fd | 22 | enum BEFORE_NUMBER{ |
takenowa | 0:4b99060621fd | 23 | NOW, |
takenowa | 0:4b99060621fd | 24 | ONE_BEFORE, |
takenowa | 0:4b99060621fd | 25 | TWO_BEFORE, |
takenowa | 0:4b99060621fd | 26 | BEFORE_NUMBER, |
takenowa | 0:4b99060621fd | 27 | }; |
takenowa | 0:4b99060621fd | 28 | |
takenowa | 0:4b99060621fd | 29 | class Encoder |
takenowa | 0:4b99060621fd | 30 | { |
takenowa | 0:4b99060621fd | 31 | public: |
takenowa | 0:4b99060621fd | 32 | Encoder(PinName aPhase , PinName bPhase ); |
takenowa | 0:4b99060621fd | 33 | void calState(); |
takenowa | 0:4b99060621fd | 34 | |
takenowa | 0:4b99060621fd | 35 | float getState(int ch); |
takenowa | 0:4b99060621fd | 36 | |
takenowa | 0:4b99060621fd | 37 | void reset(); |
takenowa | 0:4b99060621fd | 38 | |
takenowa | 0:4b99060621fd | 39 | void init(float _ppr, float _radius,float _dt); |
takenowa | 0:4b99060621fd | 40 | |
takenowa | 0:4b99060621fd | 41 | private: |
takenowa | 0:4b99060621fd | 42 | void read(); |
takenowa | 0:4b99060621fd | 43 | |
takenowa | 0:4b99060621fd | 44 | float rpm, distance, omega, velocity, radius, delta_distance, |
takenowa | 0:4b99060621fd | 45 | ppr, dt, dt_square, circle, acceleration; |
takenowa | 0:4b99060621fd | 46 | |
takenowa | 0:4b99060621fd | 47 | float count[TYPE_NUMBER][BEFORE_NUMBER]; |
takenowa | 0:4b99060621fd | 48 | InterruptIn aPhase; |
takenowa | 0:4b99060621fd | 49 | DigitalIn bPhase; |
takenowa | 0:4b99060621fd | 50 | }; |
takenowa | 0:4b99060621fd | 51 | |
takenowa | 0:4b99060621fd | 52 | #endif |
takenowa | 0:4b99060621fd | 53 |