欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1550|回復: 0
打印 上一主題 下一主題
收起左側

pid程序的應用

[復制鏈接]
跳轉到指定樓層
樓主
ID:365616 發表于 2018-7-5 14:57 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

typedef struct PID
{
        int  SetPoint;                         //  設定目標 Desired Value
        long SumError;                        //        誤差累計
               
        double  Proportion;     //  比例常數 Proportional Const
        double  Integral;       //  積分常數 Integral Const
        double  Derivative;     //  微分常數 Derivative Const

        int LastError;                 //  Error[-1]
        int PrevError;          //  Error[-2]

} PID;

static PID         sPID;
static PID         *sptr = &sPID;
//=============================================================
// Function: IncPIDInit()
// Syntax: void IncPIDInit(void);
// Description: Initialization PID parameter.
// Notes:
// parameters: none
// returns: none
//=============================================================
void PID_Init(void)
{
    sptr->LastError  = 0;                        //Error[-1]
    sptr->PrevError  = 0;                        //Error[-2]
        sptr->Proportion = 0.3;                        //比例常數 Proportional Const
    sptr->Integral   = 0.2;                        //3.5積分常數 Integral Const
    sptr->Derivative = 0.1;                        //1.25微分常數 Derivative Const
    sptr->SetPoint   = 0;
        sptr->SumError   = 0;
}

//=============================================================
// ----Function: IncPIDSetPoint()
// ------Syntax: void IncPIDSetPoint(unsigned int setpoint);
// -Description: Set PID Desired Value
// -------Notes:
// --parameters: Desired Value
// -----returns: none
//=============================================================
void PIDSetPoint(int setpoint)
{        sptr->SetPoint = setpoint;        }

int PIDGetSetpoint(void)
{        return(sptr->SetPoint);        }
//=============================================================
// ----Function: IncPIDKp()
// ------Syntax: void IncPIDKp(double dKp);
// -Description: Set PID Proportion coefficient
// -------Notes:
// --parameters: Proportion Const
// -----returns: none
//=============================================================
void PIDSetKp(double dKpp)
{        sptr->Proportion = dKpp;        }
//===================================//
// Get Proportion
//===================================//
double PIDGetKp(void)
{        return(sptr->Proportion);        }
//=============================================================
// ----Function: IncPIDKi()
// ------Syntax: void IncPIDKi(double dKi);
// -Description: Set PID Integral coefficient
// -------Notes:
// --parameters: Integral Const
// -----returns: none
//=============================================================
void PIDSetKi(double dKii)
{        sptr->Integral = dKii;        }
//===================================//
// Get Integral
//===================================//
double PIDGetKi(void)
{        return(sptr->Integral);        }
//=============================================================
// ----Function: IncPIDKd()
// ------Syntax: void IncPIDKd(double dKd);
// -Description: Set PID Derivative coefficient
// -------Notes:
// --parameters: Derivative Const
// -----returns: none
//=============================================================
void PIDSetKd(double dKdd)
{        sptr->Derivative = dKdd;        }
//===================================//
// Get Derivative
//===================================//
double PIDGetKd(void)
{        return(sptr->Derivative);        }

void Self_ConfigPID(double uiKp)
{
        double dKp;
        dKp = uiKp;
        PIDSetKp(2.45*dKp);
        PIDSetKi(3.50*dKp);
        PIDSetKd(1.25*dKp);
}

//=============================================================
// ----Function: IncPIDCalc()
// ------Syntax: int IncPIDCalc(unsigned int NextPoint);
// -Description: Increment Digital PID calculate
// -------Notes: Basic Increment Digital PID
// --parameters: Next Point
// -----returns: increase controls parameter
//=============================================================
int IncPIDCalc(int NextPoint)
{
        register int iError, iIncpid;

        iError = sptr->SetPoint - NextPoint;

        iIncpid = sptr->Proportion * iError                                //E[0]
            + sptr->Integral   * sptr->LastError        //E[-1]
            + sptr->Derivative * sptr->PrevError;        //E[-2]

        sptr->PrevError = sptr->LastError;
        sptr->LastError = iError;

        return(iIncpid);
}

//=============================================================
// ----Function: LocPIDCalc()
// ------Syntax: unsigned int locPIDCalc(unsigned int NextPoint);
// -Description: Location Digital PID calculate
// -------Notes: Basic Location Digital PID
// --parameters: Next Point
// -----returns: Location controls parameter
//=============================================================
unsigned int LocPIDCalc(int NextPoint)
{
    register 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);
}
       
//=============================================//
//        *END*
//=============================================//




評分

參與人數 2黑幣 +55 收起 理由
熱帶芒果 + 5 很給力!
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

無效樓層,該帖已經被刪除
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表