33 from collections
import namedtuple
37 from rqt_bag
import TopicMessageView
41 The datatype can either be a string message type (i.e. 'nav_msgs/Path') or list of string message types
42 The callback will take the same arguments as message_viewed
44 ExtraTopic = namedtuple(
'ExtraTopic',
'topic datatype callback')
48 """Generic tool for visualizing multiple topics in one TopicMessageView.
50 Visualization is triggered from one main_topic (whose datatype is determined
51 by Plugin.get_message_types) and then the other topics are determined by calling
52 get_extra_topics. The other messages visualized are those appearing in a time window
53 surrounding the message from the main topic.
56 def __init__(self, timeline, parent, main_topic, window=0.5):
59 main_topic provides the topic of the messages to focus on.
60 window provides the number of seconds for the surrounding time window.
62 super(MultiTopicView, self).
__init__(timeline, parent, main_topic)
68 found_topics = timeline._get_topics()
71 if extra_topic
not in found_topics:
72 missing_topics.append(extra_topic)
74 found_datatype = timeline.get_datatype(extra_topic)
75 if type(datatype) == list:
76 if found_datatype
not in datatype:
77 rospy.logwarn(
'The type of extra topic {} ({}) does not match the declared types: {}'.format(
78 extra_topic, found_datatype,
', '.join(map(str, datatype))))
80 elif datatype != found_datatype:
81 rospy.logwarn(
'The type of extra topic {} ({}) does not match the declared type {}'.format(
82 extra_topic, found_datatype, datatype))
88 rospy.logwarn(
'The following extra_topics were not found in the bag: ' +
', '.join(missing_topics))
91 """Return a list of ExtraTopic tuples with extra topics to visualize. Should be overridden."""
95 """Get all the messages within the time window."""
96 return self.timeline.get_entries([topic], ts - self.
window, ts + self.
window)
99 """Get the entry of the message closest to the given timestamp."""
103 if best
is None or abs(entry.time - ts) < best_t:
105 best_t = abs(entry.time - ts)
109 """Call the callbacks associated with the other topics.
111 Automatically called whenever a new single message is focused on.
112 Classes extending this class should call this super-version of the method first.
115 main_topic, msg, ts = msg_details
119 extra_msg_details = self.timeline.read_message(bag, best_entry.position)
120 callback(bag, extra_msg_details)