当前位置:网站首页>Understanding of PID control motor output as motor PWM duty cycle input

Understanding of PID control motor output as motor PWM duty cycle input

2022-08-09 09:20:00 running bunny

This two days have been confusedPIDHow can the output ofPWMPulse control motor output?I asked a few people and they didn't make it clear..
I think that if you can explain it to a beginner, it means you have a good grasp of it.,If you say it and others still don't understand, then you have to reflect on how you have mastered it.,Is in self-deception?Also, everyone's field of expertise is different, don't always say it's so simple and don't understand,那我只能说,You may be a noob in my area of ​​expertise.
Study a day finally understand now,Share with beginners who are as confused as me,仅代表个人理解.

1、设定PIDTarget values and parameters,The target value is the motor speed value.

set_p_i_d(1.5, 0.2, 0.0);
set_pid_target(30.0);

2、PIDis a negative feedback closed-loop system,这点很重要.

float PID_realize(float actual_val)
{
    
	/*计算目标值与实际值的误差*/
	DBG_Printf("%s: pid_target:%.2f - PID_actual:%.2f \r\n", __FUNCTION__,pid.target_val, actual_val);
	pid.err = pid.target_val - actual_val;
	
	/*积分项*/
	pid.integral += pid.err;

	DBG_Printf("%s: PID_error:%.2f - PID_sum:%.2f \r\n", __FUNCTION__,pid.err, pid.integral);
	/*PID算法实现*/
	pid.output_val = pid.Kp * pid.err + 
				     pid.Ki * pid.integral + 
				     pid.Kd * (pid.err - pid.err_last);

	/*误差传递*/
	pid.err_last = pid.err;

	/*返回当前实际值*/
	return pid.output_val;
}

3、Specific feedback process

a、首先PID算法第一步 Will do a difference the target value and actual value is calculated,The calculation deviation is very large at the beginning and gradually becomes smaller.
b、每次的PIDThe output will be used as the input of the motor,The encoder will read the speed every time,The speed of reading at first is very small,It will pass in this speed value as the actual valuePIDenter this timePIDIn the target and the actual value comparison,直到误差为0,这个过程会一直进行,just the error is0The accumulated value of the integral term becomes stable,The difference in the differential term is also stabilized,The scale term is also stable.也就是PIDoutput is stable,而这个值就是PWM的占空比,This value is the stable value of the sum of the three terms,In my example,这个PWMIn the duty ratio of stability400左右,It is determined by the negative feedback value during the motor rotation,也就是目标值30对应的占空比,Specifically, the target value is reached30,PIDOutput the cumulative value of the three items,To achieve this speed, it has to be this duty cycle,They have a linear relationship,和你设置的PID参数有直接关系.
在这里插入图片描述

c、重新设定PIDTarget values and parameters,The target value is the motor speed value.
set_p_i_d(15.0, 2.0, 0.0);
set_pid_target(30.0);
我把PIDThe parameters are increased tenfold,The speed target value does not change,The final this timePID输出的PWMThe duty cycle will remain stable at400.relative to the previous set of parameters,Its integral accumulation term is exactly one-tenth of the previous set,But the response speed is improved compared to the previous group10倍.
在这里插入图片描述

原网站

版权声明
本文为[running bunny]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090833523195.html