Wheel control software for satellite microcontroller running the motors on the Karbor

Dependencies:   mbed ros_lib_melodic

Revision:
5:44b2454a5eea
Parent:
3:4b6080e86761
Child:
6:ed47deb76adf
diff -r 9edb248c6431 -r 44b2454a5eea src/encoder.cpp
--- a/src/encoder.cpp	Mon May 31 16:47:02 2021 +0000
+++ b/src/encoder.cpp	Tue Jun 08 15:04:33 2021 +0000
@@ -1,6 +1,3 @@
-#ifndef ENCODER_H
-#define ENCODER_H
-
 /* Karbot encoder class
  *
  * This class is based upon the QEI class by Aaron Berk and the encoder class
@@ -15,6 +12,8 @@
  */
  
 #include "encoder.h"
+
+#define PI 3.1515
  
  
 encoder::encoder(
@@ -23,13 +22,14 @@
     int CPR,
     bool c,
     double p,
-    double ec
+    double diameter
     ) : channelA_(chanA, PullUp),
         channelB_(chanB, PullUp),
         c_d(c),
-        period(p),
-        enc_const(ec) {
+        period(p) {
                         
+    enc_const = ((diameter * PI) / ((double)(4 * CPR)));
+    
     pulses_       = 0;
     pulsesPerRev_ = CPR;
     tot_clicks    = 0;
@@ -193,6 +193,4 @@
 
 void encoder::tempRst(void) {temp_tot = 0;}
 
-void encoder::start(void) {sampler.attach(callback(this, &encoder::sample_func), period);}
-
-#endif
\ No newline at end of file
+void encoder::start(void) {sampler.attach(callback(this, &encoder::sample_func), period);}
\ No newline at end of file