-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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:command_int() binding
- Loading branch information
Showing
5 changed files
with
122 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,48 @@ | ||
--[[ | ||
demonstrate using the gcs:command_int() interface to send commands from MAVLink MAV_CMD_xxx set | ||
--]] | ||
|
||
local MAV_FRAME_GLOBAL = 0 | ||
|
||
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 | ||
|
||
--[[ | ||
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:command_int(MAV_FRAME_GLOBAL, MAV_CMD_DO_SET_MODE, { MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, MODE_GUIDED }) | ||
|
||
-- and fly to 200m NE of home and 100m above home | ||
local dest = home:copy() | ||
dest:offset_bearing(45, 200) | ||
dest:alt(home:alt()+100*100) | ||
|
||
gcs:command_int(MAV_FRAME_GLOBAL, MAV_CMD_DO_REPOSITION, { -1, 0, 0, 0, | ||
x = dest:lat(), | ||
y = dest:lng(), | ||
z = dest:alt()*0.01 }) | ||
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