dronekit / dronekit-python

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

Use a single communication link for several vehicles #516

Open jlecoeur opened 8 years ago

jlecoeur commented 8 years ago

It seems DroneKit promotes one link per vehicle and does not work well when more than one vehicle send messages on the same link.

What is the best way to proceed?

jlecoeur commented 8 years ago

In my setup, several vehicles communicate on the same network. As a test, I started two simulated drones (respectively sysid 1 and 2) on my computer, both sending messages to udp:127.0.0.1:14550. Then I created a vehicle object in dronekit:

import dronekit
vehicle1 = dronekit.connect('127.0.0.1:14550')

All the Vehicle methods decorated by the on_message decorator are called for messages coming from drone with sysid 1 AND the drone with sysid 2. For instance vehicle1._heartbeat_system keeps on oscillating between 1 and 2. Similarly, this leads to undefined behaviour when both drones send 'PARAM_VALUE' messages.

jlecoeur commented 8 years ago

I partially solved the problem by:

I could create a vehicle like this

import dronekit
vehicle1 = dronekit.connect('127.0.0.1:14550', target_system=1)

And it only received messages from the drone with sysid 1, which is what we want, great!

However if then I create a second vehicle object:

vehicle2 = dronekit.connect('127.0.0.1:14550', target_system=2)

Then the link to the first drone is lost. This comes down to mavutil.mavlink_connections who cannot share the same udp link.

Maybe the connect function should create a single MAVConnection object, but return a list of vehicles? I am happy to contribute to that feature, but I would like to be sure I go in the right direction.

hamishwillee commented 8 years ago

Hi @jlecoeur

What you're doing here is not talking to two separate drones - but talking to one drone twice from separate vehicle instances on the same port. This is possible but largely pointless since you will run into issues with synchronizing the two handles to the one vehicle. If you needed to make this work you would keep the the target system the same in both cases (since this is the ID of the drone on the mavlink network) and you "might" change your source id.

What I think you actually want to do is talk to two separate drones. To do this you need to attached to a real or simulated drone on a different port. I believe this can be done by passing a value to sim_vehicle.sh when you launch SITL. The help options to that script should help you work out which.

jlecoeur commented 8 years ago

Hi,

Indeed I want to talk to several drones. However, when talking to real drones, they will be using the same xbee network, so messages from N drones will be coming through the same link. With current implementation, I would have to write a MAVLINK demultiplexer that reads on xbee, and forwards messages to N udp ports according to the sysid of the incoming message. It would be a lot more convenient if dronekit could directly feed messages to a list of vehicle instances according to the sysid.

mrpollo commented 8 years ago

hey @jlecoeur can you please write a test case that proves your issue?

jlecoeur commented 8 years ago

Sure! Here is a testcase using 2 simulated mavric autopilots: https://gist.github.com/jlecoeur/ab85e970b3b048985273 The gist contains terminal outputs, but you should be able to replicate it by running the script testcase.sh. The example requires 3 terminals:

What it does:

After MAV2 is started, dronekit accepts the 'PARAM_VALUE' message from MAV2, and the parameter is set to 0.0 in the dronekit object, although it is still equal to 1.0 onboard MAV1.

jlecoeur commented 8 years ago

@hamishwillee @mrpollo any update on this?

hamishwillee commented 8 years ago

@jlecoeur Not as far as I know. Working on other priorities. @peterbarker , do have time in the coming weeks to look at this?

rmackay9 commented 8 years ago

I agree this is an issue. We should be able to speak to multiple vehicles using a single connection. It's normal for an antenna tracker and vehicle to appear to be on the same connection from dronekit's point of view. The vehicles can be distinguished by their sysid/component-id combination.

hamishwillee commented 8 years ago

My two bits

rmackay9 commented 8 years ago

I hit this problem again today in a more common situation. I'm using dronekit on a companion computer and the vehicle.mode is switching between the vehicle's actual mode (Guided, Loiter, etc) to Stabilize. the reason is that I have Mission Planner attached as well and it's sending heartbeats which include the flight mode. Of course mission planner's flight mode is not what I want! :-)

hamishwillee commented 8 years ago

Very annoying. At least for things like mode setting we really need to check that the source is our connected vehicle. @peterbarker do you want me to take this issue over. I can look probably fix it early next week.

peterbarker commented 8 years ago

Rough instructions for multiivehicle support in dronekit-python: https://github.com/peterbarker/dronekit-python/tree/source-system-filtering/examples/multivehicle

jainakshay91 commented 8 years ago

So, this is a side note, but @jlecoeur if you are using the xbee network, then I think you can filter your messages for separate vehicles based on their MAC address/IP address depending on the type of xbees you are using. This should help you to alleviate any issues with the dronekit-python library and allow you to communicate with multiple vehicles at one time.

basil-huber commented 7 years ago

Hi, are there any plans to merge @peterbarker 's solution into master?

tlillis commented 7 years ago

Hello, has there been any progress on this? Any plans for the merge of @peterbarker 's stuff? Thanks!

Sidney-L commented 6 years ago

@peterbarker, actually in your example of multivehicles, simple_go_to message is executed by every drone no matter which vehicle[i] is given

GitRevisionGandalf commented 5 years ago

@peterbarker , Hi Peter, I am having trouble getting your example case given in https://github.com/peterbarker/dronekit-python/tree/source-system-filtering/examples/multivehicle to work.

I had ran all the commands until the last command in step 5: python multivehicle.py --simulation-count 3 --extra-connection udpout:localhost:9432

This gave an error below. Could you provide some insight on this?

image

I had already tried adding 'PYTHONPATH' for the pymavlink folder in addition to the dronekit-python folder. But this did not help the multi-vehicle example to work.

peterbarker commented 5 years ago

On Mon, 8 Oct 2018, ajaiRevision wrote:

I had ran all the commands until the last command in step 5: python multivehicle.py --simulation-count 3 --extra-connection udpout:localhost:9432

This gave an error below. Could you provide some insight on this?

Wrong pymavlink; try setting PYTHONPATH to point to the relevant git repository, checked out on the correct branch.

Peter

maroquio commented 5 years ago

It's very disappointing dronekit not having a multi-vehicle protocol. There is a lot of research that uses microdrone swarms that could use this feature. I hope you have time to add this feature soon.

lauracanseco21 commented 5 years ago

@peterbarker I tried running your source system filtering, but it doesn't differentiate the two drones i am working with. how should i go about fixing this issue?

mbatra9 commented 5 years ago

Hi, I have a very minor issue that hopefully someone will be able to solve. I'm following the instructions on the ReadMe page for the github site Peter Barker posted with his example code, https://github.com/peterbarker/dronekit-python/tree/source-system-filtering/examples/multivehicle. On step 1, I typed this line into my terminal "git checkout peterbarker/source-system-filtering" and I received an error message saying that I don't have access to this repository. Anyone know what I'm doing wrong? Am really trying to figure out how to get multivehicles set up in dronekit so any help would be appreciated.

bilginmu commented 3 years ago

I tried the @peterbarker repo but I got errors. Is there any way to use a single commnication link for several vehicles ?

GRS26 commented 2 years ago

Also having problems while following the instructions, idk if already having dronekit and pymavlink installed though pip is affecting the process