Motor current controller

Fork of CURRENT_CONTROL by LDSC_Robotics_TAs

Revision:
6:bae35ca64f10
Parent:
5:7ccd2fb7ce7e
Child:
7:6794cfba3564
--- a/CURRENT_CONTROL.cpp	Thu Dec 15 22:54:54 2016 +0000
+++ b/CURRENT_CONTROL.cpp	Thu Dec 15 23:16:09 2016 +0000
@@ -22,7 +22,7 @@
                                  PinName PwmChannel1,
                                  PinName PwmChannel2,
                                  PWMIndex pwmIndex,
-                                 float Kp, float Ki, float Kd,
+                                 float Kp, float Ki, float Kd, float Ka,
                                  float samplingTime) : 
     currentAnalogIn(curChannel),
     MotorPlus(PwmChannel1),
@@ -41,9 +41,17 @@
     if(pwmIndex_ == PWM1)TIM1->CCER |= 4;
     else if(pwmIndex_ == PWM2)TIM1->CCER |= 64; //enable complimentary output
     
+    
     //
     currentOffset = 0.0;
     delta_output = 0.0;
+    
+    // Set PID's parameters                        
+    /////////////////////
+    pid.Kp = Kp;
+    pid.Ki = Ki;
+    pid.Kd = Kd;
+    pid.Ka = Ka; // Gain for anti-windup // Ka = 0.0017
 }
 //
 void CURRENT_CONTROL::SetParams(float Analog2Cur, float angSpeed2BackEmf, float voltage2DutyRatio)
@@ -77,6 +85,7 @@
     // PID
     pid.Compute_noWindUP(curRef, curFeedBack);
     
+    // Output saturation and unit changing
     MotorPlus = 0.5 + saturation((-pid.output + func_back_emf(angularSpeed) )*voltage2Duty, delta_output, 0.5, -0.5) ;
     
     // Anti-windup