diff --git a/CHANGELOG.md b/CHANGELOG.md index fe332e275..a9b1ffe41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,13 @@ ### Changed - Allow single floating point value for brightness array ([support#1547]). +- Raise a descriptive error when the `Car` class can't find a steering mechanism + end stop within 10 seconds ([support#1564]). [support#1024]: https://github.com/pybricks/support/issues/1024 [support#1537]: https://github.com/orgs/pybricks/discussions/1537 [support#1547]: https://github.com/pybricks/support/issues/1547 +[support#1564]: https://github.com/pybricks/support/issues/1564 ## [3.4.0] - 2024-03-11 diff --git a/pybricks/robotics/pb_type_car.c b/pybricks/robotics/pb_type_car.c index a2058f861..aaa247652 100644 --- a/pybricks/robotics/pb_type_car.c +++ b/pybricks/robotics/pb_type_car.c @@ -50,11 +50,16 @@ STATIC int32_t run_until_stalled_blocking(pbio_servo_t *srv, pbio_direction_t di int32_t speed = (direction == PBIO_DIRECTION_CLOCKWISE ? 1 : -1) * 300; pb_assert(pbio_servo_run_until_stalled(srv, speed, torque_limit, PBIO_CONTROL_ON_COMPLETION_COAST)); + uint32_t start_time = mp_hal_ticks_ms(); + // Wait for the movement to complete or be cancelled. while (!pbio_control_is_done(&srv->control)) { if (!pbio_servo_update_loop_is_running(srv)) { pb_assert(PBIO_ERROR_NO_DEV); } + if (mp_hal_ticks_ms() - start_time > 10000) { + mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("The steering mechanism has no end stop. Did you build a car yet?")); + } mp_hal_delay_ms(10); }