PID控制算法的C语言实现四-增量型PID的C语言实现(共28页).docx
《PID控制算法的C语言实现四-增量型PID的C语言实现(共28页).docx》由会员分享,可在线阅读,更多相关《PID控制算法的C语言实现四-增量型PID的C语言实现(共28页).docx(28页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上PID控制算法的C语言实现四 增量型PID的C语言实现 上一节中介绍了最简单的位置型PID的实现手段,这一节主要讲解增量式PID的实现方法,位置型和增量型PID的数学公式。实现过程仍然是分为定义变量、初始化变量、实现控制算法函数、算法测试四个部分,详细分类请参加PID控制算法的C语言实现三中的讲解,这里直接给出代码了。/* PID.c*/#include#includestruct _pid float SetSpeed; /定义设定值 float ActualSpeed; /定义实际值 float err; /定义偏差值 float err_next; /定义上一个
2、偏差值 float err_last; /定义最上前的偏差值 float Kp,Ki,Kd; /定义比例、积分、微分系数pid;void PID_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;float PID_realize(float speed) pid.SetSpeed=speed; pid.err=pid.SetSpeed-pid.ActualSpeed; float
3、incrementSpeed=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; return pid.ActualSpeed;int main() PID_init(); int count=0; while(count1000) float speed=PID_realize(200.0); prin
4、tf(%fn,speed); count+; return 0;运行后的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.99.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
5、.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.160.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
6、.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.184.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
7、.190.190.190.190.190.190.190.190.191.191.191.191.191.191.191.191.191.192.192.192.192.192.192.192.192.192.192.192.193.193.193.193.193.193.193.193.193.193.193.193.194.194.194.194.194.194.194.194.194.194.194.194.194.194.195.195.195.195.195.195.195.195.195.195.195.195.195.195.195.195.195.195.196.196.196
8、.196.196.196.196.196.196.196.196.196.196.196.196.196.196.196.196.196.196.196.196.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.197.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198.198
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PID 控制 算法 语言 实现 增量 28
限制150内