Skip to content

Commit

Permalink
Rebase from 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
aleph-ra committed Jan 17, 2025
1 parent a152820 commit 44ce793
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 207 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/debian_packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ on:

jobs:
build_debs:
name: Build debs on linux x86_64
runs-on: ubuntu-latest

strategy:
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm]
name: Build debs
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
Changelog for package automatika_ros_sugar
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0.2.6 (2025-01-17)
------------------
* (fix) Fixes type hint
* (fix) Fixes getting available events
* (feature) checks for components and events duplicate names
* (fix) Changes type of monitor components to activate
* (chore) Fixes OS versions in CI
* (chore) Adds arms builds to debian packaging
* (refactor) Changes the fuction to create events from jsons
* (fix) Fixes events parsing using serialized events as dictionary keys
* (docs) Adds verification tag
* (docs) Adds external links to docs
* (docs) Adds source link to docs
* Contributors: ahr, mkabtoul

0.2.5 (2025-01-07)
------------------
* (fix) Gets imports and default values based on installed distro
Expand Down
Binary file added docs/_static/automatika-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 29 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
"substitution",
"tasklist",
]

language = "en"
myst_html_meta = {
"google-site-verification": "cQVj-BaADcGVOGB7GOvfbkgJjxni10C2fYWCZ03jOeo"
}

html_theme = "sphinx_book_theme" # install with `pip install sphinx-book-theme`
html_static_path = ["_static"]
Expand All @@ -69,5 +72,29 @@
"logo": {
"image_light": "_static/ROS_SUGAR_DARK.png",
"image_dark": "_static/ROS_SUGAR.png",
}
},
"icon_links": [
{
"name": "Automatika",
"url": "https://automatikarobotics.com/",
"icon": "_static/automatika-logo.png",
"type": "local",
},
{
"name": "GitHub",
"url": "https://github.com/automatika-robotics/ros-sugar",
"icon": "fa-brands fa-github",
},
{
"name": "Discord",
"url": "https://discord.gg/cAW3BWwt",
"icon": "fa-brands fa-discord",
},
],
"path_to_docs": "docs",
"repository_url": "https://github.com/automatika-robotics/ros-sugar",
"repository_branch": "main",
"use_source_button": True,
"use_issues_button": True,
"use_edit_page_button": True,
}
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>automatika_ros_sugar</name>
<version>0.2.5</version>
<version>0.2.6</version>
<description>Syntactic sugar for ROS2 nodes creation and management</description>
<maintainer email="[email protected]">Automatika Robotics</maintainer>
<url type="website">https://github.com/automatika/ros-sugar</url>
Expand Down
54 changes: 28 additions & 26 deletions ros_sugar/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from .action import Action
from .event import Event
from ..events import json_to_events_list
from ..events import json_to_events_list, event_from_json
from ..io.callbacks import GenericCallback
from ..config.base_config import BaseComponentConfig, ComponentRunType, BaseAttrs
from ..io.topic import Topic
Expand Down Expand Up @@ -178,6 +178,16 @@ def rclpy_init_node(self, *args, **kwargs):
)
self._create_default_services()

def is_node_initialized(self) -> bool:
"""Checks if the rclpy Node is initialized
:return: Is node initialized
:rtype: bool
"""
from rclpy.utilities import ok

return ok()

def _reparse_inputs_callbacks(self, inputs: Sequence[Topic]) -> Sequence[Topic]:
"""Select inputs callbacks. Selects a callback for each input from the same component package if it exists. Otherwise, the first available callback will be assigned. Note: This method is added to enable using components from multiple packages in the same script, where each component prioritizes using callbacks from its own package.
Expand Down Expand Up @@ -388,6 +398,8 @@ def activate(self):
"""
Create required subscriptions, publications, timers, ... etc. to activate the node
"""
self.create_all_subscribers()

self.create_all_publishers()

# Setup node services: servers and clients
Expand All @@ -407,20 +419,20 @@ def deactivate(self):
"""
Destroy all declared subscriptions, publications, timers, ... etc. to deactivate the node
"""
self.destroy_all_timers()

self.destroy_all_action_servers()

self.destroy_all_services()

self.destroy_all_subscribers()

self.destroy_all_publishers()

self.destroy_all_timers()

self.destroy_all_action_clients()

self.destroy_all_service_clients()

self.destroy_all_subscribers()

self.destroy_all_publishers()

def configure(self, config_file: Optional[str] = None):
"""
Configure component from yaml file
Expand All @@ -435,9 +447,6 @@ def configure(self, config_file: Optional[str] = None):
# Init any global node variables
self.init_variables()

# Setup node subscribers
self.create_all_subscribers()

# CREATION AND DESTRUCTION METHODS
def init_variables(self):
"""
Expand Down Expand Up @@ -560,7 +569,7 @@ def destroy_all_subscribers(self):
for listener in self.__event_listeners:
self.destroy_subscription(listener)
# Destroy all input subscribers
for callback in self.callbacks:
for callback in self.callbacks.values():
if callback._subscriber:
self.destroy_subscription(callback._subscriber)
callback._subscriber = None
Expand All @@ -573,6 +582,7 @@ def destroy_all_publishers(self):
if self.__enable_health_publishing:
# Destroy health status publisher
self.destroy_publisher(self.health_status_publisher)
self.health_status_publisher = None

for publisher in self.publishers_dict.values():
if publisher._publisher:
Expand Down Expand Up @@ -813,14 +823,6 @@ def loop_rate(self) -> float:
def loop_rate(self, value: float):
self.config.loop_rate = value

@property
def events(self) -> Optional[List[Event]]:
return self.__events

@events.setter
def events(self, event_list: List[Event]) -> None:
self.__events = event_list

@property
def events_actions(self) -> Dict[str, List[Action]]:
"""Getter of component Events/Actions
Expand All @@ -837,7 +839,7 @@ def events_actions(self) -> Dict[str, List[Action]]:

@events_actions.setter
def events_actions(
self, events_actions_dict: Dict[Event, Union[Action, List[Action]]]
self, events_actions_dict: Dict[str, Union[Action, List[Action]]]
):
"""Setter of component Events/Actions
Expand All @@ -847,14 +849,14 @@ def events_actions(
"""
self.__events = []
self.__actions = []
for event, actions in events_actions_dict.items():
for event_serialized, actions in events_actions_dict.items():
action_set = actions if isinstance(actions, list) else [actions]
for action in action_set:
if not hasattr(self, action.action_name):
raise ValueError(
f"Component '{self.node_name}' does not support action '{action.action_name}'"
)
self.__events.append(event)
self.__events.append(event_from_json(event_serialized))
self.__actions.append(action_set)

# SERIALIZATION AND DESERIALIZATION
Expand Down Expand Up @@ -1691,7 +1693,7 @@ def _main(self):
# Execute main loop
self._execution_step()

if self.__enable_health_publishing:
if self.__enable_health_publishing and self.health_status_publisher:
self.health_status_publisher.publish(self.health_status())

# Execute once
Expand Down Expand Up @@ -2250,9 +2252,6 @@ def on_deactivate(
:rtype: lifecycle.TransitionCallbackReturn
"""
try:
# Call custom method
self.custom_on_deactivate()

self.deactivate()
# Declare transition
self.get_logger().info(
Expand All @@ -2262,6 +2261,9 @@ def on_deactivate(
self.destroy_timer(self.__fallbacks_check_timer)
self.health_status.set_healthy()

# Call custom method
self.custom_on_deactivate()

except Exception as e:
self.get_logger().error(
f"Transition error for node {self.get_name()} to transition to state 'inactive': {e}"
Expand Down
19 changes: 11 additions & 8 deletions ros_sugar/core/event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Event"""

import json
import os
import threading
import time
import logging
Expand Down Expand Up @@ -361,7 +360,6 @@ def __init__(
if isinstance(nested_attributes, List)
else [nested_attributes]
)

self.trigger_ref_value = trigger_value

else:
Expand Down Expand Up @@ -451,18 +449,21 @@ def dictionary(self) -> Dict:
:return: Event description dictionary
:rtype: Dict
"""
return {
event_dict = {
"event_name": self.name,
"event_class": self.__class__.__name__,
"topic": self.event_topic.to_json(),
"trigger_ref_value": self.trigger_ref_value,
"_attrs": self._attrs,
"handle_once": self._handle_once,
"event_delay": self._keep_event_delay,
}
if hasattr(self, "trigger_ref_value"):
event_dict["trigger_ref_value"] = self.trigger_ref_value
if hasattr(self, "_attrs"):
event_dict["_attrs"] = self._attrs
return event_dict

@dictionary.setter
def dictionary(self, dict_obj) -> None:
def dictionary(self, dict_obj: Dict) -> None:
"""
Setter of the event using a dictionary
Expand All @@ -476,10 +477,12 @@ def dictionary(self, dict_obj) -> None:
name="dummy_init", msg_type="String"
) # Dummy init to set from json
self.event_topic.from_json(dict_obj["topic"])
self.trigger_ref_value = dict_obj["trigger_ref_value"]
self._attrs = dict_obj["_attrs"]
self._handle_once = dict_obj["handle_once"]
self._keep_event_delay = dict_obj["event_delay"]
if dict_obj.get("trigger_ref_value"):
self.trigger_ref_value = dict_obj["trigger_ref_value"]
if dict_obj.get("_attrs"):
self._attrs = dict_obj["_attrs"]
except Exception as e:
logging.error(f"Cannot set Event from incompatible dictionary. {e}")
raise
Expand Down
Loading

0 comments on commit 44ce793

Please sign in to comment.