Skip to content

Commit

Permalink
fake_sensor_commands replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
kvkpraneeth committed Jul 18, 2022
1 parent b3e601a commit d4afc58
Show file tree
Hide file tree
Showing 4 changed files with 25 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
24 changes: 18 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,28 @@ 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 +296,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 +387,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 @@ -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 @@ -215,7 +215,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

0 comments on commit d4afc58

Please sign in to comment.