test_hz_measure.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import os
00003 import sys
00004 
00005 import unittest
00006 
00007 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", 
00008                                                 "scripts")))
00009 from topic_compare import ROSTopicCompare
00010 
00011 import rospy
00012 import time
00013 
00014 try:
00015     from std_msgs.msg import Float32
00016 except:
00017     import roslib; roslib.load_manifest("jsk_topic_tools")
00018     from std_msgs.msg import Float32
00019 
00020 def eps_equal(a, b, err=0.001):
00021     return abs(a - b) < err
00022 
00023 hz_msg = None
00024 
00025 def topic_cb(msg):
00026     global hz_msg
00027     hz_msg = msg
00028 
00029 
00030 class TestHzMeasure(unittest.TestCase):
00031     def test_hz(self):
00032         global hz_msg
00033         while hz_msg == None:
00034             if not rospy.is_shutdown():
00035                 rospy.sleep(1.0)          #wait 1 sec
00036         # should be 30Hz
00037         self.assertTrue(eps_equal(hz_msg.data,
00038                                   30,
00039                                   1))
00040         
00041 if __name__ == "__main__":
00042     import rostest
00043     rospy.init_node("test_hz_measure")
00044     s = rospy.Subscriber("/hz/output", Float32, topic_cb)
00045     rostest.rosrun("jsk_topic_tools", "test_hz_measure", TestHzMeasure)


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Mon Oct 6 2014 10:56:17