moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
test_controllers.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!! */
40
46
48{
49protected:
50 void SetUp() override
51 {
52 MoveItSetupTest::SetUp();
53 config_data_->registerType("moveit_controllers", "moveit_setup::controllers::MoveItControllersConfig");
54 config_data_->registerType("ros2_controllers", "moveit_setup::controllers::ROS2ControllersConfig");
55 config_data_->registerType("modified_urdf", "moveit_setup::ModifiedUrdfConfig");
56 config_data_->registerType("control_xacro", "moveit_setup::controllers::ControlXacroConfig");
57 }
58};
59
61{
62 config_data_->preloadWithFullConfig("moveit_resources_fanuc_moveit_config");
63 auto ros2_controllers_config = config_data_->get<ROS2ControllersConfig>("ros2_controllers");
64 const std::vector<ControllerInfo>& controllers = ros2_controllers_config->getControllers();
65 ASSERT_EQ(1u, controllers.size());
66 const ControllerInfo& ci = controllers[0];
67 EXPECT_EQ("fanuc_controller", ci.name_);
68 EXPECT_EQ("joint_trajectory_controller/JointTrajectoryController", ci.type_);
69 EXPECT_EQ(6u, ci.joints_.size());
70
71 auto moveit_controllers_config = config_data_->get<MoveItControllersConfig>("moveit_controllers");
72 const std::vector<ControllerInfo>& mcontrollers = moveit_controllers_config->getControllers();
73 ASSERT_EQ(1u, mcontrollers.size());
74 const ControllerInfo& mci = mcontrollers[0];
75 EXPECT_EQ("fanuc_controller", mci.name_);
76 EXPECT_EQ("FollowJointTrajectory", mci.type_);
77 EXPECT_EQ(6u, mci.joints_.size());
78}
79
81{
82 config_data_->preloadWithFullConfig("moveit_resources_panda_moveit_config");
83 auto ros2_controllers_config = config_data_->get<ROS2ControllersConfig>("ros2_controllers");
84 const std::vector<ControllerInfo>& controllers = ros2_controllers_config->getControllers();
85 ASSERT_EQ(2u, controllers.size());
86
87 int offset = controllers[0].name_ == "panda_arm_controller" ? 0 : 1;
88 const ControllerInfo& ci1 = controllers[offset];
89 EXPECT_EQ("panda_arm_controller", ci1.name_);
90 EXPECT_EQ("joint_trajectory_controller/JointTrajectoryController", ci1.type_);
91 EXPECT_EQ(7u, ci1.joints_.size());
92
93 const ControllerInfo& ci2 = controllers[1 - offset];
94 EXPECT_EQ("panda_hand_controller", ci2.name_);
95 EXPECT_EQ("position_controllers/GripperActionController", ci2.type_);
96 EXPECT_EQ(1u, ci2.joints_.size());
97
98 /*
99 TODO(dlu): Re-enable when moveit_resources 2.0.5 is available on the build farm
100
101 auto moveit_controllers_config = config_data_->get<MoveItControllersConfig>("moveit_controllers");
102 const std::vector<ControllerInfo>& mcontrollers = moveit_controllers_config->getControllers();
103 ASSERT_EQ(1u, mcontrollers.size());
104 const ControllerInfo& mci1 = mcontrollers[offset];
105 EXPECT_EQ("panda_arm_controller", mci1.name_);
106 EXPECT_EQ("FollowJointTrajectory", mci1.type_);
107 EXPECT_EQ(7u, mci1.joints_.size());
108 */
109}
110
112{
113 config_data_->preloadWithFullConfig("moveit_resources_fanuc_moveit_config");
114 config_data_->get<moveit_setup::controllers::ControlXacroConfig>("control_xacro")->loadFromDescription();
115 generateFiles<ROS2ControllersConfig>("ros2_controllers");
116 generateFiles<MoveItControllersConfig>("moveit_controllers");
117
118 std::filesystem::path original_config = getSharePath("moveit_resources_fanuc_moveit_config");
119 for (const std::string relative_path : { "config/moveit_controllers.yaml", "config/ros2_controllers.yaml" })
120 {
121 expectYamlEquivalence(output_dir_ / relative_path, original_config / relative_path);
122 }
123}
124
125TEST_F(ControllersTest, AddDefaultControllers)
126{
127 // only preload urdf and srdf
128 auto config_dir = getSharePath("moveit_resources_panda_moveit_config");
129 YAML::Node settings = YAML::LoadFile(config_dir / ".setup_assistant")["moveit_setup_assistant_config"];
130 config_data_->get<moveit_setup::URDFConfig>("urdf")->loadPrevious(config_dir, settings["URDF"]);
131 auto srdf_config = config_data_->get<moveit_setup::SRDFConfig>("srdf");
132 srdf_config->loadPrevious(config_dir, settings["SRDF"]);
133
134 auto ros2_controllers_config = config_data_->get<ROS2ControllersConfig>("ros2_controllers");
135
136 // Initially no controllers
137 EXPECT_EQ(ros2_controllers_config->getControllers().size(), 0u);
138
139 // Run the setup step
141 initializeStep(setup_step);
142
143 // Adding default controllers, a controller for each planning group
144 setup_step.addDefaultControllers();
145
146 // Number of the planning groups defined in the model srdf
147 size_t group_count = srdf_config->getGroups().size();
148
149 // Test that addDefaultControllers() did actually add a controller for the new_group
150 EXPECT_EQ(ros2_controllers_config->getControllers().size(), group_count);
151}
152
153int main(int argc, char** argv)
154{
155 testing::InitGoogleTest(&argc, argv);
156 rclcpp::init(argc, argv);
157 return RUN_ALL_TESTS();
158}
void SetUp() override
Test environment with DataWarehouse setup and help for generating files in a temp dir.
moveit_setup::DataWarehousePtr config_data_
void loadPrevious(const std::filesystem::path &package_path, const YAML::Node &node) override
Loads the configuration from an existing MoveIt configuration.
std::vector< ControllerInfo > & getControllers()
Gets controllers_ vector.
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="")
TEST_F(ControllersTest, ParseFanuc)
int main(int argc, char **argv)