# MCP Markup: Making Your ArduPilot Lua Scripts Visible in Mission Analyzer #3
Mission-analyzer
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Mission Analyzer scans
APM/scripts/on the SD card and shows what Lua scripts are loaded — their purpose, type, and (for mission scripts)how to embed them. This requires a small block of structured comments in the script header, called MCP markup.
Script types
ArduPilot Lua scripts fall into two categories:
Mission scripts use
vehicle:nav_script_time()to receive commands from aNAV_SCRIPT_TIME(42702) mission item. The flight controllerpauses at that waypoint, runs the script logic, and continues when the script calls
vehicle:nav_script_time_done().Background scripts start automatically with ArduPilot and run continuously alongside the mission. They cannot be triggered by a
waypoint. Examples: telemetry forwarders, engine controllers, LED managers.
Mission Analyzer needs to know which type your script is — and for mission scripts, which command numbers it accepts and what each
parameter means.
The markup format
Add this block to the top of your script, before any Lua code. Every line is a standard Lua comment (
--):Field reference:
MCP-NAMEMCP-TYPEmissionorbackgroundMCP-VERSIONMCP-DESCMCP-COMMANDMCP-PARAMMCP-PARAM syntax:
MCP-PARAM: <slot> <key> "<label>" <unit><slot>—param2,param3, orparam4(these are
arg1,arg2,arg3in the Lua API)<key>— short internal identifier, no spaces<label>— human-readable name, in double quotes<unit>— unit string, no spaces (s,m,deg,—for dimensionless)MCP-PARAMlines belong to the lastMCP-COMMANDabove them.Example: mission script
What Mission Analyzer shows in the Info report:
Example: background script
What Mission Analyzer shows:
Embedding a mission script in a waypoint file
Once the script is in
APM/scripts/andSCR_ENABLE = 1, add aNAV_SCRIPT_TIMEitem to your mission:42702(NAV_SCRIPT_TIME)10)0(not used)In
.waypointsformat (QGC WPL 110) — command 10, duration=60 s,width=40 m, as waypoint index 3:
Columns:
index current frame command param1 param2 param3 param4 lat lon alt autocontinueWithout markup: heuristic detection
If a script has no MCP markup, Mission Analyzer still tries to find command numbers using code patterns:
local CMD_SPRAY_START = 42→ extracts number and constant nameif cmd == 42 then→ extracts number onlyResult in the Info report:
Heuristic detection only works for mission scripts — background scripts are not scanned this way, since their numeric constants are
not mission command IDs.
Why comments, not code analysis?
Lua is a full programming language. A command number can be stored in a variable, computed at runtime, or looked up in a table. Reliably
extracting semantic meaning — parameter descriptions, units, human-readable names — from arbitrary Lua code would require executing
it. That is not safe to do on arbitrary third-party scripts.
Structured comments are the same approach used by JSDoc, Python docstrings, and Doxygen: the author states intent explicitly, the tool
reads it literally. Two minutes to write, works every time.
Uploading scripts to the SD card
Upload
.luafiles toAPM/scripts/over USB without removing theSD card:
APM/scripts/→ UploadAfter uploading, reboot the flight controller so the scripting engine picks up the new file (
SCR_ENABLE = 1must be set).See also
snake-sine-plane.lua— sinusoidal snake maneuver, full MCP markup examplewipe-passed-waypoints.lua— background script, no mission commandsNAV_SCRIPT_TIMEreferenceAll reactions