Skip to content

Commit

Permalink
Update the basic plugins for ROS2 (#72)
Browse files Browse the repository at this point in the history
* Update the basic plugins for ROS2

Update message_view, raw_view, and topic_message_view with
changes required to port to ROS.

Signed-off-by: Michael Jeronimo <[email protected]>

* Revert to utf_8_decode, adding decode() which was missing previously

Signed-off-by: Michael Jeronimo <[email protected]>

* Clarify the reason for stripping the leading underscore

Signed-off-by: Michael Jeronimo <[email protected]>

* Per code review, use keyword args for the base class message_viewed method and overrides

Signed-off-by: Michael Jeronimo <[email protected]>
  • Loading branch information
Michael Jeronimo authored Oct 28, 2020
1 parent 7b07c02 commit 46a3f6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
26 changes: 15 additions & 11 deletions rqt_bag/src/rqt_bag/plugins/message_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

from python_qt_binding.QtCore import QObject

import rosbag2_py


class MessageView(QObject):

Expand All @@ -47,19 +49,20 @@ def __init__(self, timeline, topic):
self.timeline = timeline
self.topic = topic

def message_viewed(self, bag, msg_details):
def message_viewed(self, *, bag, entry, ros_message, msg_type_name, topic):
"""
View the message.
@param bag: the bag file the message is contained in
@type bag: rosbag.Bag
@param msg_details: the details of the message to be viewed
@type msg_details: tuple (topic, msg, time)
@param topic: the message topic
@type topic: str
@param msg: the message
@param t: the message timestamp
@type t: rospy.Time
@param entry: the bag entry of the message to be viewed
@type entry: tuple (id, topic_id, timestamp, data)
@param ros_message: the (deserialized) ROS message
@type msg: ROS message
@param msg_type_name: the name of the message type
@type string
@param topic: the topic on which the message was recorded
@type topic: string
"""
pass

Expand Down Expand Up @@ -88,9 +91,10 @@ def event(self, event):
This function will be called to process events posted by post_event
it will call message_cleared or message_viewed with the relevant data
"""
bag, msg_data = event.data
if msg_data:
self.message_viewed(bag, msg_data)
bag, entry = event.data
if entry:
(ros_message, msg_type_name, topic) = bag.convert_entry_to_ros_message(entry)
self.message_viewed(bag=bag, entry=entry, ros_message=ros_message, msg_type_name=msg_type_name, topic=topic)
else:
self.message_cleared()
return True
25 changes: 15 additions & 10 deletions rqt_bag/src/rqt_bag/plugins/raw_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ def __init__(self, timeline, parent, topic):
# This will automatically resize the message_tree to the windowsize
parent.layout().addWidget(self.message_tree)

def message_viewed(self, bag, msg_details):
super(RawView, self).message_viewed(bag, msg_details)
_, _, _, msg = msg_details # id, topic, timestamp, msg = msg_details
if msg is None:
def message_viewed(self, *, entry, ros_message, msg_type_name, **kwargs):
super(RawView, self).message_viewed(entry=entry, ros_message=ros_message, msg_type_name=msg_type_name)
if ros_message is None:
self.message_cleared()
else:
self.message_tree.set_message(msg)
self.message_tree.set_message(ros_message, msg_type_name)

def message_cleared(self):
TopicMessageView.message_cleared(self)
self.message_tree.set_message(None)
self.message_tree.set_message(None, None)


class MessageTree(QTreeWidget):
Expand All @@ -96,7 +95,7 @@ def __init__(self, parent):
def msg(self):
return self._msg

def set_message(self, msg):
def set_message(self, msg, msg_type_name):
"""
Clears the tree view and displays the new message
:param msg: message object to display in the treeview, ''msg''
Expand All @@ -111,12 +110,12 @@ def set_message(self, msg):
self._expanded_paths.remove(path)
self.clear()
if msg:
self.setHeaderLabel(msg._type)
self.setHeaderLabel(msg_type_name)

# Populate the tree
# TODO(brawner) msg is stored in the db as a serialized byte array, needs to be
# unserialized
# self._add_msg_object(None, '', '', msg, msg._type)
self._add_msg_object(None, '', '', msg, msg_type_name)

if self._expanded_paths is None:
self._expanded_paths = set()
Expand Down Expand Up @@ -209,7 +208,7 @@ def _add_msg_object(self, parent, path, name, obj, obj_type):

elif type(obj) in [str, bool, int, long, float, complex, Time]:
# Ignore any binary data
obj_repr = codecs.utf_8_decode(str(obj), 'ignore')[0]
obj_repr = codecs.utf_8_decode(str(obj).decode(), 'ignore')[0]

# Truncate long representations
if len(obj_repr) >= 50:
Expand All @@ -229,6 +228,12 @@ def _add_msg_object(self, parent, path, name, obj, obj_type):
if subobj is None:
continue

# Strip the leading underscore for display. In ROS2, the Python IDL generator
# adds a leading underscore for each name in __slots__, whereas the name of
# the field does not have a leading underscore.
if hasattr(obj, '__slots__') and subobj_name[0] == '_':
subobj_name = subobj_name[1:]

if path == '':
subpath = subobj_name # root field
elif subobj_name.startswith('['):
Expand Down
4 changes: 2 additions & 2 deletions rqt_bag/src/rqt_bag/plugins/topic_message_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def stamp(self):

# MessageView implementation

def message_viewed(self, bag, msg_details):
_, _, self._stamp = msg_details[:3]
def message_viewed(self, *, entry, **kwargs):
self._stamp = entry.timestamp

# Events
def navigate_first(self):
Expand Down

0 comments on commit 46a3f6d

Please sign in to comment.