Skip to content

Commit

Permalink
Issue_339: Implement parse_bool and refactor a few
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Bordallo committed May 9, 2023
1 parent cb92c50 commit dd7aeff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ namespace hardware_interface
HARDWARE_INTERFACE_PUBLIC
std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string & urdf);

bool parse_bool(const std::string & bool_string);

} // namespace hardware_interface
#endif // HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_
5 changes: 5 additions & 0 deletions hardware_interface/src/component_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,9 @@ std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string &
return hardware_info;
}

bool parse_bool(const std::string & bool_string)
{
return bool_string == "true" || bool_string == "True";
}

} // namespace hardware_interface
8 changes: 3 additions & 5 deletions hardware_interface/src/mock_components/generic_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
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_mock_sensor_command_interfaces_ = it->second == "true" || it->second == "True";
use_mock_sensor_command_interfaces_ = parse_bool(it->second);
}
else
{
// 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";
use_mock_sensor_command_interfaces_ = parse_bool(it->second);
RCUTILS_LOG_WARN_NAMED(
"fake_generic_system",
"Parameter 'fake_sensor_commands' has been deprecated from usage. Use"
Expand All @@ -99,8 +98,7 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
it = info_.hardware_parameters.find("fake_gpio_commands");
if (it != info_.hardware_parameters.end())
{
// TODO(anyone): change this to parse_bool() (see ros2_control#339)
use_fake_gpio_command_interfaces_ = it->second == "true" || it->second == "True";
use_fake_gpio_command_interfaces = parse_bool(it->second);
}
else
{
Expand Down

0 comments on commit dd7aeff

Please sign in to comment.