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@6:36805e006b09, 2019-06-19 (annotated)
- Committer:
- takenowa
- Date:
- Wed Jun 19 01:46:13 2019 +0000
- Revision:
- 6:36805e006b09
- Parent:
- 5:32ee588c735d
0619(add return "count")
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 | 6:36805e006b09 | 8 | COUNT, |
| takenowa | 0:4b99060621fd | 9 | DISTANCE, |
| takenowa | 0:4b99060621fd | 10 | RPM, |
| takenowa | 0:4b99060621fd | 11 | VELOCITY, |
| takenowa | 0:4b99060621fd | 12 | ACCELERATION, |
| takenowa | 0:4b99060621fd | 13 | OMEGA, |
| takenowa | 0:4b99060621fd | 14 | DELTA_DISTANCE, |
| takenowa | 0:4b99060621fd | 15 | }; |
| takenowa | 0:4b99060621fd | 16 | |
| takenowa | 3:6dce9d79da13 | 17 | enum ENCODER_MODE{ |
| takenowa | 3:6dce9d79da13 | 18 | X1_ENCODE, |
| takenowa | 3:6dce9d79da13 | 19 | X2_ENCODE, |
| takenowa | 3:6dce9d79da13 | 20 | X4_ENCODE, |
| takenowa | 3:6dce9d79da13 | 21 | |
| takenowa | 3:6dce9d79da13 | 22 | }; |
| takenowa | 3:6dce9d79da13 | 23 | |
| takenowa | 0:4b99060621fd | 24 | enum TYPE_NUMBER{ |
| takenowa | 0:4b99060621fd | 25 | NORMAL, |
| takenowa | 0:4b99060621fd | 26 | DELTA, |
| takenowa | 0:4b99060621fd | 27 | TYPE_NUMBER, |
| takenowa | 0:4b99060621fd | 28 | }; |
| takenowa | 0:4b99060621fd | 29 | |
| takenowa | 0:4b99060621fd | 30 | enum BEFORE_NUMBER{ |
| takenowa | 2:4bb7c8730d91 | 31 | CURRENT, |
| takenowa | 0:4b99060621fd | 32 | ONE_BEFORE, |
| takenowa | 0:4b99060621fd | 33 | TWO_BEFORE, |
| takenowa | 0:4b99060621fd | 34 | BEFORE_NUMBER, |
| takenowa | 0:4b99060621fd | 35 | }; |
| takenowa | 0:4b99060621fd | 36 | |
| takenowa | 0:4b99060621fd | 37 | class Encoder |
| takenowa | 0:4b99060621fd | 38 | { |
| takenowa | 0:4b99060621fd | 39 | public: |
| takenowa | 2:4bb7c8730d91 | 40 | Encoder(PinName a_phase , PinName b_phase ); |
| takenowa | 5:32ee588c735d | 41 | void calculate(); |
| takenowa | 0:4b99060621fd | 42 | |
| takenowa | 0:4b99060621fd | 43 | float getState(int ch); |
| takenowa | 0:4b99060621fd | 44 | |
| takenowa | 0:4b99060621fd | 45 | void reset(); |
| takenowa | 0:4b99060621fd | 46 | |
| takenowa | 3:6dce9d79da13 | 47 | void init(float _ppr, float _radius,float _dt,int mode); |
| takenowa | 0:4b99060621fd | 48 | private: |
| takenowa | 3:6dce9d79da13 | 49 | void readAphaseRise(); |
| takenowa | 3:6dce9d79da13 | 50 | void readAphaseFall(); |
| takenowa | 4:c99eb511ac08 | 51 | void readBphaseRise(); |
| takenowa | 4:c99eb511ac08 | 52 | void readBphaseFall(); |
| takenowa | 0:4b99060621fd | 53 | float rpm, distance, omega, velocity, radius, delta_distance, |
| takenowa | 0:4b99060621fd | 54 | ppr, dt, dt_square, circle, acceleration; |
| takenowa | 0:4b99060621fd | 55 | |
| takenowa | 2:4bb7c8730d91 | 56 | float count[TYPE_NUMBER][BEFORE_NUMBER];/* = { |
| takenowa | 2:4bb7c8730d91 | 57 | {[NORMAL][NOW], [NORMAL][ONE_BEFORE], [NORMAL][TWO_BEFORE]}, |
| takenowa | 2:4bb7c8730d91 | 58 | {[DELTA][NOW], [DELTA][ONE_BEFORE], [DELTA][TWO_BEFORE]} |
| takenowa | 2:4bb7c8730d91 | 59 | } |
| takenowa | 2:4bb7c8730d91 | 60 | */ |
| takenowa | 0:4b99060621fd | 61 | InterruptIn aPhase; |
| takenowa | 4:c99eb511ac08 | 62 | InterruptIn bPhase; |
| takenowa | 0:4b99060621fd | 63 | }; |
| takenowa | 0:4b99060621fd | 64 | |
| takenowa | 0:4b99060621fd | 65 | #endif |
| takenowa | 0:4b99060621fd | 66 |