From 2a7c5cc88e10e743b23df92f8f3dd3527cbfbab0 Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 12 Dec 2018 22:43:07 -0800 Subject: [PATCH] Prepending node namespace to relative topics and adding validation for topic names --- src/rqt_publisher/publisher.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/rqt_publisher/publisher.py b/src/rqt_publisher/publisher.py index 8d897ec..2c457b8 100644 --- a/src/rqt_publisher/publisher.py +++ b/src/rqt_publisher/publisher.py @@ -38,6 +38,7 @@ from python_qt_binding.QtCore import Slot, QSignalMapper, QTimer, qWarning +from rclpy.exceptions import InvalidTopicNameException from rqt_gui_py.plugin import Plugin from .publisher_widget import PublisherWidget from rqt_py_common.message_helpers import get_message_class @@ -81,8 +82,15 @@ def __init__(self, context): @Slot(str, str, float, bool) def add_publisher(self, topic_name, type_name, rate, enabled): + topic_name = str(topic_name) + try: + self._node._validate_topic_or_service_name(topic_name) + except InvalidTopicNameException as e: + qWarning(str(e)) + return + publisher_info = { - 'topic_name': str(topic_name), + 'topic_name': topic_name, 'type_name': str(type_name), 'rate': float(rate), 'enabled': bool(enabled), @@ -117,6 +125,11 @@ def _add_publisher(self, publisher_info): module = importlib.import_module(package_name + '.msg') msg_module = getattr(module, message_name) + # Topic name provided was relative, remap to node namespace (if it was set) + if not publisher_info['topic_name'].startswith('/'): + publisher_info['topic_name'] = \ + self._node.get_namespace() + publisher_info['topic_name'] + # create publisher and timer publisher_info['publisher'] = self._node.create_publisher( msg_module, publisher_info['topic_name'])