void update_PID_increment(PID *pid, float setpoint, float feedback) {
float error = setpoint - feedback;
float d_error = error - pid->error;
float d_feedback = feedback - pid->prev_error;
float output_increment = pid->Kp * error +
pid->Ki * d_error +
pid->Kd * d_feedback;
pid->error = error;
pid->prev_error = feedback;
return output_increment;
} |