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

Setting rate and baud when connecting #640

Open alexblack opened 8 years ago

alexblack commented 8 years ago

What values can I use for rate and baud when calling dronekit.connect? If I set rate higher, does that mean I'll have less-stale values for things like Attitude?

https://github.com/dronekit/dronekit-python/blob/master/dronekit/__init__.py#L2739

hamishwillee commented 8 years ago

The baud rate is set based on how you're connecting/hardware used. Examples of a few baud rates for some typical connections are given in the docs here: http://python.dronekit.io/guide/connecting_vehicle.html They will be the same as used for MAVProxy in the same circumstances.

The rate is the rate at which you get some data. I'm not sure this includes the positional information - you'd have to check which parameter is actually set under the hood. So yes you could in theory change the rate that information is sent, but my understanding is that this will still be quite limited, and also that some GCS set the value themselves on a regular basis, so even if you set the rate, you may not get to keep that set value.

alexblack commented 8 years ago

Great, thanks. I tried rate=20 with sitl and attitude messages came in 5x more frequently. I'll test it out on my Solo at some point. On Jun 19, 2016 10:59 PM, "Hamish Willee" notifications@github.com wrote:

The baud rate is set based on how you're connecting/hardware used. Examples of a few baud rates for some typical connections are given in the docs here: http://python.dronekit.io/guide/connecting_vehicle.html They will be the same as used for MAVProxy in the same circumstances.

The rate is the rate at which you get some data. I'm not sure this includes the positional information - you'd have to check which parameter is actually set under the hood. So yes you could in theory change the rate that information is sent, but my understanding is that this will still be quite limited, and also that some GCS set the value themselves on a regular basis, so even if you set the rate, you may not get to keep that set value.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dronekit/dronekit-python/issues/640#issuecomment-227056378, or mute the thread https://github.com/notifications/unsubscribe/AAJFwmbywhDgyjCnmj_drONvtLht6nYMks5qNiw7gaJpZM4I5Wal .

hamishwillee commented 8 years ago

Great! The stream rate is I believe "per mavlink channel" and probably the channel is reserved for the companion computer.

alexblack commented 8 years ago

Oh wow, setting rate=20 doubled the processing time on the drone for anything, I assume thats because DroneKit (or something) is doing a lot more processing to handle that many messages.

eg my code runs 2x as slow now, with rate=20, so I've put it back to the default!

hamishwillee commented 8 years ago

Useful to know.

I assume that's because DroneKit (or something) is doing a lot more processing to handle that many messages.

I don't know - we'd need profiling to work out what is causing the problem. I wonder if the relationship is linear or not - ie at rate=10 are things half as slow?

Also important to note that even if you can get the messages fast, there is no guarantee that the sensors are updating at that rate or that you can react at a sensible rate ... ie there quite possibly is no benefit at all in real terms in having a much greater message rate.

alexblack commented 8 years ago

Presumably most sensors update at a frequency higher than 4Hz?

I tried launching an idle dronekit app, that does nothing except connect to a vehicle then sleep, to see what CPU usage of my python process is like:

92% is the max CPU I seem to be able to get from the drone, the remaining 8% is used by 3DR processes.

Ah, keep in mind, I've hacked a bit.. damn. I should try to repro this on a clean setup. I don't let shot_manager on the solo run, so instead I run this code in my process:

  mav_vehicle = dronekit.connect("udpout:127.0.0.1:14560", wait_ready=False, source_system=255, use_native=True, heartbeat_timeout=-1)
  out = MAVConnection("udpout:127.0.0.1:14550", source_system=254)
  mav_vehicle._handler.pipe(out)
  out.start()    

Update: if I fire up shot manager (/usr/bin/main.py) and taken that code out, I get very similar results. CPU usage in my process is more like 48% when rate=4, and I see /usr/bin/main.py using some CPU, between 13-17%.

alexblack commented 8 years ago

Can I just connect directly using:

vehicle = dronekit.connect(wait_ready=False, source_system=255, use_native=True, heartbeat_timeout=-1)

Thereby avoiding using /usr/bin/main.py or running that code above (and connecting to it)?

Update: I haven't flown with this yet to confirm no issues, but this is much better as far as CPU usage goes. I think that code in /usr/bin/main.py was just there to let shot manager AND your own app get MAV connections, and I was just piping my MAV connection through a hop for no reason.

hamishwillee commented 8 years ago

@alexblack I don't know sorry. @peterbarker May be able to comment.

alexblack commented 8 years ago

I tried this out, works great, got me about 1.4x speed improvement on my code with rate=4

alexblack commented 8 years ago

When I take out that extra MAVConnection proxy (that enables shot manager), then, cpu usage is much better, but not great:

tizianofiorenzani commented 6 years ago

I am facing the very same issue. Setting rate=10 caused my script to slow down so much it was not real time anymore