Trouble with Lua modules like rc: returning nil with navio2?

I have a issue where my Lua scripts keep crashing with an error saying “Lua: ./scripts/servo.lua:10: attempt to call a nil”. I believe this means that the modules have not been loaded. But it seems like they should be loaded after enough time? Not sure why there failing to load. I am running on a navio2 with a raspberry pi 4.

Share the code snippet that is causing the issue. It is more likely a problem with the script.

Also reply with the exact ArduPilot version in use.

Sure thing.

  • I am currently running ArduCopter V4.0.3

This code snippet is what I’m trying to run. I did my best to base it on the docs:

---@diagnostic disable: need-check-nil
---@diagnostic disable: param-type-mismatch

function update()
        --if not rc or not rc:has_valid_input() then
        --      gcs:send_text(6, "Waiting for rc signal...")
        --      return update, 5000
        --end
        ch5 = rc:get_pwm(5)

        gcs:send_text(6, "Channel 5: " .. ch5)

        return update, 1000
end

return update, 1000

I used to have a return update() at the very end of the script.
Let me know if I can provide any other information. Thank you in advance.

The issue is almost certainly with the extremely old version you are running. Scripting was brand new at the time, and many method names/binding references have changed since. Recommend you update the firmware rather than chasing these scripting issues.

1 Like

I will try that. Thanks for the suggestion.

That worked (should have thought about that :man_facepalming:). Thanks again.