robot

Dependencies:   FastPWM3 mbed

Revision:
14:59c4fcc1a4f7
Parent:
13:41d102a53caf
Child:
15:b583cd30b063
--- a/main.cpp	Sun Oct 30 02:06:03 2016 +0000
+++ b/main.cpp	Sun Oct 30 02:19:41 2016 +0000
@@ -25,7 +25,7 @@
 
 float d_integral = 0.0f, q_integral = 0.0f;
 float last_d = 0.0f, last_q = 0.0f;
-float d_ref = 0.0f, q_ref = 50.0f;
+float d_ref = 0.0f, q_ref = 0.0f;
 
 
 void commutate();
@@ -182,7 +182,7 @@
     float sin_p = sinf(p);
     float cos_p = cosf(p);
     
-    //float pos_dac = 0.85f * p / (2 * PI) + 0.05f;
+    //float pos_dac = 0.85f * p / (2 * PI) + 0.05f; //uncomment me to write position to the DAC
     //DAC->DHR12R2 = (unsigned int) (pos_dac * 4096);
     
     ia = ((float) adval1 / 4096.0f * AVDD - I_OFFSET - ia_supp_offset) / I_SCALE;
@@ -209,13 +209,10 @@
     if (q_integral < -INTEGRAL_MAX) q_integral = -INTEGRAL_MAX;
     if (d_integral < -INTEGRAL_MAX) d_integral = -INTEGRAL_MAX;
     
-    if(control_enabled)
-    {
+    if(control_enabled) {
         vd = KP * d_err + d_integral;
         vq = KP * q_err + q_integral;
-    }
-    else
-    {
+    } else {
         vd = 0;
         vq = 0;
     }
@@ -225,10 +222,10 @@
     if (vq < -1.0f) vq = -1.0f;
     if (vq > 1.0f) vq = 1.0f;
     
-    DAC->DHR12R2 = (unsigned int) (-q * 20 + 2048);
+    DAC->DHR12R2 = (unsigned int) (-q * 20 + 2048); //uncomment me to write I_q to the DAC
     //DAC->DHR12R2 = (unsigned int) (-vd * 2000 + 2048);
     
-    //vd = 0.0f;
+    //vd = 0.0f; //uncomment me for voltage mode testing
     //vq = 1.0f;
     
     float valpha = vd * cos_p - vq * sin_p;