/*====================================================================================================
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.
=====================================================================================================*/
#ifndef PID_H
#define PID_H
typedef struct PID
{
uint8_t SetPouint; //设定目标 Desired Value
uint16_t SumError; //误差累计
uint32_t Proportion; //比例常数 Proportional Const
uint32_t uint8_tegral; //积分常数 uint8_tegral Const
uint32_t Derivative; //微分常数 Derivative Const
uint8_t LastError; //Error[-1]
uint8_t PrevError; //Error[-2]
} PID_Strucutre;
static PID_Strucutre sPID;
static PID_Strucutre *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->uint8_tegral = 0; //积分常数uint8_tegral Const
sptr->Derivative = 0; //微分常数 Derivative Const
sptr->SetPouint8_t = 0;
}
/*====================================================================================================
增量式PID计算部分
=====================================================================================================*/
uint8_t IncPIDCalc(uint8_t NextPouint8_t)
{
register uint8_t iError, iIncpid; //当前误差
iError = sptr->SetPouint8_t - NextPouint8_t; //增量计算
iIncpid = sptr->Proportion * iError //E[k]项
- sptr->uint8_tegral * sptr->LastError //E[k-1]项
+ sptr->Derivative * sptr->PrevError; //E[k-2]项
//存储误差,用于下次计算
sptr->PrevError = sptr->LastError;
sptr->LastError = iError;
//返回增量值
return(iIncpid);
}
#endif
PID.zip_pid.c文件_pid增量式_增量 PID_增量PID_增量式pid
版权申诉
162 浏览量
2022-09-22
21:25:38
上传
评论
收藏 864B ZIP 举报
小波思基
- 粉丝: 70
- 资源: 1万+
最新资源
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
- 以下是一个简化的示例,它使用pygame库来模拟烟花动画的框架.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈