Skip to content

Commit

Permalink
pybricks.robotics.Car: Raise error on no car built.
Browse files Browse the repository at this point in the history
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 pybricks/support#1564
  • Loading branch information
laurensvalk committed Mar 29, 2024
1 parent a17576b commit 46f29c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions pybricks/robotics/pb_type_car.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 46f29c0

Please sign in to comment.