Repository navigation
mavros: optional /tf_static-only tf listener for the UAS - #2367
Conversation
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>
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
left a comment
There was a problem hiding this comment.
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
-
Static-only mode stalls a plugin executor thread (
mavros/include/mavros/setpoint_mixin.hpp:213). Withtf.static_only,tf2_start()only warns and still starts the timer. If a plugin listens on a dynamic frame pair (fake_gpstf.listen,vision_pose_estimatetf/listen,landing_targetlisten),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. -
tf2_listenerbecomes a nullablestd::unique_ptr(mavros/include/mavros/mavros_uas.hpp:396). This is a source break for out-of-tree plugins usinguas->tf2_listener.<member>, and one mechanically updated to->segfaults whentf.static_only: true. Please keep the member private behind an accessor so there is no nullable public pointer.
Should fix
-
Rejected transforms are dropped silently (
mavros/src/lib/mavros_uas.cpp:196). The/tf_staticcallback ignores theboolreturned bysetTransform, which returns false instead of throwing for an invalid quaternion or an empty/identical frame id, so thecatchblock's ERROR never fires. The authority is also hardcoded to "tf_static", soallFramesAsStringdoes not identify the publisher. -
Public header includes
tf2_msgs/msg/tf_message.hpp(mavros_uas.hpp:50) only to type a private subscription member. Arclcpp::SubscriptionBase::SharedPtrmember would keep the include and the dependency inmavros_uas.cpp. If the include stays, please check thattf2_msgsis inament_export_dependencies; I did not find it there. -
receive_transformsbusy-loops (mavros/test/test_uas.cpp:277).spin_some(10ms)returns at once when idle, so the loop publishes/tfand runs twocanTransformcalls 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_staticsample and flakeEXPECT_TRUE(received.static_frame). A sleep per iteration orspin_until_future_completewould bound the rate. -
The tests miss the path the feature exists for (
test_uas.cpp:307).EXPECT_FALSE(received.dynamic_frame)passes vacuously, and becausestartup_delay_timeris cancelled,setup_static_tf()never runs, so only an external node's static transform is checked. A regression where the UAS's ownStaticTransformBroadcasteroutput 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
-
setUsingDedicatedThread(true)is not true under a single-threaded executor (mavros_uas.cpp:184). The/tf_staticsubscription is serviced by whatever executor spins the UAS node. In a default single-threadedcomponent_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. -
Remaps now apply to
/tf_staticin 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. Flippingtf.static_onlycan silently change which static transforms reach the buffer. Is that intended? If so it should be documented.
3fceaed to
413b64e
Compare
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>
413b64e to
6fd71f8
Compare
|
Thanks for the review, all addressed in the updated commit.
|
vooon
left a comment
There was a problem hiding this comment.
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:
-
The PR description is stale. It still says
UAS::tf2_listeneris astd::unique_ptrthat out-of-tree code reaches with->, and lists two tests. The member is now private and there are three tests. Please update it. -
A plugin listening on a dynamic frame pair goes quiet with one WARN. With
tf.static_only,fake_gps,landing_targetorvision_pose_estimateconfigured 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.
Summary
The UAS always creates a tf2
TransformListenerwith its own node and threadthat subscribes to
/tfand/tf_static. In-tree onlyodometryandTF2ListenerMixin(fake_gps,landing_target,vision_pose_estimate) readthe buffer, and
odometrywith the default frame ids needs only statictransforms the UAS publishes itself. With several vehicles on one machine,
every MAVROS receives every vehicle's
/tf.Changes
UAS: new read-only parametertf.static_only(defaultfalse, whichchanges nothing). With
truethe UAS subscribes to/tf_staticitselfinstead of creating the listener: no
/tfsubscription, no listener node orthread.
TransformListener's ownstatic_onlyoption is not used: it is missing onHumble and older Jazzy, and the constructor taking node interfaces differs on
Lyrical/Rolling. The subscription needs no version switch.
(transient_local). The buffer is marked as filled by another thread, so
TF2ListenerMixinlookups with a timeout keep working; they get only statictransforms, and
tf2_start()warns.UAS::tf2_listeneris now astd::unique_ptr, null withtf.static_only.Out-of-tree code that uses the member directly needs
->.mavrosdepends ontf2_msgsdirectly.docs/nodes.md; two tests intest_uas.cpp.Testing
mavrosandmavros_extrasbuild;mavros-uas-test,mavros-plugin-params-test, uncrustify, cpplint pass.mavros_node, one UAS in a componentcontainer),
tf.static_only: true: no listener node,odometry/inispublished as without the parameter.
mavros_nodeCPU in hover, mean ofthree 60 s measurements: 39.5 % -> 30.1 % of a core.