Skip to content

Commit 083c7ad

Browse files
committed
AP_Scripting: Update rockblock and MAVLinkHL with gcs:run_command and MISSION_SET_CURRENT
1 parent aeeef36 commit 083c7ad

2 files changed

Lines changed: 50 additions & 96 deletions

File tree

libraries/AP_Scripting/applets/RockBlock.lua

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ local function MAVLinkProcessor()
102102
COMMAND_INT = 75,
103103
HIGH_LATENCY2 = 235,
104104
MISSION_ITEM_INT = 73,
105-
SET_MODE = 11
105+
SET_MODE = 11,
106+
MISSION_SET_CURRENT = 41
106107
}
107108

108109
-- private fields
@@ -121,6 +122,7 @@ local function MAVLinkProcessor()
121122
_crc_extra[235] = 0xb3
122123
_crc_extra[73] = 0x26
123124
_crc_extra[11] = 0x59
125+
_crc_extra[41] = 0x1c
124126

125127
local _messages = {}
126128
_messages[75] = { -- COMMAND_INT
@@ -156,6 +158,9 @@ local function MAVLinkProcessor()
156158
_messages[11] = { -- SET_MODE
157159
{ "custom_mode", "<I4" }, { "target_system", "<B" }, { "base_mode", "<B" },
158160
}
161+
_messages[41] = { -- MISSION_SET_CURRENT
162+
{ "seq", "<I2" }, { "target_system", "<B" }, { "target_component", "<B" },
163+
}
159164
function self.getSeqID() return _txseqid end
160165

161166
function self.generateCRC(buffer)
@@ -269,53 +274,25 @@ local function MAVLinkProcessor()
269274
end
270275
elseif _mavresult.msgid == self.SET_MODE then
271276
vehicle:set_mode(_mavresult.custom_mode)
272-
elseif _mavresult.msgid == self.COMMAND_LONG or _mavresult.msgid ==
273-
self.COMMAND_INT then
274-
if _mavresult.command == 400 then -- MAV_CMD_COMPONENT_ARM_DISARM
275-
if _mavresult.param1 == 1 then
276-
arming:arm()
277-
elseif _mavresult.param1 == 0 then
278-
arming:disarm()
279-
end
280-
elseif _mavresult.command == 176 then -- MAV_CMD_DO_SET_MODE
281-
vehicle:set_mode(_mavresult.param2)
282-
elseif _mavresult.command == 20 then -- MAV_CMD_NAV_RETURN_TO_LAUNCH (Mode RTL) may vary depending on frame
283-
if FWVersion:type() == 2 then -- copter
284-
vehicle:set_mode(6)
285-
elseif FWVersion:type() == 3 then -- plane
286-
vehicle:set_mode(11)
287-
elseif FWVersion:type() == 1 then -- rover
288-
vehicle:set_mode(11)
289-
end
290-
elseif _mavresult.command == 21 then -- MAV_CMD_NAV_LAND (Mode LAND) may vary depending on frame
291-
if FWVersion:type() == 2 then -- copter
292-
vehicle:set_mode(9)
293-
elseif FWVersion:type() == 12 then -- blimp
294-
vehicle:set_mode(0)
295-
end
296-
elseif _mavresult.command == 22 then -- MAV_CMD_NAV_TAKEOFF
297-
vehicle:start_takeoff(_mavresult.param7)
298-
elseif _mavresult.command == 84 then -- MAV_CMD_NAV_VTOL_TAKEOFF
299-
vehicle:start_takeoff(_mavresult.param7)
300-
elseif _mavresult.command == 85 then -- MAV_CMD_NAV_VTOL_LAND (Mode QLAND)
301-
vehicle:set_mode(20)
302-
elseif _mavresult.command == 300 then -- MAV_CMD_MISSION_START --mode auto and then start mission
303-
if FWVersion:type() == 2 then -- copter
304-
vehicle:set_mode(3)
305-
elseif FWVersion:type() == 3 then -- plane
306-
vehicle:set_mode(10)
307-
elseif FWVersion:type() == 1 then -- rover
308-
vehicle:set_mode(10)
309-
elseif FWVersion:type() == 7 then -- sub
310-
vehicle:set_mode(3)
311-
end
312-
elseif _mavresult.command == 2600 then -- MAV_CMD_CONTROL_HIGH_LATENCY
313-
if _mavresult.param1 == 1 then
314-
gcs:enable_high_latency_connections(true)
315-
else
316-
gcs:enable_high_latency_connections(false)
317-
end
318-
end
277+
elseif _mavresult.msgid == self.COMMAND_LONG then
278+
gcs:run_command_long(_mavresult.command, { p1 = _mavresult.param1,
279+
p2 = _mavresult.param2,
280+
p3 = _mavresult.param3,
281+
p4 = _mavresult.param4,
282+
p5 = _mavresult.param5,
283+
p6 = _mavresult.param6,
284+
p7 = _mavresult.param7})
285+
elseif _mavresult.msgid == self.COMMAND_INT then
286+
gcs:run_command_int(_mavresult.command, { p1 = _mavresult.param1,
287+
p2 = _mavresult.param2,
288+
p3 = _mavresult.param3,
289+
p4 = _mavresult.param4,
290+
x = _mavresult.x,
291+
y = _mavresult.y,
292+
z = _mavresult.z,
293+
frame = _mavresult.frame })
294+
elseif _mavresult.msgid == self.MISSION_SET_CURRENT then
295+
mission:set_current_cmd(_mavresult.seq)
319296
end
320297
_mavbuffer = ""
321298
return true

libraries/AP_Scripting/examples/MAVLinkHL.lua

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ local function MAVLinkProcessor()
4848
COMMAND_INT = 75,
4949
HIGH_LATENCY2 = 235,
5050
MISSION_ITEM_INT = 73,
51-
SET_MODE = 11
51+
SET_MODE = 11,
52+
MISSION_SET_CURRENT = 41
5253
}
5354

5455
-- private fields
@@ -67,6 +68,7 @@ local function MAVLinkProcessor()
6768
_crc_extra[235] = 0xb3
6869
_crc_extra[73] = 0x26
6970
_crc_extra[11] = 0x59
71+
_crc_extra[41] = 0x1c
7072

7173
local _messages = {}
7274
_messages[75] = { -- COMMAND_INT
@@ -102,6 +104,9 @@ local function MAVLinkProcessor()
102104
_messages[11] = { -- SET_MODE
103105
{ "custom_mode", "<I4" }, { "target_system", "<B" }, { "base_mode", "<B" },
104106
}
107+
_messages[41] = { -- MISSION_SET_CURRENT
108+
{ "seq", "<I2" }, { "target_system", "<B" }, { "target_component", "<B" },
109+
}
105110
function self.getSeqID() return _txseqid end
106111

107112
function self.generateCRC(buffer)
@@ -216,53 +221,25 @@ local function MAVLinkProcessor()
216221
end
217222
elseif _mavresult.msgid == self.SET_MODE then
218223
vehicle:set_mode(_mavresult.custom_mode)
219-
elseif _mavresult.msgid == self.COMMAND_LONG or _mavresult.msgid ==
220-
self.COMMAND_INT then
221-
if _mavresult.command == 400 then -- MAV_CMD_COMPONENT_ARM_DISARM
222-
if _mavresult.param1 == 1 then
223-
arming:arm()
224-
elseif _mavresult.param1 == 0 then
225-
arming:disarm()
226-
end
227-
elseif _mavresult.command == 176 then -- MAV_CMD_DO_SET_MODE
228-
vehicle:set_mode(_mavresult.param2)
229-
elseif _mavresult.command == 20 then -- MAV_CMD_NAV_RETURN_TO_LAUNCH (Mode RTL) may vary depending on frame
230-
if FWVersion:type() == 2 then -- copter
231-
vehicle:set_mode(6)
232-
elseif FWVersion:type() == 3 then -- plane
233-
vehicle:set_mode(11)
234-
elseif FWVersion:type() == 1 then -- rover
235-
vehicle:set_mode(11)
236-
end
237-
elseif _mavresult.command == 21 then -- MAV_CMD_NAV_LAND (Mode LAND) may vary depending on frame
238-
if FWVersion:type() == 2 then -- copter
239-
vehicle:set_mode(9)
240-
elseif FWVersion:type() == 12 then -- blimp
241-
vehicle:set_mode(0)
242-
end
243-
elseif _mavresult.command == 22 then -- MAV_CMD_NAV_TAKEOFF
244-
vehicle:start_takeoff(_mavresult.param7)
245-
elseif _mavresult.command == 84 then -- MAV_CMD_NAV_VTOL_TAKEOFF
246-
vehicle:start_takeoff(_mavresult.param7)
247-
elseif _mavresult.command == 85 then -- MAV_CMD_NAV_VTOL_LAND (Mode QLAND)
248-
vehicle:set_mode(20)
249-
elseif _mavresult.command == 300 then -- MAV_CMD_MISSION_START --mode auto and then start mission
250-
if FWVersion:type() == 2 then -- copter
251-
vehicle:set_mode(3)
252-
elseif FWVersion:type() == 3 then -- plane
253-
vehicle:set_mode(10)
254-
elseif FWVersion:type() == 1 then -- rover
255-
vehicle:set_mode(10)
256-
elseif FWVersion:type() == 7 then -- sub
257-
vehicle:set_mode(3)
258-
end
259-
elseif _mavresult.command == 2600 then -- MAV_CMD_CONTROL_HIGH_LATENCY
260-
if _mavresult.param1 == 1 then
261-
gcs:enable_high_latency_connections(true)
262-
else
263-
gcs:enable_high_latency_connections(false)
264-
end
265-
end
224+
elseif _mavresult.msgid == self.COMMAND_LONG then
225+
gcs:run_command_long(_mavresult.command, { p1 = _mavresult.param1,
226+
p2 = _mavresult.param2,
227+
p3 = _mavresult.param3,
228+
p4 = _mavresult.param4,
229+
p5 = _mavresult.param5,
230+
p6 = _mavresult.param6,
231+
p7 = _mavresult.param7})
232+
elseif _mavresult.msgid == self.COMMAND_INT then
233+
gcs:run_command_int(_mavresult.command, { p1 = _mavresult.param1,
234+
p2 = _mavresult.param2,
235+
p3 = _mavresult.param3,
236+
p4 = _mavresult.param4,
237+
x = _mavresult.x,
238+
y = _mavresult.y,
239+
z = _mavresult.z,
240+
frame = _mavresult.frame })
241+
elseif _mavresult.msgid == self.MISSION_SET_CURRENT then
242+
mission:set_current_cmd(_mavresult.seq)
266243
end
267244
_mavbuffer = ""
268245
return true

0 commit comments

Comments
 (0)