Skip to main content

Tools and REST API for configuring PX4 from a companion computer

Project description

px4-configuration

Repository that collects scripts to configure and modify PX4 from a companion Linux computer. All tooling is built on top of MAVSDK-Python.

Installation

Development Installation

# Optional: create a virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install the package (installs all required dependencies)
pip install -e .

Building a Wheel Package

To build a distributable wheel (.whl) file:

# Install build tools (if not already installed)
pip install build

# Build the wheel package
python -m build --wheel

# The wheel file will be created in the dist/ directory
# Example: dist/px4_configuration-0.1.0-py3-none-any.whl

To build both wheel and source distribution:

python -m build

Installing from a built wheel:

# Install from the wheel file
pip install dist/px4_configuration-0.1.0-py3-none-any.whl

Requirements

  • Python 3.10+
  • PX4 flight controller connected over serial (e.g. /dev/pixhawk)
  • User added to the dialout group for serial access (sudo usermod -aG dialout $USER)

Scripts

All scripts use a serial connection to talk to PX4.

  • scripts/calibrate.py – run gyro, accel, mag, level and (future) ESC calibration
  • scripts/set-params.py – bulk upload parameters from .params files in configs/
  • scripts/upload-sdcard-config.py – upload files (e.g. extras.txt) to the PX4 SD card via MAVLink FTP
  • scripts/shell.py – open an interactive PX4 NSH shell session over MAVLink
  • scripts/px_uploader.py – PX4 firmware uploader (original PX4 script, unverified here)

REST API (FastAPI)

The companion computer can expose the same functionality through a REST API located in the px4_configuration.api package.

Run the API server

# Using the packaged console script
px4-config-api --host 0.0.0.0 --port 8000

# Or via the helper module
python run_api.py

# Or directly with uvicorn
uvicorn px4_configuration.api.main:app --host 0.0.0.0 --port 8000

Endpoints

  • GET /health – health check
  • POST /calibration/start – start selected calibrations, returns Server-Sent Events (SSE) with progress
  • POST /params/upload – upload a .params file (multipart form), SSE progress stream
  • POST /sdcard/upload – upload a file (e.g. extras.txt) to the SD card, SSE progress stream
  • WS /shell/connect – interactive PX4 shell over WebSocket

All endpoints accept optional port and baudrate (defaults /dev/pixhawk, 2000000). SSE responses emit JSON payloads with keys such as type, message, progress, etc.

Calibration Message Structure

The /calibration/start endpoint returns structured JSON messages via Server-Sent Events (SSE). Each calibration type has a specific message format:

Accelerometer Calibration

The /calibration/start endpoint returns structured JSON messages via Server-Sent Events (SSE). Each calibration type has a specific message format:

{
  "type": "accelerometer_progress",
  "progress": 0.17,
  "status_text": "down side result: [0.020 0.819 -9.750]",
  "pending_orientations": ["back", "front", "left", "right", "up"],
  "current_orientation": "down",
  "current_message": "measuring",
  "result": [0.020, 0.819, -9.750],
  "is_complete": false
}

Fields:

  • pending_orientations: List of remaining orientations to measure (e.g., ["back", "front", "left", "right", "up"])
  • current_orientation: Currently detected orientation being measured (e.g., "down", "left")
  • current_message: Instruction type - "hold_still", "rest_detected", "measuring", "rotate", "orientation_detected", "already_completed", "complete"
  • progress: Progress value (0.0 to 1.0)
  • result: Measurement result array [x, y, z] when available
  • is_complete: Boolean indicating completion

Completion message:

{
  "type": "accelerometer_complete",
  "message": "Accelerometer calibration finished",
  "is_complete": true
}

Magnetometer Calibration

{
  "type": "magnetometer_progress",
  "progress": 0.33,
  "status_text": "right orientation detected",
  "pending_orientations": ["back", "front", "left", "up"],
  "current_orientation": "right",
  "current_message": "orientation_detected",
  "is_complete": false
}

Fields:

  • pending_orientations: List of remaining orientations to measure
  • current_orientation: Currently detected orientation
  • current_message: Instruction type - "rotate", "hold_still", "rest_detected", "motion_detected", "orientation_detected", "already_completed", "complete"
  • progress: Progress value (0.0 to 1.0) that increments during rotation
  • is_complete: Boolean indicating completion (true when progress >= 1.0)

Completion message:

{
  "type": "magnetometer_complete",
  "message": "Magnetometer calibration finished",
  "is_complete": true
}

Gyroscope Calibration

{
  "type": "gyroscope_progress",
  "progress": 0.5,
  "status_text": null,
  "current_message": "calibrating",
  "is_complete": false
}

Fields:

  • progress: Progress value (0.0 to 1.0)
  • current_message: "calibrating" during progress, "complete" when done
  • is_complete: Boolean indicating completion (true when progress >= 1.0)

Completion message:

{
  "type": "gyroscope_complete",
  "message": "Gyroscope calibration finished",
  "is_complete": true
}

Level Horizon Calibration

{
  "type": "horizon_progress",
  "progress": 0.4,
  "status_text": null,
  "current_message": "calibrating",
  "is_complete": false
}

Fields:

  • progress: Progress value (0.0 to 1.0)
  • current_message: "calibrating" during progress, "complete" when done
  • is_complete: Boolean indicating completion (true when progress >= 1.0)

Completion message:

{
  "type": "horizon_complete",
  "message": "Level horizon calibration finished",
  "is_complete": true
}

Status Messages

General status messages are also emitted:

{
  "type": "status",
  "message": "Starting accelerometer calibration..."
}
{
  "type": "error",
  "message": "Calibration failed: <error details>"
}
{
  "type": "success",
  "message": "All calibrations completed"
}

Notes

  • Ensure the vehicle is disarmed and stationary before running calibration or parameter uploads.
  • The API and scripts require serial access; add your user to the dialout group if needed.
  • Example parameter files and extras.txt live under the configs/ directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

px4_configuration-0.3.0.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

px4_configuration-0.3.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file px4_configuration-0.3.0.tar.gz.

File metadata

  • Download URL: px4_configuration-0.3.0.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for px4_configuration-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6f769ff7f8b197f4ca6c45f69fbeaaef3d102c3456eab1aa18fe85a98fa45865
MD5 6c1410be32ba048f7c5df89991900a3a
BLAKE2b-256 3dfac7cdcc2ca8a46b92c8496941fd203137bb6f2edb4dd3d29b3f9205f18994

See more details on using hashes here.

File details

Details for the file px4_configuration-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for px4_configuration-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5c83e526edf562138b390032fa890b8019cef35334dd6196cb361ff52285c36
MD5 a3c45eb961a417ce3c26a52d0a040247
BLAKE2b-256 4eed625453b146c9e40c54ec61dde345b116a8c9220a517aa5b95e00c162f2fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page