Mavlink commands in Python -- examples?

2,597 views
Skip to first unread message

Brandon Doyle

unread,
Apr 12, 2016, 5:02:42 PM4/12/16
to MAVLink
I've found a number of example scripts, but I still don't understand the module, namely mavlink, and its relation to pymavlink therein (actually, is the latter even necessary)?

https://www.samba.org/tridge/UAV/pymavlink/unpacked/examples/mavtest.py
https://www.samba.org/tridge/UAV/pymavlink/unpacked/examples/mavlogdump.py

I think I have a very decent understanding of Python, but not C++ or other languages. I was hoping to be able to do various things with Python by importing this module and not have to worry about these other languages. But I can't really find any documentation on this, or for that matter scripts that do basic things.

I guess I'm looking for a starting point -- where can I go to try and understand this module with Python?

Thank you for your time,
Brandon

x75

unread,
Apr 13, 2016, 4:31:55 PM4/13/16
to MAVLink
hi, last time i used it, it went something like this, here it's done for the blob type but it works the same for other types, maybe that helps.

import mavutil
import mavlinkv10 as mavlink

# receiving
mavs = mavutil.mavlink_connection("udp:127.0.0.1:17779", input=True, source_system=self.sysid)

msg = mavs.recv_msg()

if msg.get_msgId() == mavlink.MAVLINK_MSG_ID_DATA16:
    print "data16", np.fromstring(msg.data, dtype=np.float32)


# sending

mavs = mavutil.mavlink_connection("udp:127.0.0.1:17779", input=False, source_system=39)

z = np.array(np.random.uniform(low=0, high=1, size=4), dtype=np.float32)
mavs.mav.data16_send(1, 20, z.tostring())

bst

Brandon Doyle

unread,
May 8, 2016, 10:41:30 AM5/8/16
to MAVLink
Thanks for this! I will give it a try tomorrow. I have found mavlinkv10 and mavutil (I was trying to figure them out yesterday), I'm staring at the code right now as a matter of fact :P I hope we're able to get this working.

Hamish Willee

unread,
May 9, 2016, 6:37:33 PM5/9/16
to MAVLink
Brandon, perhaps a better place for you to start might be: http://python.dronekit.io/

This builds on the PyMavlink libraries. It provides some simple abstractions for common messages, but you can still use it to send and receive custom message types.

Brandon Doyle

unread,
May 10, 2016, 4:54:41 PM5/10/16
to MAVLink
I was able to use this library and get the data I needed, e.g.

Attitude:pitch=-0.0132492221892, yaw=-0.677243292332,roll=-0.148220390081

and it changes as I move around while putting it in a loop. I have yet to plug in a GPS sensor and try those data.
Reply all
Reply to author
Forward
0 new messages