scenario_simulator_v2 C++ API
test_imu_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__TEST__TEST_LIDAR_SENSOR_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__TEST__TEST_LIDAR_SENSOR_HPP_
17 
18 #include <gtest/gtest.h>
19 
20 #include <rclcpp/rclcpp.hpp>
21 #include <sensor_msgs/msg/imu.hpp>
22 #include <set>
24 #include <string>
25 #include <vector>
26 
27 #include "../../utils/helper_functions.hpp"
28 
29 using namespace simple_sensor_simulator;
30 
31 class ImuSensorTest : public ::testing::Test
32 {
33 protected:
35  : config_([] {
36  simulation_api_schema::ImuSensorConfiguration config;
37 
38  config.set_entity("ego");
39  config.set_frame_id("imu_frame");
40  config.set_add_gravity(true);
41  config.set_use_seed(true);
42  config.set_seed(1);
43  config.set_noise_standard_deviation_orientation(2);
44  config.set_noise_standard_deviation_twist(3);
45  config.set_noise_standard_deviation_acceleration(4);
46 
47  return config;
48  }())
49  {
50  rclcpp::init(0, nullptr);
51 
52  node_ = std::make_shared<rclcpp::Node>("imu_sensor_test_node");
53 
54  subscription_ = node_->create_subscription<sensor_msgs::msg::Imu>(
55  topic_, 10, [this](const sensor_msgs::msg::Imu::SharedPtr msg) { received_msg_ = msg; });
56  }
57 
58  auto initializeSensor() -> void
59  {
60  initializeEntityStatuses();
61 
62  imu_ = std::make_unique<ImuSensor<sensor_msgs::msg::Imu>>(config_, topic_, *node_);
63  }
64 
65  ~ImuSensorTest() { rclcpp::shutdown(); }
66 
67  rclcpp::Node::SharedPtr node_;
68 
69  const std::string topic_{"/imu_output"};
70  simulation_api_schema::ImuSensorConfiguration config_;
71  std::unique_ptr<ImuSensorBase> imu_;
72  rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr subscription_;
73 
74  std::vector<EntityStatus> status_;
75 
76  sensor_msgs::msg::Imu::SharedPtr received_msg_;
77 
78  double current_simulation_time_{1.0};
79  rclcpp::Time current_ros_time_{1};
80 
81 private:
82  auto initializeEntityStatuses() -> void
83  {
84  const auto dimensions = utils::makeDimensions(4.5, 2.0, 1.5);
85 
86  auto ego_status = utils::makeEntity(
87  "ego", EntityType::EGO, utils::makePose(5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0), dimensions);
88 
89  ego_status.mutable_action_status()->mutable_twist()->mutable_angular()->set_z(0.5);
90  ego_status.mutable_action_status()->mutable_accel()->mutable_linear()->set_x(1.2);
91 
92  const auto other1_status = utils::makeEntity(
93  "other1", EntityType::VEHICLE, utils::makePose(-3.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0),
94  dimensions);
95  const auto other2_status = utils::makeEntity(
96  "other2", EntityType::VEHICLE, utils::makePose(5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
97  dimensions);
98 
99  status_ = {ego_status, other1_status, other2_status};
100  }
101 };
102 #endif // SIMPLE_SENSOR_SIMULATOR__TEST__TEST_LIDAR_SENSOR_HPP_
Definition: test_imu_sensor.hpp:32
auto initializeSensor() -> void
Definition: test_imu_sensor.hpp:58
simulation_api_schema::ImuSensorConfiguration config_
Definition: test_imu_sensor.hpp:70
rclcpp::Node::SharedPtr node_
Definition: test_imu_sensor.hpp:67
rclcpp::Subscription< sensor_msgs::msg::Imu >::SharedPtr subscription_
Definition: test_imu_sensor.hpp:72
~ImuSensorTest()
Definition: test_imu_sensor.hpp:65
sensor_msgs::msg::Imu::SharedPtr received_msg_
Definition: test_imu_sensor.hpp:76
std::unique_ptr< ImuSensorBase > imu_
Definition: test_imu_sensor.hpp:71
ImuSensorTest()
Definition: test_imu_sensor.hpp:34
std::vector< EntityStatus > status_
Definition: test_imu_sensor.hpp:74
Definition: constants.hpp:19
auto makePose(const double px, const double py, const double pz, const double ox, const double oy, const double oz, const double ow) -> geometry_msgs::msg::Pose
Definition: helper_functions.hpp:45
auto makeEntity(const std::string &name, const EntityType::Enum type, const EntitySubtype::Enum subtype, const geometry_msgs::msg::Pose &pose, const geometry_msgs::msg::Vector3 &dimensions) -> EntityStatus
Definition: helper_functions.hpp:125
auto makeDimensions(const double x, const double y, const double z) -> geometry_msgs::msg::Vector3
Definition: helper_functions.hpp:54
std::string string
Definition: junit5.hpp:26