欢迎来到天天文库
浏览记录
ID:57277883
大小:11.06 KB
页数:28页
时间:2020-08-08
《PID控制算法的C语言实现四-增量型PID的C语言实现.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、PID控制算法的C语言实现四增量型PID的C语言实现 上一节中介绍了最简单的位置型PID的实现手段,这一节主要讲解增量式PID的实现方法,位置型和增量型PID的数学公式。实现过程仍然是分为定义变量、初始化变量、实现控制算法函数、算法测试四个部分,详细分类请参加《PID控制算法的C语言实现三》中的讲解,这里直接给出代码了。/* *PID.c * * /#include#includestruct_pid{ floatSetSpeed; //定义设定值 floatActualSpeed; //定义实际值 floaterr
2、; //定义偏差值 floaterr_next; //定义上一个偏差值 floaterr_last; //定义最上前的偏差值 floatKp,Ki,Kd; //定义比例、积分、微分系数}pid;voidPID_init(){ pid.SetSpeed=0.0; pid.ActualSpeed=0.0; pid.err=0.0; pid.err_last=0.0; pid.err_next=0.0; pid.Kp=0.2; pid.Ki=0.015; pid.Kd=0.2;}floa
3、tPID_realize(floatspeed){ pid.SetSpeed=speed; pid.err=pid.SetSpeed-pid.ActualSpeed; floatincrementSpeed=pid.Kp*(pid.err-pid.err_next)+pid.Ki*pid.err+pid.Kd*(pid.err-2*pid.err_next+pid.err_last); pid.ActualSpeed+=incrementSpeed; pid.err_last=pid.err_next; pid.err_next=pid.err; returnpid
4、.ActualSpeed;}intmain(){ PID_init(); intcount=0; while(count<1000) { floatspeed=PID_realize(200.0); printf("%f",speed); count++; } return0;}运行后的1000个数据为:83.11.59.28.52.38.51.46.53.51.55.55.58.59.62.63.65.67.68.70.72.73.75.76.78.79.81.82.84.85.87.88.89.91.92.94.95.96.97.9
5、9.100.101.102.104.105.106.107.108.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.130.131.132.133.134.135.135.136.137.138.139.139.140.141.142.142.143.144.144.145.146.146.147.148.148.149.150.150.151.152.152.153.153.154.154.155.156.156.157.157.158.158.159.159.160.16
6、0.161.161.162.162.163.163.164.164.164.165.165.166.166.167.167.167.168.168.169.169.169.170.170.170.171.171.172.172.172.173.173.173.174.174.174.175.175.175.175.176.176.176.177.177.177.178.178.178.178.179.179.179.179.180.180.180.180.181.181.181.181.182.182.182.182.182.183.183.183.183.183.184.184.184.18
7、4.184.185.185.185.185.185.186.186.186.186.186.186.187.187.187.187.187.187.187.188.188.188.188.188.188.188.189.189.189.189.189.189.189.190.190.190.190.190.190.190.190.190.191.191.191.191.191.191.191.19
此文档下载收益归作者所有