Wondering about a few topics (datalogging; remote control; await uses; await wait(0)) #2289
Replies: 3 comments 3 replies
-
There is an undocumented
No definite plans at this time.
This sounds like it could be done already using the Bluetooth broadcasting/observing. All of the hubs in the MOC would be observing, then add one more hub to act as the broadcaster (or some other BLE device where you can control advertising data - arduino/rpi/etc.). The same data gets broadcast to all hubs, so they would all receive the same data at the same time.
This is already documented. If the docs for a method say
Multitasking uses coroutines rather than threads. For non-programmers, this probably doesn't mean much, so I'll give an analogy. It's kind of like waiting in a queue at the bank. For threads, if someone is taking too long for the request to be handled, they are forced to step aside and let the next person in line have a turn. After a while, the teller returns their attention to the first person to see if they are ready to continue or now. This process continues and tries to fairly share the tellers time with all customers. For coroutines, no one else can force the customer to step aside. The customer has to volunteer to do that themselves. If one person keeps making more transactions and never goes to the back of the line, everyone else in the queue never gets to do anything. The Here is an example: # "bad" example
async def wait_for_sensor():
while not touch_sensor.pressed():
# There is no `await` inside of the loop.
# No other code can run until the touch sensor is pressed!
pass If the touch sensor was pressed soon or there was no control loops being blocked, you might not notice a problem with the code above. But the proper way to write it is as below. # "good" example
async def wait_for_sensor():
while not touch_sensor.pressed():
# This gives other functions/tasks a chance to run while
# we are waiting for the sensor event.
await wait(0) |
Beta Was this translation helpful? Give feedback.
-
Many thanks for your answers!!
|
Beta Was this translation helpful? Give feedback.
-
Thank you Laurens! I've myself used to print data and import into an Excel for a study, that I also posted here some years ago (BTW, I owe you an update there). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I've a few generic questions/observations, then I decided to put them into a single post rather than opening individual ones. Hope this is ok!
I can't find any Pybricks classes that support datalogging for the Technic Hub.
I know this hub does not have a file system, but still is there any other solution than writing to the console output?
Are there any plans to support custom remote control designs in the smartphone?In my use case I've a cooperative MOC with several hubs running. I'd like to have a solution where I can set or change values to test certain variables and currently the solution is to change them in code and upload them in the several hubs, which is not very convenient.This solution might allow even broader use cases.
For multitasking purposes it is necessary in some cases to add the 'await' keyword before the call of certain methods.
I understand this is required for those that take longer to complete, as is the case of some motor methods. In certain cases it is also obvious this is not needed or it can't even be used (like run and stop methods), but that's not always the case.
Would it be possible to make explicit in the documentation, which methods require an 'await' in case of multitasking use?
While programming with blocks, if one looks at the generated python code, it is possible to realize that Pybricks adds some "await wait(0)" statements. Almost always before while statements and always after these.It doesn't seem necessary when I write my own code, hence can you comment on this behaviour?
Thanks and best regards,
Fernando
Beta Was this translation helpful? Give feedback.
All reactions