This commit is contained in:
janik
2026-02-27 17:31:42 +07:00
parent 87bd6ef982
commit eddce0bc68
13 changed files with 15687 additions and 14973 deletions

View File

@@ -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;