-
Notifications
You must be signed in to change notification settings - Fork 121
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
[Discussion] async version #63
Comments
I am myself ok with async concept, since I am an experienced developer. But I believe most of the library audience is not that advanced, and blocking style is easier to learn and use for non-sophisticated users. If you'll look into library's internals, you'll see that it's multi-threaded and supports parallel operations, just it does that with classic threads (or sensor subscriptions). Also, there are non-blocking modes in Boost protocol itself, which library might not fully support at the moment. Finally, there is already an async-style lib for this: https://github.com/virantha/bricknil . I don't see a point in duplicating it. I'd rather keep alternative approach for that part of community that prefers it. Just for the sake of offering a choice. What would really help current project, is an implementation of bleak-based connection driver. There are already couple of PRs on that, but nothing that fully works. |
Thanks for detailing your considerations, makes perfect sense now. I didn't know about bricknil, will check that out! Perhaps a pointer to bricknil would be nice, as your library ranks much higher when searching for "Lego Boost Python". |
I tried bricknil and found it to be flakey and hard to use. The synchronous design suits me better. However it would be nice to be able to command a motor to make a new move before the current move has finished, with the new move replacing the current move. For example you tell a car to steer right, and then realise it should have been left. As it stands I can't "replace" the steer right command until the motor has finsihed moving. Maybe this already supported somehow, I will look into the |
I am also trying to make it work with bleak since bleak is the only library mentioned which works on MacOS according to the main README. Unfortunately the latest version of bleak doesn't work with pylgbst. It seems like there have been some API changes since bleak was introduced to this library, since there are some async function which are called without await (thus resulting in the functions not being called). Some async methods are called in constructors, so they require rather large changes to the program flow (factory pattern, or calling "follow up methods upon creation", etc.) Which PR seems most promising? PS. bricknil currently doesn't work with bleak either. This is most likely also due to changes in bleak 0.6.4. It gives me the "Unknown device with id 66 being attached..." issue, which is currently unresolved. |
I have tested Bleak connection type on my Linux and it did work fine for |
That's alright. Perhaps I can help here, since I have access to a MacOS device. The current versions are: pylgbst 1.2.0 And this is the trace when running demo.py from a fresh clone (python3 examples/demo.py): INFO:root:Trying get_connection_bluepy From the bleak project it seems like "Bluetooth device is turned off" is a known issue: hbldh/bleak#206 |
I have made an alternative implementation in #70 . But that does not help too much. It looks like bleak is quite unstable with its functioning. |
Yeah. I have not been able to make that one work either. I will try to get an MVP going with just hard coded "Discover. Connect. Send a single move command. Disconnect." If I can get this, then I will have a better comparison and starting point for debugging. Unfortunately I will at earliest have time for this next week. |
I managed to make it work on a mac, see #76 |
I have tried your fix and it works even on Catalina! Running go_toward_light.py makes Vernie travel around until he encounters: Exception in thread Thread-2: But that just have to be implemented. Now at least I have a starting point! |
First of all thanks for the wonderful library and inspiring examples!
As I was fiddling with the (asynchronous) bleak library I realized that some of the commands in pylgbst are blocking even though that is technically not necessary. As far as I can see, it is not possible to e.g. blink a light and move a motor at the same time.
As the bleak library uses asyncio, I hacked together an async/await proof-pf-concept that allows much better control over simultaneous operations. Have you considered a fully async version? And/or would you be interested to work on an async fork of this library?
The text was updated successfully, but these errors were encountered: