Replies: 2 comments
-
You can use Then you can use other conditions to wait for completion such as:
Optionally, the last one will help you catch the case where the motors are not quite stalled but just turning slowly (as you push against the lever). Here is an example. Note that from pybricks.parameters import Direction, Port
from pybricks.pupdevices import Motor
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
# Set up all devices.
left = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right = Motor(Port.B, Direction.CLOCKWISE)
drive_base = DriveBase(left, right, 56, 114)
# Use gyro for driving and turning.
drive_base.use_gyro(True)
# Normal command, wait until done. Just for comparison.
drive_base.straight(250)
# Just adding this wait so you can clearly see where the first move ends and the second begins.
wait(2000)
# This time, start the command, but don't wait for it to finish.
drive_base.straight(250, wait=False)
# Now you can do other things. For example, to wait
# until it is done, or until stalled, or a timeout.
watch = StopWatch()
while not drive_base.done() and not drive_base.stalled() and not watch.time() > 3000:
wait(10)
# Either it was done, it stalled, or the timer expired. So stop.
drive_base.stop() |
Beta Was this translation helpful? Give feedback.
0 replies
-
See also How to stop on ongoing motor motion using another condition? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm having a problem with the robot (Spike Prime) sometimes getting stalled.
For example, I'm using a Spike prime robot to move forward and execute a mission where the robot basically just pushes a lever (passive) by ramming into it.
Sometimes I see that the robot gets stalled as its stuck and not able to move the intended distance.
Is there a way to detect that the robot is stalled and move forward to the next code (for eg backing the robot or something else etc)
My rough code is below;
drive_base = GyroDriveBase(left_motor, right_motor, wheel_diameter=62.5, axle_track=136)
drive_base.settings(400, 800, 100, 200)
drive_base.straight(250)
Thanks
Hari
Beta Was this translation helpful? Give feedback.
All reactions