PX4 SITL spec
The plan for flying the X500 under PX4 in simulation, stated so each part
can be verified. It follows the form of bluerobotics_models’
SITL spec:
the spec and the source are both editable, a pull request may change either
or both, and the unit of work and review is a phase.
Decisions
PX4, not ArduPilot. The X500’s motor interface, rotor order and motor constants are PX4’s, so PX4 flies the model as it is. ArduCopter would need a bridge between
ArduPilotPlugin’s oneDoubleper channel andMulticopterMotorModel’sActuators, which nobody ships.PX4
v1.18.0, the first release that builds against Lyrical’s Gazebo.No plugin of PX4’s in the model or the world. PX4’s own process connects to a simulation that is already running (
PX4_GZ_STANDALONE).The variant is additive.
px4:=trueadds sensors; it takes nothing from the default model, so the ROS 2 side is the same with and without.Parameters live here, in
x500_gazebo/params/x500_px4.params, not in an airframe file inside PX4’s tree.
How PX4 meets Gazebo
It publishes
gz.msgs.Actuatorson/<model>/command/motor_speed, which the X500’s fourMulticopterMotorModelplugins already take.It reads four sensors from topics fixed in its code,
/world/<world>/model/<model>/link/base_link/sensor/<s>, with<s>imu_sensor/imu,air_pressure_sensor/air_pressure,magnetometer_sensor/magnetometerandnavsat_sensor/navsat, and the world’sclockandpose/info.
Phases
Phase |
Deliverable |
|---|---|
0 |
Toolchain and a setup page |
1 |
The PX4 variant of the model |
2 |
World, parameters, first flight |
3 |
A mission, and tuning |
4 |
ROS 2, several vehicles, the launch |
Each phase states an objective and how it is verified: automated is what CI runs unattended, with no autopilot installed; human is a page to follow, with what must happen at each step.
Prerequisites, assumptions and constraints
PX4 is built from source into
thirdparty/, not installed from apt and not resolved by rosdep.CI does not install or run an autopilot. Rosdep keys and packaging for it are out of scope.
Out of scope: the gimbal and the companion computer under PX4, wind, ArduPilot.
Phase 0: toolchain and a setup page
Objective: PX4 building against Lyrical’s Gazebo, and the page that says how, written alongside the work.
Verified by (human) the procedure in
Set up PX4 SITL, ending with a px4
binary that prints its usage.
Phase 1: the PX4 variant of the model
Objective: a model PX4 can read, from the same source as the default one, without changing the default one.
px4:=true on x500_gazebo/model.sdf.xacro adds a massless link with the
four flight sensors again, each on the topic PX4 subscribes to.
Every topic is written out in full. PX4 expects
.../link/base_link/sensor/..., and a sensor left on its default topic would carry the name of the link it is on, the massless one. So each of the four has an explicit<topic>, and nothing may rely on the default. The topic carries the world’s name, so the variant takespx4_world:=too.The second set is deliberate. The variant runs a second IMU at 250 Hz, and a second barometer, magnetometer and NavSat, each with its own noise, beside the ones ROS 2 reads. That is what keeps the variant additive; they are not to be merged with the first set.
The sensors carry noise. PX4 takes a sensor whose value never changes for a dead one and will not arm.
The model’s name in the world must be its
topic_namespace. PX4 builds the sensor topics and/<model>/command/motor_speedfrom the model’s name, and theMulticopterMotorModelplugins listen underrobotNamespace, which istopic_namespace. The generated model is named aftertopic_namespace, so the two agree as generated. Including it under another<name>breaks that with no error: PX4’s motor commands go nowhere.A second model,
model://x500_with_px4, is installed for the worldx500_px4and the namex500, both fixed when it is built. It is meant for that world only; for another world or name, generate the model withconfigure_vehicle.py.
Verified by (automated): the default model has no trace of the variant;
the variant has the four sensors on exactly PX4’s topics for a given world
and instance, each with noise; the model’s name, the motors’
robotNamespace and the name in those topics are the same, so the motors’
topic is /<name>/command/motor_speed; the installed model matches a fresh
expansion.
Phase 2: world, parameters, first flight
Objective: the X500 taking off, holding and landing under PX4, by a page a reviewer can follow.
worlds/x500_px4.sdf has the variant in it. params/x500_px4.params
holds what differs from PX4’s own X500 airframe. px4_sitl.py starts PX4
attached to the model with those parameters, all through PX4’s
environment:
PX4_SYS_AUTOSTART=4001selects PX4’s stock airframe,gz_x500, whose defaults are the base.Each line of the parameters file becomes
PX4_PARAM_<NAME>=<value>. PX4’s SITL startup script sets every such variable withparam set, after it has loaded the airframe, so the file overrides the airframe. No file is written into PX4’s tree.PX4_GZ_STANDALONE=1,PX4_GZ_WORLDandPX4_GZ_MODEL_NAMEattach PX4 to the model in the running simulation.
Verified by (automated): the world loads and the four PX4 topics carry
data; the parameters file agrees with the rotor positions of the model;
px4_sitl.py builds the environment PX4 needs. (human):
Fly the X500 with PX4.
Phase 3: a mission, and tuning
Objective: a waypoint mission flown and landed, from a ground station and from a script, and the vehicle’s parameters adjusted where the model differs from PX4’s.
Verified by (automated): the shipped mission stays above the ground and inside the world. (human): Fly a mission.
Phase 4: ROS 2, several vehicles, the launch
Objective: PX4’s state in ROS 2; two X500 in one world, each with its
PX4; and px4:=true on sim.launch.xml, so the usual entry point (the
bridge, RViz, loadouts) works with the variant.
Verified by (automated): the launch with px4:=true spawns a model whose
PX4 topics are those of its world and name. (human):
PX4 from ROS 2 and
Several vehicles.