I’m trying to write a Lua script for my copter to land with a fixed horizontal velocity of 3 m/s along the X axis.
I tested it in SITL, but it doesn’t seem to be working as expected.
Can anyone give me some advice or point out what I’m missing?
local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7}
function update()
local mode = vehicle:get_mode()
if mode == 9 then -- MODE_LAND
local vel = Vector2f()
vel:x(3.0)
vel:y(0.0)
vehicle:set_velocity_match(vel)
gcs:send_text(MAV_SEVERITY.INFO,
string.format("LAND mode: set_velocity_match [%.2f, %.2f]", vel:x(), vel:y()))
end
end
gcs:send_text(MAV_SEVERITY.INFO, "Lua Script: loaded")
function protected_wrapper()
local success, err = pcall(update)
if not success then
gcs:send_text(MAV_SEVERITY.ERROR, "Internal Error: " .. err)
return protected_wrapper, 1000
end
return protected_wrapper, 50
end
-- start running update loop
return protected_wrapper()