Skip to content

Commit

Permalink
AP_Scripting: update examples to not use deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Dec 26, 2024
1 parent c89eb87 commit 567f9eb
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function update()
-- get rangefinder distance
local rngfnd_distance_m = 0
if rangefinder:has_data_orient(rangefinder_rotation) then
rngfnd_distance_m = rangefinder:distance_cm_orient(rangefinder_rotation) * 0.01
rngfnd_distance_m = rangefinder:distance_orient(rangefinder_rotation)
end
local rngfnd_over_threshold = (rngfnd_distance_m == 0) or (rngfnd_distance_m > ESRC_RNGFND_MAX:get())

Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/applets/plane_package_place.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function update()
-- check the distance, if less than RNG_ORIENT_DOWN then release
local dist_m
if not landed then
dist_m = rangefinder:distance_cm_orient(RNG_ORIENT_DOWN) * 0.01
dist_m = rangefinder:distance_orient(RNG_ORIENT_DOWN)
else
dist_m = 0.0
end
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/applets/plane_precland.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ local function update()
--[[ get rangefinder distance, and if PLND_ALT_CUTOFF is set then
stop precland operation if below the cutoff
--]]
local rngfnd_distance_m = rangefinder:distance_cm_orient(rangefinder_orient) * 0.01
local rngfnd_distance_m = rangefinder:distance_orient(rangefinder_orient)
if PLND_ALT_CUTOFF:get() > 0 and rngfnd_distance_m < PLND_ALT_CUTOFF:get() then
return
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function update()
-- get rangefinder distance
local rngfnd_distance_m = 0
if rangefinder:has_data_orient(rangefinder_rotation) then
rngfnd_distance_m = rangefinder:distance_cm_orient(rangefinder_rotation) * 0.01
rngfnd_distance_m = rangefinder:distance_orient(rangefinder_rotation)
end
local rngfnd_over_threshold = (rngfnd_distance_m == 0) or (rngfnd_distance_m > rangefinder_thresh_dist)

Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/examples/ahrs-source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function update()
-- get rangefinder distance
local rngfnd_distance_m = 0
if rangefinder:has_data_orient(rangefinder_rotation) then
rngfnd_distance_m = rangefinder:distance_cm_orient(rangefinder_rotation) * 0.01
rngfnd_distance_m = rangefinder:distance_orient(rangefinder_rotation)
end
local rngfnd_over_threshold = (rngfnd_distance_m == 0) or (rngfnd_distance_m > rangefinder_thresh_dist)

Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/examples/copter-wall-climber.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function update()
if (climb_mode == 1) then
-- convert rangefinder distance to pitch speed
if rangefinder:has_data_orient(0) then
local distance_m = rangefinder:distance_cm_orient(0) * 0.01
local distance_m = rangefinder:distance_orient(0)
wall_pitch_speed = (distance_m - wall_dist_target) * wall_dist_to_speed_P
wall_pitch_speed = math.min(wall_pitch_speed, wall_pitch_speed_max)
wall_pitch_speed = math.max(wall_pitch_speed, -wall_pitch_speed_max)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function sample_rangefinder_to_get_AGL()
end

-- we're actively sampling rangefinder distance to ground
local distance_raw_m = rangefinder:distance_cm_orient(ROTATION_PITCH_270) * 0.01
local distance_raw_m = rangefinder:distance_orient(ROTATION_PITCH_270)

-- correct the range for attitude (multiply by DCM.c.z, which is cos(roll)*cos(pitch))
local ahrs_get_rotation_body_to_ned_c_z = math.cos(ahrs:get_roll())*math.cos(ahrs:get_pitch())
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/examples/land_hagl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local function send_HAGL()
last_active = false
return
end
local rangefinder_dist = rangefinder:distance_cm_orient(RANGEFINDER_ORIENT)*0.01
local rangefinder_dist = rangefinder:distance_orient(RANGEFINDER_ORIENT)
local correction = math.cos(ahrs:get_roll())*math.cos(ahrs:get_pitch())
local rangefinder_corrected = rangefinder_dist * correction
if RANGEFINDER_ORIENT == ROTATION_PITCH_90 then
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_Scripting/examples/rangefinder_quality_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ local function get_and_eval(test_idx, dist_m_in, signal_quality_pct_in, status_e

-- L U A I N T E R F A C E T E S T
-- Check that the distance and signal_quality from the frontend are as expected
local distance1_cm_out = rangefinder:distance_cm_orient(RNGFND_ORIENTATION_DOWN)
local distance1_cm_out = rangefinder:distance_orient(RNGFND_ORIENTATION_DOWN) * 100
local signal_quality1_pct_out = rangefinder:signal_quality_pct_orient(RNGFND_ORIENTATION_DOWN)

-- Make sure data was returned
if not distance1_cm_out or not signal_quality1_pct_out then
return "No data returned from rangefinder:distance_cm_orient()"
return "No data returned from rangefinder:distance_orient()"
end

send(string.format("Frontend test %i dist in_m: %.2f out_cm: %.2f, signal_quality_pct in: %.1f out: %.1f",
Expand Down

0 comments on commit 567f9eb

Please sign in to comment.