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,
33  const TrafficLightStatePredictions * predictions = nullptr) const -> void = 0;
34 
35  virtual ~TrafficLightPublisherBase() = default;
36 };
37 
38 template <typename MessageType>
40 {
41 public:
42  template <typename NodeTypePointer>
44  const NodeTypePointer & node_ptr, const std::string & topic_name,
45  const std::string & frame = "camera_link") // DIRTY HACK!!!
47  frame_(frame),
48  traffic_light_state_array_publisher_(rclcpp::create_publisher<MessageType>(
49  node_ptr, topic_name, rclcpp::QoS(10).transient_local()))
50  {
51  }
52 
53  ~TrafficLightPublisher() override = default;
54 
55  static auto generateMessage(
56  const rclcpp::Time &, const simulation_api_schema::UpdateTrafficLightsRequest & request,
57  const std::string & frame = "", const TrafficLightStatePredictions * predictions = nullptr)
58  -> std::unique_ptr<MessageType>;
59 
60  auto publish(
61  const rclcpp::Time & current_ros_time,
62  const simulation_api_schema::UpdateTrafficLightsRequest & request,
63  const TrafficLightStatePredictions * predictions = nullptr) const -> void override
64  {
65  traffic_light_state_array_publisher_->publish(
66  generateMessage(current_ros_time, request, frame_, predictions));
67  }
68 
69 private:
70  const std::string frame_;
71 
72  const typename rclcpp::Publisher<MessageType>::SharedPtr traffic_light_state_array_publisher_;
73 };
74 } // namespace traffic_simulator
75 #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 TrafficLightStatePredictions *predictions=nullptr) const -> void=0
Definition: traffic_light_publisher.hpp:40
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:43
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:60
Definition: api.hpp:32
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