From 9589b4e3c32d4a653c63fda60c2ba818b9d3478b Mon Sep 17 00:00:00 2001 From: Kvk Praneeth <55596533+kvkpraneeth@users.noreply.github.com> Date: Tue, 11 Oct 2022 13:19:11 +0530 Subject: [PATCH] [MockComponents] Rename 'fake_sensor_commands' to 'mock_sensor_commands' (#782) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bence Magyar Co-authored-by: Denis Štogl (cherry picked from commit 1cf9bf27ddd299517ff2794ef4c8a7691facc416) # Conflicts: # hardware_interface/test/mock_components/test_generic_system.cpp --- .../doc/mock_components_userdoc.rst | 2 +- .../mock_components/generic_system.hpp | 2 +- .../src/mock_components/generic_system.cpp | 25 ++++++++++++++----- .../mock_components/test_generic_system.cpp | 17 ++++++++++--- 4 files changed, 35 insertions(+), 11 deletions(-) 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 52518a52e8..e0035b1780 100644 --- a/hardware_interface/test/mock_components/test_generic_system.cpp +++ b/hardware_interface/test/mock_components/test_generic_system.cpp @@ -38,6 +38,13 @@ const auto PERIOD = rclcpp::Duration::from_seconds(0.01); class TestGenericSystem : public ::testing::Test { +<<<<<<< HEAD +======= +public: + void test_generic_system_with_mock_sensor_commands(std::string & urdf); + void test_generic_system_with_mimic_joint(std::string & urdf); + +>>>>>>> 1cf9bf2 ([MockComponents] Rename 'fake_sensor_commands' to 'mock_sensor_commands' (#782)) protected: void SetUp() override { @@ -186,7 +193,7 @@ class TestGenericSystem : public ::testing::Test mock_components/GenericSystem - true + true @@ -876,7 +883,11 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor) ASSERT_EQ(0.33, j2p_c.get_value()); } +<<<<<<< HEAD void test_generic_system_with_fake_sensor_commands(std::string urdf) +======= +void TestGenericSystem::test_generic_system_with_mock_sensor_commands(std::string & urdf) +>>>>>>> 1cf9bf2 ([MockComponents] Rename 'fake_sensor_commands' to 'mock_sensor_commands' (#782)) { hardware_interface::ResourceManager rm(urdf); // Activate components to get all interfaces available @@ -1003,7 +1014,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) @@ -1012,7 +1023,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 test_generic_system_with_mimic_joint(std::string urdf)