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.
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:
cheers!
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
Post a Comment