增量式PID控制算法
2009-11-12 19:13
169 查看
51单片机PID算法程序(三)增量式PID控制算法 -- Sheldon
当执行机构需要的不是控制量的绝对值,而是控制量的增量(例如去驱动步进电动机)时,需要用PID的“增量算法”。
增量式PID控制算法C51程序
/*====================================================================================================
PID Function
The PID (比例、积分、微分) function is used in mainly
control applications. PIDCalc performs one iteration of the PID
algorithm.
While the PID function works, main is just a dummy program showing
a typical usage.
=====================================================================================================*/
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;
/*====================================================================================================
Initialize PID Structure PID参数初始化
=====================================================================================================*/
void IncPIDInit(void)
{
sptr->SumError = 0;
sptr->LastError = 0; //Error[-1]
sptr->PrevError = 0; //Error[-2]
sptr->Proportion = 0; //比例常数 Proportional Const
sptr->Integral = 0; //积分常数Integral Const
sptr->Derivative = 0; //微分常数 Derivative Const
sptr->SetPoint = 0;
}
/*====================================================================================================
增量式PID计算部分
=====================================================================================================*/
int IncPIDCalc(int NextPoint)
{
register int iError, iIncpid; //当前误差
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);
}
增量式PID控制算法C51程序
/*====================================================================================================
PID Function
The PID (比例、积分、微分) function is used in mainly
control applications. PIDCalc performs one iteration of the PID
algorithm.
While the PID function works, main is just a dummy program showing
a typical usage.
=====================================================================================================*/
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;
/*====================================================================================================
Initialize PID Structure PID参数初始化
=====================================================================================================*/
void IncPIDInit(void)
{
sptr->SumError = 0;
sptr->LastError = 0; //Error[-1]
sptr->PrevError = 0; //Error[-2]
sptr->Proportion = 0; //比例常数 Proportional Const
sptr->Integral = 0; //积分常数Integral Const
sptr->Derivative = 0; //微分常数 Derivative Const
sptr->SetPoint = 0;
}
/*====================================================================================================
增量式PID计算部分
=====================================================================================================*/
int IncPIDCalc(int NextPoint)
{
register int iError, iIncpid; //当前误差
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);
}
相关文章推荐
- 增量式PID控制算法的MATLAB仿真及思考
- 一个简单的PID控制算法
- PID控制算法的C语言实现
- 增量式修改检验和(IP, TCP, UDP)算法的研究和实现
- 今天开始学PID电机控制,这个作者写得很不错,和大家分享一下~~~ PID控制算法通俗理解 作者:whut_wj 来源:http://blog.eccn.com/space.php?uid=35
- 位置式PID控制算法模型(数字)
- pid控制算法通俗理解
- PID控制算法的C语言实现
- Pid控制算法-PID算法的离散化
- Pid控制算法-抗积分饱和pid算法C++实现
- PID控制算法通俗理解
- PID控制及位置式与增量式区别
- 增量式PID控制
- PID控制算法举例之(一)
- 杂谈PID控制算法——第二篇:调·三个量
- 位置式和增量式PID控制
- PID控制算法 C程序的两种表述
- 四轴飞行器的位置式PID控制和增量式PID控制
- Pid控制算法-模糊算法简介
- 位置式和增量式PID控制