Skip to content

Commit

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

* Update static_transform_broadcaster.h
  • Loading branch information
roncapat authored Jun 22, 2023
1 parent dfb7eb5 commit edad1bc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tf2_ros/include/tf2_ros/static_transform_broadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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;
} ())
: StaticTransformBroadcaster(
Expand All @@ -87,6 +96,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,6 +50,22 @@ 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");
Expand All @@ -70,6 +86,15 @@ TEST(tf2_test_static_transform_broadcaster, transform_broadcaster_rclcpp_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 edad1bc

Please sign in to comment.