Skip to content

Commit

Permalink
Merge pull request #1459 from wkentaro/sanity-lib-echo-noarr
Browse files Browse the repository at this point in the history
[jsk_tools] Support echo_noarr in checkTopicIsPublished
  • Loading branch information
k-okada authored Oct 13, 2016
2 parents 462033d + 88cb2a4 commit c5d6bd1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jsk_tools/src/jsk_tools/sanity_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ class TopicPublishedChecker(object):

"""Utility class to check if topic is published"""

def __init__(self, topic_name, timeout=5, echo=False, data_class=None):
def __init__(self, topic_name, timeout=5, echo=False,
data_class=None, echo_noarr=False):
self.msg = None
self.topic_name = topic_name
self.deadline = rospy.Time.now() + rospy.Duration(timeout)
self.echo = echo
self.echo_noarr = echo_noarr
print(' Checking %s for %d seconds' % (topic_name, timeout))
msg_class, _, _ = rostopic.get_topic_class(topic_name, blocking=True)
if (data_class is not None) and (msg_class is not data_class):
Expand All @@ -66,7 +68,7 @@ def __init__(self, topic_name, timeout=5, echo=False, data_class=None):
def callback(self, msg):
if self.echo and self.msg is None: # this is first time
print(colored('--- Echo %s' % self.topic_name, 'purple'))
field_filter = rostopic.create_field_filter(echo_nostr=False, echo_noarr=True)
field_filter = rostopic.create_field_filter(echo_nostr=False, echo_noarr=self.echo_noarr)
print(colored(genpy.message.strify_message(msg, field_filter=field_filter), 'cyan'))
self.msg = msg

Expand All @@ -85,7 +87,8 @@ def checkTopicIsPublished(topic_name, class_name = None,
error_message = "",
timeout = 1,
other_topics = [],
echo = False):
echo = False,
echo_noarr = False):
"""
@type class_name: type
@property class_name:
Expand All @@ -94,7 +97,8 @@ def checkTopicIsPublished(topic_name, class_name = None,
"""
checkers = []
checkers.append(TopicPublishedChecker(topic_name, timeout, echo,
data_class=class_name))
data_class=class_name,
echo_noarr=echo_noarr))
if other_topics:
for (tpc_name, cls) in other_topics:
checkers.append(TopicPublishedChecker(tpc_name, timeout, echo,
Expand Down

0 comments on commit c5d6bd1

Please sign in to comment.