robot

Dependencies:   FastPWM3 mbed

Revision:
64:b4175385d718
Parent:
62:581aa9235ad6
Child:
65:6e1fdbfae57b
--- a/main.cpp	Sat Jan 28 09:10:07 2017 +0000
+++ b/main.cpp	Sat Jan 28 23:21:07 2017 +0000
@@ -83,14 +83,16 @@
     control.d_integral += d_err * KI_D;
     control.q_integral += q_err * KI_Q;
     
-    control.d_integral = constrain(control.d_integral, -INTEGRAL_MAX, INTEGRAL_MAX);
-    control.q_integral = constrain(control.q_integral, -INTEGRAL_MAX, INTEGRAL_MAX);
+    //control.d_integral = constrain(control.d_integral, -INTEGRAL_MAX, INTEGRAL_MAX);
+    //control.q_integral = constrain(control.q_integral, -INTEGRAL_MAX, INTEGRAL_MAX);
+    constrain_norm(&control.d_integral, &control.q_integral, 0.5f, 1.0f, 1.0f);
     
     foc.vd = KP_D * d_err + control.d_integral;// - Lq * POLE_PAIRS * read.w * foc.q / BUS_VOLTAGE / 2.0f;
     foc.vq = KP_Q * q_err + control.q_integral;// + Ld * POLE_PAIRS * read.w * foc.d / BUS_VOLTAGE / 2.0f;
     
-    foc.vd = constrain(foc.vd, -1.0f, 1.0f);
-    foc.vq = constrain(foc.vq, -1.0f, 1.0f);
+    //foc.vd = constrain(foc.vd, -1.0f, 1.0f);
+    //foc.vq = constrain(foc.vq, -1.0f, 1.0f);
+    constrain_norm(&foc.vd, &foc.vq, 1.0f, 1.0f, 1.0f);
     
     if (!control_enabled) {
         foc.vd = 0.0f;
@@ -166,7 +168,11 @@
     BREMSInit(&io, &read, &foc, &control, false);
     
     for (;;) {
-        io.pc->printf("%d,%d,%d,%d,%d,%d\n\r", (int) read.w, (int) control.d_ref, (int) control.d_filtered, (int) control.q_ref, (int) control.q_filtered, (int) (256 * io.throttle_in->get_throttle()));
+        /*
+        io.pc->printf("%d,%d,%d,%d,%d,%d,%d,%d\n\r", (int) read.w, (int) control.d_ref, (int) control.d_filtered, (int) control.q_ref, (int) control.q_filtered, (int) (256 * io.throttle_in->get_throttle()),
+                       (int) (256 * control.d_integral), (int) (256 * control.q_integral));
+        */
+        io.pc->printf("%f\n", .0743f*read.w);
         wait(0.01);
     }
 }
\ No newline at end of file