Motor current controller

Fork of CURRENT_CONTROL by LDSC_Robotics_TAs

Revision:
5:7ccd2fb7ce7e
Parent:
4:1a6ba05e7736
Child:
6:bae35ca64f10
--- a/CURRENT_CONTROL.h	Thu Apr 28 09:07:32 2016 +0000
+++ b/CURRENT_CONTROL.h	Thu Dec 15 22:54:54 2016 +0000
@@ -1,3 +1,9 @@
+/*
+#ifndef PI
+#define PI = 3.1415926
+#endif
+*/
+
 #ifndef __CURRENT_CONTROL_H__
 #define __CURRENT_CONTROL_H__
 
@@ -6,15 +12,18 @@
 
 
 
+
 class LPF
 {public:
-    float output, outputLast;
+    float output;
     
-    LPF(float samplingTime);
-    float filter(float input, float cutOff);
+    LPF(float samplingTime, float cutOff_freq_Hz_in); // cutOff_freq_Hz_in is in "Hz"
+    float filter(float input);
     
 private:
     float Ts;    
+    float cutOff_freq_Hz; // Hz
+    float alpha_Ts;
 };
 
 
@@ -27,33 +36,46 @@
     } PWMIndex;
 
     CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float samplingTime);
-    float saturation(float input, float limit_H, float limit_L);
+    void SetParams(float Analog2Cur, float angSpeed2BackEmf, float voltage2DutyRatio);
+    float saturation(float input_value, float &delta, const float &limit_H, const float &limit_L);
     void Control(float curRef, float speed);
-    void SetParams(float Analog2Cur, float angSpeed2Backemf, float voltage2DutyRatio);
+        
+    // Back emf as the function of rotational speed
+    float func_back_emf(const float &W_in);
     
     //functions for test////////
     void ChangePwmPeriod(float microSeconds);
     void SetPWMDuty(float ratio);
     float GetAnalogIn(void);
     float GetCurrent(void);
+    
+    
     //////////////////////////
     PWMIndex pwmIndex_;
     PID pid;
     PwmOut MotorPlus;
     PwmOut MotorMinus;
+    
+    //
+    float delta_output;
     float controlOutput;
-
     float currentOffset;
     float curFeedBack;
     
+    //
     AnalogIn currentAnalogIn;
     float analogInValue;
-    
+    //
     float analog2Cur;
-    float Kw;
     float voltage2Duty;
+    
+    //
+    float Ke;    
+    
+    //
     LPF lpFilter;
     
+
     
 private:
 
@@ -63,35 +85,4 @@
 };
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 #endif
\ No newline at end of file