AttributeError: 'Tello' 对象没有属性 'address' (Tello Ryze 无人机 StreamOn 错误,无法调用 streamon 函数:)

0 投票
1 回答
25 浏览
提问于 2025-04-13 15:26
from djitellopy import tello
import cv2
# Create instances for each Tello drone
drone1 = tello.Tello(ip='192.168.10.2')  # Replace with your first Wi-Fi adapter's IP
#drone2 = tello.Tello(ip='192.168.10.3')  # Replace with your second Wi-Fi adapter's IP
# ... Add more instances for additional drones

# Connect to drones
drone1.connect()
#drone2.connect()
# ... Connect other drones

# Send commands to drones
# drone1.takeoff()
# drone2.takeoff()
# ... Send other commands

# Clean up
drone1.streamon()



# while True:
#     img = drone1.get_frame_read().frame
#     img = cv2.resize(img, (360, 240))
#     cv2.imshow("results", img)
#     if cv2.waitKey(1) & 0xFF == ord('q'):
#         break

每次我尝试调用streamon函数时都会出现这个错误,我试着问ChatGPT,但没有得到答案。

Traceback (most recent call last):
  File "C:\Users\origi\PycharmProjects\DroneProject\venv\Interface.py", line 4, in <module>
    drone1 = tello.Tello(ip='192.168.10.2')  # Replace with your first Wi-Fi adapter's IP
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\origi\PycharmProjects\DroneProject\venv\Lib\site-packages\djitellopy\enforce_types.py", line 54, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
TypeError: Tello.__init__() got an unexpected keyword argument 'ip'
Exception ignored in: <function Tello.__del__ at 0x000001FAE5924720>
Traceback (most recent call last):
  File "C:\Users\origi\PycharmProjects\DroneProject\venv\Lib\site-packages\djitellopy\enforce_types.py", line 54, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\origi\PycharmProjects\DroneProject\venv\Lib\site-packages\djitellopy\tello.py", line 1028, in __del__
    self.end()
  File "C:\Users\origi\PycharmProjects\DroneProject\venv\Lib\site-packages\djitellopy\enforce_types.py", line 54, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\origi\PycharmProjects\DroneProject\venv\Lib\site-packages\djitellopy\tello.py", line 1023, in end
    host = self.address[0]
           ^^^^^^^^^^^^
AttributeError: 'Tello' object has no attribute 'address'

Process finished with exit code 1

我正在使用多个网络适配器来连接多个Ryze无人机,但连第一个都无法让streamon函数正常工作。

对于第一个Tello无人机的IP地址,我指定了我的网络适配器的IP地址,因为这些无人机的IP是一样的。

任何回复都很感谢 :)

1 个回答

0

你代码里的主要问题不是AttributeError,而是构造函数里的TypeError

TypeError: Tello.__init__() got an unexpected keyword argument 'ip'

你可能在使用一个过时的库版本,或者ChatGPT生成了无效的代码。如果你查看一下Tello类的构造函数(在这里),你会发现它接受这些参数:

    def __init__(self,
                 host=TELLO_IP,
                 retry_count=RETRY_COUNT,
                 vs_udp=VS_UDP_PORT):

所以在创建Tello实例的时候,你应该用host而不是ip

撰写回答