Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add constructor to static tf broadcaster accepting node interfaces #576

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions tf2_ros/include/tf2_ros/static_transform_broadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

#include "tf2_ros/visibility_control.h"

#include "rclcpp/node_interfaces/get_node_parameters_interface.hpp"
#include "rclcpp/node_interfaces/get_node_topics_interface.hpp"
#include "rclcpp/rclcpp.hpp"
#include "geometry_msgs/msg/transform_stamped.hpp"
#include "tf2_msgs/msg/tf_message.hpp"
Expand All @@ -53,7 +55,7 @@ namespace tf2_ros
class StaticTransformBroadcaster
{
public:
/** \brief Node interface constructor */
/** \brief Node constructor */
template<class NodeT, class AllocatorT = std::allocator<void>>
StaticTransformBroadcaster(
NodeT && node,
Expand All @@ -66,9 +68,30 @@ class StaticTransformBroadcaster
rclcpp::QosPolicyKind::Reliability};
return options;
} ())
: StaticTransformBroadcaster(
rclcpp::node_interfaces::get_node_parameters_interface(node),
rclcpp::node_interfaces::get_node_topics_interface(node),
qos,
options)
{}

/** \brief Node interfaces constructor */
template<class AllocatorT = std::allocator<void>>
StaticTransformBroadcaster(
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters,
rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics,
const rclcpp::QoS & qos = StaticBroadcasterQoS(),
const rclcpp::PublisherOptionsWithAllocator<AllocatorT> & options = [] () {
rclcpp::PublisherOptionsWithAllocator<AllocatorT> options;
options.qos_overriding_options = rclcpp::QosOverridingOptions{
rclcpp::QosPolicyKind::Depth,
rclcpp::QosPolicyKind::History,
rclcpp::QosPolicyKind::Reliability};
return options;
} ())
{
publisher_ = rclcpp::create_publisher<tf2_msgs::msg::TFMessage>(
node, "/tf_static", qos, options);
node_parameters, node_topics, "/tf_static", qos, options);
}

/** \brief Send a TransformStamped message
Expand Down
30 changes: 28 additions & 2 deletions tf2_ros/test/test_static_transform_broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,40 @@ 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);
// Construct static tf broadcaster from node pointer
{
tf2_ros::StaticTransformBroadcaster tfb(node);
}
// Construct static tf broadcaster from node object
{
tf2_ros::StaticTransformBroadcaster tfb(*node);
}
// Construct static tf broadcaster from node interfaces
{
tf2_ros::StaticTransformBroadcaster tfb(
node->get_node_parameters_interface(),
node->get_node_topics_interface());
}
}

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

tf2_ros::StaticTransformBroadcaster tfb(node);
// Construct static tf broadcaster from node pointer
{
tf2_ros::StaticTransformBroadcaster tfb(node);
}
// Construct static tf broadcaster from node object
{
tf2_ros::StaticTransformBroadcaster tfb(*node);
}
// Construct static tf broadcaster from node interfaces
{
tf2_ros::StaticTransformBroadcaster tfb(
node->get_node_parameters_interface(),
node->get_node_topics_interface());
}
}

TEST(tf2_test_static_transform_broadcaster, transform_broadcaster_as_member)
Expand Down
21 changes: 20 additions & 1 deletion tf2_ros/test/test_transform_broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,32 @@ TEST(tf2_test_transform_broadcaster, transform_broadcaster_rclcpp_node)
{
tf2_ros::TransformBroadcaster tfb(*node);
}
// Construct tf broadcaster from node interfaces
{
tf2_ros::TransformBroadcaster tfb(
node->get_node_parameters_interface(),
node->get_node_topics_interface());
}
}

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

tf2_ros::TransformBroadcaster tfb(node);
// Construct tf broadcaster from node pointer
{
tf2_ros::TransformBroadcaster tfb(node);
}
// Construct tf broadcaster from node object
{
tf2_ros::TransformBroadcaster tfb(*node);
}
// Construct tf broadcaster from node interfaces
{
tf2_ros::TransformBroadcaster tfb(
node->get_node_parameters_interface(),
node->get_node_topics_interface());
}
}

TEST(tf2_test_transform_broadcaster, transform_broadcaster_as_member)
Expand Down