From 2f9a5549d71c3e0d3eda6b885462f2d6ad30d778 Mon Sep 17 00:00:00 2001 From: Bence Magyar Date: Wed, 3 May 2023 19:04:22 +0100 Subject: [PATCH 1/4] Do not explode with empty tag --- hardware_interface/src/component_parser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hardware_interface/src/component_parser.cpp b/hardware_interface/src/component_parser.cpp index 14f2dee21e..a7ad414996 100644 --- a/hardware_interface/src/component_parser.cpp +++ b/hardware_interface/src/component_parser.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -68,7 +69,8 @@ std::string get_text_for_element( const auto get_text_output = element_it->GetText(); if (!get_text_output) { - throw std::runtime_error("text not specified in the " + tag_name + " tag"); + std::cerr << "text not specified in the " << tag_name << " tag" << std::endl; + return ""; } return get_text_output; } From 2f33675d01a45624906174fd368e4ddf3ab548be Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Thu, 11 May 2023 14:55:31 +0200 Subject: [PATCH 2/4] Update tests to allow empty URDF parameter to hardware interface --- hardware_interface/test/test_component_parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware_interface/test/test_component_parser.cpp b/hardware_interface/test/test_component_parser.cpp index 97d4a77d21..e5e851d387 100644 --- a/hardware_interface/test/test_component_parser.cpp +++ b/hardware_interface/test/test_component_parser.cpp @@ -100,14 +100,14 @@ TEST_F(TestComponentParser, component_interface_type_empty_throws_error) ASSERT_THROW(parse_control_resources_from_urdf(broken_urdf_string), std::runtime_error); } -TEST_F(TestComponentParser, parameter_empty_throws_error) +TEST_F(TestComponentParser, parameter_empty_throws_no_error) { const std::string broken_urdf_string = std::string(ros2_control_test_assets::urdf_head) + ros2_control_test_assets::invalid_urdf_ros2_control_parameter_empty + ros2_control_test_assets::urdf_tail; - ASSERT_THROW(parse_control_resources_from_urdf(broken_urdf_string), std::runtime_error); + ASSERT_NO_THROW(parse_control_resources_from_urdf(broken_urdf_string)); } TEST_F(TestComponentParser, successfully_parse_valid_urdf_system_one_interface) From 4c02c65f281a25860f1e9a28a3ec958c7d99c2de Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Mon, 15 May 2023 11:10:57 +0200 Subject: [PATCH 3/4] Replace test for empty param This replaces the test that checks that empty parameter tags work and actually checks the parsed urdf. --- .../test/test_component_parser.cpp | 35 +++++++++++++------ .../components_urdfs.hpp | 32 ++++++++--------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/hardware_interface/test/test_component_parser.cpp b/hardware_interface/test/test_component_parser.cpp index e5e851d387..c5cc4596a1 100644 --- a/hardware_interface/test/test_component_parser.cpp +++ b/hardware_interface/test/test_component_parser.cpp @@ -100,16 +100,6 @@ TEST_F(TestComponentParser, component_interface_type_empty_throws_error) ASSERT_THROW(parse_control_resources_from_urdf(broken_urdf_string), std::runtime_error); } -TEST_F(TestComponentParser, parameter_empty_throws_no_error) -{ - const std::string broken_urdf_string = - std::string(ros2_control_test_assets::urdf_head) + - ros2_control_test_assets::invalid_urdf_ros2_control_parameter_empty + - ros2_control_test_assets::urdf_tail; - - ASSERT_NO_THROW(parse_control_resources_from_urdf(broken_urdf_string)); -} - TEST_F(TestComponentParser, successfully_parse_valid_urdf_system_one_interface) { std::string urdf_to_test = @@ -625,6 +615,31 @@ TEST_F(TestComponentParser, successfully_parse_valid_urdf_system_with_size_and_d EXPECT_EQ(hardware_info.gpios[0].state_interfaces[1].size, 1); } +TEST_F(TestComponentParser, successfully_parse_parameter_empty) +{ + const std::string urdf_to_test = + std::string(ros2_control_test_assets::urdf_head) + + ros2_control_test_assets::valid_urdf_ros2_control_parameter_empty + + ros2_control_test_assets::urdf_tail; + const auto control_hardware = parse_control_resources_from_urdf(urdf_to_test); + ASSERT_THAT(control_hardware, SizeIs(1)); + auto hardware_info = control_hardware.front(); + + EXPECT_EQ(hardware_info.name, "2DOF_System_Robot_Position_Only"); + EXPECT_EQ(hardware_info.type, "system"); + EXPECT_EQ( + hardware_info.hardware_plugin_name, "ros2_control_demo_hardware/2DOF_System_Hardware_Position_Only"); + + ASSERT_THAT(hardware_info.joints, SizeIs(1)); + + EXPECT_EQ(hardware_info.joints[0].name, "joint1"); + EXPECT_EQ(hardware_info.joints[0].type, "joint"); + EXPECT_EQ(hardware_info.joints[0].command_interfaces[0].name, "position"); + + EXPECT_EQ(hardware_info.hardware_parameters.at("example_param_write_for_sec"), ""); + EXPECT_EQ(hardware_info.hardware_parameters.at("example_param_read_for_sec"), "2"); +} + TEST_F(TestComponentParser, negative_size_throws_error) { std::string urdf_to_test = std::string(ros2_control_test_assets::urdf_head) + diff --git a/ros2_control_test_assets/include/ros2_control_test_assets/components_urdfs.hpp b/ros2_control_test_assets/include/ros2_control_test_assets/components_urdfs.hpp index f3e2bda2c0..a42d39a241 100644 --- a/ros2_control_test_assets/include/ros2_control_test_assets/components_urdfs.hpp +++ b/ros2_control_test_assets/include/ros2_control_test_assets/components_urdfs.hpp @@ -398,6 +398,21 @@ const auto valid_urdf_ros2_control_system_robot_with_size_and_data_type = )"; +const auto valid_urdf_ros2_control_parameter_empty = + R"( + + + ros2_control_demo_hardware/2DOF_System_Hardware_Position_Only + + 2 + + + + + + +)"; + // Errors const auto invalid_urdf_ros2_control_invalid_child = R"( @@ -485,23 +500,6 @@ const auto invalid_urdf_ros2_control_component_interface_type_empty = )"; -const auto invalid_urdf_ros2_control_parameter_empty = - R"( - - - ros2_control_demo_hardware/2DOF_System_Hardware_Position_Only - - 2 - - - - -1 - 1 - - - -)"; - const auto invalid_urdf2_ros2_control_illegal_size = R"( From a53126452114997fd91a3fef86af41b3dc575f09 Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Mon, 15 May 2023 19:37:33 +0200 Subject: [PATCH 4/4] Code formatting --- hardware_interface/test/test_component_parser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hardware_interface/test/test_component_parser.cpp b/hardware_interface/test/test_component_parser.cpp index c5cc4596a1..b0c7c5a16d 100644 --- a/hardware_interface/test/test_component_parser.cpp +++ b/hardware_interface/test/test_component_parser.cpp @@ -628,7 +628,8 @@ TEST_F(TestComponentParser, successfully_parse_parameter_empty) EXPECT_EQ(hardware_info.name, "2DOF_System_Robot_Position_Only"); EXPECT_EQ(hardware_info.type, "system"); EXPECT_EQ( - hardware_info.hardware_plugin_name, "ros2_control_demo_hardware/2DOF_System_Hardware_Position_Only"); + hardware_info.hardware_plugin_name, + "ros2_control_demo_hardware/2DOF_System_Hardware_Position_Only"); ASSERT_THAT(hardware_info.joints, SizeIs(1));