Is it possible to send MAVLink messages through lua scripts?

Hello guys, i’m doing a project that i need my rover to move forward until a certain point is reached, and then, go in reverse without turning 180 degrees. I saw some simillar projects that use the DO_SET_REVERSE command. Is it possible to use this command in GUIDED mode and send the MAVLink message to use this function using a lua script?

Thanks in advance!

Hi @gsouza ! Do_Set_Reverse works in auto mode but I don’t think it works in guided mode.

Anyway, here’s an example lua script to send mavlink message with COMMAND_LONG using lua:

Just copy ardupilot/libraries/AP_Scripting/modules to your scripts folder

local mavlink_msgs = require("MAVLink/mavlink_msgs")

local MAV_MSG = <Command ID>  -- Command ID for Mavlink message, set it to '194' for DO_SET_REVERSE
local MAVLINK_CHANNEL = 0

local function send_command()
    -- example param
    local param1 = 0
    local message = mavlink_msgs.encode("COMMAND_LONG", {
        target_system = 1,        -- Target system
        target_component = 1,     -- Target component
        command = MAV_MSG,        -- MAVLink command ID
        confirmation = 0,         -- 0 for no confirmation
        param1 = param1,
        param2 = 0,
        param3 = 0,
        param4 = 0,
        param5 = 0,
        param6 = 0,
        param7 = 0
    })

    -- Send the message
    local mav_send = mavlink:send_chan(MAVLINK_CHANNEL, 76, message) -- 76 = ID for COMMAND_LONG

end

return send_command()

1 Like

Hey @snktshrma!

I’ve seen this issue right here. I guess i should be able to use this command in guided mode, as i’m using the newest firmware for ArduRover available.

Anyways, i will try to run some tests right here to confirm if this is even possible to use in guided mode.

Thank you so much for the support!

1 Like