top of page

LUA Scripting on the X55: A Versatile Tool for Advanced Drone Operations

What is LUA Scripting?

LUA scripting is a lightweight, high-level programming language designed primarily for embedded use in applications. LUA is known for its simplicity and flexibility, making it an ideal choice for developers who need to integrate scripting capabilities into their software. LUA is highly portable and can run on various platforms, including Windows, macOS, and Linux, as well as on embedded systems.

Lua scripting logo

The X55 aircraft has a custom version of Ardupilot firmware running on its flight controller. The great thing about Ardupilot is that it supports LUA scripting, with a growing list of functionality that can be accessed through scripting. According to Ardupilot's official documentation "scripting provides a safe, “sandboxed” environment for new behaviors to be added to the autopilot without modifying the core flight code. Scripts are stored on the SD card and run in parallel with the flight code."


What can LUA Scripts do?

At a high level, LUA scripting offers a lightweight and flexible way to enhance the X55's capabilities without requiring firmware updates or risky source code changes. LUA scripts can do things like:


  • Monitor or manipulate the state of the aircraft

  • Execute MAVLink commands

  • Read sensors or external inputs

  • And much more


Multiple LUA scripts can even be run at the same time.


This article examines the practical applications of LUA scripting and highlights specific examples of its effectiveness, particularly with our X55 drone.


How it's Done

The workflow for implementing a LUA script on the X55 is generally as follows:


  1. Identify the task or function that needs to be added

  2. Look through the existing LUA functions in the Ardupilot documentation to evaluate if the idea can be implemented without customization of the source code

  3. Create a rough draft of the script, relying on the built-in functions

  4. Run it in a simulation environment to ensure it's working as expected

  5. Copy the tested .lua file to the 'scripts' folder of the SD card on the X55

  6. Run the script on the X55 in operation


The low-level details of this process are beyond the scope of this article, but the majority of the information needed to implement this process is found in the Ardupilot documentation.


LUA Scripting Examples with the X55


Custom Flight Patterns

Some of the more useful things we have done with LUA scripts involve creating custom flight patterns. Since the script can do things like command a target velocity or target position, this lends well to custom flight profile needs. Some specific examples are listed below.


Figure-8 Pattern for LiDAR Calibration


LiDAR systems require a calibration pattern to be flown by the aircraft, typically at the beginning and end of the data collection. One such common pattern is the figure-8. A figure-8 pattern is not a built-in automated flight mode in Ardupilot, and performing this maneuver manually can be risky and difficult, especially for inexperienced pilots.


Through the use of a LUA script, we can trigger the execution of a parametrized figure-8 pattern, with adjustable speed, radius, and timing. The script is generally set up to be triggered by the press of a button on the controller. After the script completes the figure-8 pattern, it then continues to fly the automated mission.


Aerial view of our X55 drone flying in a figure-8 pattern over a field
Simulator view of the figure-8 pattern being executed.

Square (Box) Pattern


Some research projects have required the aircraft to fly a perfectly square box pattern, starting from the aircraft's current position, when the pattern command is activated. This is also quite similar to the figure-8 pattern, and can be implemented with similar commands in the LUA script. In this example, a high value on a spare RC channel triggers the pattern to run, and it executes to completion.


Eye-level view of the X55 drone performing a square flight path for data gathering
Flight log replay of the X55 executing a square box flight pattern.

Communication with Custom Payloads


LUA scripting can also provide ways of communicating with custom payloads, even when those payloads are not supported by the default firmware. Recently, we employed LUA scripts to manage a custom payload with serial and GPIO interfaces. The script is used to trigger the payload to perform a custom action during automatic waypoint missions, and it also allows the aircraft to read serial data from the payload and report this to the operator via the Ground Control Station (GCS) software. Using LUA scripting, just a small piece of code can bridge the gap between a custom payload and the existing autopilot framework.


Close-up of X55 drone attached with a custom payload interface
A custom payload that uses LUA scripting to achieve full functionality.

Custom Logging and Messaging

One other useful feature is the ability to log custom data to the aircraft's SD card. For example, if we attach an external temperature sensor or voltage sensor (or any kind of analog or digital device, really) to the flight controller, LUA scripting can give us a way to log that data and record it during flight. Additionally, we can send messages to the GCS to inform the operator if something is out of range. These sorts of features lend very well to custom or research applications.


How to Get Started and Further Resources

Ardupilot has good documentation for getting familiar with all of this. To really dive deep, you'll need to be able to build the source code to use as a simulation environment (typically easiest on Linux).


After that's all working, you can simply write new LUA scripts, test on the simulator, and repeat, until it's working as you expect.


As an obvious note, never try anything on an aircraft until you have simulated all scenarios and completely understand the consequences of executing the function you have programmed. This is especially true for scripts that modify and command the aircraft's position or speed, but less critical for things that simply involve logging, or serial communication.


In summary, the flexibility of LUA scripting, combined with the open-source nature of Ardupilot/Arducopter, significantly enhances the X55's capabilities and provides almost limitless possibilities. From custom flight patterns to intelligent payload management, LUA empowers operators to efficiently automate complex tasks and implement innovative solutions.


Please reach out if you've got something in mind that you think the X55 could do with a little help from LUA scripting.

Subscribe to our newsletter to get updates and news about Arcsky

Thanks for subscribing!

  • LinkedIn
  • Instagram
  • Facebook
  • YouTube
bottom of page