-
Notifications
You must be signed in to change notification settings - Fork 16.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_AHRS: set location implementation
- Loading branch information
Showing
15 changed files
with
284 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
-- Example of receiving MAVLink commands | ||
|
||
local mavlink_msgs = require("MAVLink/mavlink_msgs") | ||
|
||
local COMMAND_ACK_ID = mavlink_msgs.get_msgid("COMMAND_ACK") | ||
local COMMAND_LONG_ID = mavlink_msgs.get_msgid("COMMAND_LONG") | ||
|
||
local msg_map = {} | ||
msg_map[COMMAND_ACK_ID] = "COMMAND_ACK" | ||
msg_map[COMMAND_LONG_ID] = "COMMAND_LONG" | ||
|
||
-- initialize MAVLink rx with number of messages, and buffer depth | ||
mavlink:init(1, 10) | ||
|
||
-- register message id to receive | ||
mavlink:register_rx_msgid(COMMAND_LONG_ID) | ||
|
||
local MAV_CMD_USER_1 = 31010 | ||
local MAV_CMD_DO_YOU_ARE_HERE = MAV_CMD_USER_1 | ||
|
||
function handle_command_long(cmd) | ||
if (cmd.command == MAV_CMD_DO_YOU_ARE_HERE) then | ||
if cmd.param5 == 0 or cmd.param6 == 0 { | ||
return 2 -- MAV_RESULT_DENIED | ||
} | ||
local new_ahrs_location | ||
if cmd.param7 == 0 { | ||
new_ahrs_location = ahrs:get_location() | ||
} else { | ||
new_ahrs_location = Location() | ||
new_ahrs_location:alt(math.floor(cmd.param7*100)) | ||
} | ||
if new_ahrs_location ~= nil then | ||
new_ahrs_location:lat(math.floor(cmd.param5*1.0e7)) | ||
new_ahrs_location:lng(math.floor(cmd.param6*1.0e7)) | ||
return 0 -- MAV_RESULT_ACCEPTED | ||
end | ||
return 4 -- MAV_RESULT_FAILED | ||
end | ||
return nil | ||
end | ||
|
||
function update() | ||
local msg, chan = mavlink:receive_chan() | ||
if (msg ~= nil) then | ||
local parsed_msg = mavlink_msgs.decode(msg, msg_map) | ||
if (parsed_msg ~= nil) then | ||
|
||
local result | ||
if parsed_msg.msgid == COMMAND_LONG_ID then | ||
result = handle_command_long(parsed_msg) | ||
end | ||
|
||
if (result ~= nil) then | ||
-- Send ack if the command is one were intrested in | ||
local ack = {} | ||
ack.command = parsed_msg.command | ||
ack.result = result | ||
ack.progress = 0 | ||
ack.result_param2 = 0 | ||
ack.target_system = parsed_msg.sysid | ||
ack.target_component = parsed_msg.compid | ||
|
||
mavlink:send_chan(chan, mavlink_msgs.encode("COMMAND_ACK", ack)) | ||
end | ||
end | ||
end | ||
|
||
return update, 1000 | ||
end | ||
|
||
return update() |
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