|
15 | 15 |
|
16 | 16 | #include <pybricks/common.h> |
17 | 17 | #include <pybricks/parameters.h> |
| 18 | +#include <pybricks/robotics.h> |
18 | 19 |
|
19 | 20 | #include <pybricks/util_mp/pb_kwarg_helper.h> |
20 | 21 | #include <pybricks/util_mp/pb_obj_helper.h> |
@@ -53,36 +54,22 @@ STATIC mp_obj_t pb_type_DriveBase_make_new(const mp_obj_type_t *type, size_t n_a |
53 | 54 | PB_ARG_REQUIRED(left_motor), |
54 | 55 | PB_ARG_REQUIRED(right_motor), |
55 | 56 | PB_ARG_REQUIRED(wheel_diameter), |
56 | | - PB_ARG_REQUIRED(axle_track), |
57 | | - PB_ARG_DEFAULT_OBJ(positive_direction, pb_Direction_CLOCKWISE_obj), |
58 | | - PB_ARG_DEFAULT_FALSE(use_gyro)); |
| 57 | + PB_ARG_REQUIRED(axle_track)); |
59 | 58 |
|
60 | 59 | pb_type_DriveBase_obj_t *self = mp_obj_malloc(pb_type_DriveBase_obj_t, type); |
61 | 60 |
|
62 | | - // REVISIT: Allow angle getter callable on any platform. |
63 | | - bool use_gyro = mp_obj_is_true(use_gyro_in); |
64 | | - #if !PBIO_CONFIG_IMU |
65 | | - if (use_gyro) { |
66 | | - pb_assert(PBIO_ERROR_NOT_SUPPORTED); |
67 | | - } |
68 | | - #endif |
69 | | - pbio_direction_t positive_direction = pb_type_enum_get_value(positive_direction_in, &pb_enum_type_Direction); |
70 | | - // REVISIT: Gyro is currently only compatible with counterclockwise drivebase. |
71 | | - if (use_gyro && positive_direction != PBIO_DIRECTION_COUNTERCLOCKWISE) { |
72 | | - pb_assert(PBIO_ERROR_INVALID_ARG); |
73 | | - } |
74 | | - |
75 | 61 | // Pointers to servos |
76 | 62 | pbio_servo_t *srv_left = ((common_Motor_obj_t *)pb_obj_get_base_class_obj(left_motor_in, &pb_type_Motor))->srv; |
77 | 63 | pbio_servo_t *srv_right = ((common_Motor_obj_t *)pb_obj_get_base_class_obj(right_motor_in, &pb_type_Motor))->srv; |
78 | 64 |
|
79 | 65 | // Create drivebase |
80 | 66 | pb_assert(pbio_drivebase_get_drivebase(&self->db, |
81 | | - positive_direction == PBIO_DIRECTION_CLOCKWISE ? srv_left : srv_right, |
82 | | - positive_direction == PBIO_DIRECTION_CLOCKWISE ? srv_right : srv_left, |
| 67 | + srv_left, |
| 68 | + srv_right, |
83 | 69 | pb_obj_get_scaled_int(wheel_diameter_in, 1000), |
84 | 70 | pb_obj_get_scaled_int(axle_track_in, 1000), |
85 | | - use_gyro)); |
| 71 | + // Use gyro if creating instance of GyroDriveBase. |
| 72 | + type != &pb_type_drivebase)); |
86 | 73 |
|
87 | 74 | #if PYBRICKS_PY_COMMON_CONTROL |
88 | 75 | // Create instances of the Control class |
@@ -339,4 +326,18 @@ const mp_obj_type_t pb_type_drivebase = { |
339 | 326 | .locals_dict = (mp_obj_dict_t *)&pb_type_DriveBase_locals_dict, |
340 | 327 | }; |
341 | 328 |
|
| 329 | +#if PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO |
| 330 | +// type(pybricks.robotics.GyroDriveBase) |
| 331 | +const mp_obj_type_t pb_type_gyrodrivebase = { |
| 332 | + { &mp_type_type }, |
| 333 | + .name = MP_QSTR_GyroDriveBase, |
| 334 | + .make_new = pb_type_DriveBase_make_new, |
| 335 | + #if PYBRICKS_PY_COMMON_CONTROL |
| 336 | + .attr = pb_attribute_handler, |
| 337 | + .protocol = pb_type_DriveBase_attr_dict, |
| 338 | + #endif |
| 339 | + .locals_dict = (mp_obj_dict_t *)&pb_type_DriveBase_locals_dict, |
| 340 | +}; |
| 341 | +#endif // PYBRICKS_PY_ROBOTICS_DRIVEBASE_GYRO |
| 342 | + |
342 | 343 | #endif // PYBRICKS_PY_ROBOTICS && PYBRICKS_PY_COMMON_MOTORS |
0 commit comments