Skip to content

Commit 9d1327c

Browse files
committed
pybricks.robotics.GyroDriveBase: Toggle gyro use.
Completes pybricks/support#1054
1 parent 7aa8415 commit 9d1327c

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44

55
## [Unreleased]
66

7+
### Added
8+
- Added `use_gyro` method to toggle gyro use on and off in the `GyroDriveBase`
9+
class ([support#1054]).
10+
is a tuple of `(name, num_values, data_type)` tuples for each available mode.
11+
- Added `pybricks.tools.read_input_byte()` function ([support#1102]).
12+
713
### Fixed
814
- Fixed Technic (Extra) Large motors not working ([support#1131]) on all hubs.
915
- Fixed Powered Up Light not working ([support#1131]) on all hubs.
1016
- Fixed UART sensors not working on Technic Hub ([support#1137]).
1117
- Fixed incorrect number of ports on City Hub ([support#1131]).
1218

19+
[support#1054]: https://github.com/pybricks/support/issues/1054
1320
[support#1131]: https://github.com/pybricks/support/issues/1131
1421
[support#1137]: https://github.com/pybricks/support/issues/1137
1522

pybricks/robotics/pb_type_drivebase.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ STATIC mp_obj_t pb_type_DriveBase_settings(size_t n_args, const mp_obj_t *pos_ar
331331
}
332332
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pb_type_DriveBase_settings_obj, 1, pb_type_DriveBase_settings);
333333

334+
#if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO
335+
// pybricks.robotics.DriveBase.use_gyro
336+
STATIC mp_obj_t pb_type_DriveBase_use_gyro(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
337+
PB_PARSE_ARGS_METHOD(n_args, pos_args, kw_args,
338+
pb_type_DriveBase_obj_t, self,
339+
PB_ARG_REQUIRED(use_gyro));
340+
pb_assert(pbio_drivebase_set_use_gyro(self->db, mp_obj_is_true(use_gyro_in)));
341+
return mp_const_none;
342+
}
343+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pb_type_DriveBase_use_gyro_obj, 1, pb_type_DriveBase_use_gyro);
344+
#endif
345+
334346
#if PYBRICKS_PY_COMMON_CONTROL
335347
STATIC const pb_attr_dict_entry_t pb_type_DriveBase_attr_dict[] = {
336348
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_heading_control, pb_type_DriveBase_obj_t, heading_control),
@@ -353,8 +365,12 @@ STATIC const mp_rom_map_elem_t pb_type_DriveBase_locals_dict_table[] = {
353365
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&pb_type_DriveBase_reset_obj) },
354366
{ MP_ROM_QSTR(MP_QSTR_settings), MP_ROM_PTR(&pb_type_DriveBase_settings_obj) },
355367
{ MP_ROM_QSTR(MP_QSTR_stalled), MP_ROM_PTR(&pb_type_DriveBase_stalled_obj) },
368+
#if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO
369+
{ MP_ROM_QSTR(MP_QSTR_use_gyro), MP_ROM_PTR(&pb_type_DriveBase_use_gyro_obj) },
370+
#endif
356371
};
357-
STATIC MP_DEFINE_CONST_DICT(pb_type_DriveBase_locals_dict, pb_type_DriveBase_locals_dict_table);
372+
// First N entries are common to both drive base classes.
373+
STATIC MP_DEFINE_CONST_DICT_WITH_SIZE(pb_type_DriveBase_locals_dict, pb_type_DriveBase_locals_dict_table, 12);
358374

359375
// type(pybricks.robotics.DriveBase)
360376
MP_DEFINE_CONST_OBJ_TYPE(pb_type_drivebase,
@@ -368,6 +384,10 @@ MP_DEFINE_CONST_OBJ_TYPE(pb_type_drivebase,
368384
locals_dict, &pb_type_DriveBase_locals_dict);
369385

370386
#if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO
387+
388+
// GyroDriveBase has all methods enabled.
389+
STATIC MP_DEFINE_CONST_DICT(pb_type_GyroDriveBase_locals_dict, pb_type_DriveBase_locals_dict_table);
390+
371391
// type(pybricks.robotics.GyroDriveBase)
372392
MP_DEFINE_CONST_OBJ_TYPE(pb_type_gyrodrivebase,
373393
MP_QSTR_GyroDriveBase,
@@ -377,7 +397,7 @@ MP_DEFINE_CONST_OBJ_TYPE(pb_type_gyrodrivebase,
377397
attr, pb_attribute_handler,
378398
protocol, pb_type_DriveBase_attr_dict,
379399
#endif
380-
locals_dict, &pb_type_DriveBase_locals_dict);
400+
locals_dict, &pb_type_GyroDriveBase_locals_dict);
381401
#endif // PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO
382402

383403
#endif // PYBRICKS_PY_ROBOTICS && PYBRICKS_PY_COMMON_MOTORS

0 commit comments

Comments
 (0)