my_hztest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of the Willow Garage nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 #
34 
35 ## Gazebo test arm controller
36 ## sends posision
37 ## checks to see if P3D returns corresponding ground truth within TARGET_TOL of TARGET_VW
38 ## for a duration of TARGET_DURATION seconds
39 
40 PKG = 'pr2_gazebo'
41 NAME = 'my_hztest'
42 
43 import math
44 import roslib
45 roslib.load_manifest(PKG)
46 roslib.load_manifest('rostest')
47 
48 import sys, unittest
49 import os, os.path, threading, time
50 import rospy, rostest
51 from std_msgs.msg import *
52 from tf.msg import tfMessage
53 from pr2_mechanism_msgs.msg import MechanismState
54 
55 MIN_MSGS = 100
56 TEST_TIMEOUT = 100000000000.0
57 
58 class MyHzTest(unittest.TestCase):
59  def __init__(self, *args):
60  super(MyHzTest, self).__init__(*args)
61  self.success = False
62  self.count = 0
63 
64  #for time tracking
65  self.started = False
66  self.start_time = 0
67  self.end_time = 0
68 
69  def Input(self, msg):
70  self.count += 1;
71 
72  if not self.started:
73  self.start_time = rospy.get_rostime().to_sec()
74  print " got first message at: ",self.start_time, " sec"
75  self.started = True
76 
77  if self.count >= MIN_MSGS:
78  self.end_time = rospy.get_rostime().to_sec()
79  print " passed minimum ",self.count," messages at ",self.count / (self.end_time - self.start_time), " Hz"
80  self.success = True
81  #else:
82  #print " got ",self.count," messages at ",self.count / (rospy.get_rostime().to_sec() - self.start_time), " Hz"
83 
84  def test_hz(self):
85  print "LNK\n"
86  #rospy.Subscriber("/tf", tfMessage, self.Input)
87  rospy.Subscriber("/mechanism_state", MechanismState, self.Input)
88  rospy.init_node(NAME, anonymous=True)
89  timeout_t = time.time() + TEST_TIMEOUT
90  while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
91  time.sleep(1.0)
92 
93  self.assert_(self.success)
94 
95 if __name__ == '__main__':
96  rostest.run(PKG, sys.argv[0], MyHzTest, sys.argv) #, text_mode=True)
97 
def test_hz(self)
Definition: my_hztest.py:84
def __init__(self, args)
Definition: my_hztest.py:59
def Input(self, msg)
Definition: my_hztest.py:69


pr2_gazebo
Author(s): John Hsu
autogenerated on Fri May 3 2019 02:24:27