Skip to content

fossuav/aap

Repository files navigation

ArduPilot AI Playbooks

Overview

This project provides guidance documents for using Large Language Models (LLMs) to generate and modify code for the ArduPilot autopilot platform.

Three usage modes are supported:

  1. Claude Code - Anthropic's CLI tool for interactive development with Claude
  2. Gemini CLI - Google's CLI tool for interactive development with Gemini
  3. Chat-based LLMs - Traditional prompt-based code generation with any LLM

The playbooks contain rules and constraints that ensure generated code is safe, testable, and consistent with ArduPilot development standards.


Claude Code Integration

Claude Code is Anthropic's official CLI tool that provides an interactive development experience. It can read your codebase, make edits, run commands, and understand project context.

Quick Start

  1. Install the playbooks into your ArduPilot repository:

    cd /path/to/ardupilot
    curl -fsSL https://raw.githubusercontent.com/fossuav/aap/main/install-claude.sh | bash
  2. Start Claude Code:

    claude

Claude Code will automatically read the CLAUDE.md files and use them to guide its responses.

Installed Files

The install script places the following files:

File Purpose
CLAUDE.md Build system, architecture overview, C++ development guidelines
libraries/AP_Scripting/CLAUDE.md Lua scripting patterns, applet structure, parameter system
libraries/AP_Scripting/CLAUDE_CRSF_MENU.md CRSF (Crossfire) menu implementation
libraries/AP_Scripting/CLAUDE_VEHICLE_CONTROL.md Vehicle control APIs, movement commands, RC input
libraries/AP_NavEKF3/CLAUDE.md EKF3 navigation filter reference and analysis methodology
libraries/AP_HAL_ChibiOS/hwdef/CLAUDE.md ChibiOS board porting and hwdef.dat creation
ArduPlane/CLAUDE.md Plane flight modes, log analysis, QuadPlane operations
Tools/autotest/CLAUDE.md Autotest authoring conventions, event-wait patterns, Lua applet test patterns
.claude/settings.json Project permissions and hooks — auto-allows the skill scripts and a few read-only tools (not blanket python3/git/rm), enforces rules. Machine-specific allows go in settings.local.json
.claude/skills/*/SKILL.md Slash command skills (see table below)
.claude/skills/log-analyze/log_extract.py Log extraction tool used by /log-analyze
.claude/skills/autotest/autotest_results.py Autotest result parser used by /autotest to summarise pass/fail and extract failure context
.claude/skills/autotest/run_autotest.py Timed autotest runner used by /autotest — wraps autotest.py with a wall-clock timeout and lock pre-check
.claude/skills/hwdef-check/hwdef_check.py Helper used by /hwdef-check to run DMA, board-ID, file-presence, and commit-structure checks on a new-board PR
.claude/skills/pr-checks/ci_failures.py Helper used by /pr-checks to download a PR's failed CI job logs and extract the failing tests/build errors
.claude/hooks/pre_bash_check.py PreToolUse hook — enforces git commit and safety rules
.claude/hooks/post_edit_check.py PostToolUse hook — checks C++ edits for common violations

Skills (Slash Commands)

Skills are invoked as /command in Claude Code. They pre-authorize necessary tools so common operations run without repeated permission prompts.

Read-only skills (safe, no side effects):

Command Description
/boards [search] List and search available board targets
/find-code <feature> Find where features, modes, commands, or messages are implemented
/find-param <NAME> Find parameter definitions, ranges, units in source code
/build-options [search] Search compile-time feature flags (AP_*_ENABLED defines)
/style-check [files] Check code style with astyle dry-run and whitespace checks
/hwdef-info <board> Show board hardware definition (MCU, UARTs, pins, sensors)
/hwdef-check <PR> Review an hwdef PR — worktree checkout, DMA/board-ID/file/commit checks, playbook pass, draft review comment
/explain <topic> Explain ArduPilot code, architecture, or subsystems
/lua <task> Write or modify Lua applets (loads playbook + API docs)
/lua-crsf <menu> Write CRSF transmitter menu scripts with crsf_helper
/lua-vehicle <task> Lua vehicle control, movement, RC input
/log-analyze <logfile> Analyze DataFlash .bin logs (messages, params, events, plots)
/pr-checks [PR] Download a PR's failing CI checks and identify the failing tests/build errors
/aap-update Compare local playbook version with GitHub and install updates

Write skills (local only — compile, run tests, launch simulator):

Command Description
/build <vehicle> [--board board] Configure and build firmware
/check [test_name] Build and run unit tests (Google Test)
/autotest <vehicle> [test] Run SITL integration/behavior tests
/sitl <vehicle> [options] Launch interactive SITL simulator

Hooks (Rule Enforcement)

Hooks automatically enforce key CLAUDE.md rules that Claude might otherwise ignore. They run as PreToolUse/PostToolUse checks configured in .claude/settings.json.

Hook Event Enforces
pre_bash_check.py PreToolUse (Bash) No git clean, no force push to main/master, no Claude co-author in commits, commit messages must have subsystem prefix
post_edit_check.py PostToolUse (Edit/Write) No printf() in C++ flight code (use gcs().send_text())

Hooks that block (exit code 2) provide feedback to Claude explaining the rule violation, so it can fix the issue and retry.

Uninstalling

To remove the playbook files from ArduPilot:

cd /path/to/ardupilot
curl -fsSL https://raw.githubusercontent.com/fossuav/aap/main/uninstall-claude.sh | bash

Gemini CLI Integration

The Gemini CLI provides a similar interactive development experience using Google's Gemini models.

Quick Start

  1. Install the playbooks into your ArduPilot repository:

    cd /path/to/ardupilot
    curl -fsSL https://raw.githubusercontent.com/fossuav/aap/main/install-gemini.sh | bash
  2. Start Gemini:

    gemini

Gemini will automatically read the GEMINI.md files and use them to guide its responses.

Installed Files

The install script places the following files:

File Purpose
GEMINI.md Build system, architecture overview, C++ development guidelines
libraries/AP_Scripting/GEMINI.md Lua scripting patterns, applet structure, parameter system
libraries/AP_Scripting/GEMINI_CRSF_MENU.md CRSF (Crossfire) menu implementation
libraries/AP_Scripting/GEMINI_VEHICLE_CONTROL.md Vehicle control APIs, movement commands, RC input

Uninstalling

To remove the playbook files from ArduPilot:

cd /path/to/ardupilot
curl -fsSL https://raw.githubusercontent.com/fossuav/aap/main/uninstall-gemini.sh | bash

Chat-Based LLM Usage

For traditional chat-based LLMs (ChatGPT, Claude web, Gemini web, etc.), you can manually provide playbook context.

Key Components

To generate code, the LLM requires the following context:

  • API Documentation (docs.lua) This file is the definitive source for all ArduPilot-specific Lua function signatures and is the final authority on correct API usage.
  • AI Playbook This file(s) is the rule definitions for code generation telling the LLM what it may and may not do. Without this the LLM will go easily off track
  • Code Digest (digest.txt) This file contains a snapshot of existing code and tests within the ArduPilot repository. It provides the LLM with the necessary examples to create new code. Unfortunately this digest tends to be quite large and can easily overflow the LLM's context window so it is often necessary to abandon it in favour of merely the first two items.

Generating a Digest

  1. Install gitingest
  2. Run gitingest libraries/AP_Scripting -e '*.cpp' -e '*.c' -e '*.h' -e '*.txt'
  3. A LUA digest will be generated in digest.txt
  4. Run gitingest Tools/autotest -i arducopter.py -i vehicle_test_suite.py
  5. An autotest digest will be generated in digest.txt

How to Use This System

The process for generating code is as follows:

  1. Write a Prompt: Clearly describe the required functionality. Focus on what the code should do, not the implementation details.
    • Example Prompt: "Create a script to control the brightness of my drone's NeoPixel LEDs using an RC switch. It should support three levels: off, medium, and high."
  2. Provide Context: Give the LLM your prompt, AI playbook, API documentation and, optionally, the digest-lua.txt file.
  3. Generate Artifacts: The LLM will generate a complete ArduPilot Applet (in the case of lua), which includes:
    • A .lua script file.
    • A .md documentation file explaining how to set up and use the script.
  4. Generate Autotest: For every applet, the LLM should offer to generate a corresponding SITL autotest file. This allows you to verify the script's functionality in a safe, simulated environment.

Repository Structure

aap/
├── claude/                          # Claude Code playbooks (CLAUDE.md files)
│   ├── CLAUDE.md                    # Root playbook (build, architecture, C++)
│   ├── ArduPlane/
│   │   └── CLAUDE.md                # Plane log analysis, flight modes, QuadPlane
│   ├── libraries/
│   │   ├── AP_Scripting/            # Lua scripting playbooks
│   │   │   ├── CLAUDE.md
│   │   │   ├── CLAUDE_CRSF_MENU.md
│   │   │   └── CLAUDE_VEHICLE_CONTROL.md
│   │   ├── AP_NavEKF3/              # EKF3 navigation filter
│   │   │   └── CLAUDE.md
│   │   └── AP_HAL_ChibiOS/hwdef/    # ChibiOS board porting
│   │       └── CLAUDE.md
│   ├── Tools/
│   │   └── autotest/                # Autotest authoring playbook
│   │       └── CLAUDE.md
│   ├── hooks/                       # Claude Code hooks (rule enforcement)
│   │   ├── pre_bash_check.py       # PreToolUse: git commit, safety checks
│   │   └── post_edit_check.py      # PostToolUse: C++ code quality checks
│   └── skills/                      # Claude Code skills (slash commands)
│       ├── boards/SKILL.md          # /boards - list/search board targets
│       ├── find-code/SKILL.md       # /find-code - find feature implementations
│       ├── find-param/SKILL.md      # /find-param - find parameter definitions
│       ├── build-options/SKILL.md   # /build-options - search feature flags
│       ├── style-check/SKILL.md     # /style-check - check code formatting
│       ├── hwdef-info/SKILL.md      # /hwdef-info - board hardware definitions
│       ├── explain/SKILL.md         # /explain - explain code/architecture
│       ├── lua/SKILL.md            # /lua - write/modify Lua applets
│       ├── lua-crsf/SKILL.md       # /lua-crsf - CRSF menu scripts
│       ├── lua-vehicle/SKILL.md    # /lua-vehicle - vehicle control from Lua
│       ├── build/SKILL.md           # /build - configure and compile
│       ├── check/SKILL.md           # /check - run unit tests
│       ├── autotest/SKILL.md        # /autotest - run SITL integration tests
│       ├── sitl/SKILL.md            # /sitl - launch SITL simulator
│       ├── hwdef-check/             # /hwdef-check - review an hwdef PR
│       │   ├── SKILL.md
│       │   └── hwdef_check.py
│       └── log-analyze/             # /log-analyze - analyze flight logs
│           ├── SKILL.md
│           └── log_extract.py
├── gemini/                          # Gemini CLI playbooks (GEMINI.md files)
│   ├── GEMINI.md                    # Root playbook (build, architecture, C++)
│   └── libraries/AP_Scripting/      # Lua scripting playbooks
│       ├── GEMINI.md
│       ├── GEMINI_CRSF_MENU.md
│       └── GEMINI_VEHICLE_CONTROL.md
├── cpp/                             # C++ playbooks for chat-based LLMs
│   └── AI_PAIR_PROGRAMMING_PLAYBOOK_CPP.md
├── lua/                             # Lua playbooks for chat-based LLMs
│   ├── AI_PAIR_PROGRAMMING_PLAYBOOK.md
│   ├── AI_CRSF_MENU_PLAYBOOK.md
│   ├── AI_VEHICLE_CONTROL_PLAYBOOK.md
│   ├── AI_GIT_FORMAT_PATCH_PLAYBOOK.md
│   └── docs.lua                     # Lua API documentation
├── install-claude.sh                # Install Claude playbooks to ArduPilot
├── uninstall-claude.sh              # Remove Claude playbooks from ArduPilot
├── install-gemini.sh                # Install Gemini playbooks to ArduPilot
├── uninstall-gemini.sh              # Remove Gemini playbooks from ArduPilot
└── README.md

License

This project is licensed under the GNU General Public License v3.0. See COPYING.txt for details.

About

ArduPilot AI Playbooks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors