Skip to content

Commit

Permalink
[MockComponents] Rename 'fake_sensor_commands' to 'mock_sensor_comman…
Browse files Browse the repository at this point in the history
…ds' (ros-controls#782)

Co-authored-by: Bence Magyar <[email protected]>
Co-authored-by: Denis Štogl <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2022
1 parent 4584f96 commit 1cf9bf2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hardware_interface/doc/mock_components_userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <forward_command_controller_userdoc>` to provide access from ROS-world.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class HARDWARE_INTERFACE_PUBLIC GenericSystem : public hardware_interface::Syste
std::vector<InterfaceType> & 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_;
Expand Down
25 changes: 19 additions & 6 deletions hardware_interface/src/mock_components/generic_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -284,7 +297,7 @@ std::vector<hardware_interface::CommandInterface> 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))
Expand Down Expand Up @@ -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_);
}
Expand Down
10 changes: 5 additions & 5 deletions hardware_interface/test/mock_components/test_generic_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -190,7 +190,7 @@ class TestGenericSystem : public ::testing::Test
<ros2_control name="GenericSystem2dof" type="system">
<hardware>
<plugin>mock_components/GenericSystem</plugin>
<param name="fake_sensor_commands">true</param>
<param name="mock_sensor_commands">true</param>
</hardware>
<joint name="joint1">
<command_interface name="position"/>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 1cf9bf2

Please sign in to comment.