QEI library with velocity implementation based on time difference between successive encoder counts.

Dependents:   Bezier_Trajectory_Follower Dolphin 2_131TEST Jerby ... more

Files at this revision

API Documentation at this revision

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
diff -r 43b9eeecccc7 -r 58a3c9c9e956 QEI.cpp
--- 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.;
diff -r 43b9eeecccc7 -r 58a3c9c9e956 QEI.h
--- 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;