-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_Scripting: added gcs:run_command_int() binding
- Loading branch information
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--[[ | ||
demonstrate using the gcs:command_int() interface to send commands from MAVLink MAV_CMD_xxx set | ||
--]] | ||
|
||
local MAV_FRAME_GLOBAL_RELATIVE_ALT = 3 | ||
|
||
local MAV_CMD_DO_SET_MODE = 176 | ||
local MAV_CMD_DO_REPOSITION = 192 | ||
|
||
-- some plane flight modes for testing | ||
local MODE_LOITER = 12 | ||
local MODE_GUIDED = 15 | ||
|
||
local MAV_MODE_FLAG_CUSTOM_MODE_ENABLED = 1 | ||
|
||
--[[ | ||
create a NaN value | ||
--]] | ||
local function NaN() | ||
return 0/0 | ||
end | ||
|
||
--[[ | ||
test API calls. When in LOITER mode change to GUIDED and force flying to a location NE of home | ||
--]] | ||
local function test_command_int() | ||
if vehicle:get_mode() ~= MODE_LOITER then | ||
return | ||
end | ||
local home = ahrs:get_home() | ||
if not home then | ||
return | ||
end | ||
|
||
-- force mode GUIDED | ||
gcs:run_command_int(MAV_CMD_DO_SET_MODE, { p1 = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, p2 = MODE_GUIDED }) | ||
|
||
-- and fly to 200m NE of home and 100m above home | ||
local dest = home:copy() | ||
dest:offset_bearing(45, 200) | ||
|
||
gcs:run_command_int(MAV_CMD_DO_REPOSITION, { frame = MAV_FRAME_GLOBAL_RELATIVE_ALT, | ||
p1 = -1, | ||
p4 = NaN(), | ||
x = dest:lat(), | ||
y = dest:lng(), | ||
z = 100 }) | ||
end | ||
|
||
local function update() | ||
test_command_int() | ||
return update, 1000 | ||
end | ||
|
||
return update, 1000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters