Scripts not Sending GCS Messages

Greetings,

I have been attempting to run Lua scripts through Mission Planner to determine if the GCS is correctly connecting to and running the scripts. I began by writing a very simple program to print ‘Hello World’ to the GCS messages. I don’t think anything is wrong with the program, but I’ll include it anyway:

gcs:send_text(6, 'Hello World!')

I followed the Lua script set-up guide for Mission Planner and have the scripts folder in MAVFtp. However, when I upload my Lua program file into the scripts folder and reboot, nothing happens in the data messages. The SD card I’m using has 4GB, so I believe I meet the minimum SD card requirements.

I’m not sure if this is related, but I do have an error message that reads “Prearm: Terrain out of memory.” I am also vaguely aware of some sort of SITL file/firmware, but I’m not sure if I need this or how to go about acquiring it.

I’m just getting started with ArduPilot, Mission Planner, and Lua, so I honestly have no idea what I’m doing. I’ve tried browsing forums and watching videos, but I haven’t found much explanation that helps with the issues I’m running into.

Any and all help would be greatly appreciated. Thank you.

1 Like

You confirmed SCR_ENABLE is set to 1?

Yuri just had a great presentation on this very subject you might want to watch.

2 Likes

Thanks for the reply! I actually was there for his presentation and was referencing his video before I made this post. The presentation was great, but it hasn’t been able to help with the specific issues I’m having. I have also ensured SCR_ENABLE is set to 1 and have written the parameters, refreshed, and reconnected as needed.

@Yuri_Rage to the rescue.

1 Like

You likely can’t connect fast enough to pick up the message from the example hello_world script.

It should be in your log though. If you set LOG_DISARMED 1 you should see the GCS message in the log.

That example script only sends it once…

This script sends the message at 10Hz

function update ()

    gcs:send_text(0, "hello, world")

    return update, 10
end

return update()

Oh and if you include a log from 4.2Beta and up we can get your script plus your parameters.

1 Like

@hendjosh Thanks for your reply! I tried implementing the code you suggested and set LOG_DISARMED to 1. I then found a Scripts tab in Flight Data, selected my hello_world script, and ran it. I then received these errors:

I also noticed the Script Console mentions printing the Python code into the dialog box. Is this an issue since I’m using Lua rather than Python, or is this just a dialog that doesn’t change how the script is interpreted? I’m also not sure where to find the 4.2Beta log.

I’ve never used that button on Mission Planner sorry. But i think it is for python scripts.

That lua script should be placed into your flight controllers scripting folder.

You should be able to do that in Mission Planner like this by going to the “scripts” folder:

Note that image is SITL which is why there are a bunch of extra folders.

To get logs you go to the “DataFlash” tab:

1 Like

Yeah, that’s how I’ve been attempting to run the Lua scripts. I tried the Scripts tab since I thought it might help, but good to know I probably should not use that. So this is how I’ve been doing it in Mission planner:

I then go to the Actions tab and set the first drop down to Scripting_cmd_stop_and_restart to stop and re-run the script, but nothing happens. I also am not coming across any logs other than the one that has been in the logs folder for a while:

Thank you for showing me how to download the logs though. Does this issue I’m having come from not using SITL?

The scripts tab you are all referencing is for Mission Planner Python scripting (GCS scripts). They are often very painful to write, and I generally recommend staying away from them if you can help it. Technically, you can write your own GUI dialog box and everything - it’s powerful…just painful. It has NOTHING to do with Lua scripting onboard.

Accessing dataflash logs just to prove a “Hello world” script works seems like overkill. Put it in a loop (just like I showed on the live stream) and watch the Messages tab.

The logs are present in the sitl/vehicle/LOGS directory for SITL, or in the LOGS directory on the autopilot’s SD card. You should be able to access them like @hendjosh says or via MAVFTP in the logs folder (or directly off the SD card). If they are not being created, check that logging is enabled in the parameters, and if you want to log the entire power on cycle rather than just armed events, use LOG_DISARMED=1.

The memory error for terrain data could be having a negative effect as well, as noted partway down the “Getting Started” section in the wiki: Lua Scripts — Copter documentation (ardupilot.org)

1 Like

Thanks for the response Yuri! I decided to sleep on it last night and try again today. I booted up mission planner, connected to Pixhawk, and was greeted with these lovely new messages:

Maybe all I needed was to un-plug and re-plug in the Pixhawk. I’m not sure what happened, but I’m now getting the expected results, so I suppose this is a win. Now I can start testing out controlling servo motors since I know mission planner is correctly running scripts.

Thanks everyone for your help! I greatly appreciate it.

1 Like