diff --git a/libraries/AP_Scripting/applets/Hexsoon LEDs.lua b/libraries/AP_Scripting/applets/Hexsoon LEDs.lua index 142e1e49b7..29b0cad6e9 100644 --- a/libraries/AP_Scripting/applets/Hexsoon LEDs.lua +++ b/libraries/AP_Scripting/applets/Hexsoon LEDs.lua @@ -25,12 +25,11 @@ LEDs should now work!, if not try swapping AUX 5 and 6, either by physically swa To get colours to match either change the ordering in "local led_map =" below or swap headers round on the LED distribution board If using 6 les add two extra colours to "local led_map =" e.g: "local led_map = {red, red, red, green, green, green}" --]] --- luacheck: only 0 -- helper colours, red, green, blue values from 0 to 255 local red = {255, 0, 0} local green = {0, 255, 0} -local blue = {0, 0, 255} +-- local blue = {0, 0, 255} -- led map giving the colour for the LEDs plugged in local led_map = {red, red, green, green} diff --git a/libraries/AP_Scripting/examples/Serial_Dump.lua b/libraries/AP_Scripting/examples/Serial_Dump.lua index 926a97353e..bfff5392e8 100644 --- a/libraries/AP_Scripting/examples/Serial_Dump.lua +++ b/libraries/AP_Scripting/examples/Serial_Dump.lua @@ -1,5 +1,4 @@ -- this script reads data from a serial port and dumps it to a file --- luacheck: only 0 local file_name = 'raw serial dump.txt' local file_name_plain = 'serial dump.txt' @@ -11,6 +10,7 @@ local port = assert(serial:find_serial(0),"Could not find Scripting Serial Port" -- make a file local file = assert(io.open(file_name, "w"),"Could not create file " .. file_name) +file:close() file = assert(io.open(file_name_plain, "w"),"Could not create file " .. file_name) file:close() diff --git a/libraries/AP_Scripting/examples/aux_cached.lua b/libraries/AP_Scripting/examples/aux_cached.lua index 1e514055a9..e029c44e98 100644 --- a/libraries/AP_Scripting/examples/aux_cached.lua +++ b/libraries/AP_Scripting/examples/aux_cached.lua @@ -1,7 +1,6 @@ --[[ example for getting cached aux function value --]] --- luacheck: only 0 local RATE_HZ = 10 @@ -11,7 +10,6 @@ local MAV_SEVERITY_INFO = 6 local AUX_FUNCTION_NUM = 302 -local last_func_val = nil local last_aux_pos = nil function update() diff --git a/libraries/AP_Scripting/examples/copy_userdata.lua b/libraries/AP_Scripting/examples/copy_userdata.lua index 6e68c97406..5f186e3f10 100644 --- a/libraries/AP_Scripting/examples/copy_userdata.lua +++ b/libraries/AP_Scripting/examples/copy_userdata.lua @@ -1,7 +1,6 @@ --[[ An example of using the copy() method on userdata --]] --- luacheck: only 0 local loc1 = Location() @@ -24,5 +23,5 @@ local v2 = v1:copy() v2:x(v2:x()+100) v2:y(v2:y()+300) -local diff = v2 - v1 +diff = v2 - v1 gcs:send_text(0,string.format("vdiff=(%.2f,%.2f)", diff:x(), diff:y())) diff --git a/libraries/AP_Scripting/examples/opendog_demo.lua b/libraries/AP_Scripting/examples/opendog_demo.lua index d518b95c6e..cefe8f1736 100644 --- a/libraries/AP_Scripting/examples/opendog_demo.lua +++ b/libraries/AP_Scripting/examples/opendog_demo.lua @@ -1,14 +1,9 @@ -- demo of waving paw of opendog --- luacheck: only 0 -local flipflop = true - -pwm = { 1500, 1500, 2000, - 1500, 1500, 1000, - 1500, 1500, 1500, - 1500, 1500, 1500 } - -local angle = 0.0 +local pwm = { 1500, 1500, 2000, + 1500, 1500, 1000, + 1500, 1500, 1500, + 1500, 1500, 1500 } function update() local t = 0.001 * millis():tofloat() diff --git a/libraries/AP_Scripting/examples/param_get_set_test.lua b/libraries/AP_Scripting/examples/param_get_set_test.lua index 07e84764cc..29baba29b6 100644 --- a/libraries/AP_Scripting/examples/param_get_set_test.lua +++ b/libraries/AP_Scripting/examples/param_get_set_test.lua @@ -1,5 +1,4 @@ -- This script is a test of param set and get --- luacheck: only 0 local count = 0 @@ -21,7 +20,9 @@ local user_param = Parameter('SCR_USER1') -- this will error out for a bad parameter -- Parameter('FAKE_PARAM') local success, err = pcall(Parameter,'FAKE_PARAM') -gcs:send_text(0, "Lua Caught Error: " .. err) +if not success then + gcs:send_text(0, "Lua Caught Error: " .. err) +end -- this allows this example to catch the otherwise fatal error -- not recommend if error is possible/expected, use separate construction and init diff --git a/libraries/AP_Scripting/examples/rangefinder_test.lua b/libraries/AP_Scripting/examples/rangefinder_test.lua index af5058d8a5..b6832bf54b 100644 --- a/libraries/AP_Scripting/examples/rangefinder_test.lua +++ b/libraries/AP_Scripting/examples/rangefinder_test.lua @@ -1,5 +1,4 @@ -- This script checks RangeFinder --- luacheck: only 0 local rotation_downward = 25 local rotation_forward = 0 @@ -8,7 +7,7 @@ function update() local sensor_count = rangefinder:num_sensors() gcs:send_text(0, string.format("%d rangefinder sensors found.", sensor_count)) - for i = 0, rangefinder:num_sensors() do + for _ = 0, rangefinder:num_sensors() do if rangefinder:has_data_orient(rotation_downward) then info(rotation_downward) elseif rangefinder:has_data_orient(rotation_forward) then diff --git a/libraries/AP_Scripting/examples/rover-SaveTurns.lua b/libraries/AP_Scripting/examples/rover-SaveTurns.lua index 58cffa4833..9e530f2331 100644 --- a/libraries/AP_Scripting/examples/rover-SaveTurns.lua +++ b/libraries/AP_Scripting/examples/rover-SaveTurns.lua @@ -11,7 +11,6 @@ of a vehicle. Use this script AT YOUR OWN RISK. LICENSE - GNU GPLv3 https://www.gnu.org/licenses/gpl-3.0.en.html ------------------------------------------------------------------------------]] --- luacheck: only 0 local SCRIPT_NAME = 'SaveTurns' @@ -33,7 +32,6 @@ local WAYPOINT = 16 -- waypoint command local MAV_SEVERITY_WARNING = 4 local MAV_SEVERITY_INFO = 6 local MSG_NORMAL = 1 -local MSG_DEBUG = 2 local RC_CHAN = rc:find_channel_for_option(RC_OPTION) local last_wp = Location() diff --git a/libraries/AP_Scripting/examples/set-target-location.lua b/libraries/AP_Scripting/examples/set-target-location.lua index d40ca3c4c1..b7c2776b5d 100644 --- a/libraries/AP_Scripting/examples/set-target-location.lua +++ b/libraries/AP_Scripting/examples/set-target-location.lua @@ -5,7 +5,6 @@ -- a) switches to Guided mode -- b) sets the target location to be 10m above home -- c) switches the vehicle to land once it is within a couple of meters of home --- luacheck: only 0 local wp_radius = 2 local target_alt_above_home = 10 diff --git a/libraries/AP_Scripting/examples/set_target_posvel_circle.lua b/libraries/AP_Scripting/examples/set_target_posvel_circle.lua index 45c12a0ebc..87d4d95382 100644 --- a/libraries/AP_Scripting/examples/set_target_posvel_circle.lua +++ b/libraries/AP_Scripting/examples/set_target_posvel_circle.lua @@ -7,7 +7,6 @@ -- 2) switch to GUIDED mode -- 3) the vehilce will follow a circle in clockwise direction with increasing speed until ramp_up_time_s time has passed. -- 4) switch out of and into the GUIDED mode any time to restart the trajectory from the start. --- luacheck: only 0 -- Edit these variables local rad_xy_m = 10.0 -- circle radius in xy plane in m @@ -26,7 +25,7 @@ gcs:send_text(0,"Script started") gcs:send_text(0,"Trajectory period: " .. tostring(2 * math.rad(180) / omega_radps)) function circle() - local cur_freq = 0 + local cur_freq -- increase target speed lineary with time until ramp_up_time_s is reached if time <= ramp_up_time_s then cur_freq = omega_radps*(time/ramp_up_time_s)^2 @@ -57,9 +56,7 @@ function update() if arming:is_armed() and vehicle:get_mode() == copter_guided_mode_num and -test_start_location:z()>=5 then -- calculate current position and velocity for circle trajectory - local target_pos = Vector3f() - local target_vel = Vector3f() - target_pos, target_vel = circle() + local target_pos, target_vel = circle() -- advance the time time = time + sampling_time_s diff --git a/libraries/AP_Scripting/examples/terrain_warning.lua b/libraries/AP_Scripting/examples/terrain_warning.lua index 4add211232..553804f35f 100644 --- a/libraries/AP_Scripting/examples/terrain_warning.lua +++ b/libraries/AP_Scripting/examples/terrain_warning.lua @@ -1,5 +1,4 @@ -- height above terrain warning script --- luacheck: only 0 -- min altitude above terrain, script will warn if lower than this local terrain_min_alt = 20 @@ -15,7 +14,6 @@ local warn_ms = 10000 local height_threshold_passed = false -local last_warn = 0 function update() if not arming:is_armed() then diff --git a/libraries/AP_Scripting/examples/wp_test.lua b/libraries/AP_Scripting/examples/wp_test.lua index 7f1e5e889b..a52d483343 100644 --- a/libraries/AP_Scripting/examples/wp_test.lua +++ b/libraries/AP_Scripting/examples/wp_test.lua @@ -1,12 +1,9 @@ -- Example script for accessing waypoint info --- luacheck: only 0 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)