LUA script Pre arm error

i have installed VTOL quick tune Lua script on APM/ SCRIPTS folder .then inserted SD card on CUBE BLACK Flight controller .
After Reboot i got following Prearm errors:

13-06-2022 19:44:03 : quicktune.lua
13-06-2022 19:44:03 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:53 : GPS 2: detected as NMEA at 115200 baud
13-06-2022 19:43:53 : quicktune.lua
13-06-2022 19:43:53 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:48 : PreArm: Terrain out of memory
13-06-2022 19:43:48 : PreArm: AHRS: EKF3 not started
13-06-2022 19:43:48 : PreArm: EKF attitude is bad
13-06-2022 19:43:48 : PreArm: EKF3 Yaw inconsistent by 151 deg
13-06-2022 19:43:43 : quicktune.lua
13-06-2022 19:43:43 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:41 : GPS 2: detected as NMEA at 115200 baud
13-06-2022 19:43:33 : quicktune.lua
13-06-2022 19:43:33 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:28 : GPS 2: detected as NMEA at 115200 baud
13-06-2022 19:43:23 : quicktune.lua
13-06-2022 19:43:23 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:18 : PreArm: Terrain out of memory
13-06-2022 19:43:18 : PreArm: AHRS: EKF3 not started
13-06-2022 19:43:18 : PreArm: EKF attitude is bad
13-06-2022 19:43:18 : PreArm: EKF3 Yaw inconsistent by 151 deg
13-06-2022 19:43:16 : GPS 2: detected as NMEA at 115200 baud
13-06-2022 19:43:13 : quicktune.lua
13-06-2022 19:43:13 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:09 : GPS 1: detected as u-blox at 230400 baud
13-06-2022 19:43:04 : EKF3 allocation failed
13-06-2022 19:43:03 : Frame: QUAD/X
13-06-2022 19:43:03 : IMU2: fast sampling enabled 8.0kHz/1.0kHz
13-06-2022 19:43:03 : IMU0: fast sampling enabled 8.0kHz/1.0kHz
13-06-2022 19:43:03 : RCOut: PWM:1-14
13-06-2022 19:43:03 : CubeBlack 004E0028 32375116 33323538
13-06-2022 19:43:03 : ChibiOS: 93e6e03d
13-06-2022 19:43:03 : ArduCopter V4.2.1 (c8b6b674)
13-06-2022 19:43:03 : Frame: QUAD/X
13-06-2022 19:43:03 : IMU2: fast sampling enabled 8.0kHz/1.0kHz
13-06-2022 19:43:03 : IMU0: fast sampling enabled 8.0kHz/1.0kHz
13-06-2022 19:43:03 : RCOut: PWM:1-14
13-06-2022 19:43:03 : CubeBlack 004E0028 32375116 33323538
13-06-2022 19:43:03 : ChibiOS: 93e6e03d
13-06-2022 19:43:03 : ArduCopter V4.2.1 (c8b6b674)
13-06-2022 19:43:03 : Terrain: Allocation failed
13-06-2022 19:43:03 : Frame: QUAD/X
13-06-2022 19:43:03 : IMU2: fast sampling enabled 8.0kHz/1.0kHz
13-06-2022 19:43:03 : IMU0: fast sampling enabled 8.0kHz/1.0kHz
13-06-2022 19:43:03 : RCOut: PWM:1-14
13-06-2022 19:43:03 : CubeBlack 004E0028 32375116 33323538
13-06-2022 19:43:03 : ChibiOS: 93e6e03d
13-06-2022 19:43:03 : ArduCopter V4.2.1 (c8b6b674)
13-06-2022 19:43:03 : quicktune.lua
13-06-2022 19:43:03 : Lua: Insufficent memory loading /APM/scripts/VTOL-
13-06-2022 19:43:03 : GPS 2: detected as NMEA at 115200 baud
13-06-2022 19:43:03 : RCOut: PWM:1-14
13-06-2022 19:43:03 : AHRS: DCM active
13-06-2022 19:43:03 : ArduPilot Ready
13-06-2022 19:43:02 : Initialising ArduPilot
13-06-2022 19:43:02 : Barometer 2 calibration complete
13-06-2022 19:43:02 : Barometer 1 calibration complete

@kalai1219,

So the CubeBlack uses an F4 processor so it doesn’t have enough memory unless some features are turned off. We’ve been planning to add a wiki page with suggestions on what features are most effective at reducing memory but here are some ideas:

  1. EK3_IMU_MASK = 1 (this disables the 2nd IMU)
  2. TERRAIN_ENABLE = 0 (disables the terrain database which will stop missions from using AltFrame=Terrain using the inbuilt terrain database, rangefinders will still work)
  3. LOG_FILE_BUFSIZE = 8 (this reduces the memory used for logging which could lead to mission log messages but shouldn’t have any impact beyond this)

Thank you randy.
i was just followed your inputs and now I’m not getting prearm warnings but still message tap shows there is Lua :insufficient memory loading …is that normal?

I couldn’t see the QUIK_xxxx parameters too after enabled scripts

There is still an error related with insufficient memory to your scripting engine.
Try increasing SCR_HEAP_SIZE.

1 Like

thank you @Mustafa_Gokce currently its 44032 …how much should i increase?

@kalai1219,

If you double click on an item in the Action tab and select “freemem” from the huge black window you can see how much memory is free on the board. For example I have 25,000 free on this random autopilot. You’d always want to leave at least 5000 but you could increase the SCR_HEAP_SIZE parameter by whatever extra you’ve got. I’d guess that 70,000 is enough for most scripts.

i have free memory around 22000 before SCR_HEAP_SIZE set to 70000.
but after set SCR_HEAP_SIZE set to 70000 free memory left is around 6978.but still i get prearm warning as below.

@kalai1219,

Well, I’m out of ideas I’m afraid. Maybe check that there are no other scripts in the scripts directory… Maybe disable any other features that you don’t immediately need (rangefinders, optical flow, anything else)…

The CubeBlack just doesn’t have the memory required to run scripting very well I think.

There is no other script installed on the cube.similarly no other functions enabled like range finder,optical flow etc…
You can refer 1st section of this thread to see only quicktune lua script only installed.

hi @rmackay9 today i faced same issue on CUAV V5 Nano autopilot also i think its F7 board with 2M flash …but why still could not able to run the lua script.

Screenshot (103)

@kalai1219,

We’ve got a wiki page here with some instructions on reducing RAM usage although it’s not great yet.

In the screen shots above it looks like SCR_HEAP_SIZE is 202400 which is more than the available memory of 145800. I think if you reduced SCR_HEAP_SIZE to 130,000 the error would go away.

The complexity comes though because at startup many different features try to take memory. There may be other features that also couldn’t get memory so it’s possible the above change to SCR_HEAP_SIZE won’t resolve the problem.

1 Like

setting SCR_HEAP_SIZE = 130000 also doesn’t remove the problem.
still prearm:script out of memory.
now free memory is 152456

even i have set SRTL_POINTS = 0

@kalai1219,

Through trial and error you should be able to find a SCR_HEAP_SIZE that works… I think it may be that there’s an overhead above and beyond the SCR_HEAP_SIZE. Sorry about that.

Hi @tridge

If you can see this issue can be solved?

I am including a change in 4.2.2 that allows for the CAN memory pool to be reduced, which will help if you use CAN.
Scripting is hard though on F4 based boards, and it can be very tricky to get memory usage low enough to allow complex lua scripts to work.
We have discussed moving quicktune to being in C++ to avoid that issue, but that is unlikely to happen soon, sorry.