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:
Wed Jul 25 22:51:54 2018 +0000
Parent:
0:5c2ad81551aa
Child:
2:2a173fdae3ca
Commit message:
The encoder works now

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	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.cpp	Wed Jul 25 22:51:54 2018 +0000
@@ -185,11 +185,6 @@
 
 }
 
-int QEI::getRevolutions(void) {
-
-    return revolutions_;
-
-}
 
 // +-------------+
 // | X2 Encoding |
@@ -275,13 +270,23 @@
 
             pulses_ -= change;
         }
-
     }
-
     prevState_ = currState_;
 
 }
 
+float QEI::getRevolutions(){
+    if (encoding_ == X2_ENCODING)
+        return (float) ((float)pulses_ /(pulsesPerRev_));
+    else
+        return (float) (pulses_ / 4 * pulsesPerRev_);
+}
+
+float QEI::getDistance(float radius)
+{
+    return getRevolutions()*radius*3.1415926*2;
+}
+
 void QEI::index(void) {
 
     revolutions_++;
--- a/QEI.h	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.h	Wed Jul 25 22:51:54 2018 +0000
@@ -206,7 +206,11 @@
      *
      * @return Number of revolutions which have occured on the index channel.
      */
-    int getRevolutions(void);
+    
+    
+    float getRevolutions(void);
+
+    float QEI::getDistance(float radius);
 
 private:
 
@@ -232,7 +236,7 @@
     InterruptIn channelB_;
     InterruptIn index_;
 
-    int          pulsesPerRev_;
+    float        pulsesPerRev_;
     int          prevState_;
     int          currState_;