scenario_simulator_v2 C++ API
detection_sensor.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__DETECTION_SENSOR__DETECTION_SENSOR_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__DETECTION_SENSOR__DETECTION_SENSOR_HPP_
17 
18 #include <simulation_api_schema.pb.h>
19 
20 #include <geometry/plane.hpp>
21 #include <geometry_msgs/msg/pose.hpp>
22 #include <memory>
23 #include <optional>
24 #include <queue>
25 #include <random>
26 #include <rclcpp/rclcpp.hpp>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
32 {
34 {
35 protected:
37 
38  simulation_api_schema::DetectionSensorConfiguration configuration_;
39 
41  const double current_simulation_time,
42  const simulation_api_schema::DetectionSensorConfiguration & configuration)
43  : previous_simulation_time_(current_simulation_time), configuration_(configuration)
44  {
45  }
46 
48  const traffic_simulator_msgs::EntityStatus &) const -> bool;
49 
51  const std::vector<traffic_simulator_msgs::EntityStatus> &) const
52  -> std::vector<traffic_simulator_msgs::EntityStatus>::const_iterator;
53 
55  const geometry_msgs::Pose & npc_pose, const geometry_msgs::Pose & ego_pose) -> bool;
56 
57 public:
58  virtual ~DetectionSensorBase() = default;
59 
60  virtual void update(
61  const double current_simulation_time, const std::vector<traffic_simulator_msgs::EntityStatus> &,
62  const rclcpp::Time & current_ros_time,
63  const std::vector<std::string> & lidar_detected_entities) = 0;
64 
65 private:
66  std::optional<math::geometry::Plane> ego_plane_opt_{std::nullopt};
67  std::optional<geometry_msgs::msg::Pose> ego_plane_pose_opt_{std::nullopt};
68 };
69 
70 template <typename T, typename U = autoware_perception_msgs::msg::TrackedObjects>
72 {
73  const typename rclcpp::Publisher<T>::SharedPtr detected_objects_publisher;
74 
75  const typename rclcpp::Publisher<U>::SharedPtr ground_truth_objects_publisher;
76 
77  std::default_random_engine random_engine_;
78 
79  std::queue<std::pair<autoware_perception_msgs::msg::DetectedObjects, double>>
80  detected_objects_queue;
81 
82  std::queue<std::pair<autoware_perception_msgs::msg::TrackedObjects, double>>
83  ground_truth_objects_queue;
84 
85 public:
86  explicit DetectionSensor(
87  const double current_simulation_time,
88  const simulation_api_schema::DetectionSensorConfiguration & configuration,
89  const typename rclcpp::Publisher<T>::SharedPtr & publisher,
90  const typename rclcpp::Publisher<U>::SharedPtr & ground_truth_publisher = nullptr)
91  : DetectionSensorBase(current_simulation_time, configuration),
92  detected_objects_publisher(publisher),
93  ground_truth_objects_publisher(ground_truth_publisher),
94  random_engine_(configuration.random_seed())
95  {
96  }
97 
98  ~DetectionSensor() override = default;
99 
100  auto update(
101  const double, const std::vector<traffic_simulator_msgs::EntityStatus> &, const rclcpp::Time &,
102  const std::vector<std::string> & lidar_detected_entities) -> void override;
103 };
104 } // namespace simple_sensor_simulator
105 
106 #endif // SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__DETECTION_SENSOR__DETECTION_SENSOR_HPP_
Definition: detection_sensor.hpp:34
auto isOnOrAboveEgoPlane(const geometry_msgs::Pose &npc_pose, const geometry_msgs::Pose &ego_pose) -> bool
Definition: detection_sensor.cpp:67
DetectionSensorBase(const double current_simulation_time, const simulation_api_schema::DetectionSensorConfiguration &configuration)
Definition: detection_sensor.hpp:40
simulation_api_schema::DetectionSensorConfiguration configuration_
Definition: detection_sensor.hpp:38
auto isEgoEntityStatusToWhichThisSensorIsAttached(const traffic_simulator_msgs::EntityStatus &) const -> bool
Definition: detection_sensor.cpp:44
double previous_simulation_time_
Definition: detection_sensor.hpp:36
virtual void update(const double current_simulation_time, const std::vector< traffic_simulator_msgs::EntityStatus > &, const rclcpp::Time &current_ros_time, const std::vector< std::string > &lidar_detected_entities)=0
auto findEgoEntityStatusToWhichThisSensorIsAttached(const std::vector< traffic_simulator_msgs::EntityStatus > &) const -> std::vector< traffic_simulator_msgs::EntityStatus >::const_iterator
Definition: detection_sensor.cpp:51
Definition: detection_sensor.hpp:72
DetectionSensor(const double current_simulation_time, const simulation_api_schema::DetectionSensorConfiguration &configuration, const typename rclcpp::Publisher< T >::SharedPtr &publisher, const typename rclcpp::Publisher< U >::SharedPtr &ground_truth_publisher=nullptr)
Definition: detection_sensor.hpp:86
auto update(const double, const std::vector< traffic_simulator_msgs::EntityStatus > &, const rclcpp::Time &, const std::vector< std::string > &lidar_detected_entities) -> void override
Definition: constants.hpp:19
traffic_simulator_msgs::EntityStatus EntityStatus
Definition: helper_functions.hpp:32