ArduPilot’s scripting subsystem embeds a Lua 5.3.6 interpreter directly in the autopilot firmware, giving you a sandboxed environment to customise vehicle logic, add sensors, automate missions, and prototype new features without touching C++ or reflashing the board. Scripts run on the autopilot itself alongside the core flight code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ardupilot/ardupilot/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
Scripting is automatically compiled into firmware builds for boards with more than 1 MB of flash. No special build flag is needed for supported hardware.Enabling scripting
Set theSCR_ENABLE parameter to 1 and reboot the autopilot. Without this, the interpreter does not start and no scripts are loaded.
| Parameter | Default | Description |
|---|---|---|
SCR_ENABLE | 0 | Set to 1 to enable the scripting engine |
SCR_HEAP_SIZE | 43680 | Lua heap in bytes. Increase for complex scripts |
Where to place scripts
The autopilot scans a specific directory at boot and loads every.lua file it finds there.
- Real hardware
- SITL
Place scripts in the
APM/scripts/ folder on the SD card:Script lifecycle
Every script follows the same pattern: define anupdate function, and return it along with the delay in milliseconds before it should be called again. The scripting engine calls this function on a cooperative schedule — it is not a real-time thread.
(function, delay_ms) pair. Returning nil stops the script permanently.
Example: distance-from-home servo
The following script (taken from theAP_Scripting README) reads the vehicle’s current position and home location, computes the distance, and drives a servo (scripting output function 96) proportionally up to 1000 m.
Key API bindings
Scripts access autopilot state through a set of pre-bound global objects. The bindings are generated fromlibraries/AP_Scripting/bindings.desc.
AHRS and position
AHRS and position
Servo output
Servo output
Vehicle parameters
Vehicle parameters
GCS messages
GCS messages
Time
Time
Adding a new script
Create the script file
Write your Lua script following the update-loop pattern. Save it as
my_feature.lua.Copy to the scripts directory
On hardware, copy to
APM/scripts/ on the SD card. In SITL, copy to scripts/ in the working directory.Applets
Thelibraries/AP_Scripting/applets/ directory in the repository contains production-quality scripts maintained by the ArduPilot team. Each applet ships with a matching .md file describing parameters and usage. Examples include:
VTOL-quicktune.lua— automatic PID tuning for quadplanesrover-quicktune.lua— automatic tuning for roversUniversalAutoLand.lua— scripted landing logiccopter-slung-payload.lua— slung-load compensationmount-poi.lua— point-of-interest camera gimbal controlnet_webserver.lua— embedded HTTP server via networking
Example scripts
Thelibraries/AP_Scripting/examples/ directory contains over 150 example scripts covering topics including CAN bus access, mission editing, motor mixing, RC input overrides, rangefinder testing, LED control, and more. Browse the directory for a pattern close to your use case before writing from scratch.
The embedded Lua version is 5.3.6 — a lightly customised build of the official distribution. Standard Lua 5.3 language features are available; the standard I/O library is not (use
gcs:send_text() for output).