-
Notifications
You must be signed in to change notification settings - Fork 12
Lua Graph Editor
The Lua Graph Editor is a visual scripting environment for ArduPilot. Instead of writing Lua code by hand, you connect nodes in a data-flow graph. The editor compiles your graph into a valid ArduPilot Lua script that you can upload to your flight controller's SD card.
- Add nodes from the palette on the left by clicking them
- Connect ports by dragging from an output port to an input port
- Configure properties by selecting a node and editing in the inspector panel
-
Export Lua to compile the graph into a
.luafile
| Area | Purpose |
|---|---|
| Toolbar | File operations, undo/redo, export, templates, docs |
| Node Palette | All available nodes grouped by category |
| Canvas | The graph editor where you arrange and connect nodes |
| Inspector | Properties and details for the selected node |
| Lua Preview | Live preview of the compiled Lua output |
The left sidebar lists all available nodes organized into categories: Sensors (16 nodes), Logic (7), Math (9), Actions (9), Timing (6), Variables (3), and Flow (1). Use the search bar at the top to filter by name. The status bar at the bottom shows the total node count, graph validity, and estimated memory usage.

Selecting a node opens its details in the right-side inspector. It shows the node's category, name, and description, followed by editable Properties (e.g., LED Instance) and a Ports section listing each input with its expected data type (boolean, number, etc.). The Lua Preview panel at the bottom shows the compiled output in real time.

- New -- Create a blank graph
-
Open -- Load a
.adgraphfile -
Save -- Save to a
.adgraphfile - Templates -- Load a pre-built example graph
-
Export Lua -- Compile and save a
.luafile - Undo / Redo -- Standard undo/redo for all graph changes
The Templates dialog provides pre-built scripts grouped by category (Safety, Utility, etc.). Each template shows a description, node count, number of connections, and run interval so you can gauge complexity before loading. Safety templates include Low Battery Warning, Geofence Alert, Auto RTL on Low Battery, Speed Limit Warning, Wind Speed Failsafe, and GPS Satellite Monitor.

Below is the full editor with a loaded template -- the node palette on the left, the graph canvas in the center, and the inspector on the right.

- Click Battery in the Sensors category to add a battery node
- Click Compare in Logic to add a comparison node
- Connect Voltage output to A input
- Add a Constant node, set its value to
11.1 - Connect the constant's Value output to B input
- Set the Compare operator to
<(less than) - Add a Send GCS Text node from Actions
- Connect the Compare Result to the GCS text Trigger
- Click Export Lua to generate your script
This script sends a GCS message whenever battery voltage drops below 11.1V.
Graphs are saved as .adgraph JSON files containing the full node layout, connections, properties, and viewport position. You can share .adgraph files with other ArduDeck users.
The Export Lua button compiles the graph and saves a standard .lua file. Copy it to your flight controller's scripts/ directory on the SD card and reboot.
Data flows left to right through the graph. During each update cycle, the compiler evaluates nodes in topological order (upstream before downstream).
- Hover over an output port (right side of a node)
- Click and drag to an input port (left side of another node)
- Release to create the connection
Click a connection line and press Delete or Backspace to remove it.
Ports are color-coded by data type:
| Type | Color | Values |
|---|---|---|
| Number | Blue | Integers or floats (0, 3.14, -100) |
| Boolean | Purple |
true or false
|
| String | Yellow/Amber | Text values ("Hello") |
| Any | Gray | Accepts any type |
- Exact match -- Number-to-Number, Boolean-to-Boolean always works
- Any port -- Accepts connections from any type
-
Number to Boolean --
0= false, non-zero = true -
Boolean to Number --
true= 1,false= 0 - Incompatible -- String ports cannot connect to Number/Boolean ports (the editor prevents this)
- Each input port accepts only one connection
- Each output port can connect to multiple inputs (fan-out)
- Cycles are not allowed -- the compiler detects and reports them
- Unconnected input ports use their default value (shown in the inspector)
The compiler transforms your visual graph into ArduPilot-compatible Lua code:
- Topological sort -- Orders nodes so every node is evaluated after its inputs
- Variable assignment -- Each output port gets a unique Lua variable
- Code generation -- Each node emits its Lua code
- State variables -- Timing and edge-detection nodes get persistent variables at the top
-
Wrapping -- Everything is wrapped in the ArduPilot
function update() ... return update, interval endpattern
-- Auto-generated by ArduDeck Lua Graph Editor
local prev_state_1 = false
local timer_2 = 0
function update()
local voltage_3 = battery:voltage(0)
local is_low_4 = voltage_3 < 11.1
if is_low_4 then
gcs:send_text(4, "LOW BATTERY")
end
return update, 1000
end
return update, 1000The Script Settings panel (right sidebar, when no node is selected) lets you set a Name and Description for your graph. Below that, the Run Interval controls how often ArduPilot calls your script. Enter a value in milliseconds or use the preset buttons (200ms, 500ms, 1s, 2s). Lower values give faster response but use more CPU.

| Interval | Use Case |
|---|---|
| 50-100ms | Fast sensor polling, servo control |
| 200ms | General purpose (default) |
| 500-1000ms | Slow monitoring, battery checks |
| 5000ms+ | Periodic logging, status reports |
ArduPilot enforces a minimum of ~50ms.
The compiler catches errors before generating code:
- Disconnected action nodes (no trigger connected)
- Circular dependencies
- Type mismatches
- Missing required properties
- Use Comment nodes to document sections of your graph. They have no effect on compiled code but make graphs easier to understand later
- Start with Templates -- Load a pre-built graph, study how it works, then modify it
- Check the Lua Preview -- It shows compiled output in real time so you can verify correctness before exporting
- Use Debounce for alerts -- Without debounce, a rapidly toggling condition spams GCS messages every cycle. Add a Debounce or Rising Edge node before action nodes
-
Name your variables -- Use descriptive names like
lowBatteryTriggeredinstead ofxin Get/Set Variable nodes - Organize left to right -- Sensors on the left, logic in the middle, actions on the right
- Memory limit -- Scripts are limited to ~50KB of Lua heap memory
-
Instruction limit -- Each
update()call has a maximum number of bytecode instructions - No infinite loops -- Scripts that run too long are killed
- File I/O -- Writing to SD card is slow. Don't log faster than every 1-2 seconds
- No network -- Lua scripts cannot open TCP/UDP sockets
- Maximum ~100 nodes per graph for reasonable performance
- Very complex graphs may compile slowly
- Sub-graphs and nested graphs are not supported
- Use Send GCS Text nodes to trace values during development (set severity to Debug)
- Use Log to File to record data for post-flight analysis
- Check
/scripts/on the SD card for error logs if a script fails to start - Common issues: nil values (sensor not available), division by zero, exceeding memory limits
Getting Started
Configuration
- Configuration
- PID Tuning
- Rates
- Flight Modes
- Receiver
- Serial Ports
- Safety and Failsafe
- MAVLink Signing
- Battery
- Tuning Presets
- All Parameters
Firmware
Lua Graph Editor