Motor current controller
Fork of CURRENT_CONTROL by
Diff: CURRENT_CONTROL.h
- Revision:
- 7:6794cfba3564
- Parent:
- 6:bae35ca64f10
- Child:
- 8:fd6fb3cb12ec
diff -r bae35ca64f10 -r 6794cfba3564 CURRENT_CONTROL.h --- a/CURRENT_CONTROL.h Thu Dec 15 23:16:09 2016 +0000 +++ b/CURRENT_CONTROL.h Mon Dec 19 13:26:05 2016 +0000 @@ -19,11 +19,15 @@ LPF(float samplingTime, float cutOff_freq_Hz_in); // cutOff_freq_Hz_in is in "Hz" float filter(float input); + void reset(float input); private: float Ts; float cutOff_freq_Hz; // Hz float alpha_Ts; + + // Flag + bool Flag_Init; }; @@ -36,6 +40,7 @@ } PWMIndex; CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float Ka, float samplingTime); + void OffsetInit(void); 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); @@ -57,15 +62,19 @@ PwmOut MotorMinus; // - float delta_output; - float controlOutput; + // float controlOutput; float currentOffset; float curFeedBack; + float curFeedBack_filter; + // + float voltage_out; + float delta_output; // AnalogIn currentAnalogIn; float analogInValue; - // + + // Ratio for units transformation float analog2Cur; float voltage2Duty; @@ -75,6 +84,10 @@ // LPF lpFilter; + // Initialization + bool Flag_Init; + int Init_count; + float Accumulated_offset; private: