问题描述
我必须等待所有线程完成旋转 90 度
我尝试使用不同代码的 join 方法,并且与 ev3 机器人无关,但我不明白为什么它不能与 ev3 一起使用。
错误: AttributeError: 'Thread' 对象没有属性 'join'
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import (Motor,TouchSensor,ColorSensor,InfraredSensor,UltrasonicSensor,GyroSensor)
from pybricks.parameters import Port,Stop,Direction,Button,Color
from pybricks.tools import wait,StopWatch,DataLog
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile,ImageFile
import threading
# This program requires LEGO EV3 MicroPython v2.0 or higher.
# Click "Open user guide" on the EV3 extension tab for more information.
# Create your objects here.
ev3 = EV3Brick()
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
robot = DriveBase(left_motor,right_motor,wheel_diameter=55.5,axle_track=104)
obstacle_sensor = UltrasonicSensor(Port.S4)
obstacle_sensor_gyro = GyroSensor(Port.S3)
################################
def check_for_75_angle():
while True:
angle = obstacle_sensor_gyro.angle()
print(angle)
if angle > 75:
robot.drive(0,15)
break
def check_for_90_angle():
while True:
angle = obstacle_sensor_gyro.angle()
if angle == 90:
break
def turn():
robot.drive(0,80)
def main():
t1 = threading.Thread(target=check_for_75_angle)
t2 = threading.Thread(target=check_for_90_angle)
t3 = threading.Thread(target=turn)
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
while True:
cm = obstacle_sensor.distance() * 0.1
if cm < 20:
obstacle_sensor_gyro.reset_angle(0)
main()
print("Finished: 90 angle")
else:
robot.drive(20,0)
```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)