From 95847290f5575f756d62037731e8b415de46699e Mon Sep 17 00:00:00 2001 From: Christoph Froehlich Date: Fri, 29 Dec 2023 09:31:57 +0000 Subject: [PATCH] Increase test coverage for deprecated config structure --- hardware_interface/src/component_parser.cpp | 9 +++-- .../test/test_component_parser.cpp | 29 ++++++++++++++ .../ros2_control_test_assets/descriptions.hpp | 40 +++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/hardware_interface/src/component_parser.cpp b/hardware_interface/src/component_parser.cpp index ef0f01e022a..cfec6486165 100644 --- a/hardware_interface/src/component_parser.cpp +++ b/hardware_interface/src/component_parser.cpp @@ -355,8 +355,8 @@ ComponentInfo parse_component_from_xml(const tinyxml2::XMLElement * component_it if (component.is_mimic && command_interfaces_it) { throw std::runtime_error( - "Component " + std::string(component.name) + - " has mimic attribute set to true: Mimic joints cannot have command interfaces."); + "Component '" + std::string(component.name) + + "' has mimic attribute set to true: Mimic joints cannot have command interfaces."); } while (command_interfaces_it) { @@ -665,6 +665,7 @@ std::vector parse_control_resources_from_urdf(const std::string & const auto & joint = hw_info.joints.at(i); // Search for mimic joints defined in ros2_control tag (deprecated) + // TODO(christophfroehlich) delete deprecated config with ROS-J if (joint.parameters.find("mimic") != joint.parameters.cend()) { std::cerr << "Warning: Mimic joints defined in ros2_control tag are deprecated. " @@ -715,7 +716,7 @@ std::vector parse_control_resources_from_urdf(const std::string & [&name](const auto & j) { return j.name == name; }); if (it == hw_info.joints.end()) { - throw std::runtime_error("Joint `" + name + "` not found in hw_info.joints"); + throw std::runtime_error("Joint '" + name + "' not found in hw_info.joints"); } return std::distance(hw_info.joints.begin(), it); }; @@ -729,7 +730,7 @@ std::vector parse_control_resources_from_urdf(const std::string & } else { - throw std::runtime_error("Joint `" + joint.name + "` has no mimic information in URDF"); + throw std::runtime_error("Joint '" + joint.name + "' has no mimic information in URDF"); } } } diff --git a/hardware_interface/test/test_component_parser.cpp b/hardware_interface/test/test_component_parser.cpp index d1d3d1e38e9..29d1ab23659 100644 --- a/hardware_interface/test/test_component_parser.cpp +++ b/hardware_interface/test/test_component_parser.cpp @@ -691,6 +691,35 @@ TEST_F(TestComponentParser, mimic_true_valid_config) EXPECT_EQ(hw_info[0].mimic_joints[0].joint_index, 1); } +// TODO(christophfroehlich) delete deprecated config test +TEST_F(TestComponentParser, mimic_deprecated_valid_config) +{ + const auto urdf_to_test = + std::string(ros2_control_test_assets::gripper_urdf_head) + + std::string(ros2_control_test_assets::gripper_hardware_resources_mimic_deprecated) + + std::string(ros2_control_test_assets::urdf_tail); + std::vector hw_info; + ASSERT_NO_THROW(hw_info = parse_control_resources_from_urdf(urdf_to_test)); + ASSERT_THAT(hw_info, SizeIs(1)); + ASSERT_THAT(hw_info[0].mimic_joints, SizeIs(1)); + EXPECT_DOUBLE_EQ(hw_info[0].mimic_joints[0].multiplier, 1.0); + EXPECT_DOUBLE_EQ(hw_info[0].mimic_joints[0].offset, 0.0); + EXPECT_EQ(hw_info[0].mimic_joints[0].mimicked_joint_index, 0); + EXPECT_EQ(hw_info[0].mimic_joints[0].joint_index, 1); +} + +TEST_F(TestComponentParser, mimic_deprecated_unknown_joint_throws_error) +{ + const auto urdf_to_test = + std::string(ros2_control_test_assets::gripper_urdf_head) + + std::string( + ros2_control_test_assets::gripper_hardware_resources_mimic_deprecated_unknown_joint) + + std::string(ros2_control_test_assets::urdf_tail); + std::vector hw_info; + ASSERT_THROW(parse_control_resources_from_urdf(urdf_to_test), std::runtime_error); +} +// end delete deprecated config test + TEST_F(TestComponentParser, mimic_with_unknown_joint_throws_error) { const auto urdf_to_test = diff --git a/ros2_control_test_assets/include/ros2_control_test_assets/descriptions.hpp b/ros2_control_test_assets/include/ros2_control_test_assets/descriptions.hpp index a1de69e5bf8..51a2e31a2d0 100644 --- a/ros2_control_test_assets/include/ros2_control_test_assets/descriptions.hpp +++ b/ros2_control_test_assets/include/ros2_control_test_assets/descriptions.hpp @@ -873,6 +873,46 @@ const auto gripper_hardware_resources_mimic_true_no_command_if = )"; +// TODO(christophfroehlich) delete deprecated config test +const auto gripper_hardware_resources_mimic_deprecated = + R"( + + + + + + + + + right_finger_joint + 1 + + + + + + )"; + +const auto gripper_hardware_resources_mimic_deprecated_unknown_joint = + R"( + + + + + + + + + middle_finger_joint + 1 + + + + + + )"; +// end delete deprecated config test + const auto gripper_hardware_resources_mimic_true_command_if = R"(