Skip to content

Commit a4035c1

Browse files
committed
pbio/observer: Work around clamping bug.
See: pybricks/support#863
1 parent 3a0d5e3 commit a4035c1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
- Fixed Essential hub hanging on boot when bootloader entered but USB cable
1414
not connected ([support#821]).
1515
- Fixed button needs debouncing on City/Technic/Essential hubs ([support#716]).
16+
- Fixed motor hold drifting away under external input movement ([support#863]).
1617

1718
[support#716]: https://github.com/pybricks/support/issues/716
1819
[support#821]: https://github.com/pybricks/support/issues/821
1920
[support#849]: https://github.com/pybricks/support/issues/849
21+
[support#863]: https://github.com/pybricks/support/issues/863
2022

2123
## [3.2.0c1] - 2022-12-09
2224

lib/pbio/src/observer.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,16 @@ void pbio_observer_update(pbio_observer_t *obs, uint32_t time, const pbio_angle_
138138
obs->speed_numeric = pbio_differentiator_get_speed(&obs->differentiator, angle);
139139

140140
// Apply observer error feedback as voltage.
141-
int32_t feedback_voltage = pbio_observer_torque_to_voltage(m,
142-
pbio_observer_get_feedback_torque(obs, angle)
143-
);
141+
// int32_t feedback_voltage = pbio_observer_torque_to_voltage(m,
142+
// pbio_observer_get_feedback_torque(obs, angle)
143+
// );
144+
//
145+
// HACK: The following implements the commented code above, but reorders the
146+
// multiplication and division steps to avoid clamping of an
147+
// intermediate result. This should be generalized when we revisit
148+
// the way the observer gain is defined.
149+
// See https://github.com/pybricks/support/issues/863
150+
int32_t feedback_voltage = PRESCALE_TORQUE * obs->model->gain / m->d_voltage_d_torque * pbio_angle_diff_mdeg(angle, &obs->angle) / 1000;
144151

145152
// Check stall condition.
146153
update_stall_state(obs, time, actuation, voltage, feedback_voltage);

0 commit comments

Comments
 (0)