moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
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
42
44{
45protected:
46 void SetUp() override
47 {
48 MoveItSetupTest::SetUp();
49 config_data_->registerType("sensors", "moveit_setup::app::PerceptionConfig");
50 templates_path_ = getSharePath("moveit_setup_app_plugins") / "templates";
51 default_yaml_path_ = templates_path_ / "config/sensors_3d.yaml";
52 }
53 std::filesystem::path templates_path_;
54 std::filesystem::path default_yaml_path_;
55};
56
57// This tests parsing of sensors_3d.yaml
58TEST_F(PerceptionTest, ReadingSensorsConfig)
59{
60 auto sensors_config = config_data_->get<PerceptionConfig>("sensors");
61
62 // Before parsing, no config available
63 EXPECT_EQ(sensors_config->getSensorPluginConfig().size(), 0u);
64
65 // Read the file containing the default config parameters
66 auto configs = sensors_config->load3DSensorsYAML(default_yaml_path_);
67
68 // Default config for the two available sensor plugins
69 // Make sure both are parsed correctly
70 ASSERT_EQ(configs.size(), 2u);
71
72 EXPECT_EQ(configs[0]["sensor_plugin"], std::string("occupancy_map_monitor/PointCloudOctomapUpdater"));
73
74 EXPECT_EQ(configs[1]["sensor_plugin"], std::string("occupancy_map_monitor/DepthImageOctomapUpdater"));
75}
76
77// This tests writing of sensors_3d.yaml
78TEST_F(PerceptionTest, WritingSensorsConfig)
79{
80 auto sensors_config = config_data_->get<PerceptionConfig>("sensors");
81
82 // Empty Config Should have No Sensors
83 EXPECT_EQ(sensors_config->getSensorPluginConfig().size(), 0u);
84
85 generateFiles<PerceptionConfig>("sensors");
86
87 std::filesystem::path generated = output_dir_ / "config/sensors_3d.yaml";
88
89 ASSERT_TRUE(std::filesystem::is_regular_file(generated));
90
91 sensors_config->loadPrevious(std::filesystem::path("fake_path"), YAML::Node());
92
93 // Should now have the defaults loaded
94 EXPECT_EQ(sensors_config->getSensorPluginConfig().size(), 2u);
95
96 generateFiles<PerceptionConfig>("sensors");
97
98 expectYamlEquivalence(generated, default_yaml_path_);
99}
100
101int main(int argc, char** argv)
102{
103 testing::InitGoogleTest(&argc, argv);
104 rclcpp::init(argc, argv);
105 return RUN_ALL_TESTS();
106}
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:51
void expectYamlEquivalence(const YAML::Node &generated, const YAML::Node &reference, const std::filesystem::path &generated_path, const std::string &yaml_namespace="")
int main(int argc, char **argv)
TEST_F(PerceptionTest, ReadingSensorsConfig)