QEI library with velocity implementation based on time difference between successive encoder counts.
Dependents: Bezier_Trajectory_Follower Dolphin 2_131TEST Jerby ... more
Revision 4:58a3c9c9e956, committed 2015-09-23
- Comitter:
- pwensing
- Date:
- Wed Sep 23 17:33:09 2015 +0000
- Parent:
- 0:43b9eeecccc7
- Commit message:
- trying volatiles for smoother velocity
Changed in this revision
QEI.cpp | Show annotated file Show diff for this revision Revisions of this file |
QEI.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/QEI.cpp Tue Aug 11 20:02:03 2015 +0000 +++ b/QEI.cpp Wed Sep 23 17:33:09 2015 +0000 @@ -297,8 +297,10 @@ float QEI::getVelocity() { - if(prevDirection_ != currDirection_ || prevTime_ == currTime_) - { + int ct = currTime_; + int pt = prevTime_; + + if(prevDirection_ != currDirection_ || pt == ct) { return 0; } double dt = (currTime_ - prevTime_)/1000000.;
--- a/QEI.h Tue Aug 11 20:02:03 2015 +0000 +++ b/QEI.h Wed Sep 23 17:33:09 2015 +0000 @@ -244,10 +244,10 @@ int prevState_; int currState_; - int currTime_; - int prevTime_; - int currDirection_; - int prevDirection_; + volatile int currTime_; + volatile int prevTime_; + volatile int currDirection_; + volatile int prevDirection_; Timer timer;