From 8f5d6cae8ef384ece24856797530eaa6a49ff665 Mon Sep 17 00:00:00 2001 From: Dominic Reber Date: Tue, 28 May 2024 06:15:00 +0000 Subject: [PATCH 1/4] feat: remove utilities header from modulo controllers --- .../ControllerInterface.hpp | 8 +++-- .../modulo_controllers/utils/utilities.hpp | 33 ------------------- .../src/ControllerInterface.cpp | 18 +++++----- 3 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 source/modulo_controllers/include/modulo_controllers/utils/utilities.hpp diff --git a/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp b/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp index 79c3bd43..c0e8fe6d 100644 --- a/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp +++ b/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp @@ -19,6 +19,8 @@ #include #include +#include +#include namespace modulo_controllers { @@ -487,14 +489,14 @@ class ControllerInterface : public controller_interface::ControllerInterface { * @param name The name of the predicate * @param predicate The predicate variant */ - void add_variant_predicate(const std::string& name, const utilities::PredicateVariant& predicate); + void add_variant_predicate(const std::string& name, const modulo_utils::PredicateVariant& predicate); /** * @brief Set the predicate given as parameter, if the predicate is not found does not do anything. * @param name The name of the predicate * @param predicate The predicate variant */ - void set_variant_predicate(const std::string& name, const utilities::PredicateVariant& predicate); + void set_variant_predicate(const std::string& name, const modulo_utils::PredicateVariant& predicate); /** * @brief Populate a Prediate message with the name and the value of a predicate. @@ -604,7 +606,7 @@ class ControllerInterface : public controller_interface::ControllerInterface { std::map>> string_services_;///< Map of StringTrigger services - std::map predicates_; ///< Map of predicates + std::map predicates_; ///< Map of predicates std::shared_ptr> predicate_publisher_; ///< Predicate publisher std::map triggers_; ///< Map of triggers diff --git a/source/modulo_controllers/include/modulo_controllers/utils/utilities.hpp b/source/modulo_controllers/include/modulo_controllers/utils/utilities.hpp deleted file mode 100644 index e225d95c..00000000 --- a/source/modulo_controllers/include/modulo_controllers/utils/utilities.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include - -/** - * @namespace modulo_controllers::utilities - * @brief Modulo controllers utilities - */ -namespace modulo_controllers::utilities { - -typedef std::variant> PredicateVariant; - -/** - * @brief Parse a string topic name from a user-provided input. - * @details This functions removes all characters different from - * a-z, A-Z, 0-9, and _ from a string. - * @param topic_name The input string - * @return The sanitized string - */ -[[maybe_unused]] static std::string parse_topic_name(const std::string& topic_name) { - std::string output; - for (char c : topic_name) { - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { - output.insert(output.end(), std::tolower(c)); - } else if (!output.empty() && ((c >= '0' && c <= '9') || c == '_')) { - output.insert(output.end(), std::tolower(c)); - } - } - return output; -} -}// namespace modulo_controllers::utilities diff --git a/source/modulo_controllers/src/ControllerInterface.cpp b/source/modulo_controllers/src/ControllerInterface.cpp index 6a73816f..d0b640cc 100644 --- a/source/modulo_controllers/src/ControllerInterface.cpp +++ b/source/modulo_controllers/src/ControllerInterface.cpp @@ -386,14 +386,15 @@ bool ControllerInterface::on_validate_parameter_callback(const std::shared_ptr

& predicate) { - add_variant_predicate(name, utilities::PredicateVariant(predicate)); + add_variant_predicate(name, modulo_utils::PredicateVariant(predicate)); } -void ControllerInterface::add_variant_predicate(const std::string& name, const utilities::PredicateVariant& predicate) { +void ControllerInterface::add_variant_predicate( + const std::string& name, const modulo_utils::PredicateVariant& predicate) { if (name.empty()) { RCLCPP_ERROR(get_node()->get_logger(), "Failed to add predicate: Provide a non empty string as a name."); return; @@ -434,14 +435,15 @@ bool ControllerInterface::get_predicate(const std::string& predicate_name) const } void ControllerInterface::set_predicate(const std::string& name, bool predicate) { - set_variant_predicate(name, utilities::PredicateVariant(predicate)); + set_variant_predicate(name, modulo_utils::PredicateVariant(predicate)); } void ControllerInterface::set_predicate(const std::string& name, const std::function& predicate) { - set_variant_predicate(name, utilities::PredicateVariant(predicate)); + set_variant_predicate(name, modulo_utils::PredicateVariant(predicate)); } -void ControllerInterface::set_variant_predicate(const std::string& name, const utilities::PredicateVariant& predicate) { +void ControllerInterface::set_variant_predicate( + const std::string& name, const modulo_utils::PredicateVariant& predicate) { auto predicate_iterator = predicates_.find(name); if (predicate_iterator == predicates_.end()) { RCLCPP_ERROR_THROTTLE( @@ -505,7 +507,7 @@ void ControllerInterface::publish_predicates() const { std::string ControllerInterface::validate_and_declare_signal( const std::string& signal_name, const std::string& type, const std::string& default_topic, bool fixed_topic) { - auto parsed_signal_name = utilities::parse_topic_name(signal_name); + auto parsed_signal_name = modulo_utils::parse_topic_name(signal_name); if (parsed_signal_name.empty()) { RCLCPP_WARN( get_node()->get_logger(), @@ -646,7 +648,7 @@ bool ControllerInterface::check_input_valid(const std::string& name) const { } std::string ControllerInterface::validate_service_name(const std::string& service_name, const std::string& type) const { - std::string parsed_service_name = utilities::parse_topic_name(service_name); + std::string parsed_service_name = modulo_utils::parse_topic_name(service_name); if (parsed_service_name.empty()) { RCLCPP_WARN( get_node()->get_logger(), From 8b1bbd708913b9d92a52815c9ce91dde7050b955 Mon Sep 17 00:00:00 2001 From: Dominic Reber Date: Tue, 28 May 2024 06:24:47 +0000 Subject: [PATCH 2/4] feat: throw exception on get parameter --- .../modulo_controllers/ControllerInterface.hpp | 11 +++++++---- source/modulo_controllers/package.xml | 1 + source/modulo_controllers/src/ControllerInterface.cpp | 9 ++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp b/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp index c0e8fe6d..df67cf1b 100644 --- a/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp +++ b/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp @@ -14,11 +14,9 @@ #include #include #include - -#include "modulo_controllers/utils/utilities.hpp" - #include #include +#include #include #include @@ -640,7 +638,12 @@ inline void ControllerInterface::add_parameter( template inline T ControllerInterface::get_parameter_value(const std::string& name) const { - return parameter_map_.template get_parameter_value(name); + try { + return this->parameter_map_.template get_parameter_value(name); + } catch (const state_representation::exceptions::InvalidParameterException& ex) { + throw modulo_utils::exceptions::ParameterException( + "Failed to get parameter value of parameter '" + name + "': " + ex.what()); + } } template diff --git a/source/modulo_controllers/package.xml b/source/modulo_controllers/package.xml index 0e8cd25d..0b1c4a33 100644 --- a/source/modulo_controllers/package.xml +++ b/source/modulo_controllers/package.xml @@ -20,6 +20,7 @@ modulo_core modulo_interfaces + modulo_utils ament_cmake_gmock ament_lint_auto diff --git a/source/modulo_controllers/src/ControllerInterface.cpp b/source/modulo_controllers/src/ControllerInterface.cpp index d0b640cc..3235cb49 100644 --- a/source/modulo_controllers/src/ControllerInterface.cpp +++ b/source/modulo_controllers/src/ControllerInterface.cpp @@ -4,8 +4,6 @@ #include -#include "modulo_controllers/utils/utilities.hpp" - template struct overloaded : Ts... { using Ts::operator()...; @@ -13,6 +11,7 @@ struct overloaded : Ts... { template overloaded(Ts...) -> overloaded; +using namespace modulo_utils::exceptions; using namespace state_representation; using namespace std::chrono_literals; @@ -335,7 +334,11 @@ void ControllerInterface::add_parameter( } std::shared_ptr ControllerInterface::get_parameter(const std::string& name) const { - return parameter_map_.get_parameter(name); + try { + return this->parameter_map_.get_parameter(name); + } catch (const state_representation::exceptions::InvalidParameterException& ex) { + throw ParameterException("Failed to get parameter '" + name + "': " + ex.what()); + } } rcl_interfaces::msg::SetParametersResult From b344683c681113fb10ffa6b1eafd83ae35c379ea Mon Sep 17 00:00:00 2001 From: Dominic Reber Date: Tue, 28 May 2024 06:24:56 +0000 Subject: [PATCH 3/4] feat: use cl 8.1.0 --- aica-package.toml | 2 +- source/modulo_controllers/CMakeLists.txt | 2 +- source/modulo_core/CMakeLists.txt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aica-package.toml b/aica-package.toml index 5b8fe3b6..45e7b202 100644 --- a/aica-package.toml +++ b/aica-package.toml @@ -12,7 +12,7 @@ type = "ros" image = "v1.0.1-iron" [build.dependencies] -"@aica/foss/control-libraries" = "v7.4.1" +"@aica/foss/control-libraries" = "v8.1.0" [build.packages.modulo_components] source = "./source/modulo_components" diff --git a/source/modulo_controllers/CMakeLists.txt b/source/modulo_controllers/CMakeLists.txt index 9244bd8d..d409fba9 100644 --- a/source/modulo_controllers/CMakeLists.txt +++ b/source/modulo_controllers/CMakeLists.txt @@ -21,7 +21,7 @@ if (ENABLE_SIGNING) endif() find_package(ament_cmake_auto REQUIRED) -find_package(control_libraries 7.4.0 CONFIG REQUIRED COMPONENTS state_representation robot_model controllers) +find_package(control_libraries 8.1.0 CONFIG REQUIRED COMPONENTS state_representation robot_model controllers) ament_auto_find_build_dependencies() diff --git a/source/modulo_core/CMakeLists.txt b/source/modulo_core/CMakeLists.txt index b1499ca0..4cd4bfb4 100644 --- a/source/modulo_core/CMakeLists.txt +++ b/source/modulo_core/CMakeLists.txt @@ -26,8 +26,8 @@ find_package(rclcpp REQUIRED) find_package(rclcpp_lifecycle REQUIRED) find_package(tf2_msgs REQUIRED) -find_package(control_libraries 7.4.1 REQUIRED COMPONENTS state_representation) -find_package(clproto 7.4.1 REQUIRED) +find_package(control_libraries 8.1.0 REQUIRED COMPONENTS state_representation) +find_package(clproto 8.1.0 REQUIRED) add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCE_DIR}/src/communication/MessagePair.cpp From 78d06da94f8e486470d0b0e5cdb8d5f43c8c8c90 Mon Sep 17 00:00:00 2001 From: Dominic Reber Date: Wed, 29 May 2024 08:18:34 +0200 Subject: [PATCH 4/4] docs: changelog --- CHANGELOG.md | 1 + .../include/modulo_controllers/ControllerInterface.hpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ff8b6dd..f2e733a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Release Versions: - refactor: remove modulo_component_interfaces (#88) - feat: add add_interfaces function for derived controllers (#102) - refactor: remove period parameter and make rate double (#108) +- feat(modulo-controllers): use exceptions from modulo utils and update to CL v8.1.0 (#106) ## 4.2.1 diff --git a/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp b/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp index df67cf1b..a03a29fc 100644 --- a/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp +++ b/source/modulo_controllers/include/modulo_controllers/ControllerInterface.hpp @@ -295,6 +295,7 @@ class ControllerInterface : public controller_interface::ControllerInterface { /** * @brief Get a parameter by name. * @param name The name of the parameter + * @throws modulo_utils::exceptions::ParameterException if the parameter could not be accessed * @return The ParameterInterface pointer to a Parameter instance */ [[nodiscard]] std::shared_ptr get_parameter(const std::string& name) const; @@ -303,6 +304,7 @@ class ControllerInterface : public controller_interface::ControllerInterface { * @brief Get a parameter value by name. * @tparam T The type of the parameter * @param name The name of the parameter + * @throws modulo_utils::exceptions::ParameterException if the parameter value could not be accessed * @return The value of the parameter */ template