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 <rclcpp/rclcpp.hpp>
20 #include <string>
22 
23 // This message will be deleted in the future
24 #if __has_include(<autoware_perception_msgs/msg/traffic_signal_array.hpp>)
25 #include <autoware_perception_msgs/msg/traffic_signal_array.hpp>
26 #endif
27 
28 #if __has_include(<autoware_perception_msgs/msg/traffic_light_group_array.hpp>)
29 #include <autoware_perception_msgs/msg/traffic_light_group_array.hpp>
30 #endif
31 
33 {
34 namespace traffic_lights
35 {
42 {
43 public:
44  template <typename NodeType>
45  explicit TrafficLightsDetector(NodeType & node, const std::string & architecture_type)
46  : publisher_ptr_(makePublisher(node, architecture_type))
47  {
48  }
49 
51  const rclcpp::Time & current_ros_time,
52  const simulation_api_schema::UpdateTrafficLightsRequest & request) -> void
53  {
54  publisher_ptr_->publish(current_ros_time, request);
55  }
56 
57 private:
58  template <typename NodeType>
59  auto makePublisher(NodeType & node, const std::string & architecture_type)
60  -> std::unique_ptr<traffic_simulator::TrafficLightPublisherBase>
61  {
62  /*
63  TrafficLightsDetector in SimpleSensorSimulator publishes using architecture-dependent topics:
64  "/perception/traffic_light_recognition/internal/traffic_signals" for >= "awf/universe/20240605"
65  "/perception/traffic_light_recognition/internal/traffic_signals" for == "awf/universe/20230906"
66 
67  V2ITrafficLights in TrafficSimulator publishes using architecture-independent topics ("awf/universe..."):
68  "/v2x/traffic_signals" and "/perception/traffic_light_recognition/external/traffic_signals"
69  */
70  if (architecture_type == "awf/universe") {
72  "This version of scenario_simulator_v2 does not support ", std::quoted(architecture_type),
73  " as ", std::quoted("architecture_type"), ". Please use older version.");
74 #if __has_include(<autoware_perception_msgs/msg/traffic_signal_array.hpp>)
75  } else if (architecture_type == "awf/universe/20230906") {
76  using Message = autoware_perception_msgs::msg::TrafficSignalArray;
77  return std::make_unique<traffic_simulator::TrafficLightPublisher<Message>>(
78  &node, "/perception/traffic_light_recognition/internal/traffic_signals");
79 #endif
80 #if __has_include(<autoware_perception_msgs/msg/traffic_light_group_array.hpp>)
81  } else if (architecture_type >= "awf/universe/20240605") {
82  using Message = autoware_perception_msgs::msg::TrafficLightGroupArray;
83  return std::make_unique<traffic_simulator::TrafficLightPublisher<Message>>(
84  &node, "/perception/traffic_light_recognition/internal/traffic_signals");
85 #endif
86  } else {
87  std::stringstream ss;
88  ss << "Unexpected architecture_type " << std::quoted(architecture_type)
89  << " given for traffic light.";
90  throw std::invalid_argument(ss.str());
91  }
92  }
93 
94  const std::unique_ptr<traffic_simulator::TrafficLightPublisherBase> publisher_ptr_;
95 };
96 } // namespace traffic_lights
97 } // namespace simple_sensor_simulator
98 
99 #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:42
TrafficLightsDetector(NodeType &node, const std::string &architecture_type)
Definition: traffic_lights_detector.hpp:45
auto updateFrame(const rclcpp::Time &current_ros_time, const simulation_api_schema::UpdateTrafficLightsRequest &request) -> void
Definition: traffic_lights_detector.hpp:50
Definition: constants.hpp:19
std::string string
Definition: junit5.hpp:26
Although there were no syntactic errors in the description of the scenario, differences in meaning an...
Definition: exception.hpp:44