Skip to content

Commit

Permalink
fixed create subscriber node
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Tiderko committed Nov 10, 2023
1 parent cf8a560 commit 30b604f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ def shutdown(self):
def onConnect(self):
Log.info(f"{self.__class__.__name__}: autobahn connected")
self.join(self.config.realm)
for (topic, handler) in self._crossbar_subscriptions:
asyncio.run_coroutine_threadsafe(
self.subcribe_async(topic, handler), self.crossbar_loop)
for topic, msg in self._crossbar_failed_publications.items():
self.publish_to(topic, msg)
self._crossbar_failed_publications.clear()

def onDisconnect(self):
Log.info(f"{self.__class__.__name__}: autobahn disconnected")
Expand All @@ -165,6 +159,12 @@ def onJoin(self, details):
for _session_id, reg in self._registrations.items():
Log.info(f"{self.__class__.__name__}: {reg.procedure}")
self.crossbar_registered = True
for (topic, handler) in self._crossbar_subscriptions:
asyncio.run_coroutine_threadsafe(
self.subcribe_async(topic, handler), self.crossbar_loop)
for topic, msg in self._crossbar_failed_publications.items():
self.publish_to(topic, msg)
self._crossbar_failed_publications.clear()

async def crossbar_connect_async(self):
self.crossbar_connected = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import threading
import time
import traceback
from importlib import import_module
from types import SimpleNamespace
from typing import Any
from typing import Callable
Expand Down Expand Up @@ -152,9 +153,9 @@ def __init__(self, test_env=False):
Log.set_ros2_logging_node(self.rosnode)

Log.info(f"start subscriber for {self._topic}[{self._message_type}]")
splitted_type = self._message_type.replace('/', '.').split('.')
splitted_type = self._message_type.replace('/', '.').rsplit('.', 1)
splitted_type.reverse()
module = __import__(splitted_type.pop())
module = import_module(splitted_type.pop())
sub_class = getattr(module, splitted_type.pop())
while splitted_type:
sub_class = getattr(sub_class, splitted_type.pop())
Expand Down Expand Up @@ -199,7 +200,7 @@ def spin(self):
self.sub.destroy()
print('shutdown rclpy')
self.executor.shutdown()
rclpy.shutdown()
# rclpy.shutdown()
print('bye!')

def _init_arg_parser(self) -> argparse.ArgumentParser:
Expand Down

0 comments on commit 30b604f

Please sign in to comment.