中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > PID公式的推導(dǎo)過程及實現(xiàn)代碼

        PID公式的推導(dǎo)過程及實現(xiàn)代碼

        作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
        一、PID框圖







        n0(t)是要穩(wěn)定的值
        n(t)是當(dāng)前輸出值
        e(t) = n0(t) - n(t)


        一、模擬PID控制原理
        這個公式網(wǎng)絡(luò)上很好找:

        本文引用地址:http://www.antipu.com.cn/article/201612/324482.htm

        二、數(shù)字PID控制
        由于模擬的微積分運算對應(yīng)計算機(jī)來說是不太好寫代碼的,所以要利用采樣將數(shù)據(jù)離散化

        于是公式就可以轉(zhuǎn)換為:



        其中T為采樣時間,由于T之類的參數(shù)是常量,所以將Kp乘入公式中可以轉(zhuǎn)換成另一種寫法
        這個公式叫位置式算法

        由于要不斷的累加ej,增加了計算量,所以這個公式又可以轉(zhuǎn)換為增量式算法:




        然后u(k) = u(k-1) + u

        三、參數(shù)的整定
        先將Ti設(shè)置為無窮大,Td設(shè)置為0,調(diào)節(jié)Kp
        然后再調(diào)節(jié)Ti,最后是Td

        四、實現(xiàn)代碼

        typedef struct PID
        {
        int SetPoint; //設(shè)定目標(biāo) Desired Value
        longSumError; //誤差累計
        double Proportion; //比例常數(shù) Proportional Cons
        double Integral; //積分常數(shù) Integral Const
        double Derivative; //微分常數(shù) Derivative Const
        int LastError; //Error[-1]
        int PrevError; //Error[-2]
        } PID;

        /*******************************************************************************
        * 函數(shù)名稱 : IncPIDCalc
        * 函數(shù)描述 : 增量式 PID 控制計算
        * 函數(shù)輸入 : int 當(dāng)前位置
        * 函數(shù)輸出 : 無
        *函數(shù)返回 : 增量式PID結(jié)果
        *******************************************************************************/
        int IncPIDCalc(int NextPoint)
        {
        int iError, iIncpid;
        //當(dāng)前誤差
        iError = sptr->SetPoint - NextPoint;
        //增量計算
        iIncpid = sptr->Proportion * iError //E[k]項
        - sptr->Integral * sptr->LastError //E[k-1]項
        + sptr->Derivative * sptr->PrevError; //E[k-2]項
        //存儲誤差,用于下次計算
        sptr->PrevError = sptr->LastError;
        sptr->LastError = iError;
        //返回增量值
        return(iIncpid);
        }
        /*******************************************************************************
        * 函數(shù)名稱 : LocPIDCalc
        * 函數(shù)描述 : 位置式 PID 控制計算
        * 函數(shù)輸入 : int 當(dāng)前位置
        * 函數(shù)輸出 : 無
        *函數(shù)返回 : 位置式PID結(jié)果
        *******************************************************************************/
        int LocPIDCalc(int NextPoint)
        {
        int iError,dError;
        iError = sptr->SetPoint - NextPoint; //偏差
        sptr->SumError += iError; //積分
        dError = iError - sptr->LastError; //微分
        sptr->LastError = iError;
        return(sptr->Proportion * iError //比例項
        + sptr->Integral * sptr->SumError //積分項
        + sptr->Derivative * dError); //微分項
        }


        評論


        技術(shù)專區(qū)

        關(guān)閉