音影先锋亚洲天堂网|电影世界尽头的爱完整版播放|国产 熟女 91|高清无码免费观看欧美日韩|韩国一区二区三区黄色录像|美女亚洲加勒比在线|亚洲综合网 开心五月|7x成人在线入口|成人网站免费日韩毛片区|国产黄片?一级?二级?三级

登錄 免費注冊 首頁 | 行業(yè)黑名單 | 幫助
維庫電子市場網
技術交流 | 電路欣賞 | 工控天地 | 數字廣電 | 通信技術 | 電源技術 | 測控之家 | EMC技術 | ARM技術 | EDA技術 | PCB技術 | 嵌入式系統
驅動編程 | 集成電路 | 器件替換 | 模擬技術 | 新手園地 | 單 片 機 | DSP技術 | MCU技術 | IC 設計 | IC 產業(yè) | CAN-bus/DeviceNe

跪求大蝦們給這段PID程序加上注釋或說明一下!

作者:哈佛大學 欄目:單片機
跪求大蝦們給這段PID程序加上注釋或說明一下!
 
  #include <stdio.h>
  #include<math.h>
  
  struct _pid {
   int pv; /*integer that contains the PROCESS VALUE.html">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.html">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.html">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.html">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.html">VALUE;
   int count=0;
  
   pid = &warm;
  
  // printf("Enter the VALUE.html">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 VALUE.html">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 VALUE.html">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.html">VALUE for PROCESS point
   pid_bumpless(&warm);
  
   // how to DISPLAY OUTPUT
   DISPLAY_VALUE.html">VALUE = pid_calc(&warm);  
   printf("%f\n", DISPLAY_VALUE.html">VALUE);  
   //printf("\n%f%f%f%f",warm.pv,warm.sp,warm.igain,warm.dgain);  
   count++;  
    
   }  
  
  }



2樓: >>參與討論
哈佛大學
00啊,匠人啊
 
3樓: >>參與討論
哈佛大學
平常人啊
 
4樓: >>參與討論
computer00
我倒…………這么長……里面不是有注釋了么?
 
5樓: >>參與討論
hqgboy
哈佛大學???
 
參與討論
昵稱:
討論內容:
 
 
相關帖子
430的C中斷程序格式問題
430單片機的程序問題
沒人理俺,只好舔著臉舊貼重提拉,
protel99se里用LED沒錯,換成DIODE就出錯了
求助關于HEX2BIN!
免費注冊為維庫電子開發(fā)網會員,參與電子工程師社區(qū)討論,點此進入


Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號