diff --git a/hardware_interface/doc/mock_components_userdoc.rst b/hardware_interface/doc/mock_components_userdoc.rst index a285408b5f..0e74b9fb2d 100644 --- a/hardware_interface/doc/mock_components_userdoc.rst +++ b/hardware_interface/doc/mock_components_userdoc.rst @@ -25,7 +25,7 @@ Features: Parameters ,,,,,,,,,, -fake_sensor_commands (optional; boolean; default: false) +mock_sensor_commands (optional; boolean; default: false) Creates fake command interfaces for faking sensor measurements with an external command. Those interfaces are usually used by a :ref:`forward controller ` to provide access from ROS-world. diff --git a/hardware_interface/include/mock_components/generic_system.hpp b/hardware_interface/include/mock_components/generic_system.hpp index 968c781e44..ce9ff19d7e 100644 --- a/hardware_interface/include/mock_components/generic_system.hpp +++ b/hardware_interface/include/mock_components/generic_system.hpp @@ -108,7 +108,7 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste std::vector & target_interfaces, bool using_state_interfaces); bool use_fake_gpio_command_interfaces_; - bool use_fake_sensor_command_interfaces_; + bool use_mock_sensor_command_interfaces_; double position_state_following_offset_; std::string custom_interface_with_following_offset_; diff --git a/hardware_interface/src/mock_components/generic_system.cpp b/hardware_interface/src/mock_components/generic_system.cpp index 3b9746ad47..b6f298b5c3 100644 --- a/hardware_interface/src/mock_components/generic_system.cpp +++ b/hardware_interface/src/mock_components/generic_system.cpp @@ -57,16 +57,29 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i } }; - // check if to create fake command interface for sensor - auto it = info_.hardware_parameters.find("fake_sensor_commands"); + // check if to create mock command interface for sensor + auto it = info_.hardware_parameters.find("mock_sensor_commands"); if (it != info_.hardware_parameters.end()) { // TODO(anyone): change this to parse_bool() (see ros2_control#339) - use_fake_sensor_command_interfaces_ = it->second == "true" || it->second == "True"; + use_mock_sensor_command_interfaces_ = it->second == "true" || it->second == "True"; } else { - use_fake_sensor_command_interfaces_ = false; + // 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_ = it->second == "true" || it->second == "True"; + RCUTILS_LOG_WARN_NAMED( + "fake_generic_system", + "Parameter 'fake_sensor_commands' has been deprecated from usage. Use" + "'mock_sensor_commands' instead."); + } + else + { + use_mock_sensor_command_interfaces_ = false; + } } // check if to create fake command interface for gpio @@ -284,7 +297,7 @@ std::vector GenericSystem::export_command_ } // Fake sensor command interfaces - if (use_fake_sensor_command_interfaces_) + if (use_mock_sensor_command_interfaces_) { if (!populate_interfaces( info_.sensors, sensor_interfaces_, sensor_fake_commands_, command_interfaces, true)) @@ -375,7 +388,7 @@ return_type GenericSystem::read(const rclcpp::Time & /*time*/, const rclcpp::Dur } } - if (use_fake_sensor_command_interfaces_) + if (use_mock_sensor_command_interfaces_) { mirror_command_to_state(sensor_states_, sensor_fake_commands_); } diff --git a/hardware_interface/test/mock_components/test_generic_system.cpp b/hardware_interface/test/mock_components/test_generic_system.cpp index fe0a062fc1..3dd2693189 100644 --- a/hardware_interface/test/mock_components/test_generic_system.cpp +++ b/hardware_interface/test/mock_components/test_generic_system.cpp @@ -39,7 +39,7 @@ const auto PERIOD = rclcpp::Duration::from_seconds(0.01); class TestGenericSystem : public ::testing::Test { public: - void test_generic_system_with_fake_sensor_commands(std::string & urdf); + void test_generic_system_with_mock_sensor_commands(std::string & urdf); void test_generic_system_with_mimic_joint(std::string & urdf); protected: @@ -190,7 +190,7 @@ class TestGenericSystem : public ::testing::Test mock_components/GenericSystem - true + true @@ -912,7 +912,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor) ASSERT_EQ(0.33, j2p_c.get_value()); } -void TestGenericSystem::test_generic_system_with_fake_sensor_commands(std::string & urdf) +void TestGenericSystem::test_generic_system_with_mock_sensor_commands(std::string & urdf) { TestableResourceManager rm(urdf); // Activate components to get all interfaces available @@ -1039,7 +1039,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor_fake_command) auto urdf = ros2_control_test_assets::urdf_head + hardware_system_2dof_with_sensor_fake_command_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_fake_sensor_commands(urdf); + test_generic_system_with_mock_sensor_commands(urdf); } TEST_F(TestGenericSystem, generic_system_2dof_sensor_fake_command_True) @@ -1048,7 +1048,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor_fake_command_True) hardware_system_2dof_with_sensor_fake_command_True_ + ros2_control_test_assets::urdf_tail; - test_generic_system_with_fake_sensor_commands(urdf); + test_generic_system_with_mock_sensor_commands(urdf); } void TestGenericSystem::test_generic_system_with_mimic_joint(std::string & urdf)