Skip to content

Commit 4a6c3fa

Browse files
committed
pbio/drivebase: Fix order of passive actuation.
If passive actuation is required at the end of a maneuver (brake or coast), this stops control automatically. Changing integration states at that point is not a valid operation, so we need to put this after the return on passive actuation. This fixes coast and brake not working on drivebases.
1 parent 599d323 commit 4a6c3fa

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Fixed
1212
- Fixed direction for `DriveBase.turn()` and `Drivebase.curve()` for some
1313
arguments ([support#535]).
14+
- Fixed `then=Stop.COAST` not working in `DriveBase` methods ([support#535]).
1415

1516
[support#535]: https://github.com/pybricks/support/issues/535
1617
[support#536]: https://github.com/pybricks/support/issues/536

lib/pbio/src/drivebase.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ pbio_error_t pbio_drivebase_update(pbio_drivebase_t *db) {
239239
pbio_control_update(&db->control_distance, time_now, &state_distance, &ref_distance, &sum_actuation, &sum_torque);
240240
pbio_control_update(&db->control_heading, time_now, &state_heading, &ref_heading, &dif_actuation, &dif_torque);
241241

242+
// If either controller coasts, coast both, thereby also stopping control.
243+
if (sum_actuation == PBIO_ACTUATION_COAST || dif_actuation == PBIO_ACTUATION_COAST) {
244+
return pbio_drivebase_actuate(db, PBIO_ACTUATION_COAST, 0, 0);
245+
}
246+
// If either controller brakes, brake both, thereby also stopping control.
247+
if (sum_actuation == PBIO_ACTUATION_BRAKE || dif_actuation == PBIO_ACTUATION_BRAKE) {
248+
return pbio_drivebase_actuate(db, PBIO_ACTUATION_BRAKE, 0, 0);
249+
}
250+
242251
// The leading controller is able to pause when it stalls. The following controller does not do its own stall,
243252
// but follows the leader. This ensures they complete at exactly the same time.
244253

@@ -254,15 +263,6 @@ pbio_error_t pbio_drivebase_update(pbio_drivebase_t *db) {
254263
return err;
255264
}
256265

257-
// If either controller coasts, coast both
258-
if (sum_actuation == PBIO_ACTUATION_COAST || dif_actuation == PBIO_ACTUATION_COAST) {
259-
return pbio_drivebase_actuate(db, PBIO_ACTUATION_COAST, 0, 0);
260-
}
261-
// If either controller brakes, brake both
262-
if (sum_actuation == PBIO_ACTUATION_BRAKE || dif_actuation == PBIO_ACTUATION_BRAKE) {
263-
return pbio_drivebase_actuate(db, PBIO_ACTUATION_BRAKE, 0, 0);
264-
}
265-
266266
// The left servo drives at a torque and speed of sum / 2 + dif / 2
267267
int32_t feed_forward_left = pbio_observer_get_feedforward_torque(&db->left->observer, ref_distance.rate / 2 + ref_heading.rate / 2, ref_distance.acceleration / 2 + ref_heading.acceleration / 2);
268268
err = pbio_servo_actuate(db->left, sum_actuation, sum_torque / 2 + dif_torque / 2 + feed_forward_left);

0 commit comments

Comments
 (0)