The most common position is a PID algorithm (FIG. A)
int Position_PID (Feedback_value int, int User_Target)
{
static Bias a float, PWM_Out, Integral_bias, Last_Bias, Differntial_bias;
Bias=User_Target-Feedback_value; //计算偏差
Integral_bias+=Bias; //求出偏差的积分
Differntial_bias=Bias-Last_Bias;
PWM_Out=
PID. Position_KP * Bias
+PID. Position_KI * Integral_bias
+PID. Position_KD* Differntial_bias; //位置式PID控制器公式
Last_Bias=Bias; //保存上一次偏差
return PWM_Out; //位置式PWM输出
}
, Do I get PID algorithm servo PWM control, the derivative term is not used, because the differential coefficient is zero P = 0.85, I = 0.09, D = 0;
found (see Figure II) during use
in order to solve the reaction was slowly integral term, the integral term I into a product form to be used, not by the usual two cumulative deviation Integral_bias = Feedback_value * 11.2; // obtaining integration of the deviation
with the current value is multiplied by a factor such as PWM when the integral value is stable 520PWM take 5578 5578/520 = 11.2 is obtained after such a cumulative integral coefficient put into a form of distribution. . .
When the same 520 Feedback_value = 520 is calculated before the integration value and a cumulative manner 11.2 = 5578, is now the target current value is 520 520, the deviation is zero,, the output of the proportional term is zero. . Two integral term, compared with 5578 0.09 = 520 is the PWM 520 output ..
Waveform diagram (Figure 3) improved integral term
Improved algorithm
int Position_PID (Feedback_value int, int User_Target)
{
static Bias a float, PWM_Out, Integral_bias, Last_Bias, Differntial_bias;
Bias=User_Target-Feedback_value; //计算偏差
Integral_bias=Feedback_value*11.2; //改进的积分项
Differntial_bias=Bias-Last_Bias;
PWM_Out=
PID. Position_KP * Bias
+PID. Position_KI * Integral_bias
+PID. Position_KD * Differntial_bias; //位置式PID控制器公式
Last_Bias=Bias;
Upper_Computer_Phoenix(Feedback_value*11+520,User_Target*11+520); /*发送数据到上位机*/
return PWM_Out; //位置式PWM输出
}
The first post, could not put it in place. We are hoping to understand the meaning behind