dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.59k stars 1.44k forks source link

Connection issue #755

Open asiyo opened 7 years ago

asiyo commented 7 years ago

Hello I am new to dronekit and I have some trebles when I try to connect my drone via dronekit-python. I have no trebles when I'm using QGC (wifi and usb) I'm using :

when I try to run the most basic code:

from dronekit import connect
connection_string = '127.0.0.1:14550'
print "Connecting"
vehicle = connect(connection_string, wait_ready=True)

I get the following output:

Connecting

Link timeout, no heartbeat in last 5 seconds No heartbeat in 30 seconds, aborting. Traceback (most recent call last): File "hello1.py", line 6, in vehicle = connect(connection_string, wait_ready=True) File "build\bdist.win-amd64\egg\dronekit__init.py", line 2880, in connect File "build\bdist.win-amd64\egg\dronekit\init__.py", line 2147, in initialize dronekit.APIException: Timeout in initializing connection.

Can someone tell me what am I doing wrong and walk me through. (My end goal is to control multiple cuadcopters (5) simultaneously from my PC)

Thank you in advance.

hamishwillee commented 7 years ago

Suggest you try the gitter channel. I'd use DK-python from github rather than pip.

The message means what it says - you have no connection. The connection string is for a UDP connection to local host on port 14550 - that works for SITL but not for real hardware. You will need to specify the actual connection string for the method you're using to connect.

Last of all, I am not sure how well DK-Python is currently handling PX4. I suggest you look at DroneCore. It is C++ and still evolving, but it is designed for PX4 and should have Python wrappers in the coming months.

asiyo commented 7 years ago

@hamishwillee Thank you for your quick answer!

  1. Can you tell me how can I find the right connection string? (for now I'm connecting to the pixracer directly from my laptop via wifi or USB (e.g COM5 )).
  2. Is DK-Python more suited to arducopter?
  3. I tried to install arducopter (via QGC and MP) and I failed to do it. Is it possible to install arducopter on pixracer?

Thank you in advance.

hamishwillee commented 7 years ago

Sorry, no. I am off on holiday. Back in a couple of week. Raise issue on gitter channel.

guglie commented 7 years ago

Can you tell me how can I find the right connection string? (for now I'm connecting to the pixracer directly from my laptop via wifi or USB (e.g COM5 )).

I think the connection string is as simple as "COM5" in your example. Don't forget to set the baud rate.

To install DK-python from repository:

git clone https://github.com/<your_fork_of_dronekit>/dronekit-python.git
cd dronekit-python  
python setup.py build
python setup.py install
yoshiioko commented 6 years ago

Hi asiyo,

I was having the same issue as you when trying to run a program to connect to my device (Intel Aero drone). FYI, I ran the program from within the Aero drone itself. Had to make these changes:

  1. Updated the main.conf file for the mavlink-router with an additional UDP endpoint by adding these lines: [UdpEndpoint dronekit] Mode = Normal Address = 127.0.0.1 Port = 11000

  2. Restarted mavlink-router service: systemctl restart mavlink-router

  3. Changed connect() to just do this: vehicle = connect('127.0.0.1:11000')

I am not an expert! But I can now get some vehicle state data from the system.