自分用QEI
エンコーダの回転方向はデフォの状態の反対を正としたいならrotReverce()を呼び出すと反対になる.
22020/3/6 移動平均を使ってパルスを平滑化し,RPSを算出している. useAvePRS()を書くことで,エンコーダのパルスを時間平均しそのままRPSを算出する関数MoveAve_pulse_to_RPS()がタイマー割り込みで呼び出される.移動平均を使うことでエンコーダのパルスのばらつきを無くし,平均をとらないとガタガタになるRPSがそこそこ綺麗になる.3000usごとの割り込み.この時間が長いほど精度は高い.あとclass内で配列の格納数をconst int で定義しているため黄色いエラーが出るけど無視. この方法でとったRPSの呼び出しはgetRPS()を使う.
QEI.h@0:47508ccc086b, 2020-03-05 (annotated)
- Committer:
- ttrist
- Date:
- Thu Mar 05 08:27:36 2020 +0000
- Revision:
- 0:47508ccc086b
- Child:
- 1:2b1d4925ea1c
aaa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ttrist | 0:47508ccc086b | 1 | #ifndef QEI_H |
ttrist | 0:47508ccc086b | 2 | #define QEI_H |
ttrist | 0:47508ccc086b | 3 | |
ttrist | 0:47508ccc086b | 4 | #include "mbed.h" |
ttrist | 0:47508ccc086b | 5 | |
ttrist | 0:47508ccc086b | 6 | class QEI |
ttrist | 0:47508ccc086b | 7 | { |
ttrist | 0:47508ccc086b | 8 | public: |
ttrist | 0:47508ccc086b | 9 | QEI(PinName A,PinName B,int PPR,Timer *timer,Ticker *ticker); |
ttrist | 0:47508ccc086b | 10 | void init(); |
ttrist | 0:47508ccc086b | 11 | void useAvePRS(); |
ttrist | 0:47508ccc086b | 12 | void CountPulse(); |
ttrist | 0:47508ccc086b | 13 | /* |
ttrist | 0:47508ccc086b | 14 | void MoveAve_pulse(); |
ttrist | 0:47508ccc086b | 15 | */ |
ttrist | 0:47508ccc086b | 16 | void MoveAve_pulse_to_RPS(); |
ttrist | 0:47508ccc086b | 17 | float getRPS(); |
ttrist | 0:47508ccc086b | 18 | void rotReverce(); |
ttrist | 0:47508ccc086b | 19 | |
ttrist | 0:47508ccc086b | 20 | private: |
ttrist | 0:47508ccc086b | 21 | InterruptIn chA; |
ttrist | 0:47508ccc086b | 22 | InterruptIn chB; |
ttrist | 0:47508ccc086b | 23 | Timer *_timer; |
ttrist | 0:47508ccc086b | 24 | Ticker *_ticker; |
ttrist | 0:47508ccc086b | 25 | int _PPR; |
ttrist | 0:47508ccc086b | 26 | float current_rps; |
ttrist | 0:47508ccc086b | 27 | uint8_t pre_ABstate; |
ttrist | 0:47508ccc086b | 28 | const int data_sizeof = 30; |
ttrist | 0:47508ccc086b | 29 | int pulse,pulseData[data_sizeof]; |
ttrist | 0:47508ccc086b | 30 | float pulseAve; |
ttrist | 0:47508ccc086b | 31 | float rps; |
ttrist | 0:47508ccc086b | 32 | int8_t NrotDIR; |
ttrist | 0:47508ccc086b | 33 | }; |
ttrist | 0:47508ccc086b | 34 | |
ttrist | 0:47508ccc086b | 35 | #endif |