Fly a mission with PX4
Send the simulated X500 round a square of waypoints and back, from a ground station or from a script.
Prerequisites
Fly the X500 with PX4: Gazebo
running the x500_px4 world in one shell and px4_sitl.py in another.
The mission
x500_gazebo/missions/x500_square.plan: take off to 5 m, fly a square
with a side of 10 m (north, then east, then back south, then home), and
land where it took off. It is a QGroundControl
plan file, with its positions around the world’s origin.
ros2 pkg prefix --share x500_gazebo # the plan is in missions/ under this
From a script
In a third shell, with the workspace and the PX4 environment sourced:
ros2 run x500_gazebo px4_mission.py
It uploads the plan, puts PX4 in its mission mode, arms it and follows the flight:
uploaded 6 items from .../missions/x500_square.plan
armed, mission started
5 s north -0.0 east -0.0 up 0.5
reached item 1 of 6
10 s north 1.9 east -0.2 up 4.7
reached item 2 of 6
15 s north 10.1 east 3.6 up 4.9
...
reached item 6 of 6
reached 6 of 6 items; farthest 14.1 m from the start, highest 5.9 m; landed and disarmed
About 40 s. The exit code is 0 when every item was reached and the vehicle
landed and disarmed, so the script can be the check of a longer test. In
PX4’s shell the same flight reads Executing Mission, Takeoff detected,
Mission finished, landed, Disarmed by landing.
a plan file |
flown in place of the packaged one |
|
the PX4 instance to talk to, as given to |
|
seconds to let the flight take; 300 by default |
|
upload and stop, to start the mission yourself |
It needs pymavlink, which PX4’s Python environment has.
From QGroundControl
Open QGroundControl; the vehicle appears by itself. In the Plan view, open the plan file and press Upload; back in the Fly view, slide to start the mission.
Note
The mission was tried with the script, not with QGroundControl.
Your own mission
Draw it in QGroundControl’s Plan view around the vehicle, and save it. The world’s origin is latitude 47.397971, longitude 8.546164 (Zurich, PX4’s default); the ground plane reaches 100 m from it each way.
The script flies simple items: takeoff, waypoints, land. Survey patterns
and other complex items it refuses, saying which, and so it does a plan
with an item the vehicle is to stop at (autoContinue false): it flies a
mission to the ground without anyone to tell it to go on.
Things to know
The height wanders in sharp turns. Along the square the X500 holds 5 m, and at each corner it swings between about 4.2 and 6.3 m as it brakes and accelerates. PX4’s own simulated X500 does the same on the same mission, so it is how PX4 flies this, not this model. Longer legs or a gentler
MPC_ACC_HOR(3 m/s² by default) reduce it.A mission stays in PX4 across restarts, with how far it got. The script starts each flight from the first item; started by hand in PX4’s shell, a mission that already finished reports
Mission finishedat once.PX4 checks every item. A parameter a command does not use must be empty (
nullin the plan), not a number, or the upload fails withIGN MISSION_ITEM: Invalid item. QGroundControl writes them right; a plan written by hand may not.
Troubleshooting
no PX4 heard on UDP port 14540: px4_sitl.py is not running, or it
runs with another --instance (the port is 14540 plus the instance).
PX4 refused the mission: MAV_MISSION_INVALID_PARAM...: an item has a
number in a parameter its command does not use; see above.
PX4 refused to arm: at PX4’s prompt, commander check says what
fails.
PX4 disarmed without taking off: PX4 took the mission for finished
or not feasible; its shell says which.