Ground station for the SWARM – RSCL outdoor formation experiment: four Holybro X500 V2 quadcopters flown as a swarm, with RTK-grade pose streamed into ROS 2.
RSCL owns the leader–follower formation controller, which already works in simulation and indoors
under motion capture. This workspace is the outdoor replacement for the MOCAP room. The target
interface is deliberately small — the formation controller should only ever see
/droneN/odom (nav_msgs/Odometry) coming in and /droneN/cmd_vel (geometry_msgs/Twist) going
out, with MAVLink, WiFi, RTK and origin math hidden inside this stack.
The full specification is in RCSL Collab.pdf in the repo root.
Flying it: docs/FIELD_RUNBOOK.md is the procedure for a test day —
bring-up order, go/no-go at each stage, abort paths, and a troubleshooting table of failures we
have actually hit. docs/GAZEBO_RUNBOOK.md rehearses the same stack
against four simulated drones first, where mistakes are free.
docs/COMMANDS.md is the reference for every command, with what each one is
for.
The command path, which everything that moves a drone goes through:
teleop_velocity ─┐
├─> /droneN/cmd_vel ─> command_bridge ─> /droneN/mavros/setpoint_velocity/
RSCL controller ─┘ clamp + watchdog cmd_vel_unstamped
first_flight: GUIDED → arm → takeoff → hand over → land (Ctrl-C lands)
Four X500 V2 airframes with Pixhawk 6C running ArduCopter, each carrying an F9P RTK receiver and an ESP8266 WiFi bridge. Ground station is Ubuntu 22.04 running ROS 2 Humble.
| Namespace | Name | sysid | ESP8266 IP | Ground-station port |
|---|---|---|---|---|
drone1 |
PAPOI | 19 | 192.168.50.11 | 14551 |
drone2 |
TRINEO | 17 | 192.168.50.12 | 14552 |
drone3 |
BISUU | 32 | 192.168.50.13 | 14553 |
drone4 |
LUCAS | 31 | 192.168.50.14 | 14554 |
All four join the router vanttec_drones_swarm on static IPs assigned by MAC address, kept below
192.168.50.100 so they stay out of the DHCP range. The ESP8266 is wired to TELEM2 at 500000 baud
and listens on port 14555.
-
launch/mavros_x4.launch.py— brings up the whole link layer. Includes MAVROS'snode.launchfour times, one instance per drone, each with its own namespace, anfcu_urlofudp://:<port>@<esp_ip>:14555, andtgt_systemset to that drone's sysid so the four links don't mix. Each instance gets the shared plugin allowlist plus MAVROS's stockapm_config.yaml. It then startsstream_setupwith the four namespaces at 25 Hz. TheDRONESlist at the top of the file is the single place to edit when a drone's IP or sysid changes. -
launch/mavros_sitl_x4.launch.py— the same four MAVROS instances pointed at ArduPilot SITL on localhost instead of the ESP8266 bridges, using the sysids SITL assigns with--auto-sysid(1–4) rather than the aircraft's own. Connects to SITL's TCP ports 5760–5790 by default; passuse_mavproxy:=trueto use UDP 14551–14554 instead, when SITL is running with MAVProxy forwarding. See Simulation. -
config/swarm_pluginlists.yaml— MAVROS plugin allowlist. It denies*and then allows only the eleven plugins the platform actually uses:sys_status,sys_time,command,imu,local_position,global_position,setpoint_velocity,setpoint_raw,param,gps_rtkandgps_status. This cuts each drone from several hundred topics down to roughly fifty, which matters because every one of them crosses a 2.4 GHz ESP8266 telemetry link. The/**:wildcard applies it to every MAVROS node. -
gazebo/models/x500_v2/— the Holybro X500 V2 airframe for Gazebo, andgazebo/worlds/the generated worlds that bind one copter per SITL instance.gazebo/tools/gen_x500_world.pywrites those worlds. See Simulation. -
config/x500_v2.parm— the ArduCopter side of the same airframe: frame class, hover thrust, the speed limitscommand_bridgeclamps to, and the iris leftovers switched off. Pass it tosim_vehicle.pywith--add-param-file. -
setup.py— installslaunch/,config/andgazebo/intoshare/soFindPackageSharecan resolve them at launch time. -
package.xml— depends onlaunch,launch_rosandmavros; exec-depends onswarm_nodes.
-
swarm_nodes/stream_setup.py→ros2 run swarm_nodes stream_setupRequests MAVLink message rates from every drone through its/droneN/mavros/set_message_intervalservice: message ids 30ATTITUDE, 31ATTITUDE_QUATERNION, 32LOCAL_POSITION_NEDand 33GLOBAL_POSITION_INT, all at 25 Hz. It watches each/droneN/mavros/state, requests the rates when a drone connects, re-requests them on reconnect, and reapplies them every 30 s — so a flight-controller reboot or a ground control station overriding stream rates cannot silently drop the pose rate. Parameters:namespaces,message_ids,rate_hz,reapply_period. Started automatically by the launch file. -
swarm_nodes/rtcm_relay.py→ros2 run swarm_nodes rtcm_relayReads RTCM3 corrections from the local RTK base and fans them out to every drone's/droneN/mavros/gps_rtk/send_rtcm. This is what turns 1–3 m GPS into roughly 1 cm — without it the drones sit at fix type 3 however good the receivers are, and "RTK-grade pose" is not true. MAVROS fragments each message over the existing telemetry link, so no extra radio is needed. Parameters:namespaces,port(/dev/ttyACM0),baudrate,udp_port(0),report_period,reconnect_period.Corrections come from either the base's serial port, or over UDP from QGroundControl's NTRIP/RTK → UDP Forwarding. Use UDP when QGC is doing the survey-in: a serial port has only one owner, so QGC and this node cannot both read the base.
It parses whole RTCM3 frames and checks each CRC rather than forwarding raw bytes, so corrupt data is dropped instead of being pushed to four aircraft. The periodic report lists which RTCM message numbers are arriving, which is how you confirm the base is configured: 1005 or 1006 is the base position — if it never appears, the base has not finished surveying in.
-
swarm_nodes/link_monitor.py→ros2 run swarm_nodes link_monitorSubscribes to/droneN/mavros/imu/dataon all four drones, counts messages and tracks the largest gap between consecutive ones, then logs a single line per drone every 5 s and resets the counters:PAPOI: 24.8 Hz, max gap 112 ms | TRINEO: 25.0 Hz, max gap 48 ms | ...Use it to judge WiFi link health before and during a flight.
-
swarm_nodes/orientation_monitor.py→ros2 run swarm_nodes orientation_monitorSubscribes to/droneN/mavros/imu/dataand/droneN/mavros/global_position/compass_hdg. It converts the IMU quaternion to roll/pitch/yaw, turns the ENU yaw into a compass heading with(90 - yaw) % 360, and prints roll, pitch, heading from the IMU and heading from the compass for all four drones once a second. Use it to confirm the four agree and to catch a badly calibrated compass: RTK fixes position but not heading, so compass error turns directly into formation yaw error. -
swarm_nodes/odom_relay.py→ros2 run swarm_nodes odom_relaySubscribes/droneN/mavros/local_position/odomon all four drones and republishes each one on/droneN/odom— the topic the formation controller subscribes to — rewritingchild_frame_idtodroneN/base_link. Parameters:namespaces,max_rate_hz(default0.0, meaning no limit).Every message is forwarded as it arrives, so the output rate equals the input rate. The autopilot sets that rate and
stream_setuprequests 25 Hz; this node must not resample it. An earlier version latched the newest pose and published on a 25 Hz timer, which aliased against the 25 Hz input and silently lost ~24% of messages (measured 19 Hz out for 25 Hz in).max_rate_hzis an optional ceiling for when MAVLink is deliberately streaming faster than/droneN/odomneeds; it bounds rather than targets, landing at or just below the cap.It also computes the shared frame. Each drone's EKF measures from its own private origin — wherever that vehicle first got a good fix — so four drones report four incompatible frames and a formation controller cannot tell where they are relative to each other. ArduPilot will not let us force a common EKF origin while using GPS, so the shift is computed here, once per drone:
offset = geodetic_to_enu(global_fix, swarm_origin) − local_positionThe drone's absolute position expressed in the shared frame, minus where its own EKF thinks it is, is the constant gap between the two origins. Adding it to every later pose puts all four in one frame, stamped
frame_id: swarm_origin.It needs only
global_position/globalandlocal_position/odom, both already streaming at 25 Hz, so there is no extra MAVLink traffic. Offsets are averaged overorigin_samplesmessages, which means the drones must be stationary while it initialises — it warns if the samples spread more than a metre.Extra parameters:
shared_origin(true),reference_drone(drone1),origin_samples(25),origin_lat/origin_lon/origin_alt(unset),publish_global_check(false),frame_id(swarm_origin).By default
swarm_originis the reference drone's first fix. Setorigin_lat/lon/altto pin it somewhere fixed instead — the RTK base's surveyed position, so the frame is identical across sessions. Withshared_origin:=falseit reverts to raw passthrough. While the offsets are unresolved it publishes nothing: silence is safer than poses labelledswarm_originthat are not in it.publish_global_check:=trueadds/droneN/odom_global, computed straight from the GPS fix instead of local position + offset. That is the spec's method B; the two should agree within centimetres, and a growing gap means EKF drift.The geodetic conversion is verified against GeographicLib's
CartConvert— the same library MAVROS links against — agreeing to 3 nanometres. -
swarm_nodes/command_bridge.py→ros2 run swarm_nodes command_bridgeThe safety layer for everything that commands a drone. Subscribes/droneN/cmd_vel(geometry_msgs/Twist, world ENU) and forwards it to/droneN/mavros/setpoint_velocity/cmd_vel_unstampedat a steady 20 Hz. Parameters:namespaces,stream_hz(20),stale_timeout(0.5),max_xy_speed(1.0),max_z_speed(0.5),max_yaw_rate(0.5),hold_mode(empty),hold_timeout(2.0).It rejects NaN/inf, clamps speed, and watchdogs the command stream:
Since last command Action never commanded sends nothing, so it cannot fight the mission node during takeoff < 0.5 s forwards the clamped command 0.5 – 2.0 s sends zero velocity — holds position > 2.0 s only if hold_modeis set: switch to it once, then stop streamingMode switching is off by default, and that is deliberate. ArduPilot already has a backstop: after
GUID_TIMEOUTseconds (default 3.0) with no setpoint it zeroes its own target and holds position autonomously — no ground station, no pilot. Our 0.5 s zero-velocity does the same thing 2.5 s sooner, which at 1 m/s saves 2.5 m of uncommanded travel. That is the real value.Taking the drone out of GUIDED is not an improvement on that, and an earlier version of this node did it anyway, which was a mistake. Set
hold_modeonly if you specifically want a deliberate re-entry to GUIDED before anything can command the drone again:hold_modeBehaviour (empty, default) never change mode; hold in GUIDED, ArduPilot backstops BRAKEholds position and altitude by itself, ignores the sticks — use this one LOITERtakes climb rate from the pilot's throttle; with nobody on the sticks it descends and lands After a switch the bridge stays silent until the drone is back in
GUIDED. The horizontal clamp scales the (x, y) vector by its magnitude rather than clamping each axis — clamping separately would rotate the command, turning (3, 4) into (1, 1) and pointing 45° off course.Note a timer is right here but wrong in
odom_relay: commands must be synthesized when input stops (ArduPilot halts a vehicle after 3 s without a setpoint), telemetry never should be. -
swarm_nodes/first_flight.py→ros2 run swarm_nodes first_flightOwns the flight sequence: GUIDED → arm → takeoff → hand over → land, so the bridge never has to know about modes or arming. Parameters:namespaces,takeoff_altitude(2.0),confirm(false),arm_delay(5.0),connect_timeout(30.0).ros2 run swarm_nodes first_flight --ros-args \ -p confirm:=true -p namespaces:="['drone1']" -p takeoff_altitude:=2.0It refuses to arm without
confirm:=true, counts downarm_delayseconds first, and will not arm a partial swarm. Ctrl-C lands every drone — it installs its own signal handler so the ROS context survives long enough to issue the land command, which rclpy's default handler does not allow. -
swarm_nodes/sequence_player.py→ros2 run swarm_nodes sequence_playerPlays a scripted Twist sequence to/droneN/cmd_vel— the acceptance test for the velocity interface, since deliverable 5 is done when each drone "follows a scripted Twist sequence in SITL and outdoors". It goes throughcommand_bridge, so it is clamped and watchdogged like anything else. Parameters:namespaces,rate_hz(20),sequence_file(built-in default otherwise).The default is a 10 m square at 0.5 m/s returning to its start, which makes drift obvious — if it does not come back, something is wrong with the frame or the velocity scaling. A sequence file is a YAML list of steps:
- {duration: 4.0, x: 0.5} # 2 m east - {duration: 4.0, y: 0.5} # 2 m north - {duration: 2.0} # hold
x/y/zare m/s in world ENU,yawis rad/s, omitted axes are zero. Ctrl-C stops and holds zero velocity; it does not land. -
swarm_nodes/dashboard.py→ros2 run swarm_nodes dashboardQt ground-station window showing all four drones side by side: link rate, mode, armed, battery, position in the shared frame, and age of the last command — colour-coded so a problem is visible without reading numbers. A banner states whether the four are actually in one comparable frame.Per-drone buttons for GUIDED / ARM / TAKEOFF / LAND, and a large LAND ALL. ARM and TAKEOFF ask for confirmation with Cancel as the default button; LAND and GUIDED do not, because both are recoveries. LAND ALL has no dialog on purpose — in an emergency you should not have to dismiss one. For a planned launch use
first_flight, which has the countdown; these buttons are for recovering a single drone mid-session.ROS spins in a background thread, so a stalled link never freezes the window.
-
swarm_nodes/teleop_velocity.py→ros2 run swarm_nodes teleop_velocityKeyboard velocity teleop for a single drone, for bench and SITL testing. Publishes aTwistto/<drone_id>/cmd_vel— the same topic the formation controller uses — while a key is held:w/sfor ±x,a/dfor ∓y,q/efor ∓z, left/right arrows for yaw rate. Parameters:drone_id(required, e.g.drone1),speed(0.5 m/s),yaw_rate(0.5 rad/s),rate_hz(20),hold_timeout(0.5 s).ros2 run swarm_nodes teleop_velocity --ros-args -p drone_id:=drone1
Requires
command_bridgerunning — the bridge is what clamps these speeds and holds position when you stop pressing keys, so without it nothing reaches the drone. The axes are world ENU, not body:wmeans east, not forward, no matter where the drone is pointing. Run it in SITL first, and on a real aircraft only with an RC safety pilot and the geofence on. -
setup.py/package.xml— console-script entry points and dependencies (rclpy,sensor_msgs,geometry_msgs,nav_msgs,mavros_msgs).
All three nodes subscribe with qos_profile_sensor_data (best-effort), matching the QoS that MAVROS
publishes its sensor topics with.
The Gazebo runbook takes the team from a clean workspace build through four X500s in SITL, shared-frame odometry, panel takeoff, formation control and recorded mochila playback. It also covers the manual flight rehearsal and shutdown.
gazebo/models/x500_v2/ is the airframe, and config/x500_v2.parm is the matching ArduCopter
side. Against the stock gazebo-iris:
| iris (stock) | x500_v2 |
|
|---|---|---|
| wheelbase | 450 mm | 500 mm |
| all-up weight | 1.75 kg | 2.02 kg |
| inertia (x/z) | 0.008 / 0.017 | 0.022 / 0.040 kg m² |
| props | 2-blade, 0.2 m | 1045, 0.254 m |
| thrust/weight | ~3.5 | 2.2 |
Only mass, inertia and thrust reach the flight dynamics, so those are what the model gets right;
collisions and inertias are primitives sized to them. The visuals are meshes from PX4's
x500_base (frame, motors, props), fetched from Gazebo Fuel (version 1, CC0) and cached in
~/.gz/fuel the first time a world loads, so the first start needs internet (27 MB). That
frame is NXP's HoverGames X500-class kit rather than Holybro's own CAD, but the same 500 mm carbon
X layout. Visuals never change how the copter flies: the hover numbers below are identical with
the primitive model and the meshes.
The meshes cost GPU, not physics. Measured with four copters and the GUI open: 0.339x real time
with primitives, 0.332x with meshes rendered on the discrete GPU. On a laptop in NVIDIA "on-demand"
PRIME mode Gazebo renders on the integrated GPU by default, where the GUI turns choppy; render on
the discrete one with __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia in front of
./tools/sim_gazebo.sh, or use --headless.
Flown in SITL, the model arms, climbs to 5 m, and holds it at 44% throttle with under 0.2° of
tilt — matching the MOT_THST_HOVER 0.45 in the param file, which is the check that the thrust
and the weight agree.
The world is generated, not hand-written, because each copter needs its own ArduPilotPlugin on its
own FDM port and SDF cannot patch a value inside an <include>:
cd src/swarm_bringup/gazebo/tools
./gen_x500_world.py # worlds/x500_swarm.sdf, four copters 3 m apart
./gen_x500_world.py --count 1 --out ../worlds/x500_single.sdf
./gen_x500_world.py --first-instance 10 # ports 9102.., 5860.., to run beside a live simEdit gen_x500_world.py and regenerate; do not edit the .sdf.
The standard world spawns the drones at 0, 3, 6 and 9 m east. With all four SITL instances started at CMAC, local odometry can already contain that displacement. Small relay corrections are expected. Check the positions on /droneN/odom to verify spacing.
A separate offset-cancellation test used a 1.5 m world and --auto-offset-line 90,1.5. It produced offsets of approximately 0, 1.5, 3 and 4.5 m and published positions near 0, 3, 6 and 9 m. That configuration intentionally makes the reported spacing differ from Gazebo’s model spacing.
Prerequisites: Ubuntu 22.04 with ROS 2 Humble, plus
sudo apt install ros-humble-mavros ros-humble-mavros-extras and the MAVROS GeographicLib datasets
script.
cd "$(git rev-parse --show-toplevel)"
colcon build --symlink-install
source install/setup.bash
# 4x MAVROS + stream_setup
ros2 launch swarm_bringup mavros_x4.launch.py
# in other terminals
ros2 run swarm_nodes link_monitor
ros2 run swarm_nodes orientation_monitor