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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

PID控制智能小車C語言算法實現

[復制鏈接]
跳轉到指定樓層
樓主
ID:377596 發表于 2019-1-24 13:58 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
在過程控制中,按偏差的比例(P)、積分(I)和微分(D)進行控制的PID控制器(亦稱PID調節器)是應用最為廣泛的一種自動控制器。它具有原理簡單,易于實現,適用面廣,控制參數相互獨立,參數的選定比較簡單等優點;而且在理論上可以證明,對于過程控制的典型對象──“一階滯后+純滯后”與“二階滯后+純滯后”的控制對象,PID控制器是一種最優控制。PID調節規律是連續系統動態品質校正的一種有效方法,它的參數整定方式簡便,結構改變靈活(PI、PD、…)。
參數的選擇:
   ①比例系數P對系統性能的影響:比例系數加大,使系統的動作靈敏,速度加快,穩態誤差減;P偏大,振蕩次數加多,調節時間加長;P太大時,系統會趨于不穩定;P太小,又會使系統的動作緩慢。P可以選負數,這主要是由執行機構、傳感器以及控制對象的特性決定的。如果P的符號選擇不當對象測量值就會離控制目標的設定值越來越遠,如果出現這樣的情況P的符號就一定要取反。同時要注意的是,力控的策略控制器的PID控制塊的P參數是PID控制中的增益。
  ②積分控制I對系統性能的影響:積分作用使系統的穩定性下降,I小(積分作用強)會使系統不穩定,但能消除穩態誤差,提高系統的控制精度。
 、畚⒎挚刂艱對系統性能的影響:微分作用可以改善動態特性,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.    }
復制代碼

全部資料51hei下載地址:
PID控制智能小車.doc (32 KB, 下載次數: 29)

評分

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

查看全部評分

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

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 中文字幕专区 | 午夜免费精品视频 | 久久岛国 | 欧美精品一区二区三区在线 | 精品日韩在线 | 最新国产视频 | 日韩av黄色 | 日本在线一区二区 | 久久久精品久久久 | 日韩精品在线视频免费观看 | 91久久精品日日躁夜夜躁欧美 | 欧美成人精品激情在线观看 | 干干干操操操 | 伊人久久综合 | 日韩一区二区三区视频 | 日本中出视频 | 精品国产青草久久久久96 | 久久9热| 国产一级片网站 | 特级生活片| 久操伊人| 久久伊人精品 | 精品视频国产 | 欧美一区二区在线播放 | 精品一区国产 | 欧美在线色视频 | 在线欧美亚洲 | 亚洲在线日韩 | 欧美一区日韩一区 | 国产精品视频综合 | 成人影院在线观看 | 亚洲一区二区三区桃乃木香奈 | 日韩成人专区 | 99国产精品久久久久 | 国产有码 | 国产欧美一区二区三区日本久久久 | jlzzjlzz欧美大全 | 亚洲不卡在线视频 | 精品视频一区二区三区 | 黄色成人在线 | 久久草视频|