久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2437|回復: 1
打印 上一主題 下一主題
收起左側

PID算法源碼

[復制鏈接]
跳轉到指定樓層
樓主
ID:410355 發表于 2018-10-17 21:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
在過程控制中,按偏差的比例(P)、積分(I)和微分(D)進行控制的PID控制器(亦稱PID調節器)是應用最為廣泛的一種自動控制器。它具有原理簡單,易于實現,適用面廣,控制參數相互獨立,參數的選定比較簡單等優點;而且在理論上可以證明,對于過程控制的典型對象──“一階滯后+純滯后”與“二階滯后+純滯后”的控制對象,PID控制器是一種最優控制。PID調節規律是連續系統動態品質校正的一種有效方法,它的參數整定方式簡便,結構改變靈活(PI、PD、…)。
參數的選擇:
   ①比例系數P對系統性能的影響:比例系數加大,使系統的動作靈敏,速度加快,穩態誤差減小;P偏大,振蕩次數加多,調節時間加長;P太大時,系統會趨于不穩定;P太小,又會使系統的動作緩慢。P可以選負數,這主要是由執行機構、傳感器以及控制對象的特性決定的。如果P的符號選擇不當對象測量值就會離控制目標的設定值越來越遠,如果出現這樣的情況P的符號就一定要取反。同時要注意的是,力控的策略控制器的PID控制塊的P參數是PID控制中的增益。
 、诜e分控制I對系統性能的影響:積分作用使系統的穩定性下降,I。ǚe分作用強)會使系統不穩定,但能消除穩態誤差,提高系統的控制精度。
 、畚⒎挚刂艱對系統性能的影響:微分作用可以改善動態特性,D偏大時,超調量較大,調節時間較短;D偏小時,超調量也較大,調節時間也較長;只有D合適,才能使超調量較小,減短調節時間。 [轉貼]C語言實現PID算法:
  1. #include <stdio.h>
  2. #include<math.h>
  3.   struct _pid {
  4.    int pv; /*integer that contains the process value*/
  5.    int sp; /*integer that contains the set point*/
  6.    float integral;
  7.    float pgain;
  8.    float igain;
  9.    float dgain;
  10.    int deadband;
  11.    int last_error;
  12.   };
  13.   struct _pid warm,*pid;
  14.   int process_point, set_point,dead_band;
  15.   float p_gain, i_gain, d_gain, integral_val,new_integ;;
  16.   pid_init
  17.   DESCRIPTION This function initializes the pointers in the _pid structure
  18.   to the process variable and the setpoint. *pv and *sp are
  19.   integer pointers.
  20.   void pid_init(struct _pid *warm, int process_point, int set_point)
  21.   {
  22.    struct _pid *pid;
  23.    pid = warm;
  24.    pid->pv = process_point;
  25.    pid->sp = set_point;
  26.   }   
  27.   pid_tune  
  28.   DESCRIPTION Sets the proportional gain (p_gain), integral gain (i_gain),
  29.   derivitive gain (d_gain), and the dead band (dead_band) of
  30.   a pid control structure _pid.
  31.   void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d_gain, int dead_band)
  32.   {
  33.    pid->pgain = p_gain;
  34.    pid->igain = i_gain;
  35.    pid->dgain = d_gain;
  36.    pid->deadband = dead_band;
  37.    pid->integral= integral_val;
  38.    pid->last_error=0;
  39.   }      
  40. pid_setinteg
  41.     DESCRIPTION Set a new value for the integral term of the pid equation.
  42.   This is useful for setting the initial output of the
  43.   pid controller at start up.  
  44.   void pid_setinteg(struct _pid *pid,float new_integ)
  45.   {
  46.    pid->integral = new_integ;
  47.    pid->last_error = 0;
  48.   }      pid_bumpless
  49.   DESCRIPTION Bumpless transfer algorithim. When suddenly changing
  50.   setpoints, or when restarting the PID equation after an
  51.   extended pause, the derivative of the equation can cause
  52.   a bump in the controller output. This function will help
  53.   smooth out that bump. The process value in *pv should
  54.   be the updated just before this function is used.
  55.     void pid_bumpless(struct _pid *pid)
  56.   {   
  57.    pid->last_error = (pid->sp)-(pid->pv);   
  58.   }
  59. pid_calc   
  60.   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.
  61.   
  62.   RETURN VALUE The new output value for the pid loop.   
  63.   USAGE #include "control.h"*/   
  64.   float pid_calc(struct _pid *pid)  {
  65.    int err;
  66.    float pterm, dterm, result, ferror;
  67.      err = (pid->sp) - (pid->pv);
  68.    if (abs(err) > pid->deadband)   {
  69.    ferror = (float) err; /*do integer to float conversion only once*/
  70.    pterm = pid->pgain * ferror;
  71.    if (pterm > 100 || pterm < -100)   {
  72.    pid->integral = 0.0;   }
  73.    else   {
  74.    pid->integral += pid->igain * ferror;
  75.    if (pid->integral > 100.0)
  76.    {
  77.    pid->integral = 100.0;   }
  78.    else if (pid->integral < 0.0) pid->integral = 0.0;   }
  79.    dterm = ((float)(err - pid->last_error)) * pid->dgain;
  80.    result = pterm + pid->integral + dterm;   }
  81.    else result = pid->integral;
  82.    pid->last_error = err;
  83.    return (result);  }
  84.   
  85. void main(void)
  86.   {
  87.    float display_value;
  88.    int count=0;
  89.   
  90.    pid = &warm;
  91.   
  92.   // printf("Enter the values of Process point, Set point, P gain, I gain, D gain \n");
  93.   // scanf("%d%d%f%f%f", &process_point, &set_point, &p_gain, &i_gain, &d_gain);  
  94.    process_point = 30;
  95.    set_point = 40;
  96.    p_gain = (float)(5.2);
  97.    i_gain = (float)(0.77);
  98.    d_gain = (float)(0.18);
  99.     
  100.    dead_band = 2;
  101.    integral_val =(float)(0.01);
  102.     
  103.    printf("The values of Process point, Set point, P gain, I gain, D gain \n");
  104.    printf(" %6d %6d %4f %4f %4f\n", process_point, set_point, p_gain, i_gain, d_gain);
  105.   
  106.    printf("Enter the values of Process point\n");
  107.   
  108.    while(count<=20)
  109.    {  
  110.    scanf("%d",&process_point);  
  111.    pid_init(&warm, process_point, set_point);
  112.    pid_tune(&warm, p_gain,i_gain,d_gain,dead_band);
  113.    pid_setinteg(&warm,0.0); //pid_setinteg(&warm,30.0);
  114.   
  115.    //Get input value for process point
  116.    pid_bumpless(&warm);
  117.   
  118.    // how to display output
  119.    display_value = pid_calc(&warm);
  120.    printf("%f\n", display_value);
  121.    //printf("\n%f%f%f%f",warm.pv,warm.sp,warm.igain,warm.dgain);
  122.    count++;  
  123.    }
復制代碼


PID.zip

7.03 KB, 下載次數: 20, 下載積分: 黑幣 -5

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:411753 發表于 2018-10-18 15:57 | 只看該作者
學習下看看
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 99re视频这里只有精品 | 亚洲视频在线看 | 国产一区二区三区免费视频 | 在线观看www | 久久久久久久久国产成人免费 | av一级| 狠狠爱综合网 | 久草福利| 精品区一区二区 | 日韩at| 日日夜夜视频 | 99久久夜色精品国产亚洲96 | 久久国内| www亚洲精品 | 国产一区二区三区四区 | 午夜电影网址 | 日韩欧美国产一区二区 | 欧美日韩中文国产一区发布 | 国产精品成人一区 | av中文字幕在线 | 日韩免费| 国产九九九九 | 91久久国产综合久久 | 欧美专区在线 | 色爱区综合 | 欧美在线视频一区 | 成年免费大片黄在线观看岛国 | 黑人巨大精品欧美一区二区一视频 | 国产成人免费视频网站高清观看视频 | 亚洲一区精品在线 | 在线视频第一页 | 午夜小电影 | 国产亚洲一级 | 久久久久中文字幕 | 美国黄色毛片 | 亚洲一区视频在线播放 | 欧美一级欧美三级在线观看 | 中文字幕亚洲一区二区三区 | 成年人网站在线观看视频 | 伊人伊人伊人 | 草草视频在线播放 |