Skip to content

Commit

Permalink
Enable StaticTransformBroadcaster in Intra-process enabled components…
Browse files Browse the repository at this point in the history
… (backport #607) (#612)

* Enable StaticTransformBroadcaster in Intra-process enabled components (#607)

* Update static_transform_broadcaster.h

(cherry picked from commit edad1bc)

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Patrick Roncagliolo <ronca.pat@gmail.com>
  • Loading branch information
mergify[bot] and roncapat authored Jul 10, 2023
1 parent d508d9c commit 936a352
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tf2_ros/include/tf2_ros/static_transform_broadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class StaticTransformBroadcaster
rclcpp::QosPolicyKind::Depth,
rclcpp::QosPolicyKind::History,
rclcpp::QosPolicyKind::Reliability};
/*
This flag disables intra-process communication while publishing to
/tf_static topic, when the StaticTransformBroadcaster is constructed
using an existing node handle which happens to be a component
(in rclcpp terminology).
Required until rclcpp intra-process communication supports
transient_local QoS durability.
*/
options.use_intra_process_comm = rclcpp::IntraProcessSetting::Disable;
return options;
} ())
{
Expand Down
25 changes: 25 additions & 0 deletions tf2_ros/test/test_static_transform_broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,38 @@ class CustomNode : public rclcpp::Node
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> tf_broadcaster_;
};

class CustomComposableNode : public rclcpp::Node
{
public:
explicit CustomComposableNode(const rclcpp::NodeOptions & options)
: rclcpp::Node("tf2_ros_test_static_transform_broadcaster_composable_node", options)
{}

void init_tf_broadcaster()
{
tf_broadcaster_ = std::make_shared<tf2_ros::StaticTransformBroadcaster>(shared_from_this());
}

private:
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> tf_broadcaster_;
};

TEST(tf2_test_static_transform_broadcaster, transform_broadcaster_rclcpp_node)
{
auto node = rclcpp::Node::make_shared("tf2_ros_message_filter");

tf2_ros::StaticTransformBroadcaster tfb(node);
}

TEST(tf2_test_static_transform_broadcaster, transform_broadcaster_with_intraprocess)
{
rclcpp::executors::SingleThreadedExecutor exec;
rclcpp::NodeOptions options;
options = options.use_intra_process_comms(true);
auto custom_node = std::make_shared<CustomComposableNode>(options);
custom_node->init_tf_broadcaster();
}

TEST(tf2_test_static_transform_broadcaster, transform_broadcaster_custom_rclcpp_node)
{
auto node = std::make_shared<NodeWrapper>("tf2_ros_message_filter");
Expand Down

0 comments on commit 936a352

Please sign in to comment.