如何解决使用 python ev3 进行多线程处理,join 方法不起作用
我必须等待所有线程完成旋转 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 举报,一经查实,本站将立刻删除。