sihu国产精品永久免费_日韩午夜在线视频_久久99中文字幕伊人_古代男男嗯…啊h总攻

dcgdeng
級別: *
精華主題: * 篇
發(fā)帖數(shù)量: * 個
工控威望: * 點
下載積分: * 分
在線時間: (小時)
注冊時間: *
最后登錄: *
查看dcgdeng的 主題 / 回貼
樓主  發(fā)表于: 2011-01-24 14:05


#include <REGX51.H>
#include <intrins.h>
#include <string.h>
#include <stdio.h>

typedef struct PID {

        double  SetPoint;          

        double  Proportion;        
        double  Integral;        
        double  Derivative;        

        double  LastError;        

        double  PrevError;          

        double  SumError;        

} PID;
double PIDCalc( PID *pp, double NextPoint )
{
    double  dError,
            Error;

        Error = pp->SetPoint -  NextPoint;        

        pp->SumError += Error;                    

        dError = pp->LastError - pp->PrevError;  

        pp->PrevError = pp->LastError;
        pp->LastError = Error;
        return (pp->Proportion * Error        

            +   pp->Integral * pp->SumError      

            +   pp->Derivative * dError            

        );
}
//////////////////////////////////////////////////////////////////////

void PIDInit (PID *pp)
{
    memset ( pp,0,sizeof(PID));
}



double sensor (void)                

    return 100.0;
}

void actuator(double rDelta)        {}

void man(void)
{
    PID         sPID;                  

    double      rOut;                  

    double      rIn;                  

    PIDInit ( &sPID );                

    sPID.Proportion = 0.5;            

    sPID.Integral   = 0.5;
    sPID.Derivative = 0.0;
    sPID.SetPoint   = 0.3;        

    for (;;) {                        

        rIn = adc ();                

        rOut = PIDCalc ( &sPID,rIn );
        actuator ( rOut );            

    }
}