AP_Scripting: mount-poi gets param description

send_text calls also use MAV_SEVERITY definition
This commit is contained in:
Randy Mackay 2023-04-11 16:30:36 +09:00 committed by Peter Barker
parent bc9342a398
commit c1f9b59d9b

View File

@ -21,6 +21,7 @@
-- luacheck: only 0
-- global definitions
local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7}
local ALT_FRAME_ABSOLUTE = 0
local UPDATE_INTERVAL_MS = 100
@ -29,8 +30,14 @@ local PARAM_TABLE_KEY = 78
assert(param:add_table(PARAM_TABLE_KEY, "POI_", 1), "could not add param table")
assert(param:add_param(PARAM_TABLE_KEY, 1, "DIST_MAX", 10000), "could not add POI_DIST_MAX param")
local poi_dist_max = Parameter()
assert(poi_dist_max:init("POI_DIST_MAX"), "could not find POI_DIST_MAX param")
--[[
// @Param: POI_DIST_MAX
// @DisplayName: Mount POI distance max
// @Description: POI's max distance (in meters) from the vehicle
// @Range: 0 10000
// @User: Standard
--]]
local POI_DIST_MAX = Parameter("POI_DIST_MAX")
-- bind to other parameters this script depends upon
TERRAIN_SPACING = Parameter("TERRAIN_SPACING")
@ -87,7 +94,7 @@ function update()
-- find RC channel used to trigger POI
rc_switch_ch = rc:find_channel_for_option(300) --scripting ch 1
if (rc_switch_ch == nil) then
gcs:send_text(3, 'MountPOI: RCx_OPTION = 300 not set') -- MAV_SEVERITY_ERROR
gcs:send_text(MAV_SEVERITY.ERROR, 'MountPOI: RCx_OPTION = 300 not set') -- MAV_SEVERITY_ERROR
return update, 10000 -- check again in 10 seconds
end
@ -108,7 +115,7 @@ function update()
-- retrieve vehicle location
local vehicle_loc = ahrs:get_location()
if vehicle_loc == nil then
gcs:send_text(3, "POI: vehicle pos unavailable") -- MAV_SEVERITY_ERROR
gcs:send_text(MAV_SEVERITY.ERROR, "POI: vehicle pos unavailable") -- MAV_SEVERITY_ERROR
return update, UPDATE_INTERVAL_MS
end
@ -118,7 +125,7 @@ function update()
-- retrieve gimbal attitude
local roll_deg, pitch_deg, yaw_bf_deg = mount:get_attitude_euler(0)
if pitch_deg == nil or yaw_bf_deg == nil then
gcs:send_text(3, "POI: gimbal attitude unavailable") -- MAV_SEVERITY_ERROR
gcs:send_text(MAV_SEVERITY.ERROR, "POI: gimbal attitude unavailable") -- MAV_SEVERITY_ERROR
return update, UPDATE_INTERVAL_MS
end
@ -133,7 +140,7 @@ function update()
-- fail if terrain alt cannot be retrieved
if terrain_amsl_m == nil then
gcs:send_text(3, "POI: failed to get terrain alt") -- MAV_SEVERITY_ERROR
gcs:send_text(MAV_SEVERITY.ERROR, "POI: failed to get terrain alt") -- MAV_SEVERITY_ERROR
return update, UPDATE_INTERVAL_MS
end
@ -144,7 +151,7 @@ function update()
-- initialise total distance test_loc has moved
local total_dist = 0
local dist_max = poi_dist_max:get()
local dist_max = POI_DIST_MAX:get()
-- iteratively move test_loc forward until its alt-above-sea-level is below terrain-alt-above-sea-level
while (total_dist < dist_max) and ((test_loc:alt() * 0.01) > terrain_amsl_m) do
@ -162,16 +169,16 @@ function update()
-- fail if terrain alt cannot be retrieved
if terrain_amsl_m == nil then
gcs:send_text(3, "POI: failed to get terrain alt") -- MAV_SEVERITY_ERROR
gcs:send_text(MAV_SEVERITY.ERROR, "POI: failed to get terrain alt") -- MAV_SEVERITY_ERROR
return update, UPDATE_INTERVAL_MS
end
end
-- check for errors
if (total_dist >= dist_max) then
gcs:send_text(3, "POI: unable to find terrain within " .. tostring(dist_max) .. " m")
gcs:send_text(MAV_SEVERITY.ERROR, "POI: unable to find terrain within " .. tostring(dist_max) .. " m")
elseif not terrain_amsl_m then
gcs:send_text(3, "POI: failed to retrieve terrain alt")
gcs:send_text(MAV_SEVERITY.ERROR, "POI: failed to retrieve terrain alt")
else
-- test location has dropped below terrain
-- interpolate along line between prev_test_loc and test_loc
@ -179,7 +186,7 @@ function update()
local poi_loc = prev_test_loc:copy()
poi_loc:offset_bearing_and_pitch(mount_yaw_ef_deg, mount_pitch_deg, dist_interp_m)
local poi_terr_asml_m = terrain:height_amsl(poi_loc, true)
gcs:send_text(6, string.format("POI %.7f, %.7f, %.2f (asml)", poi_loc:lat()/10000000.0, poi_loc:lng()/10000000.0, poi_loc:alt() * 0.01))
gcs:send_text(MAV_SEVERITY.INFO, string.format("POI %.7f, %.7f, %.2f (asml)", poi_loc:lat()/10000000.0, poi_loc:lng()/10000000.0, poi_loc:alt() * 0.01))
end
return update, UPDATE_INTERVAL_MS