#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct _pid
{
int pv;
int sp;
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;
pterm=pid->pgain*ferror;
if(pterm>100||pterm<-100)
{
pid->integral=0.0;
}
else
{
pid->integral+=pid->igain*ferror;
if(pid->integral>100.0)
{
pid->integral=100.0;
}
else if(pid->integral<0.0)
{
pid->integral=0.0;
}
}
dterm=((float)(err-pid->last_error))*pid->dgain;
result=pterm+pid->integral+dterm;
}
else
{
result=pid->integral;
}
pid->last_error=err;
return (result);
}
int main()
{
float display_value;
int count=0;
pid=&warm;
process_point=30;
set_point=50;
p_gain=(float)(5.2);
i_gain=(float)(0.77);
d_gain=(float)(0.18);
dead_band=2;
integral_val=(float)(0.01);
printf("The values of Process point,Set point, P gain, I gain, D gain\n");
printf("%6d %6d %4f %4f %4f\n",process_point,set_point,p_gain,i_gain,d_gain);
printf("Enter the values of Process point\n");
while(1)
{
scanf("%d",&process_point);
pid_init(&warm,process_point,set_point);
pid_tune(&warm,p_gain,i_gain,d_gain,dead_band);
pid_setinteg(&warm,0.0);
pid_bumpless(&warm);
display_value=pid_calc(&warm);
printf("%f\n",display_value);
printf("%d %d %f %f\n\n",warm.pv,warm.sp,warm.igain,warm.dgain);
count++;
}
}
pid.zip_The P.I_pid
版权申诉
144 浏览量
2022-09-14
23:51:47
上传
评论
收藏 16KB ZIP 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- 129335283047061xiazaigongjuxiang(去重软件).apk
- Android环境检测工具,检测ksu,lsp,magisk等
- WordPress后台美化插件QuarterAdmin分享
- PCB_Project单片机绘制 (2024-5-11 22-22-13).zip
- nccl-local-repo-ubuntu2204-2.21.5-cuda12.4-1.0-1-amd64
- STM32移植LVGL源码工程 stm32移植GUI-Guider源码 LVGL移植源码
- Screenshot_20240522_084328_com.tencent.mm.jpg
- 附件计算机专业课选课说明-1.xlsx
- 基于TypeScript的ahousepet-admin-web管理系统设计源码
- 《广东开放大学学习指引》期末考核要求0522.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈