Skip to content

Commit 05c6c6b

Browse files
mergify[bot]GreatAlexanderbmagyar
authored
Issue 339: Implement parse_bool and refactor a few (backport #1014) (#1018)
* Implement parse_bool and refactor a few (#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]>
1 parent 37c1caa commit 05c6c6b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

hardware_interface/include/hardware_interface/component_parser.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ namespace hardware_interface
3333
HARDWARE_INTERFACE_PUBLIC
3434
std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string & urdf);
3535

36+
HARDWARE_INTERFACE_PUBLIC
37+
bool parse_bool(const std::string & bool_string);
38+
3639
} // namespace hardware_interface
3740
#endif // HARDWARE_INTERFACE__COMPONENT_PARSER_HPP_

hardware_interface/src/component_parser.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,9 @@ std::vector<HardwareInfo> parse_control_resources_from_urdf(const std::string &
590590
return hardware_info;
591591
}
592592

593+
bool parse_bool(const std::string & bool_string)
594+
{
595+
return bool_string == "true" || bool_string == "True";
596+
}
597+
593598
} // namespace hardware_interface

hardware_interface/src/mock_components/generic_system.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string>
2525
#include <vector>
2626

27+
#include "hardware_interface/component_parser.hpp"
2728
#include "hardware_interface/types/hardware_interface_type_values.hpp"
2829
#include "rcutils/logging_macros.h"
2930

@@ -61,8 +62,7 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
6162
auto it = info_.hardware_parameters.find("fake_sensor_commands");
6263
if (it != info_.hardware_parameters.end())
6364
{
64-
// TODO(anyone): change this to parse_bool() (see ros2_control#339)
65-
use_fake_sensor_command_interfaces_ = it->second == "true" || it->second == "True";
65+
use_fake_sensor_command_interfaces_ = hardware_interface::parse_bool(it->second);
6666
}
6767
else
6868
{
@@ -73,8 +73,7 @@ CallbackReturn GenericSystem::on_init(const hardware_interface::HardwareInfo & i
7373
it = info_.hardware_parameters.find("fake_gpio_commands");
7474
if (it != info_.hardware_parameters.end())
7575
{
76-
// TODO(anyone): change this to parse_bool() (see ros2_control#339)
77-
use_fake_gpio_command_interfaces_ = it->second == "true" || it->second == "True";
76+
use_fake_gpio_command_interfaces_ = hardware_interface::parse_bool(it->second);
7877
}
7978
else
8079
{

0 commit comments

Comments
 (0)