Lua Scripting Live Stream [recording available on YouTube]

I’m considering hosting a live stream session via YouTube Live, Zoom, or similar where I craft an ArduPilot Lua script from scratch with your participation and questions along the way.

I’m posting this to gauge interest in the idea, and also to ask for your suggestions for a script to write during the proposed session.

If there’s suitable interest, I’ll likely host a session during a Saturday or Sunday afternoon (GMT-6) for 1-2 hours. Thereafter, the session will be available for viewing on my YouTube channel.

Full disclosure…I will probably write a demo script ahead of time to prove the concept for whatever we choose, but still intend to start with a “blank canvas” during the live session, having digested the concepts previously.

What say you?


I am highly interested!!

1 Like

Great idea ! I’ve always wanted to try Lua Scripting, but did not know where to start.
Also, I am always afraid to test a script on my drone… Will you be demonstrating your script using SiTL ?

1 Like

Great! happy to help out if I can, hope you have got the auto complete stuff setup in VScode, I have been meaning to do a setup guide for that.


Yes, I think it’s important to understand how to use SITL for testing and debugging a script.

@iampete - happy to have you along! It would be fantastic to have your insight during the session. I agree that VS Code is an excellent environment for developing these scripts. If there’s an ArduPilot-specific autocomplete extension, I do not have it installed, but I do have a good Lua extension.

Happy to take suggestions for a script to write during the session. One possibility: read a rain/moisture sensor and initiate RTL upon sensing rain.

1 Like

You have pushed me over the edge to finally do a guide for setting up the extension :wink:


I’m interested. I fear I may not have enough of the background knowledge to take full advantage but at this point every bit helps.

1 Like

A script that would actually be useful to me is for the script to detect from accelerometer data that the vehicle is encountering rough terrain and take some action, perhaps stop or reduce speed. If the latter is done, then I suppose it could detect that the terrain is smooth again and return to the normally programmed speed.

This is one of those scripts I thought I would try my hand at one day.


I suggested something like that for boat to the devs a while ago for detecting debris in the water or wave impacts.

We can try something like that, although we may end up showcasing a limitation instead. We can’t run the script very fast (by comparison to the control loops), so it may miss peak acceleration values.


@Yuri_Rage you have a “Multi Mission” script in the examples on github, there is also a “Mission Selector” script @hwurzburg

Is it possible to make a script that would allow you to load previously created missions (saved on the autopilot SD card)?
It seems to me that this can be implemented with the help of two . One switch for 6 positions selects the mission(1-6) and the other confirms to switch to AUTO mode.

I tried to do it, but I don’t have enough knowledge in programming.

The Mission Selector script is almost exactly what you want. Instead of using the rc_switch:get_aux_switch_pos() method, you’d check for PWM thresholds on the 6 position switch using rc:get_pwm().

To mirror the flight mode PWM threshold values, you’d use, 1000, 1230, 1360, 1490, 1620, 1749, and 2000.

I’d check for HOLD mode + a change in the PWM value to trigger loading a mission.

1 Like

Yuri hello, I made some changes to the original file. In line 63, I added a check (HOLD mode). In lines 69 to 75, I changed the conditions. Are the changes correct?
My question is how do I add a trigger to load a mission?
P.S.: Thank you for your help.
MultiMissiomSelect.lua (2.3 KB)

1 Like

Totally In! Thanks for thinking of the community!

1 Like

@McKey - feeling a bit under the weather, and I’m afraid my brain is probably not fully engaged, but here’s what I have after a brief look at your updated script:

Your PWM threshold checks should look something like this:

local pwm = rc:get_pwm(15)
if pwm < 1230 then
elseif pwm < 1360 then
elseif pwm < 1490 then
elseif pwm < 1620 then
elseif pwm < 1749 then

Additionally, each time the script runs, store that PWM value in a global variable called something like last_pwm. You should only load a new mission when HOLD mode is selected and the PWM value has changed between the last run of the script update() function and the present one. It’s probably not important to check whether the vehicle is armed, but rather whether the switch position has changed.

And, of course, we should always avoid hard-coding numbers and filenames in the actual logic. I would take the time to define some “constants” to hold the RC channel number, the waypoint filenames, and the threshold values.

It seems there’s probably enough interest to move forward with the live stream. I don’t have a specific date or time in mind just yet but will probably aim for a late Saturday afternoon (GMT-6 for me) to try and capture the widest audience possible, given the large disparity in time zones. With all the sporting events happening this week and next, perhaps a late Feb date would be best.

Additionally, there have been some recent, massive improvements to the Lua bindings in the 4.2 master branch. I would be happy to explore some of the latest ones during the session, but I’m equally happy to keep things 4.1-compatible if that’s preferred. I suppose the chosen example script may dictate whether we need to explore the bleeding edge or not.

Still open to suggestions for a script to write!


Great offer! I am in too. Thanks, Yuri.

1 Like

I am in the middle of writing a blog article on multirotor lua so definitely interested!

1 Like

Will you save the stream recording on your Youtube channel?

1 Like

Yes, it’s my intent to record the stream and make it available after the fact. I may use YouTube Live but am not decided on the exact platform yet. Zoom has worked well for others in the community in the past.

You can upload to youtube later, you dont have to stream it there.

1 Like