Skip to content

Commit

Permalink
pbio/drivebase: Don't stop on calling use_gyro with same argument.
Browse files Browse the repository at this point in the history
If this is called again while already set, this is now a no-op, instead of stopping the controls as it needs to do when toggling.

Fixes pybricks/support#1858

Also add note about gyro speed control to reflect 26b8e62
  • Loading branch information
laurensvalk committed Oct 1, 2024
1 parent 759ffa2 commit b73e164
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
### Fixed
- Fixed persistent data not being deleted when swapping
from `3.6.0b1` to `3.5.0` and back to `3.6.0b1` ([support#1846]).
- Fixed controls stopping if `use_gyro` is called again with the same
argument as already active ([support#1858]).

[support#1846]: https://github.com/pybricks/support/issues/1846
[support#1858]: https://github.com/pybricks/support/issues/1858

## [3.6.0b1] - 2024-09-24

Expand Down
14 changes: 12 additions & 2 deletions lib/pbio/src/drivebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ static pbio_error_t pbio_drivebase_get_state_control(pbio_drivebase_t *db, pbio_

// Optionally use gyro to override the heading source for more accuracy.
// The gyro manages its own offset, so we don't need to subtract it here.
// Note that the heading speed estimate (used for derivative control still
// uses the motor estimate rather than the gyro speed, to guarantee the
// same stability properties to stabilize the motors.)
if (db->use_gyro) {
pbio_imu_get_heading_scaled(&state_heading->position, &state_heading->speed, db->control_heading.settings.ctl_steps_per_app_step);
}
Expand Down Expand Up @@ -361,8 +364,10 @@ pbio_error_t pbio_drivebase_get_drivebase(pbio_drivebase_t **db_address, pbio_se
// geometry, so it is done after the scaling is set.
pbio_drivebase_reset(db, 0, 0);

// Finish setup. By default, don't use gyro.
return pbio_drivebase_set_use_gyro(db, false);
// By default, don't use gyro for steering control.
db->use_gyro = false;

return PBIO_SUCCESS;
}

/**
Expand All @@ -376,6 +381,11 @@ pbio_error_t pbio_drivebase_get_drivebase(pbio_drivebase_t **db_address, pbio_se
*/
pbio_error_t pbio_drivebase_set_use_gyro(pbio_drivebase_t *db, bool use_gyro) {

// No need to reset controls if already in correct mode.
if (db->use_gyro == use_gyro) {
return PBIO_SUCCESS;
}

// We stop so that new commands will reinitialize the state using the
// newly selected input for heading control.
pbio_error_t err = pbio_drivebase_stop(db, PBIO_CONTROL_ON_COMPLETION_COAST);
Expand Down

0 comments on commit b73e164

Please sign in to comment.