Motor current controller

Fork of CURRENT_CONTROL by LDSC_Robotics_TAs

Revision:
15:d9ccd6c92a21
Parent:
14:67fc256efeb7
Child:
16:6e3bcd373f9d
--- a/CURRENT_CONTROL.h	Mon Dec 26 07:52:43 2016 +0000
+++ b/CURRENT_CONTROL.h	Mon Dec 26 08:53:09 2016 +0000
@@ -41,25 +41,34 @@
         PWM2
     } PWMIndex;
 
+    //Current-input limit
+    float current_limit_H; // +1.3
+    float current_limit_L; // -1.3
+
     //                      AD_pin,             PWM_p,               PWM_n,       pwmIndex  ,                   Ts
     // CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float samplingTime);
     //                      AD_pin,             PWM_p,               PWM_n,                pwmIndex  ,       QEI_A        , QEI_B      , pulsesPerRev    , arraysize ,  Ts
     CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, PinName QEI_A, PinName QEI_B, float pulsesPerRev, int arraysize, float samplingTime);
 
-    //
+    // Setting parameters
     void SetParams(float Analog2Cur_in, float angSpeed2BackEmf, float voltage2Duty_in);
     void SetReversal(bool reverse_current_in, bool reverse_rotationalSpeed_in, bool reverse_voltage_in);
     void SetGain(float Kp, float Ki, float Kd, float Ka);
-    //
+    void setInputLimits(float current_limit_H_in, float current_limit_L_in);
+
+    // Initialization
     void OffsetInit(void);
+    // Utilities
+    float saturation(float input_value, const float &limit_H, const float &limit_L);
     float saturation(float input_value, float &delta, const float &limit_H, const float &limit_L);
+    // Control
     void TorqueControl(float TorqueRef, bool enable);
     void Control(float curRef, bool enable);
 
     // Back emf as the function of rotational speed
     float func_back_emf(const float &W_in);
 
-    //functions for test////////
+    // Elementary function (building block)
     void ChangePwmPeriod(float microSeconds);
     void SetPWMDuty(float ratio);
     void SetVoltage(float volt);