I were testing this lua script to add more functionality to my copter and getting this error:
attempt to compare number with nil" in line number 139.
Please guide me how to resolve this error as I am new to lua scripting.
This file has been truncated.
-- Copter attempts to fly home using dead reckoning if the GPS quality deteriorates or an EKF failsafe triggers
-- CAUTION: This script only works for Copter 4.3 (and higher)
-- this script checks for low GPS quality and/or an EKF failsafe and if either occurs, flies in the last known direction towards home
-- DR_ENABLE : 1 = enabled, 0 = disabled
-- DR_ENABLE_DIST : distance from home (in meters) beyond which the dead reckoning will be enabled
-- DR_GPS_SACC_MAX : GPS speed accuracy maximum, above which deadreckoning home will begin (default is 0.8). Lower values trigger with good GPS quality, higher values will allow poorer GPS before triggering. Set to 0 to disable use of GPS speed accuracy.
-- DR_GPS_SAT_MIN : GPS satellite count threshold below which deadreckoning home will begin (default is 6). Higher values trigger with good GPS quality, Lower values trigger with worse GPS quality. Set to 0 to disable use of GPS satellite count.
-- DR_GPS_TRIGG_SEC : GPS checks must fail for this many seconds before dead reckoning will be triggered.
-- DR_FLY_ANGLE : lean angle (in degrees) during deadreckoning. Most vehicles reach maximum speed at 22deg
-- DR_FLY_ALT_MIN : min alt (above home in meters) during deadreckoning. zero to return at current alt
-- DR_FLY_TIMEOUT : timeout (in seconds). Vehicle will attempt to switch to NEXT_MODE after this many seconds of deadreckoning. If it cannot switch modes it will continue in Guided_NoGPS. Set to 0 to disable timeout
-- DR_NEXT_MODE : flight mode vehicle will change to when GPS / EKF recovers or DR_FLY_TIMEOUT expires. Default is 6=RTL, see FLTMODE1 parameter description for list of flight mode number. Set to -1 to return to mode used before deadreckoning was triggered
-- How to use:
-- 1. set SCR_ENABLE = 1 to enable scripting (and reboot the autopilot)
-- 2. set SCR_HEAP_SIZE to 80000 or higher to allocate enough memory for this script
-- 3. set DR_ENABLE = 1 to enable dead reckoning
-- 4. optionally set DR_GPS_SACC_MAX and/or DR_GPS_SAT_MIN parameters to adjust how bad the GPS quality must be before triggering
Provide the full output.
Which version of ArduPilot you’re using?
my apologies for being late my drone had crashed.
Arducopter version is V4.3.0
is an error which I am getting in messages
This is not the entire output.
I can only see there is an error on 139th line on the messages:
local stage1_flight_mode = nil -- flight mode vehicle was in during stage1 (may be used during recovery)
local stage2_start_time_ms -- system time stage2 started (level vehicle)
local stage3_start_time_ms -- system time stage3 started (deadreckon home)
local last_print_ms = 0 -- pilot update timer
local interval_ms = 100 -- update at 10hz
-- exit immediately if not enabled
if (enable:get() < 1) then
return update, 1000
-- determine if progress update should be sent to user
local now_ms = millis()
local update_user = false
if (now_ms - last_print_ms > 5000) then
last_print_ms = now_ms
update_user = true
This is getting the value of DR_ENABLE parameters.
That error is about comparing nil to a number, I think that parameter could not be able to initialize.
I am having the same issue. It errors out with the same message all parameter value comparisons (including L139). How do I go about fixing this?
Probably a version issue due to a new
Parameter() constructor in the master branch.
Try the version from the Copter-4.3 branch:
ardupilot/copter-deadreckon-home.lua at Copter-4.3 · ArduPilot/ardupilot (github.com)
And please do not post the same question more than once.
Ah ok - thanks. I ended up fixing it on my end by adjusting how the parameter value was read.
copter-deadreckon-home.lua (17.5 KB)