Issue with FOLLOW object in Lua script for rover to follow copter

Hello,

I am trying to write a Lua script for my rover to FOLLOW a flying copter. My copter SYSID = 12, and I set rover FOLL_SYSID = 12. Here is a part of my current code:

-- check key parameters
function check_parameters()
    --[[ 
       parameter values which are auto-set on startup
    --]]
    local key_params = {
        FOLL_ENABLE = 1,
        FOLL_OFS_TYPE = 1,
    }

    for p, v in pairs(key_params) do
        local current = param:get(p)
        assert(current, string.format("Parameter %s not found", p))
        if math.abs(v - current) > 0.001 then
            param:set_and_save(p, v)
            gcs:send_text(MAV_SEVERITY.INFO, string.format("Parameter %s set to %.2f was %.2f", p, v, current))
        end
    end
end

-- update target position and velocity
function update_target()
    if not follow:have_target() then
        if have_target then
            gcs:send_text(MAV_SEVERITY.WARNING, "No target")
            arming:set_aux_auth_failed(auth_id, "Follow: no target")
        end
        have_target = false
        return
    end
    if not have_target then
        gcs:send_text(MAV_SEVERITY.INFO, "Have target")
        arming:set_aux_auth_passed(auth_id)
    end
    have_target = true

    target_pos, target_velocity = follow:get_target_location_and_velocity_ofs()
end

However, I am getting the following error:

3/12/2025 5:53:35 PM : Internal Error: ./scripts/servo.lua:134: attempt to index a nil value (global 'follow')

How do I properly initialize the follow object for the rover to follow the flying copter? Or Is there a specific setup or configuration required to enable the follow functionality in ArduPilot Lua scripting?

I would appreciate any advice or suggestions to resolve this issue.
Thank you in advance!

For a reason unknown to me, the devs have chosen to limit the follow binding to Copter or Plane.

@rmackay9 could perhaps elaborate on the rationale.

I don’t think it’d be problematic to simply enable the binding for Rover, but you’d need to set up a build environment and make the change yourself unless Randy or another dev see fit to enable the follow binding for Rover.

See here for the source:

1 Like

@Yuri_Rage Thanks for your response! I’d love to hear from other developers about why the ‘follow’ feature isn’t supported for Rover in Lua scripts, or if there’s a way to modify it to make it work more easily.

Thanks @Yuri_Rage for the investigation.

I don’t think that there’s any reason why we can’t enable this for Rover so I think it’s just a small change to add Rover to that list of available vehicles.

I could raise a PR to change that or anyone else could as well I think

P.S. I’ve moved this to the Rover-4.6 category instead of “General”

@PMTAug,

I’ve created a PR that enables the Follow bindings for Rovers and Boats.

If you’d like a firmware to test with please tell me which autopilot you’re using.

BTW, any reason to not simply use Rover’s Follow mode?

Thanks for the testing and feedback!

Hello @rmackay9,

Thank you so much for your work! I’m currently using firmware version 4.5.7.

The reason I didn’t use Rover’s Follow mode is that I want the rover to move to a point calculated by optimizing the positions of several copters. To achieve this, I use a Lua script for control. Following a flying copter is simply a test case to validate the Lua script.

Thanks again for your support!

1 Like