文档详情

C语言实现PID算法.doc

发布:2017-01-01约6.18千字共7页下载文档
文本预览下载声明
C语言实现PID算法 #include stdio.h   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;;            /*------------------------------------------------------------------------   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.   ------------------------------------------------------------------------*/   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;   }         /*------------------------------------------------------------------------   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.   ------------------------------------------------------------------------*/      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;   }      /*------------------------------------------------------------------------   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.   ------------------------------------------------------------------------*/   void pid_setinteg(struct _pid *pid,float new_integ)   {    pid-integral = new_integ;    pid-last_error = 0;   }      /*---------------------------
显示全部
相似文档