Hi, new to lua scripting in ardupilot,
I have been testing out a small script were i can override my sitl mission plan set altitude which is 100m to 50m.
The code looks like this:
local target_alt = 50 -- in meters
local plane_mode_auto = 10
local set_target = true
function update()
-- gcs:send_text(0, "inside update fn")
if not arming:is_armed() then
set_target = false
-- gcs:send_text(0, "vehicle not armed")
else
-- gcs:send_text(0, "vehicle armed!!")
local mode = vehicle:get_mode()
if (mode == plane_mode_auto) then
-- gcs:send_text(0, "in auto")
local curr_pos = ahrs:get_position()
if curr_pos then
curr_pos:terrain_alt(true)
gcs:send_text(7, string.format("alt: %d", curr_pos:alt()))
if curr_pos:alt() > 5000 then
curr_pos:alt(curr_pos:alt() - (curr_pos:alt() - target_alt*100))
gcs:send_text(6, "above limit")
set_target = vehicle:set_target_location(curr_pos)
gcs:send_text(0, string.format("%s",set_target))
elseif curr_pos:alt() < 5000 then
curr_pos:alt(curr_pos:alt() + (target_alt*100 - curr_pos:alt()))
gcs:send_text(6, "below limit")
set_target = vehicle:set_target_location(curr_pos)
gcs:send_text(0, string.format("%s",set_target))
else
set_target = vehicle:set_target_location(curr_pos)
end
end
end
end
return update, 1000
end
return update, 1000
As i log the set_target variable im getting outputs as “False”, from the docs it means its not getting set
Am I doing something wrong here? Any help would be appreciated