找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7764|回復(fù): 7
打印 上一主題 下一主題
收起左側(cè)

arduino PID庫文件下載

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
arduinoPID庫文件


3個文件下載(僅供參考,有錯誤請指出):
PID_v1.rar (6.84 KB, 下載次數(shù): 146)

  1. /********************************************************
  2. * PID RelayOutput Example
  3. * Same as basic example, except that this time, the output
  4. * is going to a digital pin which (we presume) is controlling
  5. * a relay.  the pid is designed to Output an analog value,
  6. * but the relay can only be On/Off.
  7. *
  8. *   to connect them together we use "time proportioning
  9. * control"  it's essentially a really slow version of PWM.
  10. * first we decide on a window size (5000mS say.) we then
  11. * set the pid to adjust its output between 0 and that window
  12. * size.  lastly, we add some logic that translates the PID
  13. * output into "Relay On Time" with the remainder of the
  14. * window being "Relay Off Time"

  15. PID繼電器輸出范例
  16. 與基本范例相同,這一次輸出是一個數(shù)字引腳控制的繼電器。PID被設(shè)計成
  17. 輸出一個模擬值,但是繼電器只有開關(guān)狀態(tài)。
  18. 為了聯(lián)系上兩者,我們使用時間比例控制,它本質(zhì)上是一個很慢的PWM。
  19. 首先我們決定一個窗口時間(比如5000ms)。
  20. 然后設(shè)置PID適應(yīng)它的輸出在0到窗口時間的范圍。
  21. 最后我們添加一些邏輯,把PID輸出轉(zhuǎn)換成“繼電器接通時間”和剩余的
  22. “繼電器斷開時間”
  23. ********************************************************/

  24. #include <PID_v1.h>
  25. #define RelayPin 8
  26. // 定義我們將要使用的變量
  27. //Define Variables we'll be connecting to
  28. double Setpoint, Input, Output;
  29. //指定鏈接和最初的調(diào)優(yōu)參數(shù)
  30. //Specify the links and initial tuning parameters
  31. PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

  32. int WindowSize = 2000;
  33. unsigned long windowStartTime;
  34. void setup()
  35. {
  36.   windowStartTime = millis();
  37.   //初始化變量
  38.   //initialize the variables we're linked to
  39.   Setpoint = 100;
  40.   //告訴PID在從0到窗口大小的范圍內(nèi)取值
  41.   //tell the PID to range between 0 and the full window size
  42.   myPID.SetOutputLimits(0, WindowSize);
  43.   //開啟PID
  44.   //turn the PID on
  45.   myPID.SetMode(AUTOMATIC);
  46. }

  47. void loop()
  48. {
  49.   Input = analogRead(0);
  50.   myPID.Compute();

  51.   /************************************************
  52.    * turn the output pin on/off based on pid output 基于PID輸出,打開或關(guān)閉端口輸出
  53.    ************************************************/
  54.   if(millis() - windowStartTime>WindowSize)
  55.   { //time to shift the Relay Window 繼電器窗口時間
  56.     windowStartTime += WindowSize;
  57.   }
  58.   if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
  59.   else digitalWrite(RelayPin,LOW);

  60. }
復(fù)制代碼


評分

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

查看全部評分

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

使用道具 舉報

沙發(fā)
ID:277190 發(fā)表于 2019-1-12 12:52 | 只看該作者
沒有解壓密碼
回復(fù)

使用道具 舉報

板凳
ID:384581 發(fā)表于 2019-1-14 19:17 | 只看該作者
謝謝分享
回復(fù)

使用道具 舉報

地板
ID:371304 發(fā)表于 2019-5-4 01:27 | 只看該作者
感謝分享
回復(fù)

使用道具 舉報

5#
ID:341924 發(fā)表于 2019-7-14 21:24 | 只看該作者

感謝分享
回復(fù)

使用道具 舉報

6#
ID:632293 發(fā)表于 2019-11-1 17:26 | 只看該作者
謝謝分享
回復(fù)

使用道具 舉報

7#
ID:280686 發(fā)表于 2020-2-5 22:58 | 只看該作者
感謝分享
回復(fù)

使用道具 舉報

8#
ID:873833 發(fā)表于 2024-1-17 16:08 | 只看該作者
樓主,請問為什么PID定義那里編譯不過呢?會是什么原因?
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表