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

Prepending node namespace to relative topics and adding validation for topic names #7

Merged
merged 1 commit into from
Dec 13, 2018
Merged
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
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))
mlautman marked this conversation as resolved.
Show resolved Hide resolved
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