diff --git a/src/TopicPublisherROS2/generic_publisher.h b/src/TopicPublisherROS2/generic_publisher.h index eb231cc..4e3cf57 100644 --- a/src/TopicPublisherROS2/generic_publisher.h +++ b/src/TopicPublisherROS2/generic_publisher.h @@ -30,7 +30,8 @@ class GenericPublisher : public rclcpp::PublisherBase const rosidl_message_type_support_t& type_support) // The rclcpp::PublisherBase constructor grew event-callback parameters after Humble (rclcpp 16.x). #if RCLCPP_VERSION_GTE(17, 0, 0) - : rclcpp::PublisherBase(node_base, topic_name, type_support, rcl_publisher_get_default_options(), callbacks_, true) + : rclcpp::PublisherBase(node_base, topic_name, type_support, rcl_publisher_get_default_options(), + rclcpp::PublisherEventCallbacks{}, true) #else : rclcpp::PublisherBase(node_base, topic_name, type_support, rcl_publisher_get_default_options()) #endif @@ -57,10 +58,6 @@ class GenericPublisher : public rclcpp::PublisherBase return std::make_shared(node.get_node_base_interface().get(), topic_name, *type_support); } - -#if RCLCPP_VERSION_GTE(17, 0, 0) - rclcpp::PublisherEventCallbacks callbacks_; -#endif }; #endif // GENERIC_PUBLISHER_H diff --git a/src/TopicPublisherROS2/publisher_ros2.cpp b/src/TopicPublisherROS2/publisher_ros2.cpp index 7126d2d..375536b 100644 --- a/src/TopicPublisherROS2/publisher_ros2.cpp +++ b/src/TopicPublisherROS2/publisher_ros2.cpp @@ -111,15 +111,6 @@ void TopicPublisherROS2::setEnabled(bool to_enable) updatePublishers(); - if (!_tf_broadcaster) - { - _tf_broadcaster = std::make_unique(*_node); - } - if (!_tf_static_broadcaster) - { - _tf_static_broadcaster = std::make_unique(*_node); - } - _previous_play_index = std::numeric_limits::max(); } else @@ -293,10 +284,18 @@ void TopicPublisherROS2::broadcastTF(double current_time) } if (transforms_ptr == &transforms) { + if (!_tf_broadcaster) + { + _tf_broadcaster = std::make_shared(*_node); + } _tf_broadcaster->sendTransform(transforms_vector); } else { + if (!_tf_static_broadcaster) + { + _tf_static_broadcaster = std::make_shared(*_node); + } _tf_static_broadcaster->sendTransform(transforms_vector); } }