stm32控制器下經(jīng)常會(huì)用到對(duì)溫度控制,適度控制,轉(zhuǎn)速控制等需要自動(dòng)控制相關(guān)的操作,因此在使用中需要不斷提高對(duì)自動(dòng)控制 原理部分的學(xué)習(xí),一個(gè)好的自動(dòng)控制系統(tǒng)包含三個(gè) 主要因素:穩(wěn),快,準(zhǔn)。穩(wěn)即系統(tǒng)的穩(wěn)定性,快即系統(tǒng)的快速性,準(zhǔn)即控制的準(zhǔn)確性。
在自動(dòng)控制中比例增益,積分時(shí)間,微分時(shí)間三個(gè)主要變量。下面就這三個(gè)變量進(jìn)行動(dòng)態(tài)展示。

如上圖所示,假設(shè)在單位階躍響應(yīng)下,比例控制幅值,kp越大值越高相關(guān)的,積分時(shí)間控制精確度,數(shù)值越大波形超調(diào)量越大,微分時(shí)間控制波形的平緩程度。
下面貼出增量式PID算法在c代碼部分的實(shí)現(xiàn)過(guò)程。
//實(shí)現(xiàn)增量式PID算法
#include "stdio.h"
void pid_init();//PID參數(shù)初始化
float pid_realise(float speed);//實(shí)現(xiàn)PID算法
struct {
float set_speed;//設(shè)定速度
float actual_speed;//實(shí)際速度
float error;//偏差
float error_next;//上一個(gè)偏差
float error_last;//上上一個(gè)偏差
float kp,ki,kd;//定義比例,積分,微分參數(shù)
}pid;
int main()
{
pid_init();
int count = 0;
while(count<400)//進(jìn)行400次 PID 運(yùn)算,使初始值從0開(kāi)始接近200.0
{
float speed = pid_realise(200.0);//設(shè)定值設(shè)定為200.0
printf("%f\n",speed);//輸出每一次PID 運(yùn)算后的結(jié)果
count++;
}
}
void pid_init()
{
pid.set_speed = 0.0;
pid.actual_speed = 0.0;
pid.error = 0.0;
pid.error_next = 0.0;
pid.error_last = 0.0;
//可調(diào)節(jié)PID 參數(shù)。使跟蹤曲線慢慢接近階躍函數(shù)200.0 //
pid.kp = 0.2;
pid.ki = 0.01;
pid.kd = 0.2;
}
float pid_realise(float speed)//實(shí)現(xiàn)pid
{
pid.set_speed = speed;//設(shè)置目標(biāo)速度
pid.error = pid.set_speed - pid.actual_speed;
float increment_speed;//增量
increment_speed = pid.kp*(pid.error-pid.error_next)+pid.ki*pid.error+\
pid.kd*(pid.error-2*pid.error_next+pid.error_last);//增量計(jì)算公式
pid.actual_speed+= increment_speed;
pid.error_last = pid.error_next;//下一次迭代
pid.error_next = pid.error;
return pid.actual_speed;
}
運(yùn)行數(shù)據(jù)得到圖標(biāo)如下 :

審核編輯:湯梓紅
-
控制器
+關(guān)注
關(guān)注
114文章
17113瀏覽量
184304 -
STM32
+關(guān)注
關(guān)注
2293文章
11032瀏覽量
364968 -
PID
+關(guān)注
關(guān)注
37文章
1482瀏覽量
88050
發(fā)布評(píng)論請(qǐng)先 登錄
限時(shí)免積分下載:增量式與位置式PID算法的C語(yǔ)言實(shí)現(xiàn)分享
淺析位置式PID與增量式PID算法
教你用C語(yǔ)言實(shí)現(xiàn)位置式PID和增量式PID
收藏干貨 PID算法實(shí)現(xiàn)
在STM32如何去實(shí)現(xiàn)增量式PID算法
PID算法增量式算法
如何實(shí)現(xiàn)增量式PID
增量式PID的stm32實(shí)現(xiàn)及其整定過(guò)程
使用C語(yǔ)言進(jìn)行PID算法實(shí)現(xiàn)
如何去實(shí)現(xiàn)基于stm32的PID算法增量式程序呢
位置型PID的C語(yǔ)言代碼的實(shí)現(xiàn)過(guò)程詳細(xì)資料概述
如何使用免疫粒子群優(yōu)化算法實(shí)現(xiàn)增量式的PID控制

使用單片機(jī)和Arduino實(shí)現(xiàn)增量式PID位置式PID算法和PID庫(kù)免費(fèi)下載

PID控制算法的C語(yǔ)言實(shí)現(xiàn)

評(píng)論