Skip to content

Commit 08bf5b4

Browse files
committed
pybricks.robotics.DriveBase: Add hold() method.
This is more intuitive than calling straight(0), and it never needs to be awaited.
1 parent 18807f2 commit 08bf5b4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Added
88
- Added `pybricks.pupdevices.MarioHub` to control it as a peripheral. It
99
cannot be used as a standalone device since it cannot ne updated.
10+
- Added `DriveBase.hold()` method ([support#2621]).
1011

1112
### Changed
1213
- The EV3 Color Sensor now returns `Color.NONE` instead of `None` when no color

pybricks/robotics/pb_type_drivebase.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ static mp_obj_t pb_type_DriveBase_brake(mp_obj_t self_in) {
325325
}
326326
MP_DEFINE_CONST_FUN_OBJ_1(pb_type_DriveBase_brake_obj, pb_type_DriveBase_brake);
327327

328+
// pybricks.robotics.DriveBase.hold
329+
static mp_obj_t pb_type_DriveBase_hold(mp_obj_t self_in) {
330+
331+
// Cancel awaitables.
332+
pb_type_DriveBase_obj_t *self = MP_OBJ_TO_PTR(self_in);
333+
pb_type_async_schedule_stop_iteration(self->last_awaitable);
334+
335+
// Stop hardware.
336+
pb_assert(pbio_drivebase_stop(self->db, PBIO_CONTROL_ON_COMPLETION_HOLD));
337+
338+
return mp_const_none;
339+
}
340+
MP_DEFINE_CONST_FUN_OBJ_1(pb_type_DriveBase_hold_obj, pb_type_DriveBase_hold);
341+
328342
// pybricks.robotics.DriveBase.distance
329343
static mp_obj_t pb_type_DriveBase_distance(mp_obj_t self_in) {
330344
pb_type_DriveBase_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -467,6 +481,7 @@ static const mp_rom_map_elem_t pb_type_DriveBase_locals_dict_table[] = {
467481
{ MP_ROM_QSTR(MP_QSTR_drive), MP_ROM_PTR(&pb_type_DriveBase_drive_obj) },
468482
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&pb_type_DriveBase_stop_obj) },
469483
{ MP_ROM_QSTR(MP_QSTR_brake), MP_ROM_PTR(&pb_type_DriveBase_brake_obj) },
484+
{ MP_ROM_QSTR(MP_QSTR_hold), MP_ROM_PTR(&pb_type_DriveBase_hold_obj) },
470485
{ MP_ROM_QSTR(MP_QSTR_distance), MP_ROM_PTR(&pb_type_DriveBase_distance_obj) },
471486
{ MP_ROM_QSTR(MP_QSTR_angle), MP_ROM_PTR(&pb_type_DriveBase_angle_obj) },
472487
{ MP_ROM_QSTR(MP_QSTR_done), MP_ROM_PTR(&pb_type_DriveBase_done_obj) },

0 commit comments

Comments
 (0)