Skip to content

Commit

Permalink
pybricks.robotics.DriveBase: Add brake().
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Oct 26, 2023
1 parent cf73380 commit a3bbc90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Added
- Added `hub.buttons` as an alias for `hub.button` on buttons with one
hub ([support#1254]).
- Implemented `brake` for `DriveBase` ([support#881]).

### Changed
- The `use_gyro` method is added to the normal `DriveBase` class instead of
Expand All @@ -27,6 +28,7 @@
tight loop ([support#1151]).

[pybricks-micropython#104]: https://github.com/pybricks/pybricks-micropython/pull/104
[support#881]: https://github.com/pybricks/support/issues/881
[support#1054]: https://github.com/pybricks/support/issues/1054
[support#1140]: https://github.com/pybricks/support/issues/1140
[support#1151]: https://github.com/pybricks/support/issues/1151
Expand Down
15 changes: 15 additions & 0 deletions pybricks/robotics/pb_type_drivebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ STATIC mp_obj_t pb_type_DriveBase_stop(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(pb_type_DriveBase_stop_obj, pb_type_DriveBase_stop);

// pybricks.robotics.DriveBase.brake
STATIC mp_obj_t pb_type_DriveBase_brake(mp_obj_t self_in) {

// Cancel awaitables.
pb_type_DriveBase_obj_t *self = MP_OBJ_TO_PTR(self_in);
pb_type_awaitable_update_all(self->awaitables, PB_TYPE_AWAITABLE_OPT_CANCEL_ALL);

// Stop hardware.
pb_assert(pbio_drivebase_stop(self->db, PBIO_CONTROL_ON_COMPLETION_BRAKE));

return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(pb_type_DriveBase_brake_obj, pb_type_DriveBase_brake);

// pybricks.robotics.DriveBase.distance
STATIC mp_obj_t pb_type_DriveBase_distance(mp_obj_t self_in) {
pb_type_DriveBase_obj_t *self = MP_OBJ_TO_PTR(self_in);
Expand Down Expand Up @@ -355,6 +369,7 @@ STATIC const mp_rom_map_elem_t pb_type_DriveBase_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_turn), MP_ROM_PTR(&pb_type_DriveBase_turn_obj) },
{ MP_ROM_QSTR(MP_QSTR_drive), MP_ROM_PTR(&pb_type_DriveBase_drive_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&pb_type_DriveBase_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_brake), MP_ROM_PTR(&pb_type_DriveBase_brake_obj) },
{ MP_ROM_QSTR(MP_QSTR_distance), MP_ROM_PTR(&pb_type_DriveBase_distance_obj) },
{ MP_ROM_QSTR(MP_QSTR_angle), MP_ROM_PTR(&pb_type_DriveBase_angle_obj) },
{ MP_ROM_QSTR(MP_QSTR_done), MP_ROM_PTR(&pb_type_DriveBase_done_obj) },
Expand Down

0 comments on commit a3bbc90

Please sign in to comment.