scenario_simulator_v2 C++ API
traffic_lights_detector.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 SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__TRAFFIC_LIGHTS__TRAFFIC_LIGHTS_DETECTOR_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__TRAFFIC_LIGHTS__TRAFFIC_LIGHTS_DETECTOR_HPP_
17 
18 #include <autoware_auto_perception_msgs/msg/traffic_signal_array.hpp>
19 #include <autoware_perception_msgs/msg/traffic_signal_array.hpp>
20 #include <rclcpp/rclcpp.hpp>
22 #include <string>
24 
25 #if __has_include(<autoware_perception_msgs/msg/traffic_light_group_array.hpp>)
26 #include <autoware_perception_msgs/msg/traffic_light_group_array.hpp>
27 #endif
28 
30 {
31 namespace traffic_lights
32 {
39 {
40 public:
41  template <typename NodeType>
42  explicit TrafficLightsDetector(NodeType & node, const std::string & architecture_type)
43  : publisher_ptr_(makePublisher(node, architecture_type))
44  {
45  }
46 
48  const rclcpp::Time & current_ros_time,
49  const simulation_api_schema::UpdateTrafficLightsRequest & request) -> void
50  {
51  publisher_ptr_->publish(current_ros_time, request);
52  }
53 
54 private:
55  template <typename NodeType>
56  auto makePublisher(NodeType & node, const std::string & architecture_type)
57  -> std::unique_ptr<traffic_simulator::TrafficLightPublisherBase>
58  {
59  /*
60  TrafficLightsDetector in SimpleSensorSimulator publishes using architecture-dependent topics:
61  "/perception/traffic_light_recognition/internal/traffic_signals" for >= "awf/universe/20240605"
62  "/perception/traffic_light_recognition/internal/traffic_signals" for == "awf/universe/20230906"
63  "/perception/traffic_light_recognition/traffic_signals" for "awf/universe"
64 
65  V2ITrafficLights in TrafficSimulator publishes publishes using architecture-independent topics ("awf/universe..."):
66  "/v2x/traffic_signals" and "/perception/traffic_light_recognition/external/traffic_signals"
67  */
68  if (architecture_type == "awf/universe") {
69  using Message = autoware_auto_perception_msgs::msg::TrafficSignalArray;
70  return std::make_unique<traffic_simulator::TrafficLightPublisher<Message>>(
71  &node, "/perception/traffic_light_recognition/traffic_signals");
72  } else if (architecture_type == "awf/universe/20230906") {
73  using Message = autoware_perception_msgs::msg::TrafficSignalArray;
74  return std::make_unique<traffic_simulator::TrafficLightPublisher<Message>>(
75  &node, "/perception/traffic_light_recognition/internal/traffic_signals");
76 #if __has_include(<autoware_perception_msgs/msg/traffic_light_group_array.hpp>)
77  } else if (architecture_type >= "awf/universe/20240605") {
78  using Message = autoware_perception_msgs::msg::TrafficLightGroupArray;
79  return std::make_unique<traffic_simulator::TrafficLightPublisher<Message>>(
80  &node, "/perception/traffic_light_recognition/internal/traffic_signals");
81 #endif
82  } else {
83  std::stringstream ss;
84  ss << "Unexpected architecture_type " << std::quoted(architecture_type)
85  << " given for traffic light.";
86  throw std::invalid_argument(ss.str());
87  }
88  }
89 
90  const std::unique_ptr<traffic_simulator::TrafficLightPublisherBase> publisher_ptr_;
91 };
92 } // namespace traffic_lights
93 } // namespace simple_sensor_simulator
94 
95 #endif // SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__TRAFFIC_LIGHTS__TRAFFIC_LIGHTS_DETECTOR_HPP_
Implements traffic lights detector mechanism simulation Currently it only allows to set traffic light...
Definition: traffic_lights_detector.hpp:39
TrafficLightsDetector(NodeType &node, const std::string &architecture_type)
Definition: traffic_lights_detector.hpp:42
auto updateFrame(const rclcpp::Time &current_ros_time, const simulation_api_schema::UpdateTrafficLightsRequest &request) -> void
Definition: traffic_lights_detector.hpp:47
Definition: constants.hpp:19
std::string string
Definition: junit5.hpp:26