@@ -331,6 +331,18 @@ STATIC mp_obj_t pb_type_DriveBase_settings(size_t n_args, const mp_obj_t *pos_ar
331331}
332332STATIC 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
335347STATIC 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)
360376MP_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)
372392MP_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