From 46f29c09430c1e2fef4b47a1c830910082256404 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 29 Mar 2024 13:57:41 +0100 Subject: [PATCH] pybricks.robotics.Car: Raise error on no car built. We get quite a few questions about the Xbox controller not connecting, when the actual issue is the car initialization never completing because no car has been built yet. To be more explicit, raise an error if the endpoint is not found within 10 seconds. Fixes https://github.com/pybricks/support/issues/1564 --- CHANGELOG.md | 3 +++ pybricks/robotics/pb_type_car.c | 5 +++++ 2 files changed, 8 insertions(+) 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); }