欢迎来到天天文库
浏览记录
ID:59253495
大小:35.00 KB
页数:8页
时间:2020-09-08
《PID控制算法C语言.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、PID控制算法位置型公式u(k)=Kp((err(k))+T/Ti∑err(j)+Td/T(err(k)-err(k-1)))T/Ti即为KiTd/T即为Kd#include#includeusingnamespacestd;struct{floatsetnum;floatactualnum;floaterr;floatlasterr;floatkp,ki,kd;floatcontrolmachine;floatsumerr;}pid;voidPID(){pid.setnum=0.0;pid.actualnum=0.0;pi
2、d.err=0.0;pid.lasterr=0.0;pid.controlmachine=0.0;pid.sumerr=0.0;pid.kp=0.2;pid.ki=0.015;pid.kd=0.2;}floatrealizepid(floatnum){pid.setnum=num;pid.err=pid.setnum-pid.actualnum;pid.sumerr+=pid.err;pid.controlmachine=pid.kp*pid.err+pid.ki*pid.sumerr+pid.kd*(pid.err-pid.lasterr);pid.laste
3、rr=pid.err;pid.actualnum=pid.controlmachine*1.0;returnpid.actualnum;}intmain(){PID();intcount=0;while(count<1000){floatnum;num=realizepid(200.0);printf("%f",num);count++;}return0;}增量型公式:Δu(k)=Kp(err(k)-err(k-1))+Kierr(k)+Kd(err(k)-2err(k-1)+err(k-2))#include#include4、.h>#includeusingnamespacestd;struct{floatsetnum;floatactualnum;floaterr;floatnexterr;floatlasterr;floatkp,ki,kd;floatcontrolmachine;floatsumerr;}pid;voidPID(){pid.setnum=0.0;pid.actualnum=0.0;pid.err=0.0;pid.nexterr=0.0;pid.lasterr=0.0;pid.controlmachine=0.0;pid.sumerr=0.0;5、pid.kp=0.2;pid.ki=0.015;pid.kd=0.2;}floatrealizepid(floatnum){pid.setnum=num;pid.err=pid.setnum-pid.actualnum;pid.sumerr+=pid.err;floatincrementnum=pid.kp*(pid.err-pid.nexterr)+pid.ki*pid.err+pid.kd*(pid.err-2*pid.nexterr+pid.lasterr);pid.actualnum+=incrementnum;pid.lasterr=pid.nexte6、rr;pid.nexterr=pid.err;returnpid.actualnum;}intmain(){PID();intcount=0;while(count<1000){floatnum;num=realizepid(200.0);printf("%f",num);count++;}return0;}积分分离:消除静差,减少偏差积累#include#include#include#includeusingnamespacestd;struct{floatsetnum;float7、actualnum;floaterr;floatnexterr;floatlasterr;floatkp,ki,kd;floatcontrolmachine;floatsumerr;}pid;voidPID(){pid.setnum=0.0;pid.actualnum=0.0;pid.err=0.0;pid.nexterr=0.0;pid.lasterr=0.0;pid.controlmachine=0.0;pid.sumerr=0.0;pid.kp=0.2;pid.ki=0.04;pid.kd=0.2;}floatrealizepid(floatnum){in8、tindex;pid.s
4、.h>#includeusingnamespacestd;struct{floatsetnum;floatactualnum;floaterr;floatnexterr;floatlasterr;floatkp,ki,kd;floatcontrolmachine;floatsumerr;}pid;voidPID(){pid.setnum=0.0;pid.actualnum=0.0;pid.err=0.0;pid.nexterr=0.0;pid.lasterr=0.0;pid.controlmachine=0.0;pid.sumerr=0.0;
5、pid.kp=0.2;pid.ki=0.015;pid.kd=0.2;}floatrealizepid(floatnum){pid.setnum=num;pid.err=pid.setnum-pid.actualnum;pid.sumerr+=pid.err;floatincrementnum=pid.kp*(pid.err-pid.nexterr)+pid.ki*pid.err+pid.kd*(pid.err-2*pid.nexterr+pid.lasterr);pid.actualnum+=incrementnum;pid.lasterr=pid.nexte
6、rr;pid.nexterr=pid.err;returnpid.actualnum;}intmain(){PID();intcount=0;while(count<1000){floatnum;num=realizepid(200.0);printf("%f",num);count++;}return0;}积分分离:消除静差,减少偏差积累#include#include#include#includeusingnamespacestd;struct{floatsetnum;float
7、actualnum;floaterr;floatnexterr;floatlasterr;floatkp,ki,kd;floatcontrolmachine;floatsumerr;}pid;voidPID(){pid.setnum=0.0;pid.actualnum=0.0;pid.err=0.0;pid.nexterr=0.0;pid.lasterr=0.0;pid.controlmachine=0.0;pid.sumerr=0.0;pid.kp=0.2;pid.ki=0.04;pid.kd=0.2;}floatrealizepid(floatnum){in
8、tindex;pid.s
此文档下载收益归作者所有