Quadrature encoder interface library with distance function

Dependents:   QEI_with_distance wheelchaircontrol wheelchaircontrolRos wheelchaircontrol ... more

Fork of QEI by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
jvfausto
Date:
Sat Oct 27 10:09:39 2018 +0000
Parent:
3:0035b165ecc4
Commit message:
Not A lot has changed

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 0035b165ecc4 -r dc96133b5129 QEI.cpp
--- a/QEI.cpp	Fri Aug 31 17:09:18 2018 +0000
+++ b/QEI.cpp	Sat Oct 27 10:09:39 2018 +0000
@@ -139,7 +139,8 @@
     revolutions_  = 0;
     pulsesPerRev_ = pulsesPerRev;
     encoding_     = encoding;
-
+    
+    ti.start();
     //Workout what the current state is.
     int chanA = channelA_.read();
     int chanB = channelB_.read();
@@ -285,12 +286,20 @@
 
 float QEI::getDistance(float diameter)
 {
-    
-    return getRevolutions()*diameter*3.1415926;
+    oldDistance_ = newDistance_;
+    newDistance_ = getRevolutions()*diameter*3.1415926;
+    return newDistance_; 
 }
 
 void QEI::index(void) {
 
     revolutions_++;
-
 }
+float QEI::getVelosity()
+{
+    getDistance(53.975);
+    velosity_ = ti.read()*(newDistance_-oldDistance_);
+    ti.reset();
+    return velosity_;
+}
+    
diff -r 0035b165ecc4 -r dc96133b5129 QEI.h
--- a/QEI.h	Fri Aug 31 17:09:18 2018 +0000
+++ b/QEI.h	Sat Oct 27 10:09:39 2018 +0000
@@ -206,7 +206,7 @@
      *
      * @return Number of revolutions which have occured on the index channel.
      */
-    
+    float getVelosity();
     
     float getRevolutions(void);
 
@@ -237,9 +237,14 @@
     InterruptIn index_;
 
     float        pulsesPerRev_;
+    float        oldDistance_;
+    float        newDistance_;
+    float        velosity_;
     int          prevState_;
     int          currState_;
-
+    
+    Timer ti;
+    
     volatile int pulses_;
     volatile int revolutions_;