--- name: ros2-gazebo-testing description: Design and run Gazebo/PX4 integration tests for ROS 2 drone features using supplied X500-compatible drone and world SDFs. Use when a feature needs simulation evidence, not for ordinary unit tests. --- # ROS 2 Gazebo testing Use this skill alongside `ros2-development` when a ROS 2 feature needs a simulated flight or sensor test. You write the ROS code, application launch file, and test assertions. The Athena MCP tools only build a world and run your test in a supervised simulator. 1. Inspect the feature request, ROS workspace, drone SDF, and world SDF. If an SDF is missing, ask the user to create it with the available drone or environment configurator. `run_simulation_test` expects an X500-compatible drone and a world named `environment`; `build_world` supports the configurator's basement and tripleA empty rooms. 2. State what observable behavior would pass and fail. Run a simple baseline before the feature-specific scenario so simulator trouble does not masquerade as a feature failure. If a scenario needs added objects, `build_world` can add pillars, tables, chairs, and cardboard boxes. Choose positions that leave a valid drone spawn and route, and keep its output SDF beside the regression test. 3. Write a ROS integration test that connects to the running stack, waits for required nodes, topics, services, or actions with deadlines, and asserts measured behavior. Inspect clock source, QoS, units, and frames. Gazebo world coordinates are ENU; PX4 local coordinates are NED. PX4 1.16 may expose a versioned topic such as `/fmu/out/vehicle_status_v1`; discover the actual topic and use compatible QoS. For common topic directions, types, and runtime checks, read the [PX4/DDS quick reference](references/px4-dds.md). The scaffold disables XRCE time synchronization in SITL, so do not assume PX4 timestamps are ROS clock timestamps. Avoid fixed sleeps as a substitute for readiness checks. The installed `sim_bringup.test_support` module provides topic discovery, message waits, command acknowledgements, and a pausable periodic control stream. Its wait functions spin a test-owned node; verify the resulting vehicle state separately from a command acknowledgement. 4. Build the workspace with `colcon` where ROS is running. When Codex runs on the host, use `dev_exec` in `drone-development` and prepare a missing `athena_NN/sim_bringup` with `repositories.py bringup`. When Codex already runs in the ROS container, use its shell and the `athena_NN/sim_bringup` source in the workspace. Use or create an application launch file that starts the implementation, then call `run_simulation_test` with that launch entry point and the test command as an argument list. For the final run before Pi deployment, commit the feature source and pass its checkout as `source_repository_path`; the result records the exact clean Git revision. Supply `px4_parameters` for scenario-specific PX4 settings; inspect the observed values in the result and PX4 log. The tool starts Gazebo, PX4, the XRCE agent, and standard sensor bridges before launching the application and test. 5. Choose `record_topics` from the evidence the task needs; the default PX4 set already includes failsafe flags, status, local position, contacts, and manual control. Add battery or other topics only when useful for that task. Write timestamped step events around each requested behavior so evidence can be inspected in the right time window. 6. Read the returned phase, readiness, process exits, test exit code, logs, contact summaries, and rosbag. Run `flight_report` to inspect state and failsafe transitions, topic sample gaps, contact timing, and optional battery or post-failsafe manual-control readings. Use those observations to write task-specific assertions in the test and a structured result with the measured values and evidence timestamps. The report does not decide scenario success. A failed flight can come from the ROS implementation, scenario design, assertions, or simulator setup. Assign a cause only when the evidence supports it; add a focused diagnostic and rerun if needed. Repair the relevant source or test, then repeat the same scenario. Keep successful test code, application launch changes, and generated world SDF in the ROS workspace. Report the assertion evidence and any remaining uncertainty. Simulator startup by itself does not establish feature correctness. When using low-level `ControlStream` or `send_vehicle_command` directly, observe a fresh PX4 telemetry timestamp with the bundled Px4Time helper and pass its now_us method. `FlightSession` handles this internally. ROS or Gazebo clock values are not interchangeable with PX4 boot time in this SITL setup. When starting a new package, the [stationary Offboard heartbeat example](assets/offboard-heartbeat/README.md) shows the launch-file layout and timestamped stream without adding mission logic to the scaffold. For a scenario that owns the vehicle controls, use `sim_bringup.flight.FlightSession` with a test-owned ROS node. Its blocking calls spin that node; do not spin it concurrently in another executor. `Pose(north_m, east_m, up_m, yaw_rad=None)` is relative to the launch position captured by `wait_ready`; yaw is an absolute PX4 local heading in radians. `goto` reaches and settles at one pose, while `follow_path` tracks two or more points continuously. Generate circles or other paths in the scenario script and pass the resulting poses to `follow_path`. The helper also provides `arm`, `set_mode`, `takeoff`, `turn_to`, `hover`, and `land`; call `land` explicitly and close the session in a `finally` block or context manager. It does not make feature assertions. ```python from sim_bringup.flight import FlightSession, Pose with FlightSession(node) as flight: flight.wait_ready() flight.takeoff(1.5) flight.goto(Pose(1.0, 0.0, 1.5)) flight.follow_path([Pose(1.0, 0.0, 1.5), Pose(1.0, 1.0, 1.5)]) flight.set_mode("position") hold = flight.hover(2.0) # Assert the measured drift in this scenario. flight.land() ``` Offboard follows streamed position references. Pass `mode="offboard"`, `"position"`, `"altitude"`, or `"stabilized"` to `takeoff` when a task requires a specific startup mode; omit `mode` to keep the current default. In Position, Altitude, and Stabilized modes, takeoff ramps bounded climb input until PX4 position telemetry confirms liftoff, then uses the pose controller. Position mode uses bounded manual velocity input; Altitude mode needs horizontal feedback; Stabilized mode needs active horizontal and height control even for a hover. The helpers check fresh PX4 state and stop non-neutral manual input if the mode changes unexpectedly. A path speed is a target, not an arrival-time guarantee. If the application under test commands PX4, observe its behavior instead of issuing competing helper controls. After a flight, inspect the recorded bag as well as the test's own assertions. The bundled flight_report command reports measured continuous holds, timestamped PX4 state and failsafe transitions, per-topic sample gaps, contact intervals in flight context, and any recorded battery or post-failsafe manual-control readings; see [flight report usage](references/flight-report.md). For repeated targets, use step event windows so an earlier hover cannot satisfy a later one. Keep task-specific thresholds and pass/fail decisions in the authored test, and write its structured observed results from the evidence. A floor contact is evidence of touchdown only after checking which drone collision touched the floor, position, and disarming state.