From 3ae1fb893727bf4ab0a4a30b08658920747ebebc Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Thu, 13 Jul 2023 14:09:52 +0200 Subject: [PATCH] pybricks.robotics: Move use_gyro to normal DriveBase. Since we added the use_gyro() method to turn the gyro on and off, we no longer need a separate GyroDriveBase class. --- CHANGELOG.md | 14 ++++++++++++-- lib/pbio/src/drivebase.c | 2 +- pybricks/robotics.h | 4 ---- pybricks/robotics/pb_module_robotics.c | 3 --- pybricks/robotics/pb_type_drivebase.c | 24 ++---------------------- 5 files changed, 15 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f0af950..56c0d59c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ ## [Unreleased] +### Changed +- The `use_gyro` method is added to the normal `DriveBase` class instead of + having a separate `GyroDriveBase` class. Since the latter was only released + in beta versions, this is not a breaking change ([support#1054]). + +### Fixed +- Improved external device detection speed ([support#1140]). + +[support#1054]: https://github.com/pybricks/support/issues/1054 +[support#1140]: https://github.com/pybricks/support/issues/1140 + ## [3.3.0b8] - 2023-07-07 ### Added @@ -20,13 +31,12 @@ - Fixed Powered Up Light not working ([support#1131]) on all hubs. - Fixed UART sensors not working on Technic Hub ([support#1137]). - Fixed incorrect number of ports on City Hub ([support#1131]). -- Improved external device detection speed ([support#1140]). [support#1054]: https://github.com/pybricks/support/issues/1054 [support#1105]: https://github.com/pybricks/support/issues/1105 [support#1131]: https://github.com/pybricks/support/issues/1131 [support#1137]: https://github.com/pybricks/support/issues/1137 -[support#1140]: https://github.com/pybricks/support/issues/1140 + ## [3.3.0b7] - 2023-06-30 diff --git a/lib/pbio/src/drivebase.c b/lib/pbio/src/drivebase.c index ad5f50d34..eae755276 100644 --- a/lib/pbio/src/drivebase.c +++ b/lib/pbio/src/drivebase.c @@ -287,7 +287,7 @@ pbio_error_t pbio_drivebase_get_drivebase(pbio_drivebase_t **db_address, pbio_se db->right = right; // By default, don't use gyro. - db->use_gyro = false; + pbio_drivebase_set_use_gyro(db, false); // Set parents of both servos, so they can stop this drivebase. pbio_parent_set(&left->parent, db, pbio_drivebase_stop_from_servo); diff --git a/pybricks/robotics.h b/pybricks/robotics.h index 6cfa4242f..4e7f38ab2 100644 --- a/pybricks/robotics.h +++ b/pybricks/robotics.h @@ -16,10 +16,6 @@ extern const mp_obj_type_t pb_type_drivebase; -#if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO -extern const mp_obj_type_t pb_type_gyrodrivebase; -#endif - #if PYBRICKS_PY_ROBOTICS_DRIVEBASE_SPIKE extern const mp_obj_type_t pb_type_spikebase; #endif diff --git a/pybricks/robotics/pb_module_robotics.c b/pybricks/robotics/pb_module_robotics.c index 972307c28..83a730e31 100644 --- a/pybricks/robotics/pb_module_robotics.c +++ b/pybricks/robotics/pb_module_robotics.c @@ -11,9 +11,6 @@ STATIC const mp_rom_map_elem_t robotics_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_robotics) }, #if PYBRICKS_PY_COMMON_MOTORS { MP_ROM_QSTR(MP_QSTR_DriveBase), MP_ROM_PTR(&pb_type_drivebase) }, - #if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO - { MP_ROM_QSTR(MP_QSTR_GyroDriveBase), MP_ROM_PTR(&pb_type_gyrodrivebase) }, - #endif #if PYBRICKS_PY_ROBOTICS_DRIVEBASE_SPIKE { MP_ROM_QSTR(MP_QSTR_SpikeBase), MP_ROM_PTR(&pb_type_spikebase) }, #endif diff --git a/pybricks/robotics/pb_type_drivebase.c b/pybricks/robotics/pb_type_drivebase.c index 4989a1516..0f154e559 100644 --- a/pybricks/robotics/pb_type_drivebase.c +++ b/pybricks/robotics/pb_type_drivebase.c @@ -67,16 +67,13 @@ STATIC mp_obj_t pb_type_DriveBase_make_new(const mp_obj_type_t *type, size_t n_a pbio_servo_t *srv_left = ((pb_type_Motor_obj_t *)pb_obj_get_base_class_obj(left_motor_in, &pb_type_Motor))->srv; pbio_servo_t *srv_right = ((pb_type_Motor_obj_t *)pb_obj_get_base_class_obj(right_motor_in, &pb_type_Motor))->srv; - // Create drivebase + // Create drivebase. Initialized to use motor encoders (not gyro) for heading. pb_assert(pbio_drivebase_get_drivebase(&self->db, srv_left, srv_right, pb_obj_get_scaled_int(wheel_diameter_in, 1000), pb_obj_get_scaled_int(axle_track_in, 1000))); - // Use gyro if creating instance of GyroDriveBase. - pb_assert(pbio_drivebase_set_use_gyro(self->db, type != &pb_type_drivebase)); - #if PYBRICKS_PY_COMMON_CONTROL // Create instances of the Control class self->heading_control = pb_type_Control_obj_make_new(&self->db->control_heading); @@ -370,7 +367,7 @@ STATIC const mp_rom_map_elem_t pb_type_DriveBase_locals_dict_table[] = { #endif }; // First N entries are common to both drive base classes. -STATIC MP_DEFINE_CONST_DICT_WITH_SIZE(pb_type_DriveBase_locals_dict, pb_type_DriveBase_locals_dict_table, 12); +STATIC MP_DEFINE_CONST_DICT(pb_type_DriveBase_locals_dict, pb_type_DriveBase_locals_dict_table); // type(pybricks.robotics.DriveBase) MP_DEFINE_CONST_OBJ_TYPE(pb_type_drivebase, @@ -383,21 +380,4 @@ MP_DEFINE_CONST_OBJ_TYPE(pb_type_drivebase, #endif locals_dict, &pb_type_DriveBase_locals_dict); -#if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO - -// GyroDriveBase has all methods enabled. -STATIC MP_DEFINE_CONST_DICT(pb_type_GyroDriveBase_locals_dict, pb_type_DriveBase_locals_dict_table); - -// type(pybricks.robotics.GyroDriveBase) -MP_DEFINE_CONST_OBJ_TYPE(pb_type_gyrodrivebase, - MP_QSTR_GyroDriveBase, - MP_TYPE_FLAG_NONE, - make_new, pb_type_DriveBase_make_new, - #if PYBRICKS_PY_COMMON_CONTROL - attr, pb_attribute_handler, - protocol, pb_type_DriveBase_attr_dict, - #endif - locals_dict, &pb_type_GyroDriveBase_locals_dict); -#endif // PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO - #endif // PYBRICKS_PY_ROBOTICS && PYBRICKS_PY_COMMON_MOTORS