Integrate a Lua script into the .apj file

I have successfully set up the compiling environment and compiled the APJ firmware for the Cube Orange.

Now, I want to integrate the Lua script [copter-deadreckon-home.lua] into the source code. The script is currently located in libraries/AP_Scripting/applets.

Essentially, I aim to compile the Lua script into the source code persistently. Please guide me on how to achieve this.

I’ve observed that someone has successfully implemented this method on another vehicle.

Thanks to everyone for your time, i belive that some one will answer me

thanks again

Once your vehicle has accepted the apj you’ve build and is flying properly, you can upload your script using Mission Planner :
Config : Full parameter list : scr_enable 1, write params and reboot

Then Config : Mavftp + scripts : put your lua script here

reboot once or twice here and your script will run at start

1 Like

google,“ardupilot embed scripts into firmware” first hit.

1 Like

thank you sir I got it. again thanks for your time

Thank you sir for your time

the ardupilot documentation says

( You can also embed Lua scripts in the ROM of the chip that will automatically run. Since Lua is currently only run on autopilots with a lot of flash space, they are only restricted in total aggregate size to available free flash memory. Put the scripts in a sub-directory called scripts , i.e. libraries/AP_HAL_ChibiOS/hwdef/OEM_CubeOrange/scripts . Files must end in .lua .)

locating the above path i can’t find but just see [libraries/AP_HAL_ChibiOS/scripts].

so I have to upload the script.lua into this location and then compile the firmware?

I have done one but when I was searching for the parameters like (DR_)
I can’t find them

Thanks sir in advance

1 Like

Did you enabled scripting by setting the SCR_ENABLE to 1 in the firmware build ?

1 Like

thanks for your time sir

no, actually not sir, i have enabled them manually after building firmware with in full parm list.

sir please can you mention the configuration

I am facing the error also after rebooting the cube

Those errors you see about /APM/scripts are related to an sdcard probably not present - that is the path scripts get executed if they are placed on an sdcard.

There are two ways to embed the script, taken from documentation

  1. Put it in the hwdef folder of your ChibiOS board definition
  2. Create a folder in the root of your repo ardupilot/ROMFS_custom/scripts and put scripts there
    (note the documentation has an error saying you need to put it in ardupilot/build/ROMFS_custom/scripts, but waf expects it to be in the root)

I find the second one cleaner and easier to use

Dear fronders,
I tested with upload .lua file into sdcard as instructed, and it works.
However, I followed up your instrucstion which created ardupilot/ROMFS_custom/scripts/*.lua, then re-build the firmware, but the new params from the scripts didnot appear.
Is that any idea for this situation?

Well, params from the scripts can go missing for a various number of reasons.
Did you test the script runs okay? Is the scripting enabled via SCR_ENABLE?
Add some test messages like gcs:send_text(0, "test log") and check for them in the MissionPlanner messages tab to see if the script is even executed (and look for scripting engine errors there too). Or use SCR_DEBUG_OPTS param to enable some debug logs from the scripting engine.

Also posting a piece of code would help to identify what went wrong. How are you adding the script params?