test_hironx_ros_bridge_pose.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2014, JSK Lab, University of Tokyo
7 # Copyright (c) 2014, TORK
8 # All rights reserved.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 #
14 # * Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # * Redistributions in binary form must reproduce the above
17 # copyright notice, this list of conditions and the following
18 # disclaimer in the documentation and/or other materials provided
19 # with the distribution.
20 # * Neither the name of JSK Lab, University of Tokyo, TORK, nor the
21 # names of its contributors may be used to endorse or promote products
22 # derived from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 # POSSIBILITY OF SUCH DAMAGE.
36 
37 import numpy
38 import rospy
39 from tf.transformations import quaternion_matrix, euler_from_matrix
40 import time
41 
42 from hironx_ros_bridge.testutil.test_rosbridge import TestHiroROSBridge
43 
44 PKG = 'hironx_ros_bridge'
45 
46 
48 
49  def test_LArmIK(self):
50  # /WAIST /LARM_JOINT5_Link
51  # - Translation: [0.325, 0.182, 0.074]
52  # - Rotation: in Quaternion [-0.000, -0.707, 0.000, 0.707]
53  # in RPY [-1.694, -1.571, 1.693]
54  for torso_angle in ([0, -10, 10]):
55  torso_goal = self.goal_Torso()
56  torso_goal = self.setup_Positions(torso_goal, [[torso_angle]])
57  self.torso.send_goal_and_wait(torso_goal)
58  for p in [[ 0.325, 0.182, 0.074], # initial
59  [ 0.3, -0.2, 0.074], [ 0.3, -0.1, 0.074],
60  #[ 0.3, 0.0, 0.074], [ 0.3, 0.1, 0.074],
61  [ 0.3, 0.2, 0.074], [ 0.3, 0.3, 0.074],
62  [ 0.4, -0.1, 0.074], [ 0.4, -0.0, 0.074],
63  #[ 0.4, 0.1, 0.074], [ 0.4, 0.2, 0.074],
64  [ 0.4, 0.3, 0.074], [ 0.4, 0.4, 0.074],
65  ] :
66 
67  print "solve ik at p = ", p
68  ret = self.set_target_pose('LARM', p, [-1.694,-1.571, 1.693], 1.0)
69  self.assertTrue(ret.operation_return, "ik failed")
70  ret = self.wait_interpolation_of_group('LARM')
71  self.assertTrue(ret.operation_return, "wait interpolation failed")
72 
73  rospy.sleep(1)
74  now = rospy.Time.now()
75  self.listener.waitForTransform("WAIST", "LARM_JOINT5_Link", now, rospy.Duration(1.0))
76  (trans, rot) = self.listener.lookupTransform("WAIST", "LARM_JOINT5_Link", now)
77  numpy.testing.assert_array_almost_equal(trans, p, decimal=1)
78  print "current position p = ", trans
79  print " rot = ", rot
80  print " = ", quaternion_matrix(rot)[0:3,0:3]
81  # this fails?
82  #numpy.testing.assert_array_almost_equal(quaternion_matrix(rot)[0:3,0:3],
83  # numpy.array([[ 0, 0, -1],
84  # [ 0, 1, 0],
85  # [ 1, 0, 0]]),
86  # decimal=3)
87 
88 
89  def test_LArm(self):
90  goal = self.goal_LArm()
91  goal = self.setup_Positions(goal, [[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
92  [ 25,-139,-157, 45, 0, 0],
93  [ 0.618, -0.157,-100.0,-15.212, 9.501, -3.188]])
94  self.larm.send_goal_and_wait(goal)
95 
96  rospy.sleep(1)
97  now = rospy.Time.now()
98  self.listener.waitForTransform("WAIST", "LARM_JOINT5_Link", now, rospy.Duration(1.0))
99  (trans, rot) = self.listener.lookupTransform("WAIST", "LARM_JOINT5_Link", now)
100  numpy.testing.assert_array_almost_equal(trans, [0.325493, 0.18236, 0.0744674], decimal=3)
101  numpy.testing.assert_array_almost_equal(quaternion_matrix(rot)[0:3,0:3],
102  numpy.array([[ 0, 0,-1],
103  [ 0, 1, 0],
104  [ 1, 0, 0]]), decimal=2)
105 
106  def test_RArm(self):
107  goal = self.goal_RArm()
108  goal = self.setup_Positions(goal, [[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
109  [ 25,-139,-157, 45, 0, 0],
110  [-0.618, -0.157,-100.0,15.212, 9.501, 3.188]])
111  self.rarm.send_goal_and_wait(goal)
112 
113  rospy.sleep(1)
114  now = rospy.Time.now()
115  self.listener.waitForTransform("WAIST", "RARM_JOINT5_Link", now, rospy.Duration(1.0))
116  (trans, rot) = self.listener.lookupTransform("WAIST", "RARM_JOINT5_Link", now)
117  numpy.testing.assert_array_almost_equal(trans, [0.325493,-0.18236, 0.0744674], decimal=3)
118  numpy.testing.assert_array_almost_equal(quaternion_matrix(rot)[0:3,0:3],
119  numpy.array([[ 0, 0,-1],
120  [ 0, 1, 0],
121  [ 1, 0, 0]]), decimal=2)
122 
123  def test_Torso(self):
124  goal = self.goal_Torso()
125  goal = self.setup_Positions(goal, [[ 0.0],
126  [-162.949],
127  [ 162.949]])
128  self.torso.send_goal_and_wait(goal)
129 
130  rospy.sleep(1)
131  now = rospy.Time.now()
132  self.listener.waitForTransform("WAIST", "CHEST_JOINT0_Link", now, rospy.Duration(1.0))
133  (trans, rot) = self.listener.lookupTransform("WAIST", "CHEST_JOINT0_Link", now)
134  numpy.testing.assert_array_almost_equal(trans, [0.0, 0.0, 0.0], decimal=3)
135  numpy.testing.assert_array_almost_equal(quaternion_matrix(rot)[0:3,0:3],
136  numpy.array([[-0.956044, -0.293223, 0.0],
137  [ 0.293223, -0.956044, 0.0],
138  [ 0.0, 0.0, 1.0]]), decimal=3)
139 
140  def test_Head(self):
141  goal = self.goal_Head()
142  goal = self.setup_Positions(goal, [[ 0.0, 0.0],
143  [ 70.0, 70.0],
144  [-70.0,-20.0]])
145  self.head.send_goal_and_wait(goal)
146 
147  rospy.sleep(1)
148  now = rospy.Time.now()
149  self.listener.waitForTransform("WAIST", "HEAD_JOINT1_Link", now, rospy.Duration(1.0))
150  (trans, rot) = self.listener.lookupTransform("WAIST", "HEAD_JOINT1_Link", now)
151  numpy.testing.assert_array_almost_equal(trans, [0.0, 0.0, 0.5695], decimal=3)
152  numpy.testing.assert_array_almost_equal(quaternion_matrix(rot)[0:3,0:3],
153  numpy.array([[0.321394, 0.939693, -0.116978],
154  [-0.883022, 0.34202, 0.321394],
155  [0.34202, 0.0, 0.939693]]), decimal=3)
156 
157 if __name__ == '__main__':
158  import rostest
159  rostest.rosrun(PKG, 'test_hronx_ros_bridge_pose', TestHiroROSBridgePose)
160 
161 
162 


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu May 14 2020 03:52:05