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

fix(components): clean up lifecycle nodes properly #184

Merged
merged 3 commits into from
Dec 12, 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 @@ -24,6 +24,7 @@ Release Versions:
- fix(controllers): move predicate publishing rate parameter to BaseControllerInterface (#168)
- feat(components): get clproto message type from attribute (#175)
- fix(components): add missing test case (#181)
- fix(components): clean up lifecycle nodes properly (#178)

## 5.0.2

Expand Down
2 changes: 1 addition & 1 deletion aica-package.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#syntax=ghcr.io/aica-technology/package-builder:v1.3.0

[metadata]
version = "5.1.0-rc0001"
version = "5.1.0-rc0002"
description = "Modular ROS 2 extension library for dynamic composition of components and controllers with the AICA robotics framework"

[metadata.collection]
Expand Down
21 changes: 19 additions & 2 deletions source/modulo_components/modulo_components/lifecycle_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
from lifecycle_msgs.msg import State
from modulo_components.component_interface import ComponentInterface
from modulo_core.exceptions import AddSignalError
from rclpy.callback_groups import CallbackGroup
from rclpy.lifecycle import LifecycleNodeMixin, LifecycleState
from rclpy.lifecycle.node import TransitionCallbackReturn

MsgT = TypeVar('MsgT')
LIFECYCLE_NODE_MIXIN_KWARGS = ["enable_communication_interface", "callback_group"]


class LifecycleComponent(ComponentInterface, LifecycleNodeMixin):
class _LifecycleNodeMixin(LifecycleNodeMixin):
def __init__(self, enable_communication_interface: bool = True, callback_group: Optional[CallbackGroup] = None):
super().__init__(enable_communication_interface=enable_communication_interface, callback_group=callback_group)

def destroy(self):
self._state_machine = None
self._callbacks = {}


class LifecycleComponent(ComponentInterface, _LifecycleNodeMixin):
"""
Class to represent a LifecycleComponent in python, following the same logic pattern
as the C++ modulo_components::LifecycleComponent class.
Expand All @@ -25,9 +35,16 @@ def __init__(self, node_name: str, *args, **kwargs):
"""
lifecycle_node_kwargs = {key: value for key, value in kwargs.items() if key in LIFECYCLE_NODE_MIXIN_KWARGS}
ComponentInterface.__init__(self, node_name, *args, **kwargs)
LifecycleNodeMixin.__init__(self, *args, **lifecycle_node_kwargs)
_LifecycleNodeMixin.__init__(self, **lifecycle_node_kwargs)
self.__has_error = False

def destroy_node(self):
"""
Cleanly destroy the node by cleaning up the Mixin class.
"""
_LifecycleNodeMixin.destroy(self)
ComponentInterface.destroy_node(self)

def get_lifecycle_state(self) -> LifecycleState:
"""
Get the current state of the component.
Expand Down
Loading