Fly the X500 with PX4
Take off, hold and land the simulated X500 under PX4, to confirm that the autopilot and the model work together.
Prerequisites
Steps
Two shells. Both need the workspace and then the PX4 environment, in that order:
source ~/ws/install/setup.bash
source ~/ws/thirdparty/setup-px4.sh
First, the simulation:
gz sim -r $(ros2 pkg prefix --share x500_gazebo)/worlds/x500_px4.sdf
The quad sits on its landing gear and nothing moves.
Then the autopilot:
ros2 run x500_gazebo px4_sitl.py
PX4 prints its banner, finds the model, and leaves you at its prompt:
INFO [init] Gazebo world is ready
INFO [gz_bridge] world: x500_px4, model: x500
...
INFO [commander] Ready for takeoff!
pxh>
Ready for takeoff! comes a few seconds after the prompt, when PX4’s
estimator has settled. Then, at the prompt:
commander takeoff
Command |
Expected |
|---|---|
|
|
|
|
|
it comes down where it is; |
|
PX4 exits; Gazebo keeps running |
To see what PX4 commands the motors, in a third shell:
gz topic -e -t /x500/command/motor_speed
Four velocities in rad/s, about 150 when armed on the ground and about 690 in hover, of the 1000 the motors can do.
With a ground station
QGroundControl connects by itself to a PX4 on the same computer: open it at any point and the vehicle appears on the map, in Zurich, where PX4 puts its simulated vehicles and where the world has its origin. Take off and land from its toolbar.
Note
The pages here were tried without QGroundControl, with the commands above.
Things to know
Start Gazebo first. PX4 attaches to a model that is already there. Started alone it waits, printing
Waiting for Gazebo world...once a second, and after 30 seconds it gives up withTimed out waiting for Gazebo worldand exits. Start it again once Gazebo runs.PX4 remembers parameters between runs, in
build/px4_sitl_default/rootfs/<instance>/of its checkout. The ones in this package’s parameters file are given again at every start, so they win; one you set by hand withparam setstays until you set it back.Preflight Fail: system power unavailableis printed once at start, for a battery the simulation does not have. It stops nothing.A second run does not need Gazebo restarted:
shutdown, thenpx4_sitl.pyagain.
What px4_sitl.py does
It starts PX4’s own program, told to attach to a model in a running Gazebo and not to start one:
|
the world the model is in, by name or SDF file; |
|
the model; |
|
PX4’s instance number, one per vehicle |
|
the parameters file; this package’s by default |
|
one more parameter, over the file; may be repeated |
|
the PX4 checkout; |
|
no prompt; send commands with |
|
print the environment PX4 would get, and stop |
The airframe is PX4’s own simulated X500 (4001_gz_x500). What this model
needs different is in x500_gazebo/params/x500_px4.params: where its
rotors are, and two settings so the first flight needs no ground station
and no remote control.
It also gives PX4 GZ_IP=127.0.0.1, unless GZ_IP is already set: Gazebo
is on this computer. On a computer with several network interfaces, Docker’s
bridges for one, Gazebo’s transport otherwise has several to choose from,
and PX4 misses one sensor or another and never arms. With Gazebo on another
computer, set GZ_IP yourself in both, each to its own address on the
network they share; yours is kept.
Troubleshooting
Arming denied: Resolve system health failures first: ask PX4 what
fails with commander check.
No connection to the GCS: a parameters file of yours withoutNAV_DLL_ACT 0, or a value saved from another run. Open QGroundControl, orparam set NAV_DLL_ACT 0.No valid data from Gyro 0,No valid data from Accel 0,barometer 0 missing,Found 0 compass (required: 1): a sensor does not reach PX4. If it is another one on every run, Gazebo’s transport is picking a network interface on a computer with several:px4_sitl.pysetsGZ_IP=127.0.0.1for PX4 against that; check that the shell did not have anotherGZ_IP, and set the same in Gazebo’s shell if it persists. If it is all four on every run, seenever publishedbelow.Gyro #0 fail: STALE!,BARO #0 failed: STALE!: PX4 gets the same sample again and again and takes the sensor for dead. The model’s PX4 sensors lost their noise.
PX4 starts, and listener sensor_gyro says never published: PX4 is
listening to topics nobody publishes. The world’s name and the model’s
name are part of them. Check what PX4 was told (gz_bridge] world: ..., model: ...) against gz topic -l | grep base_link/sensor. A model
generated for one world does not work in a world of another name
(the PX4 variant).
Waiting for Gazebo world..., then Timed out waiting for Gazebo world: Gazebo is not running, or the two shells do not share
GZ_PARTITION.
It takes off and flips, or spins: the rotor order, spin or positions
PX4 has do not match the model. Compare param show CA_ROTOR* with
x500_px4.params.