scenario_simulator_v2 C++ API
sensor_simulation.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__SENSOR_SIMULATION_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__SENSOR_SIMULATION_HPP_
17 
18 #include <simulation_api_schema.pb.h>
19 
20 #include <agnocast_wrapper/agnocast_wrapper.hpp>
21 #include <autoware_perception_msgs/msg/detected_objects.hpp>
22 #include <autoware_perception_msgs/msg/tracked_objects.hpp>
23 #include <iomanip>
24 #include <memory>
25 #include <rclcpp/rclcpp.hpp>
31 #include <vector>
32 
33 // This message will be deleted in the future
34 #if __has_include(<autoware_perception_msgs/msg/traffic_signal_array.hpp>)
35 #include <autoware_perception_msgs/msg/traffic_signal_array.hpp>
36 #endif
37 
38 #if __has_include(<autoware_perception_msgs/msg/traffic_light_group_array.hpp>)
39 #include <autoware_perception_msgs/msg/traffic_light_group_array.hpp>
40 #endif
41 
43 {
45 {
46 public:
48  const double current_simulation_time,
49  const simulation_api_schema::LidarConfiguration & configuration, rclcpp::Node & node) -> void
50  {
51  if (configuration.architecture_type().find("awf/universe") != std::string::npos) {
52  lidar_sensors_.push_back(std::make_unique<LidarSensor<sensor_msgs::msg::PointCloud2>>(
53  current_simulation_time, configuration,
54  agnocast_wrapper::create_publisher<sensor_msgs::msg::PointCloud2>(
55  node, "/perception/obstacle_segmentation/pointcloud", 1)));
56  } else {
57  std::stringstream ss;
58  ss << "Unexpected architecture_type " << std::quoted(configuration.architecture_type())
59  << " given.";
60  throw std::runtime_error(ss.str());
61  }
62  }
63 
65  const double current_simulation_time,
66  const simulation_api_schema::DetectionSensorConfiguration & configuration, rclcpp::Node & node)
67  -> void
68  {
69  if (configuration.architecture_type().find("awf/universe") != std::string::npos) {
70  using Message = autoware_perception_msgs::msg::DetectedObjects;
71  using GroundTruthMessage = autoware_perception_msgs::msg::TrackedObjects;
72  detection_sensors_.push_back(std::make_unique<DetectionSensor<Message>>(
73  current_simulation_time, configuration,
74  node.create_publisher<Message>("/perception/object_recognition/detection/objects", 1),
75  node.create_publisher<GroundTruthMessage>(
76  "/perception/object_recognition/ground_truth/objects", 1)));
77  } else {
78  std::stringstream ss;
79  ss << "Unexpected architecture_type " << std::quoted(configuration.architecture_type())
80  << " given.";
81  throw std::runtime_error(ss.str());
82  }
83  }
84 
86  const double current_simulation_time,
87  const simulation_api_schema::OccupancyGridSensorConfiguration & configuration,
88  rclcpp::Node & node) -> void
89  {
90  if (configuration.architecture_type().find("awf/universe") != std::string::npos) {
91  using Message = nav_msgs::msg::OccupancyGrid;
92  occupancy_grid_sensors_.push_back(std::make_unique<OccupancyGridSensor<Message>>(
93  current_simulation_time, configuration,
94  node.create_publisher<Message>("/perception/occupancy_grid_map/map", 1)));
95  } else {
96  std::stringstream ss;
97  ss << "Unexpected architecture_type " << std::quoted(configuration.architecture_type())
98  << " given.";
99  throw std::runtime_error(ss.str());
100  }
101  }
102 
104  const double /*current_simulation_time*/,
105  const simulation_api_schema::PseudoTrafficLightDetectorConfiguration & configuration,
106  rclcpp::Node & node) -> void
107  {
108  traffic_lights_detectors_.push_back(std::make_unique<traffic_lights::TrafficLightsDetector>(
109  node, configuration.architecture_type()));
110  }
111 
113  const double /*current_simulation_time*/,
114  const simulation_api_schema::ImuSensorConfiguration & configuration, rclcpp::Node & node)
115  -> void
116  {
117  imu_sensors_.push_back(std::make_unique<ImuSensor<sensor_msgs::msg::Imu>>(
118  configuration, node.create_publisher<sensor_msgs::msg::Imu>("/sensing/imu/imu_data", 1)));
119  }
120 
121  auto updateSensorFrame(
122  double current_simulation_time, const rclcpp::Time & current_ros_time,
123  const std::vector<traffic_simulator_msgs::EntityStatus> &,
124  const simulation_api_schema::UpdateTrafficLightsRequest &) -> void;
125 
126 private:
127  std::vector<std::unique_ptr<ImuSensorBase>> imu_sensors_;
128  std::vector<std::unique_ptr<LidarSensorBase>> lidar_sensors_;
129  std::vector<std::unique_ptr<DetectionSensorBase>> detection_sensors_;
130  std::vector<std::unique_ptr<OccupancyGridSensorBase>> occupancy_grid_sensors_;
131  std::vector<std::unique_ptr<traffic_lights::TrafficLightsDetector>> traffic_lights_detectors_;
132 };
133 } // namespace simple_sensor_simulator
134 
135 #endif // SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__SENSOR_SIMULATION_HPP_
Definition: detection_sensor.hpp:75
Definition: imu_sensor.hpp:76
Definition: lidar_sensor.hpp:61
occupancy grid sensor implementation
Definition: occupancy_grid_sensor.hpp:83
Definition: sensor_simulation.hpp:45
auto attachDetectionSensor(const double current_simulation_time, const simulation_api_schema::DetectionSensorConfiguration &configuration, rclcpp::Node &node) -> void
Definition: sensor_simulation.hpp:64
auto attachImuSensor(const double, const simulation_api_schema::ImuSensorConfiguration &configuration, rclcpp::Node &node) -> void
Definition: sensor_simulation.hpp:112
auto attachOccupancyGridSensor(const double current_simulation_time, const simulation_api_schema::OccupancyGridSensorConfiguration &configuration, rclcpp::Node &node) -> void
Definition: sensor_simulation.hpp:85
auto attachLidarSensor(const double current_simulation_time, const simulation_api_schema::LidarConfiguration &configuration, rclcpp::Node &node) -> void
Definition: sensor_simulation.hpp:47
auto updateSensorFrame(double current_simulation_time, const rclcpp::Time &current_ros_time, const std::vector< traffic_simulator_msgs::EntityStatus > &, const simulation_api_schema::UpdateTrafficLightsRequest &) -> void
Definition: sensor_simulation.cpp:22
auto attachPseudoTrafficLightsDetector(const double, const simulation_api_schema::PseudoTrafficLightDetectorConfiguration &configuration, rclcpp::Node &node) -> void
Definition: sensor_simulation.hpp:103
Definition: constants.hpp:19