ArduPilot Maintenance Tracker - Lua Odometer for Drones
A persistent Lua script for ArduPilot that tracks lifetime flight stats like hours, max speed, altitude, and events directly on your flight controller's SD card.
2 min read
What is Lua Scripting in ArduPilot?
Lua is a lightweight, embeddable scripting language ideal for extending applications without altering core code. ArduPilot integrates Lua 5.3 in a sandboxed environment, allowing scripts to run on the flight controller alongside flight controls. This enables custom behaviors like monitoring sensors or automating tasks safely at low priority.[1][2][3][4]
Features of Maintenance Tracker
This script creates a persistent “odometer” file on the SD card, surviving log rotations. It tracks boot cycles, flight count, total hours, max ground speed, max altitude, peak vibrations, geofence breaches, and battery failsafes—saving on every disarm.[file:README
.md] Data logs to maintenance.log in a simple key-value format for easy review.[file:README
.md]
Installation and Setup
-
Download the script: Download
maintainance_tracker.luaandREADME.mdfrom the repository.Terminal window git clone https://github.com/rohith8272-uas-lua.gitcd rohith8272-uas-lua -
Copy to SD card: Insert the flight controller’s SD card into your computer. Place
maintainance_tracker.luain theAPM/scripts/folder. Create the folder if needed.[file:README .md][1] -
Enable scripting: Connect via Mission Planner or QGC. Set
SCR_ENABLEto1and reboot the autopilot.[5][1] -
Verify: Check the Messages tab for:
MNT: System Loaded. Boot Count: X. New parametersMNT_*appear after refresh.[file:README .md]
For SITL simulation, place in the scripts/ folder of your working directory.[file:README
.md]
Configuration and Customization
Tune via parameters:
MNT_ENABLE: 0 disables, 1 enables (default 1).MNT_LOG_MASK: Bitmask for features (1=vibration, 2=perf, 4=breaches, 8=failsafes; default 15=all).MNT_RESET: Set to 1 to clear log.[file:README .md]
Edit the script for custom logic. Use bitwise checks like if (mask & 1) ~= 0 then for vibration monitoring.[file:README
.md][file:maintainance_tracker
.lua] Access ArduPilot APIs like ahrs:get_vibration(), gps:ground_speed(), fence:get_breaches().[file:maintainance_tracker
.lua][1]
Viewing Data
Download maintenance.log without removing the SD card:
- In Mission Planner, press Ctrl + F > MAVFtp.
- Select and download
maintenance.log.[file:README .md]
Example:
BOOTS=42FLIGHTS=15TIME_MIN=124.50MAX_VIBE=14.20MAX_SPD=22.50MAX_ALT=120.00BREACHES=0FAILSAFES=1[file:README .md]
Developing Your Own Lua Scripts
Start with ArduPilot docs for APIs. Use tables for state (e.g., local state = {boots = 0}).[file:maintainance_tracker
.lua] Main loop via function update() returning update, 1000 for 1Hz.[file:maintainance_tracker
.lua][1]
- Load/save state with
io.open(). - Bind params:
param:add_table(). - Monitor arming:
arming:is_armed(). - Send messages:
gcs:send_text().[file:maintainance_tracker .lua][1]
Test in SITL first. Scripts run in parallel, prioritized low for safety.[1]
Contribute
Fork the repo, tweak for your needs like adding GPS health or custom alerts. Open issues or PRs!
📍 Repository: https://github.com/rohith8272/UAS-lua-scripts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29