Structure and function with pointer for PID


hi !

i trying compile code uses structure , function pointer pid controller.
the compiler says ''invalid use of incomplete type 'struct spid' ".
i can not understand why gives error.
the program seems correct.

thanks in advance help.


code: [select]
#include <stdio.h>

  struct {
  double dstate; // last position input
  double istate; // integrator state
  double imax;
  double imin; // maximum , minimum allowable integrator state
  double igain; // integral gain
  double pgain; // proportional gain
  double dgain; // derivative gain
}spid;


void setup(){

  serial.begin(9600);

};

void loop(){

};

double updatepid(struct spid *pid, double error, double position)
{
  double pterm;
  double dterm;
  double iterm;
  pterm = pid->pgain * error;
  // calculate proportional term
  // calculate integral state appropriate limiting
  pid->istate += error;
  if (pid->istate > pid->imax) pid->istate = pid->imax;
  else if (pid->istate < pid->imin) pid->istate = pid->imin;
  iterm = pid->igain * istate; // calculate integral term
  dterm = pid->dgain * (position - pid->dstate);
  pid->dstate = position;
  return pterm + iterm - dterm;
}



just 2 small changes , syntax right:

code: [select]

  struct spid_t {
  double dstate; // last position input
  double istate; // integrator state
  double imax;
  double imin; // maximum , minimum allowable integrator state
  double igain; // integral gain
  double pgain; // proportional gain
  double dgain; // derivative gain
};
...
double updatepid(spid_t *pid, double error, double position)
...


cheers!


Arduino Forum > Using Arduino > Programming Questions > Structure and function with pointer for PID


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support