I am unable to run lua scripts on a Pixhawk 4. I have successfully run the scripts on an orange cube, so I believe I followed the process correctly and I know the scripts work.
I get an error message:
Lua: Couldn’t allocate a lua state
I found a forum post stating it was a memory problem, so I changed the SCR_HEAP_SIZE as per Lua Scripts — Copter documentation. It was originally 1024, and increasing it to 2048 gave me the same error massage. When I tried increasing it to 4096 I got a different error:
Lua: Panic: not enough mem, increase scr_heap_size
I also had trouble staying connected to the drone with Mission Planner when I increased the heap size to 4096.
If I increase the heap to the maximum, 1048576, I get different errors:
Scripting: Unable to allocate memory
PreArm: Scripting out of memory
Are the errors due to the size of the heap, or are there other parameters that require changes?
I can run the hello_world.lua script when I set it to 44000, but it fails if I try adding other scripts. I tried adding more scripts that are essentially hello_world with a different string, and I can only add two or three scripts before I get Lua: Panic: not enough mem, increase scr_heap_size
When I try increasing the 44000 it still disconnects Mission Planner from the drone.
How do you determine the correct heap size for the given scripts?
I see the options in Mission Planner are 1024 to 1048576, and the default is 102400. Do you know why I didn’t have the default column previously?
At 102400, I can run a few small scripts, but I would like to know more about how to determine the correct size of the heap for the scripts that are uploaded to the drone. What happens to the drone if it’s flying and there is not enough memory? Is there a failsafe that must be set?
Please point me to documentation about this that I may have missed.
No idea why you didn’t have the default set. 100k of scripting memory will run more than just a small script or two. You can safely increase it within reason (an order of magnitude is probably not “within reason”). The scripting engine will crash/quit gracefully and allow critical processes to continue if it overruns the allotted memory space (I was a bit hyperbolic in my first reply here). If scripting is performing critical functions, I recommend incremental testing before fully deploying all desired/required scripts.