Ikhee Jo / T-Motor_AK80_BaseCode

Dependencies:   mbed-dev-f303 FastPWM3

Revision:
18:f1d56f4acb39
Parent:
15:ef00814e38e2
--- a/CurrentRegulator/CurrentRegulator.cpp	Sat Dec 10 05:46:08 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.cpp	Sun Dec 11 04:19:15 2016 +0000
@@ -132,6 +132,12 @@
         //V_Q = V_Q - w_elec*I_D;
         V_D = D_Integral + _Kp*D_Error;     
         //V_D = V_D + w_elec*I_Q;   //decoupling needs moar testing
+        float mag2 = (V_Q*V_Q + V_D*V_D);
+        if(mag2>1){
+            V_Q = V_Q/mag2;
+            V_D = V_D/mag2;
+            }
+        
     }
         
 void CurrentRegulator::SetVoltage(){