Skip to content
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 @@ -20,6 +20,7 @@ Release Versions:
- refactor: rename function in modulo translators (#77)
- feat: add mutex around step callback (#67)
- refactor: move utilities to modulo_utils package (#89)
- refactor: move exceptions to modulo_utils (#90)

## 4.1.0

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ As a general rule, a component interface methods do not throw an exception or ra
meaningful option. More precisely, only non-void public/protected methods throw, i.e. all setters and `add_xxx` methods
do not throw but catch all exceptions and log an error.

If an exception is thrown, it is either a `ComponentException` (in C++) or a `ComponentError` (in Python) or any
If an exception is thrown, it is either a `ModuloException` (in C++) or a `ModuloError` (in Python) or any
derived exception, such that all exceptions thrown by a component can be caught with those base exceptions (for example
in the periodic `step` function).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <modulo_component_interfaces/srv/string_trigger.hpp>
#include <modulo_component_interfaces/msg/predicate.hpp>

#include <modulo_utils/exceptions/AddSignalException.hpp>
#include <modulo_utils/exceptions/ParameterException.hpp>
#include <modulo_utils/parsing.hpp>
#include <modulo_utils/predicate_variant.hpp>

#include "modulo_components/exceptions/AddSignalException.hpp"
#include "modulo_components/exceptions/ComponentParameterException.hpp"
#include "modulo_components/utilities/utilities.hpp"

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ class ComponentInterface {
* @param parameter A ParameterInterface pointer to a Parameter instance
* @param description The description of the parameter
* @param read_only If true, the value of the parameter cannot be changed after declaration
* @throws ComponentParameterError if the parameter could not be added
* @throws ParameterException if the parameter could not be added
*/
void add_parameter(
const std::shared_ptr<state_representation::ParameterInterface>& parameter, const std::string& description,
Expand All @@ -106,15 +106,15 @@ class ComponentInterface {
* @param value The value of the parameter
* @param description The description of the parameter
* @param read_only If true, the value of the parameter cannot be changed after declaration
* @throws ComponentParameterError if the parameter could not be added
* @throws ParameterException if the parameter could not be added
*/
template<typename T>
void add_parameter(const std::string& name, const T& value, const std::string& description, bool read_only = false);

/**
* @brief Get a parameter by name.
* @param name The name of the parameter
* @throws modulo_components::exceptions::ComponentParameterException if the parameter could not be found
* @throws modulo_utils::exceptions::ParameterException if the parameter could not be found
* @return The ParameterInterface pointer to a Parameter instance
*/
[[nodiscard]] std::shared_ptr<state_representation::ParameterInterface> get_parameter(const std::string& name) const;
Expand All @@ -123,7 +123,7 @@ class ComponentInterface {
* @brief Get a parameter value by name.
* @tparam T The type of the parameter
* @param name The name of the parameter
* @throws modulo_components::exceptions::ComponentParameterException if the parameter value could not be accessed
* @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 @@ -211,7 +211,7 @@ class ComponentInterface {
* @param signal_name The signal name of the input
* @param default_topic If set, the default value for the topic name to use
* @param fixed_topic If true, the topic name of the signal is fixed
* @throws modulo_components::exceptions::AddSignalException if the input could not be declared
* @throws modulo_utils::exceptions::AddSignalException if the input could not be declared
* (empty name or already created)
*/
void declare_input(const std::string& signal_name, const std::string& default_topic = "", bool fixed_topic = false);
Expand All @@ -221,7 +221,7 @@ class ComponentInterface {
* @param signal_name The signal name of the output
* @param default_topic If set, the default value for the topic name to use
* @param fixed_topic If true, the topic name of the signal is fixed
* @throws modulo_components::exceptions::AddSignalException if the output could not be declared
* @throws modulo_utils::exceptions::AddSignalException if the output could not be declared
* (empty name or already created)
*/
void declare_output(const std::string& signal_name, const std::string& default_topic = "", bool fixed_topic = false);
Expand Down Expand Up @@ -277,7 +277,7 @@ class ComponentInterface {
* @param default_topic If set, the default value for the topic name to use
* @param fixed_topic If true, the topic name of the output signal is fixed
* @param publish_on_step If true, the output is published periodically on step
* @throws modulo_components::exceptions::AddSignalException if the output could not be created
* @throws modulo_utils::exceptions::AddSignalException if the output could not be created
* (empty name, already registered)
* @return The parsed signal name
*/
Expand Down Expand Up @@ -379,7 +379,7 @@ class ComponentInterface {
* @param reference_frame The desired reference frame of the transform
* @param time_point The time at which the value of the transform is desired
* @param duration How long to block the lookup call before failing
* @throws modulo_components::exceptions::LookupTransformException if TF buffer/listener are unconfigured or
* @throws modulo_utils::exceptions::LookupTransformException if TF buffer/listener are unconfigured or
* if the lookupTransform call failed
* @return If it exists, the requested transform
*/
Expand All @@ -394,7 +394,7 @@ class ComponentInterface {
* @param reference_frame The desired reference frame of the transform
* @param validity_period The validity period of the latest transform from the time of lookup in seconds
* @param duration How long to block the lookup call before failing
* @throws modulo_components::exceptions::LookupTransformException if TF buffer/listener are unconfigured,
* @throws modulo_utils::exceptions::LookupTransformException if TF buffer/listener are unconfigured,
* if the lookupTransform call failed, or if the transform is too old
* @return If it exists and is still valid, the requested transform
*/
Expand Down Expand Up @@ -481,7 +481,7 @@ class ComponentInterface {
* @param type The type of the signal (input or output)
* @param default_topic If set, the default value for the topic name to use
* @param fixed_topic If true, the topic name of the signal is fixed
* @throws modulo_components::exceptions::AddSignalException if the signal could not be declared
* @throws modulo_utils::exceptions::AddSignalException if the signal could not be declared
* (empty name or already created)
*/
void declare_signal(
Expand All @@ -504,7 +504,7 @@ class ComponentInterface {
/**
* @brief Validate an add_service request by parsing the service name and checking the maps of registered services.
* @param service_name The name of the service
* @throws modulo_components::exceptions::AddServiceException if the service could not be created
* @throws modulo_utils::exceptions::AddServiceException if the service could not be created
* (empty name or already registered)
* @return The parsed service name
*/
Expand All @@ -529,7 +529,7 @@ class ComponentInterface {
* @param reference_frame The desired reference frame of the transform
* @param time_point The time at which the value of the transform is desired
* @param duration How long to block the lookup call before failing
* @throws modulo_components::exceptions::LookupTransformException if TF buffer/listener are unconfigured or
* @throws modulo_utils::exceptions::LookupTransformException if TF buffer/listener are unconfigured or
* if the lookupTransform call failed
* @return If it exists, the requested transform
*/
Expand Down Expand Up @@ -590,7 +590,7 @@ inline T ComponentInterface::get_parameter_value(const std::string& name) const
try {
return this->parameter_map_.template get_parameter_value<T>(name);
} catch (const state_representation::exceptions::InvalidParameterException& ex) {
throw exceptions::ComponentParameterException(
throw modulo_utils::exceptions::ParameterException(
"Failed to get parameter value of parameter '" + name + "': " + ex.what());
}
}
Expand Down Expand Up @@ -740,10 +740,10 @@ inline std::string ComponentInterface::create_output(
parsed_signal_name, std::make_shared<PublisherInterface>(publisher_type, message_pair));
this->periodic_outputs_.insert_or_assign(parsed_signal_name, publish_on_step);
return parsed_signal_name;
} catch (const exceptions::AddSignalException&) {
} catch (const modulo_utils::exceptions::AddSignalException&) {
throw;
} catch (const std::exception& ex) {
throw exceptions::AddSignalException(ex.what());
throw modulo_utils::exceptions::AddSignalException(ex.what());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ inline void LifecycleComponent::add_output(
this->create_output(
modulo_core::communication::PublisherType::LIFECYCLE_PUBLISHER, signal_name, data, default_topic, fixed_topic,
publish_on_step);
} catch (const exceptions::AddSignalException& ex) {
} catch (const modulo_utils::exceptions::AddSignalException& ex) {
RCLCPP_ERROR_STREAM(this->get_logger(), "Failed to add output '" << signal_name << "': " << ex.what());
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

27 changes: 13 additions & 14 deletions source/modulo_components/modulo_components/component_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from geometry_msgs.msg import TransformStamped
from modulo_component_interfaces.msg import Predicate
from modulo_component_interfaces.srv import EmptyTrigger, StringTrigger
from modulo_utils.exceptions import AddServiceError, AddSignalError, ModuloError, ParameterError, LookupTransformError
from modulo_utils.parsing import parse_topic_name
from modulo_components.exceptions import AddServiceError, AddSignalError, ComponentError, ComponentParameterError, \
LookupTransformError
from modulo_components.utilities import modify_parameter_overrides
from modulo_core import EncodedState
from modulo_core.exceptions import MessageTranslationError, ParameterTranslationError
Expand Down Expand Up @@ -105,7 +104,7 @@ def add_parameter(self, parameter: Union[str, sr.Parameter], description: str, r
:param parameter: Either the name of the parameter attribute or the parameter itself
:param description: The parameter description
:param read_only: If True, the value of the parameter cannot be changed after declaration
:raises ComponentParameterError: if the parameter could not be added
:raises ParameterError: if the parameter could not be added
"""
try:
if isinstance(parameter, sr.Parameter):
Expand All @@ -122,7 +121,7 @@ def add_parameter(self, parameter: Union[str, sr.Parameter], description: str, r
"containing the name of the attribute that refers to the parameter to add.")
ros_param = write_parameter(sr_parameter)
except (TypeError, ParameterTranslationError) as e:
raise ComponentParameterError(f"Failed to add parameter: {e}")
raise ParameterError(f"Failed to add parameter: {e}")
if not self.has_parameter(sr_parameter.get_name()):
self.get_logger().debug(f"Adding parameter '{sr_parameter.get_name()}'.")
self._parameter_dict[sr_parameter.get_name()] = parameter
Expand All @@ -136,7 +135,7 @@ def add_parameter(self, parameter: Union[str, sr.Parameter], description: str, r
self.declare_parameter(ros_param.name, ros_param.value, descriptor=descriptor)
except Exception as e:
del self._parameter_dict[sr_parameter.get_name()]
raise ComponentParameterError(f"Failed to add parameter: {e}")
raise ParameterError(f"Failed to add parameter: {e}")
else:
self.get_logger().debug(f"Parameter '{sr_parameter.get_name()}' already exists.")

Expand All @@ -147,7 +146,7 @@ def get_parameter(self, name: str) -> Union[sr.Parameter, Parameter]:
dictionary.

:param name: The name of the parameter
:raises ComponentParameterError: if the parameter does not exist
:raises ParameterError: if the parameter does not exist
:return: The requested parameter
"""
try:
Expand All @@ -158,32 +157,32 @@ def get_parameter(self, name: str) -> Union[sr.Parameter, Parameter]:
else:
return self.__get_component_parameter(name)
except Exception as e:
raise ComponentParameterError(f"Failed to get parameter '{name}': {e}")
raise ParameterError(f"Failed to get parameter '{name}': {e}")

def __get_component_parameter(self, name: str) -> sr.Parameter:
"""
Get the parameter from the parameter dictionary by its name.

:param name: The name of the parameter
:raises ComponentParameterError: if the parameter does not exist
:raises ParameterError: if the parameter does not exist
:return: The parameter, if it exists
"""
if name not in self._parameter_dict.keys():
raise ComponentParameterError(f"Parameter '{name}' is not in the dict of parameters")
raise ParameterError(f"Parameter '{name}' is not in the dict of parameters")
try:
if isinstance(self._parameter_dict[name], str):
return self.__getattribute__(self._parameter_dict[name])
else:
return self._parameter_dict[name]
except AttributeError as e:
raise ComponentParameterError(f"{e}")
raise ParameterError(f"{e}")

def get_parameter_value(self, name: str) -> T:
"""
Get the parameter value from the parameter dictionary by its name.

:param name: The name of the parameter
:raises ComponentParameterError: if the parameter does not exist
:raises ParameterError: if the parameter does not exist
:return: The value of the parameter, if the parameter exists
"""
return self.__get_component_parameter(name).get_value()
Expand Down Expand Up @@ -777,13 +776,13 @@ def publish_output(self, signal_name: str):
Trigger the publishing of an output

:param signal_name: The name of the output signal
:raises ComponentError: if the output is being published periodically or if the signal name could not be found
:raises ModuloError: if the output is being published periodically or if the signal name could not be found
"""
parsed_signal_name = parse_topic_name(signal_name)
if parsed_signal_name not in self._outputs.keys():
raise ComponentError(f"Output with name '{signal_name}' doesn't exist")
raise ModuloError(f"Output with name '{signal_name}' doesn't exist")
if self._periodic_outputs[parsed_signal_name]:
raise ComponentError("An output that is published periodically cannot be triggered manually")
raise ModuloError("An output that is published periodically cannot be triggered manually")
try:
self.__translate_and_publish(parsed_signal_name)
except Exception as e:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import clproto
from lifecycle_msgs.msg import State
from modulo_components.component_interface import ComponentInterface
from modulo_components.exceptions import AddSignalError
from modulo_utils.exceptions import AddSignalError
from rclpy.lifecycle import LifecycleNodeMixin, LifecycleState
from rclpy.lifecycle.node import TransitionCallbackReturn

Expand Down
Loading