3
3
-- Reset the mission0.txt if AUX is high for more than 3 seconds
4
4
-- Prevents mission change if the vehicle is in AUTO mode
5
5
-- Prevents the script from loading if the vehicle is in AUTO
6
+ -- For each loaded mission it also shows the number of events it contains
6
7
7
8
local MAV_SEVERITY = {EMERGENCY = 0 , ALERT = 1 , CRITICAL = 2 , ERROR = 3 , WARNING = 4 , NOTICE = 5 , INFO = 6 , DEBUG = 7 }
8
9
local rc_switch = rc :find_channel_for_option (24 )
9
10
10
11
if not rc_switch then
11
- gcs :send_text (MAV_SEVERITY .ERROR , " Mission Reset switch not assigned" )
12
+ gcs :send_text (MAV_SEVERITY .ERROR , " Mission Reset switch not right assigned" )
12
13
return
13
14
end
14
15
16
+ local vehicle_type
15
17
local vehicle_fw_type = FWVersion :type ()
16
18
17
- local vehicle_type
18
- if vehicle_fw_type == 1 then
19
- vehicle_type = " Rover"
20
- elseif vehicle_fw_type == 2 then
21
- vehicle_type = " Copter"
22
- elseif vehicle_fw_type == 3 then
19
+ if vehicle_fw_type == 3 then
23
20
vehicle_type = " Plane"
21
+ elseif vehicle_fw_type == 2 then
22
+ vehicle_type = " Rover"
24
23
elseif vehicle_fw_type == 4 then
25
- vehicle_type = " Tracker "
24
+ vehicle_type = " Copter "
26
25
elseif vehicle_fw_type == 5 then
27
26
vehicle_type = " Submarine"
27
+ elseif vehicle_fw_type == 10 then
28
+ vehicle_type = " Tracker"
28
29
else
29
30
gcs :send_text (MAV_SEVERITY .ERROR , " Unrecognized vehicle type!" )
30
31
return
@@ -41,8 +42,18 @@ elseif vehicle_type == "Rover" then
41
42
mode_auto = 10
42
43
elseif vehicle_type == " Submarine" then
43
44
mode_auto = 10
45
+ elseif vehicle_type == " Helicopter" then
46
+ mode_auto = 3
44
47
elseif vehicle_type == " Tracker" then
45
48
mode_auto = 10
49
+ elseif vehicle_type == " Sailboat" then
50
+ mode_auto = 3
51
+ elseif vehicle_type == " Car" then
52
+ mode_auto = 10
53
+ elseif vehicle_type == " Boat" then
54
+ mode_auto = 3
55
+ elseif vehicle_type == " VTOL" then
56
+ mode_auto = 10
46
57
else
47
58
return
48
59
end
@@ -74,39 +85,45 @@ local function read_mission(file_name)
74
85
75
86
local item = mavlink_mission_item_int_t ()
76
87
local index = 0
88
+ local last_event = nil
77
89
78
90
while true do
91
+ local line = file :read (' l' )
92
+ if not line then break end
93
+ if string.match (line , ' ^%s*$' ) == nil then
94
+ last_event = line
95
+ end
79
96
local data = {}
80
- for i = 1 , 12 do
81
- data [i ] = file :read (' n' )
82
- if data [i ] == nil then
83
- if i == 1 then
84
- file :close ()
85
- return true
86
- else
87
- mission :clear ()
88
- error (' Failed to read file: premature end of data' )
89
- end
97
+ for number in string.gmatch (line , " [^%s]+" ) do
98
+ table.insert (data , tonumber (number ))
99
+ end
100
+ if # data >= 12 then
101
+ item :seq (data [1 ])
102
+ item :frame (data [3 ])
103
+ item :command (data [4 ])
104
+ item :param1 (data [5 ])
105
+ item :param2 (data [6 ])
106
+ item :param3 (data [7 ])
107
+ item :param4 (data [8 ])
108
+ item :x (data [9 ] * 10 ^ 7 )
109
+ item :y (data [10 ] * 10 ^ 7 )
110
+ item :z (data [11 ])
111
+ if not mission :set_item (index , item ) then
112
+ mission :clear ()
113
+ error (string.format (' Failed to set mission item %i' , index ))
90
114
end
115
+ index = index + 1
91
116
end
117
+ end
118
+ file :close ()
92
119
93
- item :seq (data [1 ])
94
- item :frame (data [3 ])
95
- item :command (data [4 ])
96
- item :param1 (data [5 ])
97
- item :param2 (data [6 ])
98
- item :param3 (data [7 ])
99
- item :param4 (data [8 ])
100
- item :x (data [9 ] * 10 ^ 7 )
101
- item :y (data [10 ] * 10 ^ 7 )
102
- item :z (data [11 ])
103
-
104
- if not mission :set_item (index , item ) then
105
- mission :clear ()
106
- error (string.format (' Failed to set mission item %i' , index ))
107
- end
108
- index = index + 1
120
+ if last_event then
121
+ local first_number = tonumber (string.match (last_event , " ^%d+" ))
122
+ gcs :send_text (MAV_SEVERITY .WARNING , " Loaded " .. file_name .. " with " .. tostring (first_number ) .. " events" )
123
+ else
124
+ gcs :send_text (MAV_SEVERITY .WARNING , " Loaded " .. file_name .. " with 0 events" )
109
125
end
126
+ return true
110
127
end
111
128
112
129
if not read_mission (" mission0.txt" ) then
@@ -128,7 +145,6 @@ local function load_next_mission()
128
145
if file then
129
146
file :close ()
130
147
if read_mission (file_name ) then
131
- gcs :send_text (MAV_SEVERITY .WARNING , " Loaded mission: " .. file_name )
132
148
return
133
149
end
134
150
end
@@ -163,5 +179,4 @@ function update()
163
179
end
164
180
165
181
gcs :send_text (MAV_SEVERITY .NOTICE , " Mission Rotation loaded" )
166
- gcs :send_text (MAV_SEVERITY .NOTICE , " Loaded default mission: mission0.txt" )
167
182
return update , 1000
0 commit comments