当前位置:网站首页>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倍.
边栏推荐
猜你喜欢
随机推荐
MySQL Leak Check (4) Stored Procedures and Cursors
canal工作原理及简单案例演示
PoPW token distribution mechanism may ignite the next bull market
支付宝小程序使用自定义组件(原生)
Amplify Shader Editor手册 Unity ASE(中文版)
【培训课程专用】CA/TA调用模型-代码导读
vim 按了Ctrl+S后 卡死
Redis Basics
Flutter的基础知识之Dart语法
全球19级谷歌卫星地图免费查看下载
这12个GIS软件一个比一个好用
数据库期末复习这一篇就够了(期末预习大概也行)
MySQL Leak Detection and Filling (3) Calculated Fields
Teach you how to get a 0.1-meter high-precision satellite map for free
Django实现对数据库数据增删改查(一)
Venture DAO Industry Research Report: Macro and Classic Case Analysis, Model Summary, Future Suggestions
MySQL event_single event_timed loop event
[Environmental Construction] tensorrt
MySQL创建索引的技巧
VoLTE基础自学系列 | IMS的业务触发机制