scenario_simulator_v2 C++ API
traffic_light_publisher.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
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 TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_PUBLISHER_HPP_
16 #define TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_PUBLISHER_HPP_
17 
18 #include <memory>
19 #include <rclcpp/rclcpp.hpp>
20 #include <string>
24 
25 namespace traffic_simulator
26 {
28 {
29 public:
30  virtual auto publish(
31  const rclcpp::Time & current_ros_time,
32  const simulation_api_schema::UpdateTrafficLightsRequest & request) const -> void = 0;
33 
34  virtual ~TrafficLightPublisherBase() = default;
35 };
36 
37 template <typename MessageType>
39 {
40 public:
41  template <typename NodeTypePointer>
43  const NodeTypePointer & node_ptr, const std::string & topic_name,
44  const std::string & frame = "camera_link") // DIRTY HACK!!!
46  frame_(frame),
47  traffic_light_state_array_publisher_(rclcpp::create_publisher<MessageType>(
48  node_ptr, topic_name, rclcpp::QoS(10).transient_local()))
49  {
50  }
51 
52  ~TrafficLightPublisher() override = default;
53 
54  static auto generateMessage(
55  const rclcpp::Time &, const simulation_api_schema::UpdateTrafficLightsRequest & request,
56  const std::string & frame = "") -> std::unique_ptr<MessageType>;
57 
58  auto publish(
59  const rclcpp::Time & current_ros_time,
60  const simulation_api_schema::UpdateTrafficLightsRequest & request) const -> void override
61  {
62  traffic_light_state_array_publisher_->publish(
63  generateMessage(current_ros_time, request, frame_));
64  }
65 
66 private:
67  const std::string frame_;
68 
69  const typename rclcpp::Publisher<MessageType>::SharedPtr traffic_light_state_array_publisher_;
70 };
71 } // namespace traffic_simulator
72 #endif // TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_PUBLISHER_HPP_
Definition: traffic_light_publisher.hpp:28
virtual auto publish(const rclcpp::Time &current_ros_time, const simulation_api_schema::UpdateTrafficLightsRequest &request) const -> void=0
Definition: traffic_light_publisher.hpp:39
auto publish(const rclcpp::Time &current_ros_time, const simulation_api_schema::UpdateTrafficLightsRequest &request) const -> void override
Definition: traffic_light_publisher.hpp:58
static auto generateMessage(const rclcpp::Time &, const simulation_api_schema::UpdateTrafficLightsRequest &request, const std::string &frame="") -> std::unique_ptr< MessageType >
TrafficLightPublisher(const NodeTypePointer &node_ptr, const std::string &topic_name, const std::string &frame="camera_link")
Definition: traffic_light_publisher.hpp:42
Definition: api.hpp:48
std::string string
Definition: junit5.hpp:26