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!