Skip to content

Commit

Permalink
Prepending node namespace to relative topics and adding validation fo…
Browse files Browse the repository at this point in the history
…r topic names (#7)
  • Loading branch information
brawner authored and mlautman committed Dec 13, 2018
1 parent b153751 commit 62297c5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/rqt_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -115,7 +123,17 @@ def _add_publisher(self, publisher_info):
# Allow user to create a message instance using the fully qualified package
self._eval_locals[package_name] = importlib.import_module(package_name)
module = importlib.import_module(package_name + '.msg')
msg_module = getattr(module, message_name)

try:
msg_module = getattr(module, message_name)
except AttributeError as e:
qWarning(str(e))
return

# 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(
Expand Down

0 comments on commit 62297c5

Please sign in to comment.