-
-
Notifications
You must be signed in to change notification settings - Fork 6
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] Multitasking #613
Comments
Yes. Have a look at #356 and https://github.com/pybricks/support/issues?q=label%3A%22topic%3A+multitasking%22+. |
Depending on what you need, the following solution may be a bit simpler: |
I found this example avaible for EV3 does it work for the technic hub Motors? from pybricks.experimental import run_parallel
from pybricks.tools import wait
def task1():
wait(1000)
return 'OK1'
def task2():
wait(500)
return 'OK2'
result = run_parallel(task1, task2)
print('task1:', repr(result[task1]))
print('task2:', repr(result[task2]))
# prints:
# task1: 'OK1'
# task2: 'OK2' |
No, the EV3 has experimental support for threads, but the newer hubs don't support threads. |
So is there a way to re-use wait=False in some kind of closed stages? The parallel task for running multiple Motors didn´t work well :c |
What is the expected behavior and what is the actual behavior of the code that you shared? |
Well, it controls a delta robot so it uses 3 motors to incline the arms that hold the tools. The Demo raises and lowers the tool, therefore all the motors have to run at the same time in one direction, then, all of them 3 run in the opposite direction to go down. That is the Demo, seeing that it didn't work, I didn't continue with the rest. I first planned to control multiple motors in divided sections to get different angles and distances of the tool |
video-1642723407.mp4It's supposed to do something like this for the Demo |
the co-routine might be applicable? https://gist.github.com/dlech/fa48f9b2a3a661c79c2c5880684b63ae |
yes, that is what #356 is |
You can extend this for any number of motors. from pybricks.pupdevices import Motor
from pybricks.parameters import Port
from pybricks.tools import wait
# Initialize motors on port A and B.
track_motor = Motor(Port.A)
gripper_motor = Motor(Port.B)
# Make both motors perform an action with wait=False
track_motor.run_angle(500, 360, wait=False)
gripper_motor.run_angle(200, 720, wait=False)
# While one or both of the motors are not done yet,
# do something else. In this example, just wait.
while not track_motor.control.done() or not gripper_motor.control.done():
wait(10)
print("Both motors are done!") But in your example, you use DURATION = 350
rojo.run_time(500, DURATION, wait=False)
azul.run_time(500, DURATION, wait=False)
amarillo.run_time(500, DURATION, wait=False)
wait(DURATION) |
Yes, I did that, but i couldn't run these 3 motors at the same time in reverse after this instruction to raise the tool in the center of the robot |
I could, thanks, i used def to separate every action as dlech said. Thanks for your support :) |
Future visitors will be interested in the latest developments #917. |
Question
Is there a way of using "wait=False" an amount infinite of times or another funtion for parallel tasks?
Context
I was coding a robot using a technic hub. The robot consists in 4 motors, which 3 of them have to move at the same time in different directions and speeds continuously. So, if I try to use wait=False for the different stages of moving, it won't work. I was wondering if there was a way or trick to use this many times or another function (I work directly in the pybricks web by the way). Maybe it´s something basic, I know
Here is part of the code:
The text was updated successfully, but these errors were encountered: