#include <stdio.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;
  float p_gain, i_gain, d_gain, integral_val,new_integ;;
  
  
  
  /*------------------------------------------------------------------------
  pid_init
  
  DESCRIPTION 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;
  
   pid = warm;
   pid->pv = process_point;
   pid->sp = set_point;
  }
  
  
  /*------------------------------------------------------------------------
  pid_tune
  
  DESCRIPTION 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_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_setinteg
  
  DESCRIPTION Set a new value for the integral term of the pid equation.
  This is useful for setting the initial 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_bumpless
  
  DESCRIPTION Bumpless transfer algorithim. When suddenly changing
  setpoints, or when restarting the PID equation after an
  extended pause, 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_calc
  
   DESCRIPTION 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.
  
  RETURN VALUE 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*/
   pterm = pid->pgain * ferror;
   if (pterm > 100 || pterm < -100)
   {
   pid->integral = 0.0;
   }
   else
   {
   pid->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->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%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 gain, D gain \n");
   printf(" %6d %6d %4f %4f %4f\n", process_point, set_point, p_gain, i_gain, d_gain);
  
   printf("Enter the values of Process point\n");
  
   while(count<=20)
   {
  
  
  
   scanf("%d",&process_point);
  
   pid_init(&warm, process_point, set_point);
   pid_tune(&warm, p_gain,i_gain,d_gain,dead_band);
   pid_setinteg(&warm,0.0); //pid_setinteg(&warm,30.0);

  
   //Get input value for process point

   pid_bumpless(&warm);
  
   // how to display output

   display_value = pid_calc(&warm);
   printf("%f\n", display_value);
   //printf("\n%f%f%f%f",warm.pv,warm.sp,warm.igain,warm.dgain);

   count++;
  
   }
  
  }

<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>

阅读(1122) | 评论(3) | 转发(0) |

0

上一篇:ubuntu9.10中scim中文输入法无法使用--解决方法

下一篇:2009年下半年计算机专业技术资格考试安排

相关热门文章
  • 网站设计:复杂产品的响应式设...
  • 卢松松:38岁老男孩个人建站方...
  • 江苏镇江自愿连鎖经营也“办理...
  • 純繪本版《山海經》作者尹戈坐...
  • 月薪6千美元的谷歌实习生让我...
  • test123
  • 编写安全代码——小心有符号数...
  • 使用openssl api进行加密解密...
  • 一段自己打印自己的c程序...
  • sql relay的c++接口
  • GCC编译命令
  • 推荐系统常用算法
  • C++Primer笔记 第八章 标准IO...
  • c语言中的#号和##号的作用...
  • gstreamer插件开发-------sink...
给主人留下些什么吧!~~

chinaunix网友2010-07-19 22:53:30

即使别人是抄的,也是很帮助别人的事情。你没看在其他地方下载要金币啊~!

回复 | 举报

tastesweet2010-04-28 20:59:45

到底是谁写就不知道了,转这边帖子的时候真要做一个PID的小算法,当时对PID理解不太深刻,放了这个帖子来看,现在都是对PID有了一定的理解。

回复 | 举报

chinaunix网友2010-04-08 09:22:42

你前面说你掌握了这掌握了那,面对这么一篇被抄来抄去的老外的文章,竟然没有一点自己的想法??

回复 | 举报

评论热议

C语言实现PID算法相关推荐

  1. C语言实现pid算法(附完整源码)

    实现pid算法 pid结构体定义 C语言实现pid算法完整源码(定义,实现,main函数测试) pid结构体定义 struct pid {// Controller gainsfloat kP;flo ...

  2. C语言实现PID算法:位置式PID和增量式PID

    原创者微信公众号 PID算法可以说是在自动控制原理中比较经典的一套算法,在现实生活中应用的比较广泛. 大学参加过电子竞赛的朋友都应该玩过电机(或者说循迹小车),我们要控制电机按照设定的速度运转,PID ...

  3. 小型温控系统c语言程序,pid算法温度控制c语言程序 - 全文

    温度控制PID自整定原理介绍 整定PID(三模式)控制器 整定温度控制器涉及设置比例.积分和微分值,以得到对特定过 程的可能的最佳控制.如果控制器不包含自动整定算法,或者自 动整定算法未提供适合特定应 ...

  4. c语言写pid算法,用c语言实现的pid算法

    pid算法应该算是所以算法中最稳定最可靠最简单的算法,在库函数中添加这种算法对实际控制的时延有非常大的帮助. 全部资料51hei下载地址:   C语言PID算法.doc PID算法(c语言)(来自老外 ...

  5. PID算法:位置式PID和增量式PID

    口诀 参数整定找最佳, 从小到大顺序查. 先是比例后积分, 最后再把微分加. 曲线振荡很频繁, 比例度盘要放大. 曲线漂浮绕大弯, 比例度盘往小扳. 曲线偏离回复慢, 积分时间往下降. 曲线波动周期长 ...

  6. c语言程序位置式pid算法,位置式PID算法的C语言代码

    描述 位置式PID的C语言写法详解 PID调节口诀: 参数整定找最佳,从小到大顺序查 先是比例后积分,最后再把微分加 曲线振荡很频繁,比例度盘要放大 曲线漂浮绕大湾,比例度盘往小扳 曲线偏离回复慢,积 ...

  7. pid温度控制c语言程序及仿真,温度控制PID算法的C语言程序实例代码

    //PID算法温控C语言 #include #include #include #include struct PID { unsigned int SetPoint; // 设定目标 Desired ...

  8. PID算法入门与C语言代码实现

    PID算法的入门理解以及C代码实现 在结束了自控原理的学习后,了解到PID算法是一种万能算法,在课设中也是经常使用到的一种算法,所以想具体的来进行以下总结与学习,如果有错漏的地方,欢迎大家共同来探讨与 ...

  9. matlab控制算法C语言,PID算法Matlab仿真程序和C程序

    <PID算法Matlab仿真程序和C程序>由会员分享,可在线阅读,更多相关<PID算法Matlab仿真程序和C程序(6页珍藏版)>请在人人文库网上搜索. 1.增量式PID控制算 ...

最新文章

  1. 穿越传统藩篱,当统计学闯入人工智能“后花园”
  2. 2021-9-下旬 数据结构-线性表-链表-java代码实现(复习用)
  3. springboot中下面哪一个作为jpa默认实现_35个超高频SpringBoot知识点(附解析),别怪我没给你机会收藏...
  4. AndroidStudio中使用XML和Java代码混合控制UI界面实现QQ相册照片列表页面
  5. gview java_java - 如何在干净模式下运行eclipse? 如果我们这样做会发生什么?
  6. why CRMFSH01 failed to return any value for my case
  7. 数据链路层: HDLC
  8. APL开发日志--2013-01-17
  9. java @valid 密码不一致_一个成熟的Java项目如何优雅地处理异常
  10. L2-033 简单计算器 (25 分)-PAT 团体程序设计天梯赛 GPLT
  11. CodeForces 551E(平方分割
  12. XMLConfigBuilder文件
  13. 弹性板计算和板带划分计算_彻底搞懂板带的配筋及范围
  14. get 请求中文乱码问题
  15. 百度wz竞价开户推广营销的四大好处
  16. @Aspect不生效
  17. 应用软件设计不是CRUD:如何进行应用系统功能模块的耦合性设计
  18. 【铁矿石期货怎么开通】11月22日午盘基本面资讯整理
  19. 财务管理系统属于计算机应用领域中的,计算机基础套题及其答案.doc
  20. 如何在图片里藏其他文件

热门文章

  1. JavaScript简餐——原型链是什么?
  2. Redis设置访问密码
  3. 首届“天权信安catf1ag”网络安全联合公开赛-部分misc
  4. 【API接口工具】postman-Workspaces工作空间 VS Scratch Pad草稿面板
  5. Excel如何快速自定义序列排序
  6. oracle 语句提高查询效率的方法
  7. cdr入门之复制对象的几种方式
  8. Ubuntu20.04 -- 小白系列1 之 你可能会遇到
  9. 《C++ Primer》第13章 13.5节习题答案
  10. MySQL数据库基本操作-正则表达式