LUA scripts within SITL simulations?

Is it possible to setup the LUA script environment to test scripts within SITL simulations? How does one do that?

yup, if you are using sim_vehicle.py approach to simulate then create a scripts folder in your /home/user/ardupilot directory, and add your lua scripts in that folder, then just follow the rest of the instructions as given in this link: https://ardupilot.org/copter/docs/common-lua-scripts.html

Thank you very much - it worked out beautifully! One pitfall that I discovered is that one can not control servos that are passthrough (Servo#_Function=1) with LUA scripts. Of course, this should have been obvious since the beginning but hey, I am a mortal.

Cheers!

I think you should be able to control any servo with the new override binding with a timeout.

Thanks Peter, I will give it another shot but out of the 8 channels I have, only one was pass through and failed to work. When I assigned a new function to it it started working.

For instance in the example you sent the servo function is 4 (aileron). That’s why the code works. If the function were 1, it would not work. I think it makes sense that it doesn’t because pass through should mean that the APM can not manipulate it whether with or without a script.

Thanks

Has anyone faced an issue whereby when running the lua script, it comes out with the following message: “Ready to FLY AP: Lua: Insufficient memory loading ./scripts/pid_change”

I have followed all the steps as mentioned above and placed the required .lua scripts in the correct folder. do advise if this is a virtual memory error or could it be potentially a hardware limitation. However when checking the RAM usage, it was only about 50% utilization of my RAM.

The free memory you are seeing might be pre or post script failure.

I suggest to gradually increase the SCR_HEAP_SIZE while making sure the freememory visible in the Mission Planner’s status window is in the positive with some safety margin.

Please also review the wiki to liberate memory allocated for other functionalities to dedicate it to lua script execution via the above parameter adjustment.

For most of the sample Lua scripts provided by the developers, the approach above works on a Pixhawk 1 board. Make sure that your board has similar or larger memory.