Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fake_sensor_commands renamed (backport #782) #835

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 21 additions & 8 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(
"mock_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 @@ -163,14 +176,14 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
index_custom_interface_with_following_offset_ =
std::distance(other_interfaces_.begin(), if_it);
RCUTILS_LOG_INFO_NAMED(
"fake_generic_system", "Custom interface with following offset '%s' found at index: %zu.",
"mock_generic_system", "Custom interface with following offset '%s' found at index: %zu.",
custom_interface_with_following_offset_.c_str(),
index_custom_interface_with_following_offset_);
}
else
{
RCUTILS_LOG_WARN_NAMED(
"fake_generic_system",
"mock_generic_system",
"Custom interface with following offset '%s' does not exist. Offset will not be applied",
custom_interface_with_following_offset_.c_str());
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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 @@ -876,7 +876,7 @@ TEST_F(TestGenericSystem, generic_system_2dof_sensor)
ASSERT_EQ(0.33, j2p_c.get_value());
}

void test_generic_system_with_fake_sensor_commands(std::string urdf)
void test_generic_system_with_mock_sensor_commands(std::string urdf)
{
hardware_interface::ResourceManager rm(urdf);
// Activate components to get all interfaces available
Expand Down Expand Up @@ -1003,7 +1003,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 @@ -1012,7 +1012,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)
Expand Down