test_base_odomxyw_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 
37 PKG = 'pr2_gazebo'
38 NAME = 'test_base_odomw_gt'
39 
40 import math
41 import roslib
42 roslib.load_manifest(PKG)
43 roslib.load_manifest('rostest')
44 
45 import sys, unittest
46 import os, time
47 import rospy, rostest
48 from geometry_msgs.msg import Twist,Vector3
49 from nav_msgs.msg import Odometry
50 
51 TEST_DURATION = 10.0
52 
53 TARGET_VX = 0.25
54 TARGET_VY = 0.25
55 TARGET_VW = 0.25
56 TARGET_DURATION = 2.0
57 TARGET_TOL = 0.15
58 
59 
60 from test_base import BaseTest, Q, E
62  def __init__(self, *args):
63  super(XYW_GT, self).__init__(*args)
64 
65  def test_base(self):
66  self.init_ros(NAME)
67  timeout_t = None
68  while not rospy.is_shutdown() and not self.success and ( timeout_t is None or time.time() < timeout_t ) :
69  #do not start commanding base until p3d and odom are initialized
70  if self.p3d_initialized == True and self.odom_initialized == True:
71  self.pub.publish(Twist(Vector3(TARGET_VX,TARGET_VY, 0), Vector3(0,0,TARGET_VW)))
72  if timeout_t is None: # initialize timeout_t when p3d and odom is received
73  timeout_t = time.time() + TEST_DURATION
74  time.sleep(0.1)
75  #self.debug_e()
76  # display what the odom error is
77  error = E(0,0,0)
78  error.shortest_euler_distance(self.p3d_e,self.odom_e)
79  # print " error " + " x:" + str(self.odom_x - self.p3d_x) \
80  # + " y:" + str(self.odom_y - self.p3d_y) \
81  # + " e:" + str(error.x) + "," + str(error.y) + "," + str(error.z) \
82  # + " t_odom:" + str(self.odom_e.x) + "," + str(self.odom_e.y) + "," + str(self.odom_e.z) \
83  # + " t_p3d:" + str(self.p3d_e.x) + "," + str(self.p3d_e.y) + "," + str(self.p3d_e.z)
84 
85  # check total error
86  total_error = abs(self.odom_x - self.p3d_x) + abs(self.odom_y - self.p3d_y) + abs(error.x) + abs(error.y) + abs(error.z)
87  # print "total error:" + str(total_error) + " tol:" + str(TARGET_TOL)
88  total_dist = math.sqrt(self.p3d_x*self.p3d_x + self.p3d_y*self.p3d_y + self.p3d_t*self.p3d_t)
89  if total_error/total_dist < TARGET_TOL:
90  self.success = True
91 
92  if not self.success:
93  rospy.logerr("Testing pr2 base odometry control against simulated ground truth with target (vx,vy) = (0.25,0.25), but odom data does not match gound truth from simulation. Total deviation in position is %f percent over a distance of %f meters."%(total_error/total_dist, total_dist));
94  else:
95  rospy.loginfo("Testing pr2 base odometry control against simulated ground truth with target (vx,vy) = (0.25,0.25), total deviation in position is %f percent over a distance of %f meters."%(total_error/total_dist, total_dist));
96 
97  self.assert_(self.success)
98 
99 if __name__ == '__main__':
100  rostest.run(PKG, sys.argv[0], XYW_GT, sys.argv) #, text_mode=True)
101 
102 
def init_ros(self, name)
Definition: test_base.py:209


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