您的位置 首页 硬件

单片机PID算法完成

在avr单片机上实现的100%通过测试,用单片机调的倒立摆非常稳定includestdioh>includemathh>struct_pid{intpv;integert

在avr单片机上完成的100%经过测验,用单片机调的倒竖摆十分安稳.

#include
#include
struct _pid
{
int pv; //integer that contains the process value 进程量
int sp; //*integer that contains the set point 设定值
float integral; // 积分值
float pgain;
float igain;
float dgain;
int deadband; //死区
int last_error;
};
struct _pid warm,*pid;
int process_point, set_point,dead_band;
float p_gain, i_gain, d_gain, integral_val,new_integ;;
void pid_init(struct _pid *warm, int process_point, int set_point)
{
struct _pid *pid;
pid = warm;
pid->pv = process_point;
pid->sp = set_point;
}
void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d_gain, int dead_band)
{
pid->pgain = p_gain;
pid->igain = i_gain;
pid->dgain = d_gain;
pid->deadband = dead_band;
pid->integral= integral_val;
pid->last_error=0;
}
void pid_setinteg(struct _pid *pid,float new_integ)
{
pid->integral = new_integ;
pid->last_error = 0;
}
void pid_bumpless(struct _pid *pid)
{
pid->last_error = (pid->sp)-(pid->pv); //设定值与反应值误差
}
float pid_calc(struct _pid *pid)
int err;
float pterm, dterm, result, ferror;
// 核算误差
err = (pid->sp) – (pid->pv);
// 判别是否大于死区
if (abs(err) > pid->deadband)
{
ferror = (float) err; //do integer to float conversion only once 数据类型转化

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/yingjian/255061.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部