当前位置:首页 > 单片机 > 单片机
[导读]typedef struct PID{ double SetPoint; // Desired Value double Proportion; // Proportional Const double Integral; // Integral Const double Derivative; // Derivative Const double LastError; // Error[-1]

typedef struct PID
{
double SetPoint; // Desired Value

double Proportion; // Proportional Const
double Integral; // Integral Const
double Derivative; // Derivative Const

double LastError; // Error[-1]
double PrevError; // Error[-2]
double SumError; // Sums of Errors
} PID;

/*=========================================================================*
Perform One PID Iteration
*=========================================================================*/

double PIDCalc ( PID *pp, double NextPoint )

{ double dError, Error;

pp->SumError += (Error = pp->SetPoint - NextPoint);
dError = pp->LastError - pp->PrevError;
pp->PrevError = pp->LastError;
pp->LastError = Error;
return ( pp->Proportion * Error
+ pp->Integral * pp->SumError
+ pp->Derivative * dError
);
}

/*=========================================================================*
Initialize PID Structure
*=========================================================================*/

void PIDInit ( PID *pp )

{ memset ( pp,0,sizeof(PID) );
}

/***************************************************************************
Main Program
***************************************************************************/

double sensor ( void ) // Dummy Sensor Function
{ return 100.0;
}

void actuator ( double rDelta ) // Dummy Actuator Function
{}

void main ( void )
{ PID sPID; // PID Control Structure
double rOut; // PID Response (Output)
double rIn; // PID Feedback (Input)

PIDInit ( &sPID ); // Initialize Structure
sPID.Proportion = 0.5; // Set PID Coefficients
sPID.Integral = 0.5;
sPID.Derivative = 0.0;
sPID.SetPoint = 100.0; // Set PID Setpoint

for (;;) // Mock Up of PID Processing
{ rIn = sensor (); // Read Input
rOut = PIDCalc ( &sPID,rIn ); // Perform PID Interation
actuator ( rOut ); // Effect Needed Changes
}
}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

/**************************文件所用资源1.端口:P22.调用delay_ms函数**************************/#include #include #define key...

关键字: 4*4 c51程序 矩阵键盘

/**************************文件所用资源1.端口:P0.2,P0.32.调用delay_ms函数**************************//*********************...

关键字: c51程序 读写驱动 24cxx

/**************************文件所用资源1.端口:P0.4,P0.5,P0.6,P0.72.调用delay_ms函数**************************//***********...

关键字: c51程序 io口 模拟spi通信

/********************************文件所用资源1.外部中断0、1 定时中断0、1 串口中断2.端口:P3.0,P3.1,P3.3,P3.4,P3.5********************...

关键字: c51程序 串口中断 外部中断 定时中断

模块内接口:使用如下标志符:asm汇编语句endasm注意:如果在程序中使用了,注意在Keil编译器中需要激活Properties中的“GenerateAssemblerFile”和“AssemblerFile”两个选项...

关键字: keil c51程序 嵌入汇编

关于spi协议见:http://hi.baidu.com/gilbertjuly/blog/item/0be222eeac9abae5cf1b3e38.html ISD4002芯片资料参考:http://downloa...

关键字: c51程序 spi总线 单片机 发送数据

/*--------------------------24C01的IIC 读写的c51程序---------------------程序中很多NOP是冗余的,希望读者能进一步精简,但必须经过验证。 Atmel 24C...

关键字: c51程序 单片机 读写24c01

void X5045SpiOpen(void);//打开X5045片选void X5045SpiClose(void);//关闭X5045片选 void X5045WriteEnable(void);//软件使能X50...

关键字: c51程序 x5045 读写一体化

/*------------------------------------------------------------------------------为了安全起见,程序中很多NOP是冗余的,希望读者能进一步精简...

关键字: c51程序 iic 读写 24c01

/**************************文件所用资源1.外部中断02.端口:P3.3、P3.4**************************/sbit BT_REC =P3^3;//接收 P3.0sb...

关键字: c51程序 io口 模拟串口
关闭
关闭