Skip to content

Commit 7223631

Browse files
committed
pbio/control: Avoid chatter in integration state while stopped.
This fixes the pause state frequently resetting because of negligible speed changes.
1 parent 55de591 commit 7223631

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/pbio/src/control.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ void pbio_control_update(pbio_control_t *ctl, uint32_t time_now, pbio_control_st
130130
int32_t windup_margin = pbio_control_settings_mul_by_loop_time(pbio_int_math_abs(state->speed)) * 2;
131131
int32_t max_windup_torque = ctl->settings.actuation_max + pbio_control_settings_mul_by_gain(windup_margin, ctl->settings.pid_kp);
132132

133+
// Speed value that is rounded to zero if small. This is used for a
134+
// direction error check below to avoid false reverses near zero.
135+
int32_t speed_for_direction_check = pbio_int_math_abs(state->speed) < ctl->settings.stall_speed_limit ? 0 : state->speed;
136+
133137
// Position anti-windup: pause trajectory or integration if falling behind despite using maximum torque
134138
bool pause_integration =
135139
// Pause if proportional torque is beyond maximum windup torque:
136140
pbio_int_math_abs(torque_proportional) >= max_windup_torque &&
137141
// But not if we're trying to run in the other direction (else we can get unstuck by just reversing).
138-
pbio_int_math_sign(torque_proportional) != -pbio_int_math_sign(ref->speed - state->speed) &&
142+
pbio_int_math_sign(torque_proportional) != -pbio_int_math_sign(ref->speed - speed_for_direction_check) &&
139143
// But not if we should be accelerating in the other direction (else we can get unstuck by just reversing).
140144
pbio_int_math_sign(torque_proportional) != -pbio_int_math_sign(ref->acceleration);
141145

0 commit comments

Comments
 (0)