test_base_vw_gt.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 base controller vw
36 ## sends cmd_vel vx= 0, vy=0, vw =TARGET_VW
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 = 'test_base_vw_gt'
42 
43 import math
44 import roslib
45 roslib.load_manifest(PKG)
46 
47 import sys, unittest
48 import os, time
49 import rospy, rostest
50 from geometry_msgs.msg import Twist,Vector3
51 from nav_msgs.msg import Odometry
52 
53 TEST_DURATION = 60.0
54 
55 TARGET_VW = 0.25
56 TARGET_DURATION = 2.0
57 #TARGET_TOL = 0.15 #empirical test result john - 20090420
58 TARGET_TOL = 0.18 #empirical test result john - 20120810 - slight regression
59 
60 from test_base import BaseTest, Q, E
61 class VW_GT(BaseTest):
62  def __init__(self, *args):
63  super(VW_GT, self).__init__(*args)
64  self.reached_target_vw = False
65  self.duration_start = 0
66 
67  def odomInput(self, odom):
68  # override parent
69  #self.printBaseOdom(odom)
70  error = 0
71 
72  def p3dInput(self, p3d):
73  # override parent
74  i = 0
75  #self.printBaseP3D(p3d)
76  error = abs(p3d.twist.twist.angular.z - TARGET_VW)
77  print " Error: " + str(error) + " Duration: " + str(time.time() - self.duration_start)
78  # has to reach target vw and maintain target vw for a duration of TARGET_DURATION seconds
79  if self.reached_target_vw:
80  if error < TARGET_TOL:
81  if time.time() - self.duration_start > TARGET_DURATION:
82  self.success = True
83  else:
84  # failed to maintain target vw, reset duration
85  self.success = False
86  self.reached_target_vw = False
87  else:
88  if error < TARGET_TOL:
89  self.reached_target_vw = True
90  self.duration_start = time.time()
91 
92  def test_base(self):
93  self.init_ros(NAME)
94  timeout_t = time.time() + TEST_DURATION
95  while not rospy.is_shutdown() and not self.success and time.time() < timeout_t:
96  self.pub.publish(Twist(Vector3(0.0,0.0,0), Vector3(0,0,TARGET_VW)))
97  time.sleep(0.1)
98  self.assert_(self.success)
99 
100 if __name__ == '__main__':
101  rostest.run(PKG, sys.argv[0], VW_GT, sys.argv) #, text_mode=True)
102 
103 
def odomInput(self, odom)
def p3dInput(self, p3d)
def __init__(self, args)
def init_ros(self, name)
Definition: test_base.py:209


pr2_gazebo
Author(s): John Hsu
autogenerated on Mon Jun 10 2019 14:28:51