#include <stdio.h>
#include<math.h>
//定义PID的结构体
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;
};
//------------------------
----------------------
pid_init DESCRIPTION This function initializes the
pointers in the _pid structure to the
process variable
and the
setpoint
.
*pv and *sp are integer pointers
.
//------------------------
----------------------
//------------------------
----------------------
========================================第3页========================================
pid_tune DESCRIPTION Sets the proportional gain
(p_gain), integral gain (i_gain),
derivitive gain (d_gain), and the dead band (dead_band)
of a pid control structure _pid.
//------------------------
----------------------
========================================第4页========================================
pid_setinteg DESCRIPTION Set a new value for the
integral term of the pid equation.
This is useful for setting the initial output of the
pid controller at start up.
//------------------------
----------------------
pid_bumpless DESCRIPTION Bumpless transfer
algorithim.
When suddenly changing setpoints, or when restarting
the PID equation after an extended pause,
the derivative of the equation can cause a bump in the
========================================第5页========================================
controller output. This function will help smooth out
that bump.
The process value in *pv should be the updated just
before this function is used.
//------------------------
----------------------
pid_calc DESCRIPTION
Performs PID calculations
for the
_pid structure *a.
========================================第6页========================================
This function uses the positional form of the pid
equation, and incorporates an integral windup
prevention algorithim.
Rectangular integration is used, so this function must
be repeated on a consistent time basis for accurate
control.
RETURN VALUE The new output value for the pid loop.
USAGE #include "control.h"
// printf("Enter the values of Process point, Set
point, P gain, I gain, D gain \n");
// scanf("%d%d%f%f%f", &process_point, &set_point,
&p_gain, &i_gain, &d_gain);
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(count<=20)
{
scanf("%d",&process_point);