mirror of https://github.com/ArduPilot/ardupilot
AP_Scripting: add bindings for fence
This commit is contained in:
parent
ff3925a0fd
commit
ae2ab08b1f
|
@ -3032,3 +3032,19 @@ function mavlink:send_chan(chan, msgid, message) end
|
|||
-- Block a given MAV_CMD from being procceced by ArduPilot
|
||||
---@param comand_id integer
|
||||
function mavlink:block_command(comand_id) end
|
||||
|
||||
-- Geofence library
|
||||
---@class fence
|
||||
fence = {}
|
||||
|
||||
-- Returns the time at which the current breach started
|
||||
---@return uint32_t_ud system_time milliseconds
|
||||
function fence:get_breach_time() end
|
||||
|
||||
-- Returns the type bitmask of any breached fences
|
||||
---@return integer fence_type bitmask
|
||||
---| 1 # Maximim altitude
|
||||
---| 2 # Circle
|
||||
---| 4 # Polygon
|
||||
---| 8 # Minimum altitude
|
||||
function fence:get_breaches() end
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
-- Example of checking and reporting on geo-fence breach
|
||||
|
||||
local breach_lookup = {
|
||||
[1] = "Maximim altitude",
|
||||
[2] = "Circle",
|
||||
[4] = "Polygon",
|
||||
[8] = "Minimum altitude"
|
||||
}
|
||||
|
||||
-- Lookup brach type bitmask and return the names of any breached fences
|
||||
local function get_breach_names(breaches)
|
||||
local msg = ""
|
||||
for bitmaks, name in pairs(breach_lookup) do
|
||||
if (breaches & bitmaks) ~= 0 then
|
||||
-- And + delimiter between types if more than one
|
||||
if (string.len(msg) > 0) then
|
||||
msg = msg .. " + "
|
||||
end
|
||||
msg = msg .. name
|
||||
end
|
||||
end
|
||||
|
||||
return msg
|
||||
end
|
||||
|
||||
function update()
|
||||
|
||||
local breaches = fence:get_breaches()
|
||||
if breaches ~= 0 then
|
||||
-- Time passed since fence breach
|
||||
local breach_time = millis() - fence:get_breach_time()
|
||||
|
||||
gcs:send_text(0, string.format("Breached: %s fence, outside for %0.2f seconds", get_breach_names(breaches), breach_time:tofloat() * 0.001))
|
||||
end
|
||||
|
||||
return update, 1000
|
||||
end
|
||||
|
||||
return update()
|
|
@ -805,3 +805,10 @@ singleton mavlink manual register_rx_msgid lua_mavlink_register_rx_msgid 1
|
|||
singleton mavlink manual send_chan lua_mavlink_send_chan 3
|
||||
singleton mavlink manual receive_chan lua_mavlink_receive_chan 0
|
||||
singleton mavlink manual block_command lua_mavlink_block_command 1
|
||||
|
||||
include AC_Fence/AC_Fence.h depends AP_FENCE_ENABLED
|
||||
include AC_Fence/AC_Fence_config.h
|
||||
singleton AC_Fence depends AP_FENCE_ENABLED
|
||||
singleton AC_Fence rename fence
|
||||
singleton AC_Fence method get_breaches uint8_t
|
||||
singleton AC_Fence method get_breach_time uint32_t
|
||||
|
|
Loading…
Reference in New Issue