bugfixes
This commit is contained in:
@@ -80,9 +80,18 @@ static inline pid_motor_cmd_t pid_update_motor(pid_i32_t *pid,
|
||||
{
|
||||
pid_motor_cmd_t cmd;
|
||||
|
||||
// Basic PID (no overflow protection, as requested)
|
||||
int32_t error = setpoint - position;
|
||||
|
||||
// Deadband: if within ±3 counts, hold position and reset integrator
|
||||
if (error >= -3 && error <= 3) {
|
||||
pid->integrator = 0;
|
||||
pid->prev_error = 0;
|
||||
pid->last_output = 0;
|
||||
cmd.pwm = 0;
|
||||
cmd.dir = 1;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
int32_t p = pid->kp * error;
|
||||
|
||||
int32_t i = pid->integrator + pid->ki * error;
|
||||
|
||||
Reference in New Issue
Block a user