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@3:6dce9d79da13, 2018-12-04 (annotated)
- Committer:
- takenowa
- Date:
- Tue Dec 04 09:42:15 2018 +0000
- Revision:
- 3:6dce9d79da13
- Parent:
- 2:4bb7c8730d91
- Child:
- 4:c99eb511ac08
1204 update;
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 | 3:6dce9d79da13 | 16 | enum ENCODER_MODE{ |
| takenowa | 3:6dce9d79da13 | 17 | X1_ENCODE, |
| takenowa | 3:6dce9d79da13 | 18 | X2_ENCODE, |
| takenowa | 3:6dce9d79da13 | 19 | X4_ENCODE, |
| takenowa | 3:6dce9d79da13 | 20 | |
| takenowa | 3:6dce9d79da13 | 21 | }; |
| takenowa | 3:6dce9d79da13 | 22 | |
| takenowa | 0:4b99060621fd | 23 | enum TYPE_NUMBER{ |
| takenowa | 0:4b99060621fd | 24 | NORMAL, |
| takenowa | 0:4b99060621fd | 25 | DELTA, |
| takenowa | 0:4b99060621fd | 26 | TYPE_NUMBER, |
| takenowa | 0:4b99060621fd | 27 | }; |
| takenowa | 0:4b99060621fd | 28 | |
| takenowa | 0:4b99060621fd | 29 | enum BEFORE_NUMBER{ |
| takenowa | 2:4bb7c8730d91 | 30 | CURRENT, |
| takenowa | 0:4b99060621fd | 31 | ONE_BEFORE, |
| takenowa | 0:4b99060621fd | 32 | TWO_BEFORE, |
| takenowa | 0:4b99060621fd | 33 | BEFORE_NUMBER, |
| takenowa | 0:4b99060621fd | 34 | }; |
| takenowa | 0:4b99060621fd | 35 | |
| takenowa | 0:4b99060621fd | 36 | class Encoder |
| takenowa | 0:4b99060621fd | 37 | { |
| takenowa | 0:4b99060621fd | 38 | public: |
| takenowa | 2:4bb7c8730d91 | 39 | Encoder(PinName a_phase , PinName b_phase ); |
| takenowa | 0:4b99060621fd | 40 | void calState(); |
| takenowa | 0:4b99060621fd | 41 | |
| takenowa | 0:4b99060621fd | 42 | float getState(int ch); |
| takenowa | 0:4b99060621fd | 43 | |
| takenowa | 0:4b99060621fd | 44 | void reset(); |
| takenowa | 0:4b99060621fd | 45 | |
| takenowa | 3:6dce9d79da13 | 46 | void init(float _ppr, float _radius,float _dt,int mode); |
| takenowa | 0:4b99060621fd | 47 | private: |
| takenowa | 3:6dce9d79da13 | 48 | void readAphaseRise(); |
| takenowa | 3:6dce9d79da13 | 49 | void readAphaseFall(); |
| takenowa | 0:4b99060621fd | 50 | float rpm, distance, omega, velocity, radius, delta_distance, |
| takenowa | 0:4b99060621fd | 51 | ppr, dt, dt_square, circle, acceleration; |
| takenowa | 0:4b99060621fd | 52 | |
| takenowa | 2:4bb7c8730d91 | 53 | float count[TYPE_NUMBER][BEFORE_NUMBER];/* = { |
| takenowa | 2:4bb7c8730d91 | 54 | {[NORMAL][NOW], [NORMAL][ONE_BEFORE], [NORMAL][TWO_BEFORE]}, |
| takenowa | 2:4bb7c8730d91 | 55 | {[DELTA][NOW], [DELTA][ONE_BEFORE], [DELTA][TWO_BEFORE]} |
| takenowa | 2:4bb7c8730d91 | 56 | } |
| takenowa | 2:4bb7c8730d91 | 57 | */ |
| takenowa | 0:4b99060621fd | 58 | InterruptIn aPhase; |
| takenowa | 0:4b99060621fd | 59 | DigitalIn bPhase; |
| takenowa | 0:4b99060621fd | 60 | }; |
| takenowa | 0:4b99060621fd | 61 | |
| takenowa | 0:4b99060621fd | 62 | #endif |
| takenowa | 0:4b99060621fd | 63 |