-
Notifications
You must be signed in to change notification settings - Fork 12
Lua Node Reference
Complete catalog of all nodes available in the Lua Graph Editor, organized by category. For usage examples, see Lua Examples.
Sensor nodes read data from the flight controller. They have no inputs and provide output values each update cycle.
| Node | Outputs | Properties | ArduPilot API |
|---|---|---|---|
| GPS Position | Latitude, Longitude, Altitude (m) | -- | gps:location(0) |
| Baro Altitude | Altitude (m) | -- | baro:get_altitude() |
| Battery | Voltage, Current (A), Remaining % | Battery Instance (0-3) | battery |
| Airspeed | Airspeed (m/s) | -- | ahrs:airspeed_estimate() |
| RC Channel | Value (us) | Channel (1-16) | rc:get_pwm(ch) |
| Rangefinder | Distance (m) | Instance (0-3) | rangefinder:distance_cm() |
| Attitude | Roll, Pitch, Yaw (deg) | -- | ahrs:get_roll/pitch/yaw() |
| Ground Speed | Speed (m/s) | -- | ahrs:groundspeed_vector() |
| RC Aux Switch | State (0-2), Is High, Is Mid | Aux Function (0-999) | rc:get_aux_cached() |
| Rangefinder (Oriented) | Distance (m) | Orientation (Forward/Down/Up) | rangefinder:distance_cm_orient() |
Logic nodes handle boolean and comparison operations.
| Node | Inputs | Outputs | Properties |
|---|---|---|---|
| Compare | A (number), B (number) | Result (boolean) | Operator: >, <, ==, !=, >=, <=
|
| If / Else | Condition (boolean) | True, False | -- |
| AND | A (boolean), B (boolean) | Result (boolean) | -- |
| OR | A (boolean), B (boolean) | Result (boolean) | -- |
| NOT | Input (boolean) | Result (boolean) | -- |
| Range Check | Value (number) | In Range (boolean) | Min, Max |
| Switch | Value (number) | Case 0, Case 1, Case 2, Default | Case 0/1/2 Values |
Math nodes perform numeric calculations.
| Node | Inputs | Outputs | Properties |
|---|---|---|---|
| Add | A, B | Result | -- |
| Subtract | A, B | Result | -- |
| Multiply | A, B | Result | -- |
| Divide | A, B | Result (zero-safe) | -- |
| Clamp | Value | Result | Min, Max |
| Map Range | Value | Result | Input Min/Max, Output Min/Max |
| Abs | Value | Result | -- |
| Min | A, B | Result | -- |
| Max | A, B | Result | -- |
Action nodes produce side effects. They require a boolean trigger input -- the action only fires when the trigger is true.
| Node | Inputs | Properties | ArduPilot API |
|---|---|---|---|
| Send GCS Text | Trigger | Message, Severity (Emergency..Debug) | gcs:send_text() |
| Set Servo | Trigger, PWM (number) | Servo Number (1-16) | SRV_Channels:set_output_pwm() |
| Set Flight Mode | Trigger | Mode Number (0-30) | vehicle:set_mode() |
| Set Parameter | Trigger, Value (number) | Parameter Name | param:set() |
| Trigger Relay | Trigger | Relay Number (0-5), State (ON/OFF) | relay:on/off() |
| Log to File | Trigger, Value 1-3 (any) | File Name, Separator | io.open/write/close |
| Set LED | Trigger, R, G, B (numbers) | LED Instance (0-15) | serialLED:set_RGB() |
Timing nodes control when and how often things happen.
| Node | Inputs | Outputs | Properties |
|---|---|---|---|
| Run Every | Trigger (boolean) | Flow (boolean) | Interval (100-60000 ms) |
| Debounce | Input (boolean) | Output (boolean) | Delay (50-10000 ms) |
| On Change | Value (number) | Changed (boolean) | -- |
| Rising Edge | Input (boolean) | Triggered (boolean) | -- |
Variable nodes store and retrieve values that persist across update cycles.
| Node | Inputs | Outputs | Properties |
|---|---|---|---|
| Constant | -- | Value (any) | Type (Number/String/Boolean), Value |
| Get Variable | -- | Value (any) | Variable Name |
| Set Variable | Trigger, Value (any) | -- | Variable Name |
Utility nodes for organizing your graph.
| Node | Purpose |
|---|---|
| Comment | A text label for documentation. No effect on compiled code |
The graph editor generates code using these ArduPilot Lua bindings.
gcs:send_text(severity, message)Severity levels: 0=Emergency, 1=Alert, 2=Critical, 3=Error, 4=Warning, 5=Notice, 6=Info, 7=Debug.
vehicle:set_mode(mode_number)
vehicle:get_mode()
vehicle:is_armed()Mode numbers are vehicle-specific (e.g., Plane: 0=Manual, 10=Auto, 11=RTL).
ahrs:get_roll() -- radians
ahrs:get_pitch() -- radians
ahrs:get_yaw() -- radians
ahrs:get_home() -- Location object
ahrs:groundspeed_vector()
ahrs:airspeed_estimate()baro:get_altitude() -- metersbattery:voltage(instance)
battery:current_amps(instance)
battery:capacity_remaining_pct(instance)Instance 0 is the primary battery.
rc:get_pwm(channel) -- 1-16, returns PWM in microseconds
rc:get_aux_cached(aux_fn) -- returns switch position 0/1/2SRV_Channels:set_output_pwm(channel, pwm)
SRV_Channels:set_output_pwm_chan_timeout(channel, pwm, timeout_ms)Use set_output_pwm_chan_timeout for temporary overrides.
param:get(name) -- returns value or nil
param:set(name, value) -- returns true on success
param:set_and_save(name, value)rangefinder:distance_cm(instance)
rangefinder:distance_cm_orient(orientation)Orientations: 0=Forward, 24=Up, 25=Down.
relay:on(relay_num)
relay:off(relay_num)
relay:toggle(relay_num)Relay numbers 0-5.
serialLED:set_num_neopixel(instance, count)
serialLED:set_RGB(instance, led_index, r, g, b)
serialLED:send(instance)Every ArduPilot Lua script follows this pattern:
function update()
-- Your logic here
return update, interval_ms
end
return update, interval_msThe return update, interval_ms tells ArduPilot to call update() again after interval_ms milliseconds. The graph editor handles this automatically based on the Run Interval setting.
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