PX4 uses the Google C++ Style Guide as its baseline, with a small set of project-specific modifications. Formatting is enforced automatically in CI — pull requests that fail the format check are not merged. Run the format tools locally before pushing to avoid round-trips.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/PX4/PX4-Autopilot/llms.txt
Use this file to discover all available pages before exploring further.
Not all existing PX4 source code matches the style guide. You are only required to style the code you write or modify. You do not need to reformat an entire file when you touch one function.
Running format checks locally
Use these two targets to check and fix formatting on changed C/C++ files:make format on every changed file before committing. If make check_format exits with a non-zero status, CI will reject your pull request.
Key style rules
The following rules differ from or extend the Google C++ style guide:Indentation
- Correct
- Incorrect
- Tabs for indentation (equivalent to 8 spaces in display width).
- Spaces for alignment (e.g., lining up values after a tab-indented line).
Line length
Maximum line length is 140 characters. Lines that exceed this will be flagged bycheck_format.
File extensions
Use.cpp for C++ source files, not .cc.
Naming conventions
| Construct | Convention | Example |
|---|---|---|
| Functions and methods | lowerCamelCase() | computeAltitude() |
| Classes and constructors | UpperCamelCase() | EkfInterface() |
| Private member variables | _underscore_prefixed_snake_case | _private_member_variable |
| Constants | kUpperCamelCase | kConstantFloat |
Class access keywords
Placepublic:, protected:, and private: with zero spaces of indentation inside the class body:
Documented code snippet
The following shows a well-formatted PX4 class that follows all style rules:clang-tidy
In addition to formatting, PX4 runs clang-tidy for static analysis. The project’s.clang-tidy file in the repository root configures which checks are enabled. Common checks enforce:
- Use of
nullptrinstead ofNULLor0for pointers. - Avoiding C-style casts in favor of
static_cast,reinterpret_cast, etc. - Proper use of
constandconstexpr. - Range-based
forloops where applicable.
Python style
Python files in the repository are checked with mypy for type correctness and flake8 for style. Run both locally if you modify Python tooling:Commit conventions for style changes
Follow the conventional commit format for formatting commits. Use thestyle type: