Skip to content

Commit

Permalink
Issue 339: Implement parse_bool and refactor a few (backport ros-cont…
Browse files Browse the repository at this point in the history
…rols#1014) (ros-controls#1018)

* Implement parse_bool and refactor a few (ros-controls#1014)

(cherry picked from commit c9709f3)

# Conflicts:
#	hardware_interface/src/component_parser.cpp
#	hardware_interface/src/mock_components/generic_system.cpp

* Alex fixed conflicts

Co-authored-by: Alejandro Bordallo <[email protected]>

---------

Co-authored-by: Alejandro Bordallo <[email protected]>
Co-authored-by: Bence Magyar <[email protected]>
  • Loading branch information
3 people authored and flochre committed Jul 5, 2023
1 parent 3a791fe commit 0d68175
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ namespace hardware_interface
HARDWARE_INTERFACE_PUBLIC
std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string & urdf);

HARDWARE_INTERFACE_PUBLIC
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 @@ -590,4 +590,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
7 changes: 3 additions & 4 deletions hardware_interface/src/mock_components/generic_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <vector>

#include "hardware_interface/component_parser.hpp"
#include "hardware_interface/types/hardware_interface_type_values.hpp"
#include "rcutils/logging_macros.h"

Expand Down Expand Up @@ -61,8 +62,7 @@ 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_fake_sensor_command_interfaces_ = hardware_interface::parse_bool(it->second);
}
else
{
Expand All @@ -86,8 +86,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_ = hardware_interface::parse_bool(it->second);
}
else
{
Expand Down

0 comments on commit 0d68175

Please sign in to comment.