Logical condition not working in LUA

first of all, thank you so much to the community.
I was no idea when the first time I had used the dead_reckoning_home lua script, but gradually I understood the working of lua.

firstly I have used Lua as default If GPS is bad then return home using the previous bearings of Yaw.

then I want to reach point C(the last point) from point A(the initial point), so I have set the yaw for the target position and the recovery mode to auto instead of RTL. tested through the simulation and the test was success full.

but I am tired of the lua when they are not accepting my logical condition for the recovery mode.

I have set the Auto mode for use just once after NO_GPS_GUIDED_MODE and then when GPS is good,

set the Auto to = nill, because the next mode after nill is RTL.

(first attempt to reach the target point used =‘AUto’ (if the target is affected area so the auto loop will be infinite)) to avoid the loop (the next mode is RTL), but the condition not working and each everytime just the Auto mode working!

can anyone give me hints about this

thanks in advance

While I can’t really see what’s happening overall, it appears that the recovery_counter variable’s scope is local to a function. Therefore, it is reinitialized to zero every time the function runs, and it will never increment beyond 1.

To fix that, you need to move this declaration:
local recovery_counter = 0
to the top level scope (outside of the function).

Also, if you really are using Copter 4.0, you should update to the latest stable version, 4.3.7.

1 Like