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>
23 
24 namespace traffic_simulator
25 {
27 {
28 public:
29  virtual auto publish(
30  const rclcpp::Time & current_ros_time,
31  const simulation_api_schema::UpdateTrafficLightsRequest & request,
32  const TrafficLightStatePredictions * predictions = nullptr) 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 = "", const TrafficLightStatePredictions * predictions = nullptr)
57  -> std::unique_ptr<MessageType>;
58 
59  auto publish(
60  const rclcpp::Time & current_ros_time,
61  const simulation_api_schema::UpdateTrafficLightsRequest & request,
62  const TrafficLightStatePredictions * predictions = nullptr) const -> void override
63  {
64  traffic_light_state_array_publisher_->publish(
65  generateMessage(current_ros_time, request, frame_, predictions));
66  }
67 
68 private:
69  const std::string frame_;
70 
71  const typename rclcpp::Publisher<MessageType>::SharedPtr traffic_light_state_array_publisher_;
72 };
73 } // namespace traffic_simulator
74 #endif // TRAFFIC_SIMULATOR__TRAFFIC_LIGHTS__TRAFFIC_LIGHT_PUBLISHER_HPP_
Definition: traffic_light_publisher.hpp:27
virtual auto publish(const rclcpp::Time &current_ros_time, const simulation_api_schema::UpdateTrafficLightsRequest &request, const TrafficLightStatePredictions *predictions=nullptr) const -> void=0
Definition: traffic_light_publisher.hpp:39
static auto generateMessage(const rclcpp::Time &, const simulation_api_schema::UpdateTrafficLightsRequest &request, const std::string &frame="", const TrafficLightStatePredictions *predictions=nullptr) -> 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
auto publish(const rclcpp::Time &current_ros_time, const simulation_api_schema::UpdateTrafficLightsRequest &request, const TrafficLightStatePredictions *predictions=nullptr) const -> void override
Definition: traffic_light_publisher.hpp:59
Definition: api.hpp:33
std::unordered_map< lanelet::Id, std::vector< std::pair< rclcpp::Time, std::vector< simulation_api_schema::TrafficLight > >> > TrafficLightStatePredictions
Definition: traffic_lights_base.hpp:35
std::string string
Definition: junit5.hpp:26