简体   繁体   中英

DroneKit: Failed to connect to /dev/tty.usbmodem1411 : 'Serial' object has no attribute 'setBaudrate'

Following the DroneKit instructions, I was able to run the hello.py code from their QuickStart guide: http://python.dronekit.io/guide/quick_start.html .

However, when I try to run their basic mission example, I get the setBaudrate error in the title:

$ python mission_basic.py --connect=/dev/tty.usbmodem1411

Connecting to vehicle on: /dev/tty.usbmodem1411
Traceback (most recent call last):
  File "mission_basic.py", line 23, in <module>
    vehicle = connect(args.connect, wait_ready=True)
  File "/Library/Python/2.7/site-packages/dronekit/__init__.py", line 2344, in connect
    handler = MAVConnection(ip, baud=baud, source_system=source_system)
  File "/Library/Python/2.7/site-packages/dronekit/mavlink.py", line 37, in __init__
    self.master = mavutil.mavlink_connection(ip, baud=baud, source_system=source_system)
  File "/Library/Python/2.7/site-packages/pymavlink/mavutil.py", line 1106, in mavlink_connection
    return mavserial(device, baud=baud, source_system=source_system, autoreconnect=autoreconnect, use_native=use_native)  
  File "/Library/Python/2.7/site-packages/pymavlink/mavutil.py", line 735, in __init__
    self.set_baudrate(self.baud)
  File "/Library/Python/2.7/site-packages/pymavlink/mavutil.py", line 746, in set_baudrate
    self.port.setBaudrate(baudrate)
AttributeError: 'Serial' object has no attribute 'setBaudrate'

Note: tty.usbmodem1411 is my USB cable running straight from my Mac running Yosemite to the APM. I have also tried with the 3DR telemetry kit with the same results. I have also tried adding in the baud rate option with the same result.


UPDATE: Using the link's patch that 陳昭宇 gave resolved my baud rate issue; however, I still had an issue with never finding a heartbeat. This issue was also because of the pyserial update. Using the older pyserial solution that Tim Ryan provided fixed both problems.

Fin, it looks like pySerial 3.0 was released in the past week which changes its API. pymavlink (used by DroneKit-Python) requires pySerial 2.0. I've filed an issue and will work to resolve it.

In the meantime, try pip install "pySerial>=2.0,<=2.9999" and see if this resolves your problem.

In the new python setBaudrate() looks removed from class SerialBase . Please refer a similar issue of mavlink.

Shot in the dark here, so apologies if this doesn't fix your problem, but I've suspicions that it will.

You need to install FTDI Drivers ( https://learn.sparkfun.com/tutorials/how-to-install-ftdi-drivers/mac )

I had similar issues creating a serial connection over USB, using python, between my Arduino and my Mac running Mavericks and subsequently El Capitan. (Worked out of the box on Ubuntu, if you're afraid to mess with your fancy Mac) Expect this to break after an OSX upgrade. (Thanks Apple) It will also only work on the USB port that you specified during this process. So choose wisely ;)

Hope this helps. I lost days to this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM