pr2_right_arm_fk_unittest.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 Willow Garage, Inc. 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 import roslib; roslib.load_manifest('pr2_calibration_estimation')
36 
37 import sys
38 import unittest
39 import rospy
40 import time
41 
42 from calibration_estimation.full_chain import FullChainRobotParams
43 from calibration_estimation.urdf_params import UrdfParams
44 from sensor_msgs.msg import JointState
45 
46 import yaml
47 from pr2_calibration_estimation.srv import FkTest
48 from numpy import *
49 import numpy
50 
51 class LoadData(unittest.TestCase):
52  def setUp(self):
53  config = yaml.load(open(rospy.get_param('config_file')))
54  self.robot_params = UrdfParams(rospy.get_param('robot_description'), config)
55 
56  rospy.wait_for_service('fk', 3.0)
57  self._fk_ref = rospy.ServiceProxy('fk', FkTest)
58 
59  def loadCommands(self, param_name):
60  command_str = rospy.get_param(param_name)
61  cmds = [ [float(y) for y in x.split()] for x in command_str.strip().split('\n')]
62  return cmds
63 
64  def getExpected(self, root, tip, cmd):
65  resp = self._fk_ref(root, tip, cmd)
66  T = matrix(zeros((4,4)), float)
67  T[0:3, 0:3] = reshape( matrix(resp.rot, float), (3,3))
68  T[3,3] = 1.0;
69  T[0:3,3] = reshape( matrix(resp.pos, float), (3,1))
70  return T
71 
73 
74  def run_test(self, full_chain, root, tip, cmds):
75  for cmd in cmds:
76  print("On Command: %s" % cmd)
77 
78  expected_T = self.getExpected(root, tip, cmd)
79  chain_state = JointState(position=cmd)
80  actual_T = full_chain.calc_block.fk(chain_state)
81 
82  print("Expected_T:")
83  print(expected_T)
84  print("Actual T:")
85  print(actual_T)
86 
87  self.assertAlmostEqual(numpy.linalg.norm(expected_T-actual_T), 0.0, 6)
88 
89 
90  def test_right_arm_fk(self):
91  print("")
92  full_chain = FullChainRobotParams('right_arm_chain','r_wrist_roll_link')
93  full_chain.update_config(self.robot_params)
94  cmds = self.loadCommands('r_arm_commands')
95  self.run_test(full_chain, 'torso_lift_link', 'r_wrist_roll_link', cmds)
96 
97 
99  print("")
100  full_chain = FullChainRobotParams('right_arm_chain','r_forearm_roll_link')
101  full_chain.update_config(self.robot_params)
102  cmds = self.loadCommands('r_arm_commands')
103  self.run_test(full_chain, 'torso_lift_link', 'r_forearm_roll_link', cmds)
104 
105 
107  print("")
108  full_chain = FullChainRobotParams('right_arm_chain','r_forearm_cam_frame')
109  full_chain.update_config(self.robot_params)
110  cmds = self.loadCommands('r_arm_commands')
111  self.run_test(full_chain, 'torso_lift_link', 'r_forearm_cam_frame', cmds)
112 
113 
115  print("")
116  full_chain = FullChainRobotParams('right_arm_chain','r_forearm_cam_optical_frame')
117  full_chain.update_config(self.robot_params)
118  cmds = self.loadCommands('r_arm_commands')
119  self.run_test(full_chain, 'torso_lift_link', 'r_forearm_cam_optical_frame', cmds)
120 
121 
122 if __name__ == '__main__':
123  import rostest
124  rospy.init_node("fk_test")
125  rostest.unitrun('pr2_calibration_estimation', 'test_PR2Fk', TestPR2Fk)
def run_test(self, full_chain, root, tip, cmds)


pr2_calibration_launch
Author(s): Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:50:59