Browse Source

AP_Scripting: added bindings and example for waypoint info

c415-sdk
yaapu 4 years ago committed by Peter Barker
parent
commit
89f0ed2f8f
  1. 50
      libraries/AP_Scripting/examples/wp_test.lua
  2. 3
      libraries/AP_Scripting/generator/description/bindings.desc

50
libraries/AP_Scripting/examples/wp_test.lua

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
-- Example script for accessing waypoint info
local wp_index
local wp_distance
local wp_bearing
local wp_error
local wp_max_distance = 0
local last_log_ms = millis()
function on_wp_change(index, distance)
wp_index = index
wp_distance = distance
wp_distance_max = distance;
gcs:send_text(0, string.format("NEW WP: idx=%d, dist=%.01fm", index, distance))
end
function refresh_wp_info()
local index = mission:get_current_nav_index()
local distance = vehicle:get_wp_distance_m()
local bearing = vehicle:get_wp_bearing_deg()
local error = vehicle:get_wp_crosstrack_error_m()
if index ~= nil and index ~= wp_index and distance ~= nil then
on_wp_change(index, distance)
end
if index ~= nil and distance ~= nil and bearing ~= nil and error ~= nil then
wp_index = index
wp_bearing = bearing
wp_distance = distance
wp_error = error
wp_distance_max = math.max(wp_distance_max, wp_distance)
end
end
function log_wp_info(index, distance, bearing, error)
if index ~= nil and distance ~= nil and bearing ~= nil and error ~= nil then
local perc = wp_distance_max > 0 and 100-(100*(distance/wp_distance_max)) or 0
gcs:send_text(0, string.format("WP: %d, %.01fm (%.01f%%), b: %d°, xe:%.01fm", index, distance, perc, math.floor(bearing+0.5), error))
end
end
function update()
refresh_wp_info()
log_wp_info(wp_index, wp_distance, wp_bearing, wp_error)
return update, 1000 -- 1Hz
end
return update(), 1000 -- start with a 1 sec delay

3
libraries/AP_Scripting/generator/description/bindings.desc

@ -188,6 +188,9 @@ singleton AP_Vehicle method get_target_location boolean Location'Null @@ -188,6 +188,9 @@ singleton AP_Vehicle method get_target_location boolean Location'Null
singleton AP_Vehicle method set_target_velocity_NED boolean Vector3f
singleton AP_Vehicle method set_target_angle_and_climbrate boolean float -180 180 float -90 90 float -360 360 float -FLT_MAX FLT_MAX boolean float -FLT_MAX FLT_MAX
singleton AP_Vehicle method set_steering_and_throttle boolean float -1 1 float -1 1
singleton AP_Vehicle method get_wp_distance_m boolean float'Null
singleton AP_Vehicle method get_wp_bearing_deg boolean float'Null
singleton AP_Vehicle method get_wp_crosstrack_error_m boolean float'Null
include AP_SerialLED/AP_SerialLED.h
singleton AP_SerialLED alias serialLED

Loading…
Cancel
Save