From 0d681759b6b1fb052dc537926cbb9ade75f5707c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 11:59:10 +0100 Subject: [PATCH] Issue 339: Implement parse_bool and refactor a few (backport #1014) (#1018) * Implement parse_bool and refactor a few (#1014) (cherry picked from commit c9709f3ce2ebf31ab5ea2c25829c422f7465f0d7) # Conflicts: # hardware_interface/src/component_parser.cpp # hardware_interface/src/mock_components/generic_system.cpp * Alex fixed conflicts Co-authored-by: Alejandro Bordallo --------- Co-authored-by: Alejandro Bordallo Co-authored-by: Bence Magyar --- .../include/hardware_interface/component_parser.hpp | 3 +++ hardware_interface/src/component_parser.cpp | 5 +++++ hardware_interface/src/mock_components/generic_system.cpp | 7 +++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hardware_interface/include/hardware_interface/component_parser.hpp b/hardware_interface/include/hardware_interface/component_parser.hpp index 1d0f07d94b..9f81a2a863 100644 --- a/hardware_interface/include/hardware_interface/component_parser.hpp +++ b/hardware_interface/include/hardware_interface/component_parser.hpp @@ -33,5 +33,8 @@ namespace hardware_interface HARDWARE_INTERFACE_PUBLIC std::vector 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_ diff --git a/hardware_interface/src/component_parser.cpp b/hardware_interface/src/component_parser.cpp index b8d20e763d..0e3ed226e5 100644 --- a/hardware_interface/src/component_parser.cpp +++ b/hardware_interface/src/component_parser.cpp @@ -590,4 +590,9 @@ std::vector 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 diff --git a/hardware_interface/src/mock_components/generic_system.cpp b/hardware_interface/src/mock_components/generic_system.cpp index 4d5cf82fd2..17a9522b47 100644 --- a/hardware_interface/src/mock_components/generic_system.cpp +++ b/hardware_interface/src/mock_components/generic_system.cpp @@ -24,6 +24,7 @@ #include #include +#include "hardware_interface/component_parser.hpp" #include "hardware_interface/types/hardware_interface_type_values.hpp" #include "rcutils/logging_macros.h" @@ -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 { @@ -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 {