Skip to content

mavros: optional /tf_static-only tf listener for the UAS - #2367

Merged
vooon merged 1 commit into
mavlink:ros2from
ctu-mrs:feat/uas-tf-static-only
Nov 15, 2026
Merged

vooon merged 1 commit into
mavlink:ros2from
ctu-mrs:feat/uas-tf-static-only

Conversation

@spurnvoj

Copy link
Copy Markdown
Contributor

Summary

The UAS always creates a tf2 TransformListener with its own node and thread
that subscribes to /tf and /tf_static. In-tree only odometry and
TF2ListenerMixin (fake_gps, landing_target, vision_pose_estimate) read
the buffer, and odometry with the default frame ids needs only static
transforms the UAS publishes itself. With several vehicles on one machine,
every MAVROS receives every vehicle's /tf.

Changes

  • UAS: new read-only parameter tf.static_only (default false, which
    changes nothing). With true the UAS subscribes to /tf_static itself
    instead of creating the listener: no /tf subscription, no listener node or
    thread.
  • TransformListener's own static_only option is not used: it is missing on
    Humble and older Jazzy, and the constructor taking node interfaces differs on
    Lyrical/Rolling. The subscription needs no version switch.
  • The subscription has its own callback group and no intra-process
    (transient_local). The buffer is marked as filled by another thread, so
    TF2ListenerMixin lookups with a timeout keep working; they get only static
    transforms, and tf2_start() warns.
  • UAS::tf2_listener is now a std::unique_ptr, null with tf.static_only.
    Out-of-tree code that uses the member directly needs ->.
  • mavros depends on tf2_msgs directly.
  • docs/nodes.md; two tests in test_uas.cpp.

Testing

  • Jazzy: mavros and mavros_extras build; mavros-uas-test,
    mavros-plugin-params-test, uncrustify, cpplint pass.
  • PX4 SITL, Jazzy, 2 vehicles (one mavros_node, one UAS in a component
    container), tf.static_only: true: no listener node, odometry/in is
    published as without the parameter. mavros_node CPU in hover, mean of
    three 60 s measurements: 39.5 % -> 30.1 % of a core.

spurnvoj added a commit to fly4future/mrs_uav_px4_api that referenced this pull request Nov 11, 2026
The MAVROS UAS subscribes to /tf, but in this setup MAVROS uses no
dynamic transforms: odometry needs only the static frames the UAS
publishes, and no plugin with tf.listen is loaded. With several vehicles
on one machine every MAVROS gets every vehicle's /tf; in PX4 SITL with
two vehicles, tf.static_only lowers mavros_node CPU in hover from 39.5 %
to 30.1 % of a core.

tf.static_only is in ctu-mrs/mavros mrs_2.17.0 (mavlink/mavros#2367);
other MAVROS versions ignore it. A mavros_config that enables a plugin
listening to tf (fake_gps, landing_target, vision_pose_estimate) has to
set it to false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spurnvoj added a commit to spurnvoj/buildfarm2 that referenced this pull request Nov 11, 2026
mrs_2.17.0 is MAVROS 2.17.0 + the UAS tf.static_only parameter
(mavlink/mavros#2367). testing and stable stay on mrs_2.14.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@vooon vooon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. A few things need fixing before this can go in. This is from reading the diff and the surrounding code; I have not built or run it.

Must fix

  1. Static-only mode stalls a plugin executor thread (mavros/include/mavros/setpoint_mixin.hpp:213). With tf.static_only, tf2_start() only warns and still starts the timer. If a plugin listens on a dynamic frame pair (fake_gps tf.listen, vision_pose_estimate tf/listen, landing_target listen), canTransform(..., 3.0 s) can never succeed, and because the buffer is marked as having a dedicated thread it waits the full timeout on every tick. One thread of the shared UAS plugin executor is stalled permanently and the plugin sends nothing, with only a single startup WARN. Please do not start the timer in this mode, or use a zero timeout.

  2. tf2_listener becomes a nullable std::unique_ptr (mavros/include/mavros/mavros_uas.hpp:396). This is a source break for out-of-tree plugins using uas->tf2_listener.<member>, and one mechanically updated to -> segfaults when tf.static_only: true. Please keep the member private behind an accessor so there is no nullable public pointer.

Should fix

  1. Rejected transforms are dropped silently (mavros/src/lib/mavros_uas.cpp:196). The /tf_static callback ignores the bool returned by setTransform, which returns false instead of throwing for an invalid quaternion or an empty/identical frame id, so the catch block's ERROR never fires. The authority is also hardcoded to "tf_static", so allFramesAsString does not identify the publisher.

  2. Public header includes tf2_msgs/msg/tf_message.hpp (mavros_uas.hpp:50) only to type a private subscription member. A rclcpp::SubscriptionBase::SharedPtr member would keep the include and the dependency in mavros_uas.cpp. If the include stays, please check that tf2_msgs is in ament_export_dependencies; I did not find it there.

  3. receive_transforms busy-loops (mavros/test/test_uas.cpp:277). spin_some(10ms) returns at once when idle, so the loop publishes /tf and runs two canTransform calls as fast as the CPU allows for 1 to 5 s. On loaded CI runners this can starve DDS discovery of the transient_local /tf_static sample and flake EXPECT_TRUE(received.static_frame). A sleep per iteration or spin_until_future_complete would bound the rate.

  4. The tests miss the path the feature exists for (test_uas.cpp:307). EXPECT_FALSE(received.dynamic_frame) passes vacuously, and because startup_delay_timer is cancelled, setup_static_tf() never runs, so only an external node's static transform is checked. A regression where the UAS's own StaticTransformBroadcaster output fails to reach the new subscription (same node, intra-process, transient_local, e.g. on Humble) would break the odometry plugin while both tests stay green.

Design questions

  1. setUsingDedicatedThread(true) is not true under a single-threaded executor (mavros_uas.cpp:184). The /tf_static subscription is serviced by whatever executor spins the UAS node. In a default single-threaded component_container, any timeout lookup from a UAS-node callback blocks the only thread that could deliver /tf_static, then fails, and tf2's own "no dedicated thread" diagnostic is suppressed. The comment acknowledges this, but nothing detects or warns about it at runtime. At minimum this needs a runtime warning or a doc note.

  2. Remaps now apply to /tf_static in one mode only (mavros_uas.cpp:191). The subscription is created on the UAS node, so node-specific remap rules and QoS overrides apply to it, while the old listener's internal node ignored them. Flipping tf.static_only can silently change which static transforms reach the buffer. Is that intended? If so it should be documented.

@spurnvoj
spurnvoj force-pushed the feat/uas-tf-static-only branch from 3fceaed to 413b64e Compare November 12, 2026 10:26
The UAS always creates a tf2 TransformListener with its own node and
thread that subscribes to /tf and /tf_static. In-tree, only odometry and
TF2ListenerMixin (fake_gps, landing_target, vision_pose_estimate) read
the buffer, and odometry with the default frame ids needs only static
transforms the UAS publishes itself.

With tf.static_only (read-only, default false) the UAS subscribes to
/tf_static itself instead of creating the listener: no /tf subscription,
no listener node or thread. TransformListener's static_only option is
not used: it is missing on Humble and older Jazzy, and the constructor
that takes node interfaces differs on Lyrical/Rolling. The subscription
has its own callback group, no intra-process (transient_local) and the
listener's QoS overrides. The buffer is marked as filled by another
thread, so lookups with a timeout keep working. TF2ListenerMixin gets
only static transforms in this mode: tf2_start() warns and its lookups
do not wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@spurnvoj
spurnvoj force-pushed the feat/uas-tf-static-only branch from 413b64e to 6fd71f8 Compare November 12, 2026 11:20
@spurnvoj

Copy link
Copy Markdown
Contributor Author

Thanks for the review, all addressed in the updated commit.

  1. Fixed: with tf.static_only the mixin now uses a zero timeout, so a timer tick never blocks a plugin executor thread; static frame pairs still work, dynamic ones fail immediately (the startup WARN stays). Default mode keeps the 3 s timeout.

  2. Fixed: tf2_listener is now a private member. No accessor: TransformListener has no API a plugin needs (it only fills tf2_buffer, which stays public), and an accessor would expose the nullable pointer again. Out-of-tree code referring to uas->tf2_listener no longer compiles; in-tree nothing referenced it.

  3. BufferCore::setTransform() logs every rejection itself before returning false (TF_SELF_TRANSFORM, TF_NO_FRAME_ID, TF_NAN_INPUT, TF_DENORMALIZED_QUATERNION, …) on all supported distros, so nothing is dropped silently; it never throws, so the try/catch was unreachable and is removed (TransformListener::subscription_callback likewise ignores the bool). A subscription callback doesn't know the publisher either; I switched the authority to tf2's "Authority undetectable" for consistency.

  4. Fixed: the member is now rclcpp::SubscriptionBase::SharedPtr and the include moved to mavros_uas.cpp. (Downstream was not affected either way: mavros_uas.hpp includes tf2_ros/transform_listener.hpp, which includes tf2_msgs/msg/tf_message.hpp itself, and tf2_ros exports tf2_msgs.)

  5. Fixed: spin_some() plus a 10 ms sleep per iteration, so the loop publishes and polls at ~100 Hz.

  6. Added tf_static_only_receives_own_static_tf: calls setup_static_tf() on a static-only UAS (intra-process, as in mavros_node) and checks that map_ned, odom_ned and base_link_frd reach its own buffer. On the dynamic_frame check: tf_default_listens_to_tf uses the same publisher and loop and does receive the dynamic frame, so its absence in static-only mode comes from the mode, not the test setup.

  7. Documented in docs/nodes.md. With fix 1 nothing in-tree waits on the buffer in this mode (the mixin uses a zero timeout, odometry looks up without one), and mavros_node spins the UAS with a 2-thread executor. A runtime warning isn't possible reliably: the node can't tell which executor spins it.

  8. Not a goal, but a consequence of subscribing on the UAS node (the point of the mode is to have no extra node): ROS applies a node's remap rules to all of its subscriptions, and that can't be disabled per subscription. Global remaps (-r /tf_static:=...) apply in both modes; only rules targeting the UAS node by name (mavros:/tf_static:=...) differ, and in default mode such a rule would silently do nothing. Documented in docs/nodes.md. On QoS it was the other way round: the subscription had no qos_overriding_options, so it now allows the same overrides as TransformListener (depth, history, reliability).

@vooon vooon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all eight items from the previous review are resolved at 6fd71f8. As before, this is from reading the diff and the surrounding code; I have not built or run it locally.

On item 2, making tf2_listener private without an accessor is fine: nothing in-tree used it, and out-of-tree code gets a compile error instead of a possible null dereference. On item 6, agreed that tf_default_listens_to_tf covers the publisher side of the dynamic_frame check.

Two non-blocking notes:

  1. The PR description is stale. It still says UAS::tf2_listener is a std::unique_ptr that out-of-tree code reaches with ->, and lists two tests. The member is now private and there are three tests. Please update it.

  2. A plugin listening on a dynamic frame pair goes quiet with one WARN. With tf.static_only, fake_gps, landing_target or vision_pose_estimate configured for a dynamic pair send nothing, and the only signal is the startup warning, which also fires for static pairs that work. It is documented, so no change needed.

@vooon vooon added this to the Version 2.18 milestone Nov 15, 2026
@vooon
vooon merged commit eacb526 into mavlink:ros2 Nov 15, 2026
6 checks passed
@spurnvoj
spurnvoj deleted the feat/uas-tf-static-only branch November 15, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants