Motor current controller
Fork of CURRENT_CONTROL by
CURRENT_CONTROL.h
- Committer:
- benson516
- Date:
- 2016-12-15
- Revision:
- 5:7ccd2fb7ce7e
- Parent:
- 4:1a6ba05e7736
- Child:
- 6:bae35ca64f10
File content as of revision 5:7ccd2fb7ce7e:
/* #ifndef PI #define PI = 3.1415926 #endif */ #ifndef __CURRENT_CONTROL_H__ #define __CURRENT_CONTROL_H__ #include "mbed.h" #include "PID.h" class LPF {public: float output; 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; }; class CURRENT_CONTROL { public: typedef enum { PWM1, PWM2 } PWMIndex; CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float samplingTime); 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); // 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 voltage2Duty; // float Ke; // LPF lpFilter; private: float Ts; }; #endif