Lua Script Test: Setting Horizontal Velocity During LAND Mode

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()

On a quick look it looks like only plane supports velocity match.

You would need to port the binding to copter.

Thank you for your response.

Could you please show me how to check whether only Plane supports velocity matching?

And I’m wondering if, when binding to Copter, we can implement it ourselves or if we need help from the developers?

I looked up the function on GitHub.

It does not look like it should be terribly complicated.

1 Like

you can look at AP_Vehicle/AP_Vehicle.h in github

// allow for VTOL velocity matching of a target
virtual bool set_velocity_match(const Vector2f &velocity) { return false; }

1 Like

Thank you @LupusTheCanine @PMTAug

Is there any way to make vehicle:set_velocity_match(vel) work on Copter?

I’m currently operating on a ship, so I already have a beacon system for VTOL. I’d like to use the same setup for Copter since I don’t necessarily need high precision.

However, during takeoff and landing, I’m not sure how to make the copter match the ship’s velocity in these two phases.