diff --git a/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp b/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp new file mode 100644 index 0000000000000..7daaa21d2482f --- /dev/null +++ b/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp @@ -0,0 +1,54 @@ +// Copyright 2020 Tier IV, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef TIER4_AUTOWARE_UTILS__ROS__PUBLISHED_TIME_PUBLISHER_HPP_ +#define TIER4_AUTOWARE_UTILS__ROS__PUBLISHED_TIME_PUBLISHER_HPP_ + +#include + +#include + +namespace tier4_autoware_utils +{ +using autoware_common_msgs::msg::PublishedTime; + +class PublishedTimePublisher +{ +public: + explicit PublishedTimePublisher( + rclcpp::Node * node, const std::string & name = "~/debug/published_time", + const rclcpp::QoS & qos = rclcpp::QoS(1)) + { + pub_published_time_ = node->create_publisher(name, qos); + } + + void publish(const rclcpp::Time & header_stamp) const + { + // Check if there are any subscribers, otherwise don't do anything + if (pub_published_time_->get_subscription_count() > 0) { + PublishedTime published_time; + + published_time.header_stamp = header_stamp; + published_time.published_stamp = rclcpp::Clock().now(); + + pub_published_time_->publish(published_time); + } + } + +private: + rclcpp::Publisher::SharedPtr pub_published_time_; +}; +} // namespace tier4_autoware_utils + +#endif // TIER4_AUTOWARE_UTILS__ROS__PUBLISHED_TIME_PUBLISHER_HPP_ diff --git a/common/tier4_autoware_utils/package.xml b/common/tier4_autoware_utils/package.xml index 04a07b88edf4e..c6d150e887a69 100644 --- a/common/tier4_autoware_utils/package.xml +++ b/common/tier4_autoware_utils/package.xml @@ -15,6 +15,7 @@ autoware_auto_perception_msgs autoware_auto_planning_msgs autoware_auto_vehicle_msgs + autoware_common_msgs builtin_interfaces diagnostic_msgs geometry_msgs