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
Diff: encoder.cpp
- Revision:
- 2:4bb7c8730d91
- Parent:
- 1:c4643cba43a9
- Child:
- 3:6dce9d79da13
--- a/encoder.cpp Sat Jun 09 02:24:14 2018 +0000 +++ b/encoder.cpp Sun Jul 22 00:15:08 2018 +0000 @@ -1,21 +1,21 @@ #include "encoder.h" -Encoder::Encoder(PinName aPhase , PinName bPhase ) : aPhase(aPhase) , bPhase(bPhase) {} +Encoder::Encoder(PinName a_phase , PinName b_phase ) : aPhase(a_phase) , bPhase(b_phase) {} void Encoder::calState(){ //パルスの差分を更新 count[DELTA][ONE_BEFORE] = count[NORMAL][ONE_BEFORE] - count[NORMAL][TWO_BEFORE]; - count[DELTA][NOW] = count[NORMAL][NOW] - count[NORMAL][ONE_BEFORE]; + count[DELTA][CURRENT] = count[NORMAL][CURRENT] - count[NORMAL][ONE_BEFORE]; - distance = count[NORMAL][NOW] * circle / ppr; - rpm = (count[DELTA][NOW]/ppr) * 60 / dt; - velocity = (count[DELTA][NOW]/ppr)*circle/dt; - acceleration = (count[DELTA][NOW]-count[DELTA][ONE_BEFORE])/(dt_square*ppr) * circle; - omega = (2*PI*count[DELTA][NOW])/(ppr*dt); - delta_distance = (count[DELTA][NOW]/ppr)*circle; + distance = count[NORMAL][CURRENT] * circle / ppr; + rpm = (count[DELTA][CURRENT]/ppr) * 60 / dt; + velocity = (count[DELTA][CURRENT]/ppr)*circle/dt; + acceleration = (count[DELTA][CURRENT]-count[DELTA][ONE_BEFORE])/(dt_square*ppr) * circle; + omega = (2*PI*count[DELTA][CURRENT])/(ppr*dt); + delta_distance = (count[DELTA][CURRENT]/ppr)*circle; //1つ前・2つ前のデータを更新 count[NORMAL][TWO_BEFORE] = count[NORMAL][ONE_BEFORE]; - count[NORMAL][ONE_BEFORE] = count[NORMAL][NOW]; + count[NORMAL][ONE_BEFORE] = count[NORMAL][CURRENT]; } float Encoder::getState(int ch){ @@ -44,7 +44,7 @@ } void Encoder::reset(){ - for(int i=NOW;i<BEFORE_NUMBER;i++){ + for(int i=CURRENT;i<BEFORE_NUMBER;i++){ count[NORMAL][i] = 0; count[DELTA][i] = 0; } @@ -52,9 +52,9 @@ void Encoder::read(){ if(bPhase){ - count[NORMAL][NOW]++; + count[NORMAL][CURRENT]++; } else { - count[NORMAL][NOW]--; + count[NORMAL][CURRENT]--; } }