Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to custom-code input/controller #128

Closed
joosbuijsNL opened this issue Sep 11, 2020 · 5 comments
Closed

[Question] How to custom-code input/controller #128

joosbuijsNL opened this issue Sep 11, 2020 · 5 comments
Labels
platform: Powered Up Issues related to LEGO Powered Up support Request for technical support for a problem that is not a bug or feature request topic: remote control Issues related to remotly controlling hubs

Comments

@joosbuijsNL
Copy link

Question
I see on the roadmap that Powered Up remote handset support is expected in v4 or later. Is there any way we can custom-build this (or use alpha code) such that we can use this already in the mean time? If desired I could also help a bit in bringing this to pyBricks but would need a bit of a start to get going.

Ideally pyBricks would also support a smartphone as controller, or the different IR remotes that exist.

Context
Using pyBricks actually control and drive cars.

@joosbuijsNL joosbuijsNL added support Request for technical support for a problem that is not a bug or feature request triage Issues that have not been triaged yet labels Sep 11, 2020
@GianCann
Copy link

Is there any way we can custom-build this (or use alpha code) such that we can use this already in the mean time?

At this moment, you can connect to Pybricks using the nRF UART Service and send commands to the hub.
You can read the commands with mycropython input() function.

Nothing else, for now...

@joosbuijsNL
Copy link
Author

Note to self/others: https://github.com/virantha/bricknil/blob/master/bricknil/hub.py might be a good lead to start understanding the Bluetooth communication.

Question to the devs/community which I could not find myself during the weekend: which Python bluetooth library(/ies) are used in the firmware? ubluetooth? This would help me understand how to program something that can run on the hub.

@laurensvalk
Copy link
Member

We don't really have this capability yet, and probably not for a while. At the moment, a device can connect to a hub, but not yet the other way around.

Here's a demo how you can make two hubs communicate with a PC in the middle for now.

Note to self/others: https://github.com/virantha/bricknil/blob/master/bricknil/hub.py might be a good lead to start understanding the Bluetooth communication.

Pybricks does not use this protocol, at least not for now. That protocol is great for remote controlling the hubs from a smart phone / tablet, but in case of Pybricks the code runs on the hub.

Note that you can still nicely make remote-control-like functionality, by just sending small scripts to the hub that do the same thing as the remote control command would do. You can do that with the demo above as well.

We'd like to implement this simple protocol in the long run, so it is easy do do non-blocking communication.

which Python bluetooth library(/ies) are used in the firmware?

There are none. Except for the SPIKE Prime Hub, none of the hubs has enough space for pure Python libraries.

Everything in the firmware is programmed in C, including the pybricks package itself, from which you import motors and sensors.

@joosbuijsNL
Copy link
Author

Hi Laurens,

Again, thanks for the lightning-fast and extensive reply.

This helps me to understand the issues why 'just' adding controllers is not feasible, you're working 100% on-brick, which is limited.

The example you mention helps in understanding how the PC-in-the-middle approach could work, thanks a lot! (The Brick Automation Project seems similar, but then in a GUI style, instead of through Python).

I was trying to understand and implement the low-level Bluetooth protocol, assuming at least something like uBluetooth would be available, this should be feasible. I also came across your C code, which I did not want to get into (Using C and helper functions to build a Python interface looks cumbersome :) ).

I'm looking forward to pyBricks v4 or v5 which hopefully will include controller support, as I feel this is currently lacking (but I fully understand why!).

Keep up the good work!!!

@dlech dlech added topic: remote control Issues related to remotly controlling hubs platform: Powered Up Issues related to LEGO Powered Up and removed triage Issues that have not been triaged yet labels Oct 9, 2020
@laurensvalk
Copy link
Member

This is done now in #186, so we can close his one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Powered Up Issues related to LEGO Powered Up support Request for technical support for a problem that is not a bug or feature request topic: remote control Issues related to remotly controlling hubs
Projects
None yet
Development

No branches or pull requests

4 participants