moveit2
The MoveIt Motion Planning Framework for ROS 2.
test_perception.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2022, Metro Robots
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Metro Robots nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: David V. Lu!! */
38 
39 static const rclcpp::Logger LOGGER = rclcpp::get_logger("test_perception");
40 
44 
46 {
47 protected:
48  void SetUp() override
49  {
50  MoveItSetupTest::SetUp();
51  config_data_->registerType("sensors", "moveit_setup::app::PerceptionConfig");
52  templates_path_ = getSharePath("moveit_setup_app_plugins") / "templates";
53  default_yaml_path_ = templates_path_ / "config/sensors_3d.yaml";
54  }
55  std::filesystem::path templates_path_;
56  std::filesystem::path default_yaml_path_;
57 };
58 
59 // This tests parsing of sensors_3d.yaml
60 TEST_F(PerceptionTest, ReadingSensorsConfig)
61 {
62  auto sensors_config = config_data_->get<PerceptionConfig>("sensors");
63 
64  // Before parsing, no config available
65  EXPECT_EQ(sensors_config->getSensorPluginConfig().size(), 0u);
66 
67  // Read the file containing the default config parameters
68  auto configs = sensors_config->load3DSensorsYAML(default_yaml_path_);
69 
70  // Default config for the two available sensor plugins
71  // Make sure both are parsed correctly
72  ASSERT_EQ(configs.size(), 2u);
73 
74  EXPECT_EQ(configs[0]["sensor_plugin"], std::string("occupancy_map_monitor/PointCloudOctomapUpdater"));
75 
76  EXPECT_EQ(configs[1]["sensor_plugin"], std::string("occupancy_map_monitor/DepthImageOctomapUpdater"));
77 }
78 
79 // This tests writing of sensors_3d.yaml
80 TEST_F(PerceptionTest, WritingSensorsConfig)
81 {
82  auto sensors_config = config_data_->get<PerceptionConfig>("sensors");
83 
84  // Empty Config Should have No Sensors
85  EXPECT_EQ(sensors_config->getSensorPluginConfig().size(), 0u);
86 
87  generateFiles<PerceptionConfig>("sensors");
88 
89  std::filesystem::path generated = output_dir_ / "config/sensors_3d.yaml";
90 
91  ASSERT_TRUE(std::filesystem::is_regular_file(generated));
92 
93  sensors_config->loadPrevious(std::filesystem::path("fake_path"), YAML::Node());
94 
95  // Should now have the defaults loaded
96  EXPECT_EQ(sensors_config->getSensorPluginConfig().size(), 2u);
97 
98  generateFiles<PerceptionConfig>("sensors");
99 
100  expectYamlEquivalence(generated, default_yaml_path_);
101 }
102 
103 int main(int argc, char** argv)
104 {
105  testing::InitGoogleTest(&argc, argv);
106  rclcpp::init(argc, argv);
107  return RUN_ALL_TESTS();
108 }
void SetUp() override
std::filesystem::path templates_path_
std::filesystem::path default_yaml_path_
Test environment with DataWarehouse setup and help for generating files in a temp dir.
moveit_setup::DataWarehousePtr config_data_
std::filesystem::path getSharePath(const std::string &package_name)
Return a path for the given package's share folder.
Definition: utilities.hpp:50
void expectYamlEquivalence(const YAML::Node &generated, const YAML::Node &reference, const std::filesystem::path &generated_path, const std::string &yaml_namespace="")
const rclcpp::Logger LOGGER
Definition: async_test.h:31
int main(int argc, char **argv)
TEST_F(PerceptionTest, ReadingSensorsConfig)