Skip to content

Implements target_system lookup. Implements better target semantics. - #461

Merged
tcr3dr merged 4 commits into
masterfrom
tcr-forward
Nov 18, 2015
Merged

tcr3dr merged 4 commits into
masterfrom
tcr-forward

Conversation

@tcr3dr

@tcr3dr tcr3dr commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

Exposing a target_system on connect() is probably not what we want. Exposing source_system might be, though.

This does a bit of an overhaul over the MAVLink object in the backend to make sure we get this right. The target_system is loaded from the first heartbeat we get and fixed after that point. We also have some backend classes which we might expose eventually, but for now demonstrate the use of multiple target systems in one program. e.g.

dronekit-sitl copter

In one window,

import time
from dronekit import connect
from dronekit.mavlink import MAVConnection

v = connect('tcp:127.0.0.1:5760', wait_ready=True, source_system=255)

o = MAVConnection('udpout:127.0.0.1:14550', source_system=254)
v._handler.pipe(o)
o.start()

while True:
    time.sleep(1)

in the next, and

mavproxy.py --master 0.0.0.0:14550 --source-system=254

Works to daisy chain a connection through DroneKit. This is obviously using undocumented features (MAVConnection directly) but demonstrates the logic should work if we expose it publicly later.

@tcr3dr

tcr3dr commented Nov 18, 2015

Copy link
Copy Markdown
Contributor Author

Another proposal is that vehicle.send_mavlink fixes the target_system, but vehicle._handler.send_mavlink would be a "raw" write on the connection. We could also expose this as vehicle.connection instead of _handler, but I don't want to commit too early (as in, we can do this after 2.0.0)

@hamishwillee

Copy link
Copy Markdown
Contributor

My first reaction (second to follow)

  • target_system is the MAVLink network ID of the vehicle our script is talking to. AFAIK most vehicles set themselves as 1 by default. We can set this to 0 to talk to everything, but we should set it to whatever the vehicle thinks its id is.
  • source_system is the id of the script on the MAVLink network. This ID is what vehicles will use to send messages back to us, and needs to be unique. As a result it needs to be settable.

UPshot,

  • yes, removing target_system from the connect API and getting the id from the connected vehicle makes sense (I can't think of a use case where we would want to set this to anything other than what the connected vehicle says it is). NOTE - the vehicle can change its ID, so we may need to monitor for this?
  • Yes we need source_system to be set for the same reason - to enable our DK instructions to be uniquely identified. This actually does matter because there are settings on the autopilot where the autopilot will only take guided instructions from a specific GCS/id.

@hamishwillee

Copy link
Copy Markdown
Contributor

@tcr3dr Second thoughts ...

  1. Why is this approach for setting up connections to multiple targets within a script better than creating a second vehicle class and connecting it to that target?
  2. Some of our customers will be very happy (based on what they've asked) because I think what you've done here is enable automated forwarding of all packets to a specified address. ie MAVProxy in dronekit. Is that correct?
  3. Not sure how this would look in a real app - will need more examples if you want this documented.

As an aside, the two reasons I wanted UDP was to be able to use the loopback address (simplify instructions) and to have consistency with main instructions on old SITL. I did test tcp connection to sitl via loopback at one point and it failed. However it seems to work now, so I'm thinking perhaps just using tcp is fine for the examples.

Are there other reasons why we might want UDP?

W.r.t the example, did you mean?

mavproxy.py --master 0.0.0.0:14550 --target-system=254

@tcr3dr

tcr3dr commented Nov 18, 2015

Copy link
Copy Markdown
Contributor Author

@hamishwillee Using SITL with TCP means for more connection overhead we gain predictability. I'm inclined to want this in most examples; for real-world testing, UDP is more practical, but so are a number of other simulation variables (wind speed, battery depletion, real physics, etc.) Since examples are meant to be short and understandable, I prefer TCP.

NOTE - the vehicle can change its ID, so we may need to monitor for this?

We would! I'd want to be able to test this before adding it in, though, so I can say post-2.0.0 we should get back to it.

Why is this approach for setting up connections to multiple targets within a script better than creating a second vehicle class and connecting it to that target?

If you want two vehicle objects, you should connect to the same master. This particular scenario is for if you want to create i.e. udpout connections. Right now we have the scaffolding in place that will allow that down the line.

Some of our customers will be very happy (based on what they've asked) because I think what you've done here is enable automated forwarding of all packets to a specified address. ie MAVProxy in dronekit. Is that correct?

Yup. Right now I have a DK script that forwards to udpout:127.0.0.1:14550 for the Solo app in emulation. Works well!

Not sure how this would look in a real app - will need more examples if you want this documented.

Let's just document the source_system param, not the rest of this. You can still connect multiple vehicles to the same source address, which was necessary.

@hamishwillee

Copy link
Copy Markdown
Contributor

Hi @tcr3dr

That all makes sense - and agree. I will assume you'll create a tracking issue on watching for system id changes.

Can you merge #461 first and then merge this on top of it? I can update the docs fairly easily after that (and more easily) than starting fresh. If that is too hard, I'll take a shot at merging fresh - just confirm which is best.

Cheers
H

@tcr3dr

tcr3dr commented Nov 18, 2015

Copy link
Copy Markdown
Contributor Author

Done.

@hamishwillee

Copy link
Copy Markdown
Contributor

@tcr3dr Docs updated now. Please check the statements just on the connect() method for heartbeat_timeout and source_system. Mostly I want to check that heartbeat_timeout only applies to the connection - or is this the same timeout value used to monitor the link for activity after connection?

@tcr3dr

tcr3dr commented Nov 18, 2015

Copy link
Copy Markdown
Contributor Author

This looks good! heartbeat_timeout applies to the connection even after heartbeat is established. (it may be the case that we don’t want this behavior, but right now that’s what it does)

tcr3dr added a commit that referenced this pull request Nov 18, 2015
Implements target_system lookup. Implements better target semantics.
@tcr3dr
tcr3dr merged commit de0f45b into master Nov 18, 2015
@tcr3dr
tcr3dr deleted the tcr-forward branch November 18, 2015 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants