scenario_simulator_v2 C++ API
helper.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 TRAFFIC_SIMULATOR__HELPER__HELPER_HPP_
16 #define TRAFFIC_SIMULATOR__HELPER__HELPER_HPP_
17 
18 #include <simulation_api_schema.pb.h>
19 
20 #include <algorithm>
21 #include <cmath>
22 #include <geometry_msgs/msg/pose.hpp>
23 #include <geometry_msgs/msg/quaternion.hpp>
24 #include <geometry_msgs/msg/vector3.hpp>
25 #include <iostream>
26 #include <string>
28 #include <traffic_simulator_msgs/msg/action_status.hpp>
29 #include <traffic_simulator_msgs/msg/lanelet_pose.hpp>
30 #include <unordered_set>
31 #include <vector>
32 
33 namespace traffic_simulator
34 {
35 namespace helper
36 {
46 traffic_simulator_msgs::msg::ActionStatus constructActionStatus(
47  double linear_vel = 0, double angular_vel = 0, double linear_accel = 0, double angular_accel = 0);
48 
61  lanelet::Id lanelet_id, double s, double offset = 0, double roll = 0, double pitch = 0,
62  double yaw = 0);
63 
74  lanelet::Id lanelet_id, double s, double offset,
75  const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr) -> CanonicalizedLaneletPose;
76 
90  lanelet::Id lanelet_id, double s, double offset, double roll, double pitch, double yaw,
91  const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr) -> CanonicalizedLaneletPose;
92 
101 geometry_msgs::msg::Vector3 constructRPY(double roll = 0, double pitch = 0, double yaw = 0);
102 
109 geometry_msgs::msg::Vector3 constructRPYfromQuaternion(geometry_msgs::msg::Quaternion quaternion);
110 
122 geometry_msgs::msg::Pose constructPose(
123  double x, double y, double z, double roll, double pitch, double yaw);
124 
131 template <typename T>
132 std::vector<T> getUniqueValues(const std::vector<T> & input_vector)
133 {
134  std::vector<T> output_vector(input_vector);
135 
136  std::unordered_set<T> unique_values;
137  auto empty_elements_start = std::remove_if(
138  output_vector.begin(), output_vector.end(),
139  [&unique_values](T const & element) { return !unique_values.insert(element).second; });
140  output_vector.erase(empty_elements_start, output_vector.end());
141 
142  return output_vector;
143 }
144 
145 enum class LidarType { VLP16, VLP32 };
146 
147 const simulation_api_schema::LidarConfiguration constructLidarConfiguration(
148  const LidarType type, const std::string & entity, const std::string & architecture_type,
149  const double lidar_sensor_delay = 0, const double horizontal_resolution = 1.0 / 180.0 * M_PI);
150 
151 const simulation_api_schema::DetectionSensorConfiguration constructDetectionSensorConfiguration(
152  const std::string & entity, const std::string & architecture_type, const double update_duration,
153  const double range = 300.0, const bool detect_all_objects_in_range = false,
154  const double pos_noise_stddev = 0, const int random_seed = 0,
155  const double probability_of_lost = 0, const double object_recognition_delay = 0,
156  const double object_recognition_ground_truth_delay = 0);
157 } // namespace helper
158 } // namespace traffic_simulator
159 
160 std::ostream & operator<<(std::ostream & os, const traffic_simulator::LaneletPose & ll_pose);
161 
162 std::ostream & operator<<(std::ostream & os, const geometry_msgs::msg::Point & point);
163 
164 std::ostream & operator<<(std::ostream & os, const geometry_msgs::msg::Vector3 & vector);
165 
166 std::ostream & operator<<(std::ostream & os, const geometry_msgs::msg::Quaternion & quat);
167 
168 std::ostream & operator<<(std::ostream & os, const geometry_msgs::msg::Pose & pose);
169 
170 template <typename T>
171 auto operator+(const std::vector<T> & v0, const std::vector<T> & v1) -> decltype(auto)
172 {
173  auto result = v0;
174  result.reserve(v0.size() + v1.size());
175  result.insert(result.end(), v1.begin(), v1.end());
176  return result;
177 }
178 
179 template <typename T>
180 auto operator+=(std::vector<T> & v0, const std::vector<T> & v1) -> decltype(auto)
181 {
182  v0.reserve(v0.size() + v1.size());
183  v0.insert(v0.end(), v1.begin(), v1.end());
184  return v0;
185 }
186 
187 template <typename T>
188 auto sortAndUnique(const std::vector<T> & data) -> std::vector<T>
189 {
190  std::vector<T> ret = data;
191  std::sort(ret.begin(), ret.end());
192  ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
193  return ret;
194 }
195 
196 #endif // TRAFFIC_SIMULATOR__HELPER__HELPER_HPP_
std::ostream & operator<<(std::ostream &os, const traffic_simulator::LaneletPose &ll_pose)
Definition: helper.cpp:192
auto operator+(const std::vector< T > &v0, const std::vector< T > &v1) -> decltype(auto)
Definition: helper.hpp:171
auto operator+=(std::vector< T > &v0, const std::vector< T > &v1) -> decltype(auto)
Definition: helper.hpp:180
auto sortAndUnique(const std::vector< T > &data) -> std::vector< T >
Definition: helper.hpp:188
geometry_msgs::msg::Vector3 constructRPY(double roll=0, double pitch=0, double yaw=0)
helper function for constructing rpy
Definition: helper.cpp:77
auto constructCanonicalizedLaneletPose(lanelet::Id lanelet_id, double s, double offset, const std::shared_ptr< hdmap_utils::HdMapUtils > &hdmap_utils_ptr) -> CanonicalizedLaneletPose
helper function for constructing canonicalized lanelet pose
Definition: helper.cpp:70
geometry_msgs::msg::Pose constructPose(double x, double y, double z, double roll, double pitch, double yaw)
helper function for constructing pose
Definition: helper.cpp:91
const simulation_api_schema::LidarConfiguration constructLidarConfiguration(const LidarType type, const std::string &entity, const std::string &architecture_type, const double lidar_sensor_delay=0, const double horizontal_resolution=1.0/180.0 *M_PI)
Definition: helper.cpp:122
std::vector< T > getUniqueValues(const std::vector< T > &input_vector)
helper function for creating vector without duplicates, with preserved order
Definition: helper.hpp:132
const simulation_api_schema::DetectionSensorConfiguration constructDetectionSensorConfiguration(const std::string &entity, const std::string &architecture_type, const double update_duration, const double range=300.0, const bool detect_all_objects_in_range=false, const double pos_noise_stddev=0, const int random_seed=0, const double probability_of_lost=0, const double object_recognition_delay=0, const double object_recognition_ground_truth_delay=0)
Definition: helper.cpp:102
geometry_msgs::msg::Vector3 constructRPYfromQuaternion(geometry_msgs::msg::Quaternion quaternion)
helper function for constructing rpy
Definition: helper.cpp:86
traffic_simulator_msgs::msg::ActionStatus constructActionStatus(double linear_vel=0, double angular_vel=0, double linear_accel=0, double angular_accel=0)
helper function for constructing action status
Definition: helper.cpp:25
LidarType
Definition: helper.hpp:145
LaneletPose constructLaneletPose(lanelet::Id lanelet_id, double s, double offset=0, double roll=0, double pitch=0, double yaw=0)
helper function for constructing lanelet pose
Definition: helper.cpp:40
Definition: api.hpp:49
traffic_simulator_msgs::msg::LaneletPose LaneletPose
Definition: lanelet_pose.hpp:22
std::string string
Definition: junit5.hpp:26
traffic_simulator::lanelet_pose::CanonicalizedLaneletPose CanonicalizedLaneletPose
Definition: test_lanelet_pose.cpp:21