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