Skip to content

Commit

Permalink
Update MissionRotation.lua
Browse files Browse the repository at this point in the history
If a mission switch is attempted in AUTO flight mode, a warning “Could not clear current mission” will be shown and no operation will be performed.
  • Loading branch information
robustini authored Dec 2, 2024
1 parent a5e5eef commit 526f336
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions libraries/AP_Scripting/applets/MissionRotation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ local max_missions = 9
local high_timer = 0

local function read_mission(file_name)
if vehicle:get_mode() == 10 then -- 10 = AUTO mode
gcs:send_text(MAV_SEVERITY.ERROR, "Cannot load mission in AUTO mode")
if vehicle:get_mode() == 3 then
return false
end

Expand All @@ -26,7 +25,14 @@ local function read_mission(file_name)

local header = file:read('l')
assert(string.find(header, 'QGC WPL 110') == 1, file_name .. ': incorrect format')
assert(mission:clear(), 'Could not clear current mission')

if vehicle:get_mode() ~= 3 then
if not mission:clear() then
gcs:send_text(MAV_SEVERITY.ERROR, "Could not clear current mission")
file:close()
return false
end
end

local item = mavlink_mission_item_int_t()
local index = 0
Expand Down Expand Up @@ -72,6 +78,10 @@ if not read_mission("mission0.txt") then
end

local function load_next_mission()
if vehicle:get_mode() == 3 then
return
end

current_mission_index = (current_mission_index + 1) % (max_missions + 1)
local file_name = string.format("mission%d.txt", current_mission_index)
if read_mission(file_name) then
Expand All @@ -85,9 +95,12 @@ function update()
if sw_pos == 2 then
high_timer = high_timer + 1
if high_timer >= 3 then
current_mission_index = 0
read_mission("mission0.txt")
gcs:send_text(MAV_SEVERITY.WARNING, "Reset to mission0.txt")
if vehicle:get_mode() ~= 3 then
current_mission_index = 0
if read_mission("mission0.txt") then
gcs:send_text(MAV_SEVERITY.WARNING, "Reset to mission0.txt")
end
end
high_timer = 0
end
else
Expand Down

0 comments on commit 526f336

Please sign in to comment.