Parsing a MAVLink message in a lua script

I am attempting to use a Lua script to interpret fields from a MANUAL_CONTROL message, but it appears that there isn’t a built-in binding to parse the mavlink msg received from
msg, chan = mavlink:receive_chan()
msg is a string and I haven’t found a decode method.

Is this the current state of the art to parse MAVLink messages in Lua scripts right now?

Or, is there a cleaner approach that I haven’t found?

This approach looked promising, but Lua can’t find the “MAVLink/mavlink_msgs” module.

After experimenting more and rummaging around the Lua module, I discovered that I need to generate Lua parses for the messages using pymavlink and then put the MAVLink module in the Lua module on my sdcard in the scripts/modules/MAVLink. Then I was able to use:

local mavlink_msgs = require(“MAVLink/mavlink_msgs”)
functions update()
local msg, chan = mavlink:receive_chan()
if msg then
local parsed_msg = mavlink_msgs.decode(msg, msg_map)
– if (parsed_msg ~= nil) then
local id = parsed_msg.msgid

1 Like

Hi @rrr6399,

Thanks for the post. Yes, it’s a bit difficult to get a Lua script parsing a new message especially because we only have a few of the message definitions in this directory.

I have considered filling up that directory with every message AP supports to remove the need for people to generate them themselves.

Perhaps we should have more documentation about parting mavlink with lua on our Lua wiki page.