Multitask #2013
Unanswered
Meki-Zeyad
asked this question in
Q&A
Multitask
#2013
Replies: 1 comment 1 reply
-
Hi, From the pybricks documentation The following example shows how to use multitasking to make a robot drive forward, then turn and move a gripper at the same time, and then drive backward. from pybricks.pupdevices import Motor
from pybricks.parameters import Direction, Port
from pybricks.robotics import DriveBase
from pybricks.tools import multitask, run_task
# Set up all devices.
left = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right = Motor(Port.B)
gripper = Motor(Port.C)
drive_base = DriveBase(left, right, 56, 114)
# Move the gripper up and down.
async def move_gripper():
await gripper.run_angle(500, -90)
await gripper.run_angle(500, 90)
# Drive forward, turn move gripper at the same time, and drive backward.
async def main():
await drive_base.straight(250)
await multitask(drive_base.turn(90), move_gripper())
await drive_base.straight(-250)
# Runs the main program from start to finish.
run_task(main()) Maybe this helps. PS Please add before your source (three backtcks python), like this:
and three backticks after it. Bert |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i was trying to use the multitask function but it really doesn’t do what its attending to do it should run all the motors that i programmed to run at the same time but it runs the first command then the other one like a normal program,
i even tryed using the async def it didnt work at all, and here are some videos of what happens
IMG_4786.2.mov
Beta Was this translation helpful? Give feedback.
All reactions