新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 外置式PID程序模板

        外置式PID程序模板

        作者: 時間:2016-12-01 來源:網絡 收藏
        外置式PID模板

        #define MuBiaoCS 0 //目標常數
        #define CHang_aCS 0 //比例常數
        #define CHang_bCS 0 //積分常數
        #define CHang_cCS 0 //微分常數
        /*******************************************************************************************/
        struct P_I_D {
        int MuBiao; //設定目標 Desired Value
        double CHang_a; //比例常數 Proportional Const
        double CHang_b; //積分常數 Integral Const
        doubleCHang_c; //微分常數 Derivative Const
        int Error1; //Error[-1]
        int Error2; //Error[-2]
        }Pidn;
        struct P_I_D *PID=&Pidn;
        /********************************************************************************************/
        void Pidinit(void) //pid初始化
        {
        PID->MuBiao=MuBiaoCS;
        PID->CHang_a=CHang_aCS;
        PID->CHang_b=CHang_bCS;
        PID->CHang_c=CHang_cCS;
        PID->Error1=0;
        PID->Error2=0;
        }

        本文引用地址:http://www.104case.com/article/201612/324211.htm

        int PID_WZ(int SRuu) //位置式PID
        {
        int Error0,SCuu;
        Error0 = PID->MuBiao - SRuu;
        PID->Error1+=Error0;
        SCuu = PID->CHang_a*Error0 //比例項
        + PID->CHang_b*PID->Error1 //積分項
        + PID->CHang_c*(Error0-PID->Error2);//微分項
        PID->Error2=Error0;
        return SCuu;
        }
        void main(void)
        {
        Pidinit();
        }

        增量式PID模板

        #define MuBiaoCS 0 //目標常數
        #define CHang_aCS 0 //比例常數
        #define CHang_bCS 0 //積分常數
        #define CHang_cCS 0 //微分常數
        /*******************************************************************************************/
        struct P_I_D {
        int MuBiao; //設定目標 Desired Value
        double CHang_a; //比例常數 Proportional Const
        double CHang_b; //積分常數 Integral Const
        doubleCHang_c; //微分常數 Derivative Const
        int Error1; //Error[-1]
        int Error2; //Error[-2]
        }Pidn;
        struct P_I_D *PID=&Pidn;
        /********************************************************************************************/
        void Pidinit(void) //pid初始化
        {
        PID->MuBiao=MuBiaoCS;
        PID->CHang_a=CHang_aCS;
        PID->CHang_b=CHang_bCS;
        PID->CHang_c=CHang_cCS;
        PID->Error1=0;
        PID->Error2=0;
        }

        int PID_WC(int SRuu) //增量式PID
        {
        int Error0,SCuu;
        Error0 = PID->MuBiao - SRuu; //偏差
        SCuu = PID->CHang_a*Error0 //Error項
        - PID->CHang_b*PID->Error1 //Error1項
        + PID->CHang_c*PID->Error2; //Error2項
        PID->Error2=PID->Error1; //將上次偏差存PID->Error2
        PID->Error1=Error0; //將這次偏差存PID->Error1
        return SCuu;
        }

        void main(void)
        {
        Pidinit();
        }



        關鍵詞: 外置式PID程序模

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 佳木斯市| 遵化市| 东方市| 文山县| 平潭县| 敦煌市| 太白县| 沁阳市| 万宁市| 岢岚县| 肇东市| 庆云县| 太白县| 九龙城区| 巴林右旗| 清镇市| 彭阳县| 泗洪县| 凌源市| 石林| 平阴县| 新密市| 肇东市| 措勤县| 梁河县| 峡江县| 元江| 潢川县| 伊金霍洛旗| 威海市| 梁平县| 宣化县| 德保县| 南昌市| 左贡县| 大兴区| 宁陵县| 蒙山县| 永昌县| 藁城市| 屯留县|