增量式pid的算法程序1_第1页
增量式pid的算法程序1_第2页
增量式pid的算法程序1_第3页
增量式pid的算法程序1_第4页
增量式pid的算法程序1_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include <stdio.h> #include<math.h> struct _pid int pv; /*integer that contains the process value*/ int sp; /*integer that contains the set point*/ float integral;float pgain;float igain;float dgain;int deadband;int last_error;struct _pid warm,*pid;int process_point, set_point,dead_band;

2、float p_gain, i_gain, d_gain, integral_val,new_integ;/*pid_initDESCRIPTION This function initializes the pointers in the _pid structure to the process variable and the setpoint. *pv and *sp are integer pointers.*/ void pid_init(struct _pid *warm, int process_point, int set_point) struct _pid *pid;pi

3、d = warm;pid->pv = process_point; pid->sp = set_point;/*pid_tuneDESCRIPTION Sets the proportional gain (p_gain), integral gain (i_gain), derivitive gain (d_gain), and the dead band (dead_band) of a pid control structure _pid.*/void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d

4、_gain, int dead_band) pid->pgain = p_gain; pid->igain = i_gain; pid->dgain = d_gain; pid->deadband = dead_band; pid->integral= integral_val; pid->last_error=0;/*pid_setintegDESCRIPTION Set a new value for the integral term of the pid equation. This is useful for setting the initial

5、 output of the pid controller at start up. */ void pid_setinteg(struct _pid *pid,float new_integ) pid->integral = new_integ; pid->last_error = 0;/*pid_bumplessDESCRIPTION Bumpless transfer algorithim. When suddenly changing setpoints, or when restarting the PID equation after an extended pause

6、, the derivative of the equation can cause a bump in the controller output. This function will help smooth out that bump. The process value in *pv should be the updated just before this function is used. */ void pid_bumpless(struct _pid *pid)pid->last_error = (pid->sp)-(pid->pv);/*pid_calcD

7、ESCRIPTION Performs PID calculations for the _pid structure *a. This function uses the positional form of the pid equation, and incorporates an integral windup prevention algorithim. Rectangular integration is used, so this function must be repeated on a consistent time basis for accurate control.RE

8、TURN V ALUE The new output value for the pid loop.USAGE #include "control.h"*/float pid_calc(struct _pid *pid)int err;float pterm, dterm, result, ferror;err = (pid->sp) - (pid->pv);if (abs(err) > pid->deadband)ferror = (float) err; /*do integer to float conversion only once*/ p

9、term = pid->pgain * ferror;if (pterm > 100 | pterm < -100)pid->integral = 0.0;elsepid->integral += pid->igain * ferror;if (pid->integral > 100.0)pid->integral = 100.0;else if (pid->integral < 0.0) pid->integral = 0.0;dterm = (float)(err - pid->last_error) * pid

10、->dgain;result = pterm + pid->integral + dterm;else result = pid->integral;pid->last_error = err;return (result);void main(void)float display_value;int count=0;pid = &warm;/ printf("Enter the values of Process point, Set point, P gain, I gain, D gain n");/ scanf("%d%d%

11、f%f%f", &process_point, &set_point, &p_gain, &i_gain, &d_gain);process_point = 30; set_point = 40; p_gain = (float)(5.2); i_gain = (float)(0.77); d_gain = (float)(0.18);dead_band = 2; integral_val =(float)(0.01);printf("The values of Process point, Set point, P gain, I

12、gain, D gain n"); printf(" %6d %6d %4f %4f %4fn", process_point, set_point, p_gain, i_gain, d_gain);printf("Enter the values of Process pointn");while(count<=20)scanf("%d",&process_point);pid_init(&warm, process_point, set_point);pid_tune(&warm, p_ga

13、in,i_gain,d_gain,dead_band);pid_setinteg(&warm,0.0); /pid_setinteg(&warm,30.0);/Get input value for process pointpid_bumpless(&warm);/ how to display outputdisplay_value = pid_calc(&warm);printf("%fn", display_value);/printf("n%f%f%f%f",warm.pv,warm.sp,warm.igain,

14、warm.dgain);count+;. PID 调试步骤没有一种控制算法比 PID 调节规律更有效、更方便的了。现在一些时髦点的调节器基本源自 PID 。甚 至可以这样说: PID 调节器是其它控制调节算法的吗。为什么 PID 应用如此广泛、又长久不衰?因为 PID 解决了自动控制理论所要解决的最基本问题,既系统的稳定性、快速性和准确性。调节 PID 的参 数,可实现在系统稳定的前提下,兼顾系统的带载能力和抗扰能力,同时,在 PID 调节器中引入积分项, 系统增加了一个零积点,使之成为一阶或一阶以上的系统,这样系统阶跃响应的稳态误差就为零。由于自动控制系统被控对象的千差万别, PID 的参数

15、也必须随之变化,以满足系统的性能要求。这就 给使用者带来相当的麻烦,特别是对初学者。下面简单介绍一下调试 PID 参数的一般步骤:1负反馈自动控制理论也被称为负反馈控制理论。首先检查系统接线,确定系统的反馈为负反馈。例如电机调 速系统,输入信号为正,要求电机正转时,反馈信号也为正( PID 算法时,误差 =输入 -反馈),同时电机转 速越高,反馈信号越大。其余系统同此方法。2 PID 调试一般原则a. 在输出不振荡时,增大比例增益P。b. 在输出不振荡时,减小积分时间常数Ti。c. 在输出不振荡时,增大微分时间常数Td。3一般步骤a. 确定比例增益P确定比例增益P时,首先去掉PID的积分项和微

16、分项, 一般是令Ti=O、Td=O (具体见PID的参数设定说明),使PID为纯比例调节。输入设定为系统允许的最大值的60%70%,由0逐渐加大比例增益 P,直至系统出现振荡;再反过来,从此时的比例增益P逐渐减小,直至系统振荡消失,记录此时的比例增益P,设定PID的比例增益P为当前值的60%70%。比例增益P调试完成。b. 确定积分时间常数Ti比例增益P确定后,设定一个较大的积分时间常数Ti的初值,然后逐渐减小 Ti,直至系统出现振荡,之后在反过来,逐渐加大 Ti,直至系统振荡消失。记录此时的Ti,设定PID的积分时间常数 Ti为当前值的 150%180% 。积分时间常数 Ti 调试完成。c.

17、 确定积分时间常数Td积分时间常数Td 一般不用设定,为0即可。若要设定,与确定P和Ti的方法相同,取不振荡时的30%。d. 系统空载、带载联调,再对PID参数进行微调,直至满足要求。2.PID 控制简介目前工业自动化水平已成为衡量各行各业现代化水平的一个重要标志。同时,控制理论的发展也经历了古 典控制理论、现代控制理论和智能控制理论三个阶段。智能控制的典型实例是模糊全自动洗衣机等。自动 控制系统可分为开环控制系统和闭环控制系统。一个控制系统包括控制器、传感器、变送器、执行机构、 输入输出接口。控制器的输出经过输出接口、执行机构,加到被控系统上;控制系统的被控量,经过传感 器,变送器,通过输入接口送到控制器。不同的控制系统,其传感器、变送器、执行机构是不一样的。比 如压力控制系统要采用压力传感器。电加热控制系统的传感器是温度传感器。目前,PID 控制及其控制器或智能 PID 控制器(仪表)已经很多,产品已在工程实际中得到了广泛的应用,有各种各样的PID 控制器产品,各大公司均开发了具有 PID 参数自整定功能的智能调节器 (intelligent regulato

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论