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
Revision 8:dd1732f51780, committed 2019-05-03
- Comitter:
- takenowa
- Date:
- Fri May 03 08:36:12 2019 +0000
- Parent:
- 4:c99eb511ac08
- Commit message:
- removed divide calculate
Changed in this revision
encoder.cpp | Show annotated file Show diff for this revision Revisions of this file |
encoder.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/encoder.cpp Sat Jan 05 07:16:33 2019 +0000 +++ b/encoder.cpp Fri May 03 08:36:12 2019 +0000 @@ -7,12 +7,12 @@ count[DELTA][ONE_BEFORE] = count[NORMAL][ONE_BEFORE] - count[NORMAL][TWO_BEFORE]; count[DELTA][CURRENT] = count[NORMAL][CURRENT] - count[NORMAL][ONE_BEFORE]; - distance = count[NORMAL][CURRENT] * circle / ppr; - rpm = (count[DELTA][CURRENT]/ppr) * 60 / dt; - velocity = (count[DELTA][CURRENT]/ppr)*circle/dt; + distance = count[NORMAL][CURRENT] * circle * ppr_rev; + rpm = (count[DELTA][CURRENT]) * 60 *dt_rev * ppr_rev; + velocity = (count[DELTA][CURRENT])*circle*dt_rev * ppr_rev; //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; + delta_distance = (count[DELTA][CURRENT])*circle*ppr_rev; //1つ前・2つ前のデータを更新 count[NORMAL][TWO_BEFORE] = count[NORMAL][ONE_BEFORE]; count[NORMAL][ONE_BEFORE] = count[NORMAL][CURRENT]; @@ -89,7 +89,8 @@ dt_square = dt*dt; circle = PI*2.0f*_radius; radius = _radius; - + dt_rev = 1/dt; + ppr_rev = 1/ppr; switch(mode){ case X1_ENCODE: aPhase.rise(this,&Encoder::readAphaseRise);
--- a/encoder.h Sat Jan 05 07:16:33 2019 +0000 +++ b/encoder.h Fri May 03 08:36:12 2019 +0000 @@ -52,7 +52,7 @@ void readBphaseFall(); float rpm, distance, omega, velocity, radius, delta_distance, ppr, dt, dt_square, circle, acceleration; - + float ppr_rev, dt_rev; float count[TYPE_NUMBER][BEFORE_NUMBER];/* = { {[NORMAL][NOW], [NORMAL][ONE_BEFORE], [NORMAL][TWO_BEFORE]}, {[DELTA][NOW], [DELTA][ONE_BEFORE], [DELTA][TWO_BEFORE]}