However now I’m trying to embed it in the firmware to use on a SkyStarsH7HD, which doesn’t have an SD card, and it’s throwing the following error:
Debug: Lua: @ROMFS/scripts/myscript.lua:164: module ‘MAVLink/mavlink_msgs’ not found: MAVLink/mavlink_msgs …
So myscript.lua is obviously running from onboard flash, therefore the embedding process worked, at least for the main script.
I have tried compiling the firmware with the script in ardupilot/ROMFS_custom, and also in ardupilot/libraries/AP_HAL_Chibios/hwdef/SkystarsH7HD
Both with the same results
In these cases, the file structure is the same, a la:
First, I have no knowledge about LUA scripts but I want to learn so I read all these Threads and try to analysis.
In this case I might see a mismatch in your file structure:
I believe you are searching for mavlink_msgs in a directory MAVLink/ but this does’t exist in your file structure.
Currently I am experimenting with a similar setup, trying to receive MAVLink messages, and I used the same Lua modules from the repository. But I couldn’t figure out where to put them on the SD card (except the main script), because the documentation only stated
Upload scripts (files with extension .lua) to the autopilot’s SD card’s APM/scripts folder.
Which I did, but where to put the required modules? I tried putting them next to the script like in APM/scripts/MAVLink/... but that relative path did not work. Only when defining an absolute path in the call, e.g. require("/APM/scripts/MAVLink/mavlink/msgs").
Now I see that modules are searched in module subdirectory next to the current script. And that is the actual relative path. Thank you @phinchey for pointing that out and providing the correct directory structure! I nowhere did find this bit of information …
About your problem, is your require call with @ROMFS an absolute path? Or maybe trying "/scripts/modules/..."?
I checked out master, and now local mavlink_msgs = require("MAVLink/mavlink_msgs") works when embedded from ardupilot/libraries/AP_HAL_Chibios/hwdef/SkystarsH7HD/scripts/modules/MAVLink/mavlink_msgs.lua just as well as when included on the SD card at /APM/scripts/modules/MAVLink/mavlink_msgs.lua