hi tom thanks. oh no i posted reply but the post was lost.
i read your pid.c but there was no update of the d-state.
yup! i made a mistake, it should be /dt instead of *dt.
what's wrong with remembering previous error as a global variable, then finding d(error) =previous_error-error_roll?
is it possible to balance the see saw using only P gain?
no matter what P gain i tried, it just oscillate about and will never stop at 0degree.
shouldn't we limit the maximum pwm and minimum pwm to climb?
Tom wrote:Hey Pizza,
You code is not correct. Please take a look at the gluon pid.c code
- Code: Select all
float PIDroll(float Kp, float Ki, float Kd)
{
float previous_error;
previous_error = error_roll; // WRONG
//setpoint @ 0 degree to balance seesaw
error_roll = 0 - kalman_roll;
derivative_roll = (error_roll-previous_error)*dt; // dt=0.01; 100Hz WRONG derivative = dE/dt, thus / dt
return (Kp*error_roll)-(Kd*derivative_roll); // WRONG multiply with dt
}