MicroPython 1.0.0,ev3dev Linux回声4.14.96-ev3dev-2.3.2-ev3 #1抢占Sun Jan 27 21:27:35 CST 2019 armv5tejl GNU/Linux
#!/usr/bin/env pybricks-micropython
from pybricks import ev3brick as brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop
from pybricks.tools import print, wait
leftMotor = Motor(Port.B)
rightMotor = Motor(Port.C)
# speed range -100 to 100
def leftWheel():
leftMotor.run_target(50, 360, Stop.COAST, True)
def rightWheel():
rightMotor.run_target(50, -360, Stop.COAST, True)
leftWheel()
rightWheel()如果我使用True,这是可行的,所以它向左然后向右运行。但如果我把它设为假,它就什么也做不了。应该并行运行
发布于 2019-07-05 15:02:51
当您选择wait=False时,将启动run_target命令,并且您的程序将立即继续执行您的程序的其余部分。发动机在后台完成了它的指挥。
但是如果你的程序中没有其他的东西,这个程序就会马上结束。当程序结束时,马达就停止了,所以在这种情况下你看不到任何运动。
如果你的程序中有其他东西,比如等待,你会看到马达在运动:
#!/usr/bin/env pybricks-micropython
from pybricks import ev3brick as brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop
from pybricks.tools import print, wait
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
# Initiate the run target commands, without waiting for completion.
left_motor.run_target(50, 360, Stop.COAST, False)
right_motor.run_target(50, -360, Stop.COAST, False)
# Do something else while the motors are moving, like waiting.
wait(10000)如果您的目标是等待两个电机都达到目标,则可以等待每个电机的angle值等于给定的目标:
#!/usr/bin/env pybricks-micropython
from pybricks import ev3brick as brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop
from pybricks.tools import print, wait
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
target_left = 360
target_right = -360
tolerance = 2
left_motor.run_target(50, target_left, Stop.COAST, False)
right_motor.run_target(50, target_right, Stop.COAST, False)
# Wait until both motors have reached their targets up to a desired tolerance.
while abs(left_motor.angle()-target_left) > tolerance or abs(right_motor.angle()-target_right) > tolerance:
wait(10)
# Make a sound when we're done.
brick.sound.beep()https://stackoverflow.com/questions/56869525
复制相似问题