Skip to content

Commit

Permalink
Update MissionRotation.lua
Browse files Browse the repository at this point in the history
Fixed issue that sent duplicate mission change messages.
  • Loading branch information
robustini authored Dec 2, 2024
1 parent 4c108b1 commit 8186d84
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions libraries/AP_Scripting/applets/MissionRotation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7}
local rc_switch = rc:find_channel_for_option(24)

if not rc_switch then
gcs:send_text(MAV_SEVERITY.ERROR, "Mission Reset switch not assigned")
return
end

local current_mission_index = 0
local max_missions = 9
local max_missions = 6 -- Aggiornato a 6 poiché hai fino a mission6.txt
local high_timer = 0
local latest_mission_loaded = -1 -- Track the last loaded mission

local function read_mission(file_name)
if vehicle:get_mode() == 3 then
Expand Down Expand Up @@ -43,7 +45,6 @@ local function read_mission(file_name)
data[i] = file:read('n')
if data[i] == nil then
if i == 1 then
gcs:send_text(MAV_SEVERITY.WARNING, "Loaded mission: " .. file_name)
file:close()
return true
else
Expand Down Expand Up @@ -78,14 +79,14 @@ 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
gcs:send_text(MAV_SEVERITY.WARNING, "Loaded mission: " .. file_name)
if latest_mission_loaded ~= current_mission_index then
gcs:send_text(MAV_SEVERITY.WARNING, "Loaded mission: " .. file_name)
latest_mission_loaded = current_mission_index
end
end
end

Expand All @@ -105,11 +106,11 @@ function update()
end
else
if high_timer > 0 and high_timer < 3 then
load_next_mission()
load_next_mission() -- Load next mission if switched back before 3 seconds
end
high_timer = 0
end

return update, 1000
end

Expand Down

0 comments on commit 8186d84

Please sign in to comment.