|
| 1 | +// Copyright 2020 Tier IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef TIER4_AUTOWARE_UTILS__ROS__PUBLISHED_TIME_PUBLISHER_HPP_ |
| 16 | +#define TIER4_AUTOWARE_UTILS__ROS__PUBLISHED_TIME_PUBLISHER_HPP_ |
| 17 | + |
| 18 | +#include <rclcpp/rclcpp.hpp> |
| 19 | + |
| 20 | +#include <autoware_common_msgs/msg/published_time.hpp> |
| 21 | + |
| 22 | +namespace tier4_autoware_utils |
| 23 | +{ |
| 24 | +using autoware_common_msgs::msg::PublishedTime; |
| 25 | + |
| 26 | +class PublishedTimePublisher |
| 27 | +{ |
| 28 | +public: |
| 29 | + explicit PublishedTimePublisher( |
| 30 | + rclcpp::Node * node, const std::string & name = "~/debug/published_time", |
| 31 | + const rclcpp::QoS & qos = rclcpp::QoS(1)) |
| 32 | + { |
| 33 | + pub_published_time_ = node->create_publisher<PublishedTime>(name, qos); |
| 34 | + } |
| 35 | + |
| 36 | + void publish(const rclcpp::Time & header_stamp) const |
| 37 | + { |
| 38 | + // Check if there are any subscribers, otherwise don't do anything |
| 39 | + if (pub_published_time_->get_subscription_count() > 0) { |
| 40 | + PublishedTime published_time; |
| 41 | + |
| 42 | + published_time.header_stamp = header_stamp; |
| 43 | + published_time.published_stamp = rclcpp::Clock().now(); |
| 44 | + |
| 45 | + pub_published_time_->publish(published_time); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | +private: |
| 50 | + rclcpp::Publisher<PublishedTime>::SharedPtr pub_published_time_; |
| 51 | +}; |
| 52 | +} // namespace tier4_autoware_utils |
| 53 | + |
| 54 | +#endif // TIER4_AUTOWARE_UTILS__ROS__PUBLISHED_TIME_PUBLISHER_HPP_ |
0 commit comments