An interface to send trajectories to the PX4 flight controller
Project description
PX4 CLI Utility
A command-line interface for commanding PX4 quadrotors over MAVLink with support for agile trajectories and motion capture feedback.
Installation
pip install -e .
Or to build and install:
python3 -m build
pip install dist/px4-*.whl
Usage
Basic Command Structure
px4 {URL} {COMMAND} {TRAJECTORY} [OPTIONS]
Mandatory Arguments
-
URL: PX4 connection URL (positional, required)
- Format:
udp:localhost:14540ortcp:192.168.1.5:5760
- Format:
-
COMMAND: Command to execute (positional, required)
track: Track a trajectory (more commands may be added in the future)
-
TRAJECTORY: Type of trajectory to execute (positional, required for track command)
lissajous: Figure-eight trajectorycircle: Circular trajectoryposition: Hold a fixed position
Optional Arguments
General Options
--mocap URL: Motion capture system URL (e.g.,vicon:192.168.1.3)--takeoff HEIGHT: Takeoff to the specified height before executing the trajectory- If specified, trajectories are executed relative to the takeoff position
- If not specified, trajectories are executed relative to the current position (must be flying with height > 0.5m)
--iterations N: Number of times to repeat the trajectory (default: 5)
Trajectory Types and Parameters
Lissajous (Figure-Eight)
Optional keyword arguments:
--A AMPLITUDE: Amplitude in X direction in meters (default: 1.0)--B AMPLITUDE: Amplitude in Y direction in meters (default: 0.5)--z HEIGHT: Target height in meters (default: 2.0)--duration SECONDS: Duration of one iteration in seconds (default: 10.0)--ramp-duration SECONDS: Time to ramp up/down in seconds (default: 3.0)
Example:
px4 udp:localhost:14540 track lissajous --mocap vicon:192.168.1.3 --A 1.5 --B 0.75 --z 2.5 --duration 10 --ramp-duration 3 --takeoff 1.0
This executes a lissajous trajectory with A=1.5m, B=0.75m, height=2.5m, duration=10s, ramp=3s, taking off to 1m first.
Circle
Optional keyword arguments:
--radius METERS: Radius of the circle in meters (default: 1.0)--z HEIGHT: Target height in meters (default: 2.0)--duration SECONDS: Duration of one iteration in seconds (default: 6.5)--ramp-duration SECONDS: Time to ramp up/down in seconds (default: 1.0)
Example:
px4 tcp:192.168.1.5:5760 track circle --mocap vicon:192.168.1.3 --radius 1.5 --z 2.5 --duration 6.5 --ramp-duration 1.0
This executes a circular trajectory with radius=1.5m, height=2.5m, duration=6.5s, ramp=1s.
Position
Optional keyword arguments:
--x METERS: X coordinate in meters (default: 0.0)--y METERS: Y coordinate in meters (default: 0.0)--z METERS: Z coordinate in meters (default: 2.0)
Example:
px4 udp:localhost:14540 track position --x 1.0 --y 0.5 --z 2.0 --takeoff 1.0
This takes off to 1m and then moves to and holds position (1.0, 0.5, 2.0).
Examples
With Takeoff (Starting from Ground)
# Lissajous trajectory with takeoff
px4 udp:localhost:14540 track lissajous --mocap vicon:192.168.1.3 --A 1.5 --B 0.75 --z 2.5 --duration 10 --ramp-duration 3 --takeoff 1.0
# Circle with takeoff, 3 iterations
px4 udp:localhost:14540 track circle --mocap vicon:192.168.1.3 --radius 1.0 --z 2.0 --duration 6.5 --ramp-duration 1.0 --takeoff 1.0 --iterations 3
# Hold position with takeoff
px4 udp:localhost:14540 track position --mocap vicon:192.168.1.3 --z 2.0 --takeoff 1.0
Without Takeoff (Already Flying)
# Lissajous from current position (must be > 0.5m high)
px4 tcp:192.168.1.5:5760 track lissajous --mocap vicon:192.168.1.3 --A 2.0 --B 1.0 --z 3.0 --duration 12 --ramp-duration 4
# Circle from current position
px4 udp:localhost:14540 track circle --mocap vicon:192.168.1.3 --radius 1.5 --z 2.5 --duration 7 --ramp-duration 1.5
Without Motion Capture
# Use onboard position estimation only (omit --mocap)
px4 udp:localhost:14540 track lissajous --A 1.0 --B 0.5 --z 2.0 --duration 8 --ramp-duration 2 --takeoff 1.0
Safety Features
- Minimum Height Check: If not using
--takeoff, the current height must be > 0.5m to prevent accidental ground execution - Gradual Position Changes: Position commands are ramped gradually
- Controlled Landing: After trajectory completion, the quadrotor hovers briefly then lands at the initial position
Behavior Details
With --takeoff Flag
- Arms the quadrotor
- Takes off to specified height
- Moves to trajectory start position
- Executes trajectory relative to takeoff position
- Hovers for 2 seconds after completion
- Lands at initial ground position
Without --takeoff Flag
- Checks current height is > 0.5m (safety check)
- Arms the quadrotor (if not already armed)
- Moves to trajectory start position
- Executes trajectory relative to current position
- Hovers for 2 seconds after completion
- Lands at initial ground position
Dependencies
numpy: Numerical computingmultirobot: Interface to PX4 and motion capture systems- Includes trajectory functions (
lissajous,circle) - MAVLink communication
- Vicon motion capture interface
- Includes trajectory functions (
Integration with Multirobot Package
This CLI uses the multirobot package for:
- Registry: Robot configuration management (
multirobot.registry) - MOCAP: Vicon motion capture system interface (
multirobot.mocap.Vicon) - Trajectories: Pre-defined trajectory functions (
multirobot.trajectories.lissajous,multirobot.trajectories.circle) - Client: Async client interface with methods like
arm(),goto(),command()
Development
To install in development mode:
pip install -e .
To build for distribution:
./build.sh
License
MIT License - see LICENSE file for details
Author
Jonas Eschmann (jonas.eschmann@gmail.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file px4-0.0.1.tar.gz.
File metadata
- Download URL: px4-0.0.1.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a9216db61dadf298f21ebd144546db03321554f3d9e6460c30167ea003973a1
|
|
| MD5 |
9d26970b1d78e649758fa8a8feed908b
|
|
| BLAKE2b-256 |
0da86ba2fe9567bfd58ca5022c3f793d908b5d64c3ed821b5ec1c8e5e91b04d9
|