Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modulo-controllers): use exceptions from modulo utils and update to CL v8.1.0 #106

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion aica-package.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion source/modulo_controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include <modulo_core/translators/message_writers.hpp>
#include <modulo_core/translators/parameter_translators.hpp>
#include <modulo_interfaces/msg/predicate_collection.hpp>

#include "modulo_controllers/utils/utilities.hpp"

#include <modulo_interfaces/srv/empty_trigger.hpp>
#include <modulo_interfaces/srv/string_trigger.hpp>
#include <modulo_utils/exceptions/ParameterException.hpp>
#include <modulo_utils/parsing.hpp>
#include <modulo_utils/predicate_variant.hpp>

namespace modulo_controllers {

Expand Down Expand Up @@ -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<state_representation::ParameterInterface> get_parameter(const std::string& name) const;
Expand All @@ -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<typename T>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -604,7 +606,7 @@ class ControllerInterface : public controller_interface::ControllerInterface {
std::map<std::string, std::shared_ptr<rclcpp::Service<modulo_interfaces::srv::StringTrigger>>>
string_services_;///< Map of StringTrigger services

std::map<std::string, utilities::PredicateVariant> predicates_; ///< Map of predicates
std::map<std::string, modulo_utils::PredicateVariant> predicates_; ///< Map of predicates
std::shared_ptr<rclcpp::Publisher<modulo_interfaces::msg::PredicateCollection>>
predicate_publisher_; ///< Predicate publisher
std::map<std::string, bool> triggers_; ///< Map of triggers
Expand Down Expand Up @@ -638,7 +640,12 @@ inline void ControllerInterface::add_parameter(

template<typename T>
inline T ControllerInterface::get_parameter_value(const std::string& name) const {
return parameter_map_.template get_parameter_value<T>(name);
try {
return this->parameter_map_.template get_parameter_value<T>(name);
} catch (const state_representation::exceptions::InvalidParameterException& ex) {
throw modulo_utils::exceptions::ParameterException(
"Failed to get parameter value of parameter '" + name + "': " + ex.what());
domire8 marked this conversation as resolved.
Show resolved Hide resolved
domire8 marked this conversation as resolved.
Show resolved Hide resolved
}
}

template<typename T>
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions source/modulo_controllers/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<depend>modulo_core</depend>
<depend>modulo_interfaces</depend>
<depend>modulo_utils</depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ament_lint_auto</test_depend>
Expand Down
27 changes: 16 additions & 11 deletions source/modulo_controllers/src/ControllerInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

#include <modulo_core/translators/message_readers.hpp>

#include "modulo_controllers/utils/utilities.hpp"

template<class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

using namespace modulo_utils::exceptions;
using namespace state_representation;
using namespace std::chrono_literals;

Expand Down Expand Up @@ -335,7 +334,11 @@ void ControllerInterface::add_parameter(
}

std::shared_ptr<ParameterInterface> 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
Expand Down Expand Up @@ -386,14 +389,15 @@ bool ControllerInterface::on_validate_parameter_callback(const std::shared_ptr<P
}

void ControllerInterface::add_predicate(const std::string& name, bool predicate) {
add_variant_predicate(name, utilities::PredicateVariant(predicate));
add_variant_predicate(name, modulo_utils::PredicateVariant(predicate));
}

void ControllerInterface::add_predicate(const std::string& name, const std::function<bool(void)>& 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;
Expand Down Expand Up @@ -434,14 +438,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<bool(void)>& 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(
Expand Down Expand Up @@ -505,7 +510,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(),
Expand Down Expand Up @@ -646,7 +651,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(),
Expand Down
4 changes: 2 additions & 2 deletions source/modulo_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading