diff --git a/hardware_interface/CMakeLists.txt b/hardware_interface/CMakeLists.txt index e486302c4c..2108bab17c 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -54,23 +54,6 @@ target_compile_definitions(mock_components PRIVATE "HARDWARE_INTERFACE_BUILDING_ pluginlib_export_plugin_description_file( hardware_interface mock_components_plugin_description.xml) -add_library(fake_components SHARED - src/mock_components/generic_system.cpp - src/mock_components/fake_generic_system.cpp -) -target_compile_features(fake_components PUBLIC cxx_std_17) -target_include_directories(fake_components PUBLIC - $ - $ -) -ament_target_dependencies(fake_components PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS}) -# Causes the visibility macros to use dllexport rather than dllimport, -# which is appropriate when building the dll but not consuming it. -target_compile_definitions(fake_components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL") - -pluginlib_export_plugin_description_file( - hardware_interface fake_components_plugin_description.xml) - if(BUILD_TESTING) find_package(ament_cmake_gmock REQUIRED) @@ -145,7 +128,6 @@ install( ) install( TARGETS - fake_components mock_components hardware_interface EXPORT export_hardware_interface diff --git a/hardware_interface/fake_components_plugin_description.xml b/hardware_interface/fake_components_plugin_description.xml deleted file mode 100644 index 604170849a..0000000000 --- a/hardware_interface/fake_components_plugin_description.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - Generic components for simple faking of system hardware. - - - - diff --git a/hardware_interface/include/fake_components/generic_system.hpp b/hardware_interface/include/fake_components/generic_system.hpp deleted file mode 100644 index 3dfb2b9b70..0000000000 --- a/hardware_interface/include/fake_components/generic_system.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2021 PickNik, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Author: Jafar Abdi, Denis Stogl - -#ifndef FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_ -#define FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_ - -#include "mock_components/generic_system.hpp" - -namespace fake_components -{ -using GenericSystem [[deprecated]] = mock_components::GenericSystem; - -using GenericSystem [[deprecated]] = mock_components::GenericRobot; -} // namespace fake_components - -#endif // FAKE_COMPONENTS__GENERIC_SYSTEM_HPP_ diff --git a/hardware_interface/include/fake_components/visibility_control.h b/hardware_interface/include/fake_components/visibility_control.h deleted file mode 100644 index 1e60a9d990..0000000000 --- a/hardware_interface/include/fake_components/visibility_control.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2021 PickNik, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef FAKE_COMPONENTS__VISIBILITY_CONTROL_H_ -#define FAKE_COMPONENTS__VISIBILITY_CONTROL_H_ - -// This logic was borrowed (then namespaced) from the examples on the gcc wiki: -// https://gcc.gnu.org/wiki/Visibility - -#if defined _WIN32 || defined __CYGWIN__ -#ifdef __GNUC__ -#define FAKE_COMPONENTS_EXPORT __attribute__((dllexport)) -#define FAKE_COMPONENTS_IMPORT __attribute__((dllimport)) -#else -#define FAKE_COMPONENTS_EXPORT __declspec(dllexport) -#define FAKE_COMPONENTS_IMPORT __declspec(dllimport) -#endif -#ifdef FAKE_COMPONENTS_BUILDING_DLL -#define FAKE_COMPONENTS_PUBLIC FAKE_COMPONENTS_EXPORT -#else -#define FAKE_COMPONENTS_PUBLIC FAKE_COMPONENTS_IMPORT -#endif -#define FAKE_COMPONENTS_PUBLIC_TYPE FAKE_COMPONENTS_PUBLIC -#define FAKE_COMPONENTS_LOCAL -#else -#define FAKE_COMPONENTS_EXPORT __attribute__((visibility("default"))) -#define FAKE_COMPONENTS_IMPORT -#if __GNUC__ >= 4 -#define FAKE_COMPONENTS_PUBLIC __attribute__((visibility("default"))) -#define FAKE_COMPONENTS_LOCAL __attribute__((visibility("hidden"))) -#else -#define FAKE_COMPONENTS_PUBLIC -#define FAKE_COMPONENTS_LOCAL -#endif -#define FAKE_COMPONENTS_PUBLIC_TYPE -#endif - -#endif // FAKE_COMPONENTS__VISIBILITY_CONTROL_H_ diff --git a/hardware_interface/src/mock_components/fake_generic_system.cpp b/hardware_interface/src/mock_components/fake_generic_system.cpp deleted file mode 100644 index 736575c8a6..0000000000 --- a/hardware_interface/src/mock_components/fake_generic_system.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2022 PickNik, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Author: Jafar Abdi, Denis Stogl - -#include "fake_components/generic_system.hpp" -#include "pluginlib/class_list_macros.hpp" -PLUGINLIB_EXPORT_CLASS(fake_components::GenericSystem, hardware_interface::SystemInterface) diff --git a/hardware_interface/src/mock_components/generic_system.cpp b/hardware_interface/src/mock_components/generic_system.cpp index 1b339c71ce..7b62af105b 100644 --- a/hardware_interface/src/mock_components/generic_system.cpp +++ b/hardware_interface/src/mock_components/generic_system.cpp @@ -79,20 +79,7 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i } else { - // check if fake_sensor_commands was set instead and issue warning. - it = info_.hardware_parameters.find("fake_sensor_commands"); - if (it != info_.hardware_parameters.end()) - { - use_mock_sensor_command_interfaces_ = hardware_interface::parse_bool(it->second); - RCUTILS_LOG_WARN_NAMED( - "mock_generic_system", - "Parameter 'fake_sensor_commands' has been deprecated from usage. Use" - "'mock_sensor_commands' instead."); - } - else - { - use_mock_sensor_command_interfaces_ = false; - } + use_mock_sensor_command_interfaces_ = false; } // check if to create mock command interface for gpio @@ -103,20 +90,7 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i } else { - // check if fake_gpio_commands was set instead and issue warning - it = info_.hardware_parameters.find("fake_gpio_commands"); - if (it != info_.hardware_parameters.end()) - { - use_mock_gpio_command_interfaces_ = hardware_interface::parse_bool(it->second); - RCUTILS_LOG_WARN_NAMED( - "mock_generic_system", - "Parameter 'fake_gpio_commands' has been deprecated from usage. Use" - "'mock_gpio_commands' instead."); - } - else - { - use_mock_gpio_command_interfaces_ = false; - } + use_mock_gpio_command_interfaces_ = false; } // check if there is parameter that disables commands @@ -707,7 +681,6 @@ void GenericSystem::initialize_storage_vectors( } // Initialize with values from URDF - bool print_hint = false; for (auto i = 0u; i < component_infos.size(); i++) { const auto & component = component_infos[i]; @@ -725,33 +698,9 @@ void GenericSystem::initialize_storage_vectors( { states[index][i] = parse_double(interface.initial_value); } - else - { - // Initialize the value in old way with warning message - auto it2 = component.parameters.find("initial_" + interface.name); - if (it2 != component.parameters.end()) - { - states[index][i] = parse_double(it2->second); - print_hint = true; - } - else - { - print_hint = true; - } - } } } } - if (print_hint) - { - RCUTILS_LOG_WARN_ONCE_NAMED( - "mock_generic_system", - "Parsing of optional initial interface values failed or uses a deprecated format. Add " - "initial values for every state interface in the ros2_control.xacro. For example: \n" - " \n" - " 0.0 \n" - ""); - } } template diff --git a/hardware_interface/test/mock_components/test_generic_system.cpp b/hardware_interface/test/mock_components/test_generic_system.cpp index 9556ed6f8b..57b5796d0d 100644 --- a/hardware_interface/test/mock_components/test_generic_system.cpp +++ b/hardware_interface/test/mock_components/test_generic_system.cpp @@ -40,128 +40,120 @@ const auto COMPARE_DELTA = 0.0001; class TestGenericSystem : public ::testing::Test { public: - void test_generic_system_with_mimic_joint(std::string & urdf); - void test_generic_system_with_mock_sensor_commands(std::string & urdf); - void test_generic_system_with_mock_gpio_commands(std::string & urdf); + void test_generic_system_with_mimic_joint(std::string & urdf, const std::string & component_name); + void test_generic_system_with_mock_sensor_commands( + std::string & urdf, const std::string & component_name); + void test_generic_system_with_mock_gpio_commands( + std::string & urdf, const std::string & component_name); protected: void SetUp() override { - // REMOVE THIS MEMBER ONCE FAKE COMPONENTS ARE REMOVED - hardware_fake_system_2dof_ = - R"( - - - fake_components/GenericSystem - - - - - 1.57 - - - - - 0.7854 - - -)"; - hardware_system_2dof_ = R"( - + mock_components/GenericSystem - - 1.57 + + 1.57 + - - 0.7854 + + 0.7854 + )"; hardware_system_2dof_asymetric_ = R"( - + mock_components/GenericSystem - - 1.57 + + 1.57 + - - 0.7854 - 0.8554 + + 0.7854 + )"; hardware_system_2dof_standard_interfaces_ = R"( - + mock_components/GenericSystem - + + 3.45 + - 3.45 - + + 2.78 + - 2.78 )"; hardware_system_2dof_with_other_interface_ = R"( - + mock_components/GenericSystem - - - 1.55 - 0.1 + + 1.55 + + + 0.1 + - - - 0.65 - 0.2 + + 0.65 + + + 0.2 + - - 0.5 + + 0.5 + )"; hardware_system_2dof_with_sensor_ = R"( - + mock_components/GenericSystem @@ -189,7 +181,7 @@ class TestGenericSystem : public ::testing::Test hardware_system_2dof_with_sensor_mock_command_ = R"( - + mock_components/GenericSystem true @@ -218,10 +210,10 @@ class TestGenericSystem : public ::testing::Test hardware_system_2dof_with_sensor_mock_command_True_ = R"( - + mock_components/GenericSystem - True + True @@ -247,16 +239,17 @@ class TestGenericSystem : public ::testing::Test hardware_system_2dof_with_mimic_joint_ = R"( - + mock_components/GenericSystem - + + 1.57 + - 1.57 joint1 @@ -271,7 +264,7 @@ class TestGenericSystem : public ::testing::Test hardware_system_2dof_standard_interfaces_with_offset_ = R"( - + mock_components/GenericSystem -3 @@ -297,7 +290,7 @@ class TestGenericSystem : public ::testing::Test hardware_system_2dof_standard_interfaces_with_custom_interface_for_offset_missing_ = R"( - + mock_components/GenericSystem -3 @@ -306,23 +299,29 @@ class TestGenericSystem : public ::testing::Test - - - 3.45 + + 3.45 + + + 0.0 + - - - 2.78 + + 2.78 + + + 0.0 + )"; hardware_system_2dof_standard_interfaces_with_custom_interface_for_offset_ = R"( - + mock_components/GenericSystem -3 @@ -331,25 +330,29 @@ class TestGenericSystem : public ::testing::Test - + + 3.45 + - 3.45 - - + + 2.78 + + + 0.0 + - 2.78 )"; valid_urdf_ros2_control_system_robot_with_gpio_ = R"( - + mock_components/GenericSystem 2 @@ -366,9 +369,10 @@ class TestGenericSystem : public ::testing::Test - + + 2.78 + - 2.78 @@ -385,7 +389,7 @@ class TestGenericSystem : public ::testing::Test valid_urdf_ros2_control_system_robot_with_gpio_mock_command_ = R"( - + mock_components/GenericSystem true @@ -393,16 +397,18 @@ class TestGenericSystem : public ::testing::Test - + + 3.45 + - 3.45 - + + 2.78 + - 2.78 @@ -419,24 +425,26 @@ class TestGenericSystem : public ::testing::Test valid_urdf_ros2_control_system_robot_with_gpio_mock_command_True_ = R"( - + mock_components/GenericSystem - True + True - + + 3.45 + - 3.45 - + + 2.78 + - 2.78 @@ -453,9 +461,9 @@ class TestGenericSystem : public ::testing::Test sensor_with_initial_value_ = R"( - + - fake_components/GenericSystem + mock_components/GenericSystem @@ -473,9 +481,9 @@ class TestGenericSystem : public ::testing::Test gpio_with_initial_value_ = R"( - + - fake_components/GenericSystem + mock_components/GenericSystem @@ -487,7 +495,7 @@ class TestGenericSystem : public ::testing::Test hardware_system_2dof_standard_interfaces_with_different_control_modes_ = R"( - + mock_components/GenericSystem true @@ -560,9 +568,9 @@ class TestGenericSystem : public ::testing::Test disabled_commands_ = R"( - + - fake_components/GenericSystem + mock_components/GenericSystem True @@ -577,9 +585,7 @@ class TestGenericSystem : public ::testing::Test )"; } - std::string hardware_robot_2dof_; std::string hardware_system_2dof_; - std::string hardware_fake_system_2dof_; std::string hardware_system_2dof_asymetric_; std::string hardware_system_2dof_standard_interfaces_; std::string hardware_system_2dof_with_other_interface_; @@ -611,7 +617,6 @@ class TestableResourceManager : public hardware_interface::ResourceManager public: friend TestGenericSystem; - FRIEND_TEST(TestGenericSystem, generic_fake_system_2dof_symetric_interfaces); FRIEND_TEST(TestGenericSystem, generic_system_2dof_symetric_interfaces); FRIEND_TEST(TestGenericSystem, generic_system_2dof_asymetric_interfaces); FRIEND_TEST(TestGenericSystem, generic_system_2dof_other_interfaces); @@ -677,37 +682,6 @@ TEST_F(TestGenericSystem, load_generic_system_2dof) ASSERT_NO_THROW(TestableResourceManager rm(urdf)); } -// REMOVE THIS TEST ONCE FAKE COMPONENTS ARE REMOVED -TEST_F(TestGenericSystem, generic_fake_system_2dof_symetric_interfaces) -{ - auto urdf = ros2_control_test_assets::urdf_head + hardware_fake_system_2dof_ + - ros2_control_test_assets::urdf_tail; - TestableResourceManager rm(urdf); - // Activate components to get all interfaces available - activate_components(rm); - - // Check interfaces - EXPECT_EQ(1u, rm.system_components_size()); - ASSERT_EQ(2u, rm.state_interface_keys().size()); - EXPECT_TRUE(rm.state_interface_exists("joint1/position")); - EXPECT_TRUE(rm.state_interface_exists("joint2/position")); - - ASSERT_EQ(2u, rm.command_interface_keys().size()); - EXPECT_TRUE(rm.command_interface_exists("joint1/position")); - EXPECT_TRUE(rm.command_interface_exists("joint2/position")); - - // Check initial values - hardware_interface::LoanedStateInterface j1p_s = rm.claim_state_interface("joint1/position"); - hardware_interface::LoanedStateInterface j2p_s = rm.claim_state_interface("joint2/position"); - hardware_interface::LoanedCommandInterface j1p_c = rm.claim_command_interface("joint1/position"); - hardware_interface::LoanedCommandInterface j2p_c = rm.claim_command_interface("joint2/position"); - - ASSERT_EQ(1.57, j1p_s.get_value()); - ASSERT_EQ(0.7854, j2p_s.get_value()); - ASSERT_TRUE(std::isnan(j1p_c.get_value())); - ASSERT_TRUE(std::isnan(j2p_c.get_value())); -} - // Test inspired by hardware_interface/test_resource_manager.cpp TEST_F(TestGenericSystem, generic_system_2dof_symetric_interfaces) { @@ -715,7 +689,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_symetric_interfaces) ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"HardwareSystem2dof"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -746,7 +720,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_asymetric_interfaces) ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"HardwareSystem2dofAsymetric"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -782,30 +756,30 @@ TEST_F(TestGenericSystem, generic_system_2dof_asymetric_interfaces) hardware_interface::LoanedCommandInterface j2a_c = rm.claim_command_interface("joint2/acceleration"); - ASSERT_EQ(0.0, j1v_s.get_value()); + ASSERT_EQ(1.57, j1v_s.get_value()); ASSERT_EQ(0.7854, j2p_s.get_value()); ASSERT_TRUE(std::isnan(j1p_c.get_value())); ASSERT_TRUE(std::isnan(j2a_c.get_value())); } -void generic_system_functional_test(const std::string & urdf, const double offset = 0) +void generic_system_functional_test( + const std::string & urdf, const std::string component_name = "GenericSystem2dof", + const double offset = 0) { TestableResourceManager rm(urdf); // check is hardware is configured auto status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::UNCONFIGURED); - configure_components(rm); + configure_components(rm, {component_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::INACTIVE); - activate_components(rm); + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::INACTIVE); + activate_components(rm, {component_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::ACTIVE); + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::ACTIVE); // Check initial values hardware_interface::LoanedStateInterface j1p_s = rm.claim_state_interface("joint1/position"); @@ -881,11 +855,10 @@ void generic_system_functional_test(const std::string & urdf, const double offse ASSERT_EQ(0.77, j2p_c.get_value()); ASSERT_EQ(0.88, j2v_c.get_value()); - deactivate_components(rm); + deactivate_components(rm, {component_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::INACTIVE); + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::INACTIVE); } TEST_F(TestGenericSystem, generic_system_2dof_functionality) @@ -893,7 +866,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_functionality) auto urdf = ros2_control_test_assets::urdf_head + hardware_system_2dof_standard_interfaces_ + ros2_control_test_assets::urdf_tail; - generic_system_functional_test(urdf); + generic_system_functional_test(urdf, {"HardwareSystem2dofStandardInterfaces"}); } TEST_F(TestGenericSystem, generic_system_2dof_other_interfaces) @@ -902,7 +875,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_other_interfaces) ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"HardwareSystem2dofWithOtherInterface"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -985,7 +958,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor) ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"HardwareSystem2dofWithSensor"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1079,11 +1052,12 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor) ASSERT_EQ(0.33, j2p_c.get_value()); } -void TestGenericSystem::test_generic_system_with_mock_sensor_commands(std::string & urdf) +void TestGenericSystem::test_generic_system_with_mock_sensor_commands( + std::string & urdf, const std::string & component_name) { TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {component_name}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1206,7 +1180,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor_mock_command) auto urdf = ros2_control_test_assets::urdf_head + hardware_system_2dof_with_sensor_mock_command_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_mock_sensor_commands(urdf); + test_generic_system_with_mock_sensor_commands(urdf, "HardwareSystem2dofWithSensorMockCommand"); } TEST_F(TestGenericSystem, generic_system_2dof_sensor_mock_command_True) @@ -1215,14 +1189,16 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor_mock_command_True) hardware_system_2dof_with_sensor_mock_command_True_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_mock_sensor_commands(urdf); + test_generic_system_with_mock_sensor_commands( + urdf, "HardwareSystem2dofWithSensorMockCommandTrue"); } -void TestGenericSystem::test_generic_system_with_mimic_joint(std::string & urdf) +void TestGenericSystem::test_generic_system_with_mimic_joint( + std::string & urdf, const std::string & component_name) { TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {component_name}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1289,7 +1265,7 @@ TEST_F(TestGenericSystem, hardware_system_2dof_with_mimic_joint) auto urdf = ros2_control_test_assets::urdf_head + hardware_system_2dof_with_mimic_joint_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_mimic_joint(urdf); + test_generic_system_with_mimic_joint(urdf, "HardwareSystem2dofWithMimicJoint"); } TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset) @@ -1298,7 +1274,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset) hardware_system_2dof_standard_interfaces_with_offset_ + ros2_control_test_assets::urdf_tail; - generic_system_functional_test(urdf, -3); + generic_system_functional_test(urdf, "HardwareSystem2dofStandardInterfacesWithOffset", -3); } TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset_custom_interface_missing) @@ -1308,7 +1284,8 @@ TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset_custom_i ros2_control_test_assets::urdf_tail; // custom interface is missing so offset will not be applied - generic_system_functional_test(urdf, 0.0); + generic_system_functional_test( + urdf, "HardwareSystem2dofStandardInterfacesWithCustomInterfaceForOffsetMissing", 0.0); } TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset_custom_interface) @@ -1321,22 +1298,23 @@ TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset_custom_i TestableResourceManager rm(urdf); + const std::string hardware_name = + "HardwareSystem2dofStandardInterfacesWithCustomInterfaceForOffset"; + // check is hardware is configured auto status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::UNCONFIGURED); - configure_components(rm); + configure_components(rm, {hardware_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::INACTIVE); - activate_components(rm); + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::INACTIVE); + activate_components(rm, {hardware_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::ACTIVE); + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::ACTIVE); // Check initial values hardware_interface::LoanedStateInterface j1p_s = rm.claim_state_interface("joint1/position"); @@ -1422,11 +1400,10 @@ TEST_F(TestGenericSystem, generic_system_2dof_functionality_with_offset_custom_i ASSERT_EQ(0.77, j2p_c.get_value()); ASSERT_EQ(0.88, j2v_c.get_value()); - deactivate_components(rm); + deactivate_components(rm, {hardware_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::INACTIVE); + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::INACTIVE); } TEST_F(TestGenericSystem, valid_urdf_ros2_control_system_robot_with_gpio) @@ -1435,21 +1412,21 @@ TEST_F(TestGenericSystem, valid_urdf_ros2_control_system_robot_with_gpio) valid_urdf_ros2_control_system_robot_with_gpio_ + ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); + const std::string hardware_name = "ValidURDFros2controlSystemRobotWithGPIO"; + // check is hardware is started auto status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::UNCONFIGURED); - configure_components(rm); + configure_components(rm, {hardware_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::INACTIVE); - activate_components(rm); + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::INACTIVE); + activate_components(rm, {hardware_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::ACTIVE); + status_map[hardware_name].state.label(), hardware_interface::lifecycle_state_names::ACTIVE); ASSERT_EQ(8u, rm.state_interface_keys().size()); ASSERT_EQ(6u, rm.command_interface_keys().size()); @@ -1524,28 +1501,27 @@ TEST_F(TestGenericSystem, valid_urdf_ros2_control_system_robot_with_gpio) ASSERT_EQ(0.444, gpio2_vac_c.get_value()); // check other functionalities are working well - generic_system_functional_test(urdf); + generic_system_functional_test(urdf, hardware_name); } -void TestGenericSystem::test_generic_system_with_mock_gpio_commands(std::string & urdf) +void TestGenericSystem::test_generic_system_with_mock_gpio_commands( + std::string & urdf, const std::string & component_name) { TestableResourceManager rm(urdf); // check is hardware is started auto status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::UNCONFIGURED); - configure_components(rm); + configure_components(rm, {component_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::INACTIVE); - activate_components(rm); + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::INACTIVE); + activate_components(rm, {component_name}); status_map = rm.get_components_status(); EXPECT_EQ( - status_map["GenericSystem2dof"].state.label(), - hardware_interface::lifecycle_state_names::ACTIVE); + status_map[component_name].state.label(), hardware_interface::lifecycle_state_names::ACTIVE); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1641,7 +1617,8 @@ TEST_F(TestGenericSystem, valid_urdf_ros2_control_system_robot_with_gpio_mock_co valid_urdf_ros2_control_system_robot_with_gpio_mock_command_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_mock_gpio_commands(urdf); + test_generic_system_with_mock_gpio_commands( + urdf, "ValidURDFros2controlSystemRobotWithGPIOMockCommand"); } TEST_F(TestGenericSystem, valid_urdf_ros2_control_system_robot_with_gpio_mock_command_True) @@ -1650,7 +1627,8 @@ TEST_F(TestGenericSystem, valid_urdf_ros2_control_system_robot_with_gpio_mock_co valid_urdf_ros2_control_system_robot_with_gpio_mock_command_True_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_mock_gpio_commands(urdf); + test_generic_system_with_mock_gpio_commands( + urdf, "ValidURDFros2controlSystemRobotWithGPIOMockCommandTrue"); } TEST_F(TestGenericSystem, sensor_with_initial_value) @@ -1659,7 +1637,7 @@ TEST_F(TestGenericSystem, sensor_with_initial_value) ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"SensorWithInitialValue"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1687,7 +1665,7 @@ TEST_F(TestGenericSystem, gpio_with_initial_value) ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"GPIOWithInitialValue"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1708,7 +1686,7 @@ TEST_F(TestGenericSystem, simple_dynamics_pos_vel_acc_control_modes_interfaces) TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"HardwareSystem2dofStandardInterfacesWithDifferentControlModes"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size()); @@ -1902,7 +1880,7 @@ TEST_F(TestGenericSystem, disabled_commands_flag_is_active) ros2_control_test_assets::urdf_head + disabled_commands_ + ros2_control_test_assets::urdf_tail; TestableResourceManager rm(urdf); // Activate components to get all interfaces available - activate_components(rm); + activate_components(rm, {"DisabledCommands"}); // Check interfaces EXPECT_EQ(1u, rm.system_components_size());