pybricks / support

Pybricks support and general discussion
MIT License
109 stars 7 forks source link

[Feature] Allow scanning for remote asynchronously. #1800

Open laurensvalk opened 2 months ago

laurensvalk commented 2 months ago

I was wondering if it would be possible to connect asynchronously with the controller at any time while the main program is already running, and let the robot check whether the controller is connected and behave differently when it is (remote-controlled) or not (autonomous).

Originally posted by @DanieleBenedettelli in https://github.com/pybricks/support/discussions/1598

laurensvalk commented 2 months ago

What I think would be helpful is if the XboxController constructor took an auto_connect parameter. So you could create XboxController(auto_connect=False), and then later you could call an (async) connect method. When the controller isn't connected then it should behave as if the joysticks are centered and nothing is pressed.

That way you could write code for menus, for example, that could use either the controller or the hub buttons to control the robot. With just a connection timeout parameter, I think we'd have to create a wrapper class around the controller instead of using it directly.

It seems like an auto_connect parameter and connect method might also work well with the block coding.

Originally posted by @dsplaisted in https://github.com/pybricks/support/discussions/1598#discussioncomment-9166479

laurensvalk commented 2 months ago

This would also be nice to have for the upcoming builtin "port view" or "port control" application discussed in https://github.com/pybricks/support/issues/139

Then we can have it scan for remotes, but also allow you to operate it without a remote.

We can make make this optional, and make it use the current behavior as the default so that it isn't a breaking change.