Skip to content

Commit

Permalink
pybricks.robotics: Move use_gyro to normal DriveBase.
Browse files Browse the repository at this point in the history
Since we added the use_gyro() method to turn the gyro on and off, we no
longer need a separate GyroDriveBase class.
  • Loading branch information
laurensvalk committed Jul 13, 2023
1 parent ef4cd2c commit 3ae1fb8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/src/drivebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions pybricks/robotics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions pybricks/robotics/pb_module_robotics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 2 additions & 22 deletions pybricks/robotics/pb_type_drivebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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

0 comments on commit 3ae1fb8

Please sign in to comment.