|
arduinoPID庫(kù)文件
0.png (6.29 KB, 下載次數(shù): 106)
下載附件
2019-1-10 17:33 上傳
3個(gè)文件下載(僅供參考,有錯(cuò)誤請(qǐng)指出):
PID_v1.rar
(6.84 KB, 下載次數(shù): 146)
2019-1-10 17:25 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
- /********************************************************
- * PID RelayOutput Example
- * Same as basic example, except that this time, the output
- * is going to a digital pin which (we presume) is controlling
- * a relay. the pid is designed to Output an analog value,
- * but the relay can only be On/Off.
- *
- * to connect them together we use "time proportioning
- * control" it's essentially a really slow version of PWM.
- * first we decide on a window size (5000mS say.) we then
- * set the pid to adjust its output between 0 and that window
- * size. lastly, we add some logic that translates the PID
- * output into "Relay On Time" with the remainder of the
- * window being "Relay Off Time"
-
- PID繼電器輸出范例
- 與基本范例相同,這一次輸出是一個(gè)數(shù)字引腳控制的繼電器。PID被設(shè)計(jì)成
- 輸出一個(gè)模擬值,但是繼電器只有開(kāi)關(guān)狀態(tài)。
- 為了聯(lián)系上兩者,我們使用時(shí)間比例控制,它本質(zhì)上是一個(gè)很慢的PWM。
- 首先我們決定一個(gè)窗口時(shí)間(比如5000ms)。
- 然后設(shè)置PID適應(yīng)它的輸出在0到窗口時(shí)間的范圍。
- 最后我們添加一些邏輯,把PID輸出轉(zhuǎn)換成“繼電器接通時(shí)間”和剩余的
- “繼電器斷開(kāi)時(shí)間”
- ********************************************************/
- #include <PID_v1.h>
- #define RelayPin 8
- // 定義我們將要使用的變量
- //Define Variables we'll be connecting to
- double Setpoint, Input, Output;
- //指定鏈接和最初的調(diào)優(yōu)參數(shù)
- //Specify the links and initial tuning parameters
- PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
- int WindowSize = 2000;
- unsigned long windowStartTime;
- void setup()
- {
- windowStartTime = millis();
- //初始化變量
- //initialize the variables we're linked to
- Setpoint = 100;
- //告訴PID在從0到窗口大小的范圍內(nèi)取值
- //tell the PID to range between 0 and the full window size
- myPID.SetOutputLimits(0, WindowSize);
- //開(kāi)啟PID
- //turn the PID on
- myPID.SetMode(AUTOMATIC);
- }
- void loop()
- {
- Input = analogRead(0);
- myPID.Compute();
- /************************************************
- * turn the output pin on/off based on pid output 基于PID輸出,打開(kāi)或關(guān)閉端口輸出
- ************************************************/
- if(millis() - windowStartTime>WindowSize)
- { //time to shift the Relay Window 繼電器窗口時(shí)間
- windowStartTime += WindowSize;
- }
- if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
- else digitalWrite(RelayPin,LOW);
- }
復(fù)制代碼
|
評(píng)分
-
查看全部評(píng)分
|