基本信息
源码名称:PID算法
源码大小:1.01KB
文件格式:.c
开发语言:C/C++
更新时间:2024-12-05
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
//PID结构体
PID Motor_pid[14];
float Angle_PID_Out[3];//角度环
PID pid;
void PID_initfuc(PID *pid,float kp,float ki,float kd,int16_t L_limit,int16_t l_limit)
{
pid -> Kp = kp;
pid -> Ki = ki;
pid -> Kd = kd;
pid -> L_limit = L_limit;
pid -> l_limit = l_limit;
}
float FeedbaceControl(PID *pid,float Target,float Now)
{
pid -> Bias = Target - Now;
pid -> Integral_Bias = pid -> Bias;
if(pid -> Integral_Bias > pid -> L_limit)
{
pid -> Integral_Bias = pid -> L_limit;
}
if(pid -> Integral_Bias < -pid -> L_limit)
{
pid -> Integral_Bias = -pid -> L_limit;
}
pid -> out = pid -> Kp * pid -> Bias pid -> Ki * pid -> Integral_Bias pid -> Kd * (pid -> Bias - pid -> last_Bias);
pid -> last_Bias = pid -> Bias;
if(pid -> out > pid -> l_limit)
{
pid -> out = pid -> l_limit;
}
if(pid -> out < -pid -> l_limit)
{
pid -> out = -pid -> l_limit;
}
int16_t a=2;
return pid -> out;
}
这段代码实现了一个简单的PID(比例-积分-微分)控制器,用于控制系统中的反馈控制。PID控制器广泛应用于各种自动化控制系统中,如电机控制、温度控制等
#include "PID.h"
//PID结构体
PID Motor_pid[14];
float Angle_PID_Out[3];//角度环
PID pid;
void PID_initfuc(PID *pid,float kp,float ki,float kd,int16_t L_limit,int16_t l_limit)
{
pid -> Kp = kp;
pid -> Ki = ki;
pid -> Kd = kd;
pid -> L_limit = L_limit;
pid -> l_limit = l_limit;
}
float FeedbaceControl(PID *pid,float Target,float Now)
{
pid -> Bias = Target - Now;
pid -> Integral_Bias = pid -> Bias;
if(pid -> Integral_Bias > pid -> L_limit)
{
pid -> Integral_Bias = pid -> L_limit;
}
if(pid -> Integral_Bias < -pid -> L_limit)
{
pid -> Integral_Bias = -pid -> L_limit;
}
pid -> out = pid -> Kp * pid -> Bias pid -> Ki * pid -> Integral_Bias pid -> Kd * (pid -> Bias - pid -> last_Bias);
pid -> last_Bias = pid -> Bias;
if(pid -> out > pid -> l_limit)
{
pid -> out = pid -> l_limit;
}
if(pid -> out < -pid -> l_limit)
{
pid -> out = -pid -> l_limit;
}
int16_t a=2;
return pid -> out;
}