0

I'm trying to build my first dronekit python program, and I'm doing some tests with some examples but I couldn't connect to my UAV(Iris+). I plugged the usb radio(3DR 915 MHz) and I put vehicle = connect('/dev/ttyUSB0', wait_ready=True). Actually I have no idea which string I should put in. Thanks in advance guys, I need some help!

My code:

print "Start simulator (SITL)"
from dronekit_sitl import SITL
sitl = SITL()
sitl.download('copter', '3.3', verbose=True)
sitl_args = ['-I0', '--model', 'quad', '--home=-35.363261,149.165230,584,353']
sitl.launch(sitl_args, await_ready=True, restart=True)

# Import DroneKit-Python
from dronekit import connect, VehicleMode
import time

# Connect to the Vehicle.
print "Connecting to vehicle on: '/dev/ttyUSB0'"
vehicle = connect('/dev/ttyUSB0', wait_ready=True)

# Get some vehicle attributes (state)
print "Get some vehicle attribute values:"
print " GPS: %s" % vehicle.gps_0
print " Battery: %s" % vehicle.battery
print " Last Heartbeat: %s" % vehicle.last_heartbeat
print " Is Armable?: %s" % vehicle.is_armable
print " System status: %s" % vehicle.system_status.state
print " Mode: %s" % vehicle.mode.name    # settable

# Close vehicle object before exiting script
vehicle.close()

# Shut down simulator
sitl.stop()
print("Completed")
JamesThiago
  • 33
  • 1
  • 8

1 Answers1

0

Best place for getting dk support now is probably here: https://discuss.dronekit.io/c/python

In answer, I have not tried this on Linux. I suspect the connection string is correct, but you may have to also set the baud rate using baud=57600

Hamish Willee
  • 372
  • 1
  • 3
  • 11
  • thanks for reply @Hamish, I tried that bas well, but nothing happens. `vehicle = connect('/dev/ttyUSB0', wait_ready=True, baud=57600)` and came out with erros: `Start simulator (SITL) SITL already Downloaded. Connecting to vehicle on: 'tcp:127.0.0.1:5760' >>> Link timeout, no heartbeat in last 5 seconds >>> No heartbeat in 30 seconds, aborting. Traceback (most recent call last): File "hello.py", line 14, in vehicle = connect('/dev/ttyUSB0', wait_ready=True, baud=57600)` – JamesThiago Feb 19 '16 at 15:44
  • The simple version of your code should look like this. from dronekit import connect, VehicleMode import time # Connect to the Vehicle. print "Connecting to vehicle on: '/dev/ttyUSB0'" vehicle = connect('/dev/ttyUSB0', wait_ready=True, baud=57600) # Get some vehicle attributes (state) print "Get some vehicle attribute values:" print " Is Armable?: %s" % vehicle.is_armable print " Mode: %s" % vehicle.mode.name # settable # Close vehicle object before exiting script vehicle.close() print("Completed") – Hamish Willee Feb 21 '16 at 03:30
  • Sorry about that, SO stopped me editing my response. Remove the code for SITL, you're not using it. The connect you have defined looks good to me. All I can think of is that perhaps your telemetry link isn't on that port. Perhaps you could try looking at something like http://unix.stackexchange.com/questions/144029/command-to-determine-ports-of-a-device-like-dev-ttyusb0 to verify that this device is indeed where your telemetry radio is connected. I'd also try mavproxy - with this same connection string and baud (search google). – Hamish Willee Feb 21 '16 at 03:50
  • Hi @Hamish, I think I'm using the right connection string because when I execute the python code, a little led starts flashing and when stops the code, stop flash. I've tried MAVProxy as well, but was the same thing. And also, I've tried before the same link that u gave me to find the correct port and it's correct. – JamesThiago Feb 23 '16 at 17:29
  • SOLVED! I did a stupid thing. I was trying to connect with a wrong usb radio(I have 2). Thanks for the help! – JamesThiago Feb 23 '16 at 19:20