test_hironx_moveit.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2015, Tokyo Opensource Robotics Kyokai Association
6 # (TORK) All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of TORK. nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 # Author: Isaac I.Y. Saito
36 
37 # This test script needs improved so that it becomes call-able from ROS test
38 # structure.
39 
40 import numpy
41 import unittest
42 
43 from geometry_msgs.msg import Pose, PoseStamped
44 from moveit_commander import MoveGroupCommander
45 import rospy
46 import tf
47 
48 from hironx_ros_bridge.ros_client import ROS_Client
49 
50 _PKG = 'hironx_ros_bridge'
51 _SEC_WAIT_BETWEEN_TESTCASES = 3
52 
53 
54 class TestHironxMoveit(unittest.TestCase):
55 
56  def __init__(self, *args, **kwargs):
57  super(TestHironxMoveit, self).__init__(*args, **kwargs)
58 
59  @classmethod
60  def setUpClass(self):
61 
62  self._ros = ROS_Client()
63 
64  self._botharms_joints = ['LARM_JOINT0', 'LARM_JOINT1',
65  'LARM_JOINT2', 'LARM_JOINT3',
66  'LARM_JOINT4', 'LARM_JOINT5',
67  'RARM_JOINT0', 'RARM_JOINT1',
68  'RARM_JOINT2', 'RARM_JOINT3',
69  'RARM_JOINT4', 'RARM_JOINT5']
70 
71  self._ros.MG_RARM_current_pose = self._ros.MG_RARM.get_current_pose().pose
72  self._ros.MG_LARM_current_pose = self._ros.MG_LARM.get_current_pose().pose
73  # For botharms get_current_pose ends with no eef error.
74 
75  self.init_rtm_jointvals = [0.010471975511965976, 0.0, -1.7453292519943295, -0.26529004630313807, 0.16406094968746698, -0.05585053606381855,
76  -0.010471975511965976, 0.0, -1.7453292519943295, 0.26529004630313807, 0.16406094968746698, 0.05585053606381855]
77 
78  self.init_rtm_jointvals_factory = [-1.3877787807814457e-17, 1.0842021724855044e-19, -2.2689280275926285, -4.440892098500626e-16, -2.220446049250313e-16, 0.0,
79  0.0, 1.0842021724855044e-19, -2.2689280275926285, 2.220446049250313e-16, -1.1102230246251565e-16, 5.551115123125783e-17]
80 
81  self.offpose_jointvals = [0.0, 0.0, 0.0,
82  -0.4363323129985819, -2.4260076602721163, -2.7401669256310983, -0.7853981633974487, 0.0, 0.0,
83  0.4363323129985819, -2.4260076602721163, -2.7401669256310983, 0.7853981633974487, 0.0, 0.0]
84 
85  # These represent a pose as in the image https://goo.gl/hYa15h
86  self.banzai_pose_larm_goal = [-0.0280391167993, 0.558512828409, 0.584801820449,
87  0.468552399035, -0.546097642377, -0.449475560632, 0.529346516701]
88  self.banzai_pose_rarm_goal = [0.0765219167208, -0.527210000725, 0.638387081642,
89  -0.185009037721, -0.683111796219, 0.184872589841, 0.681873929223]
90  self.banzai_jointvals_goal = [1.3591412928962834, -1.5269810342586994, -1.5263864987632225, -0.212938998306429,
91  -0.19093239258017988, -1.5171864827145887, -0.7066724299606867, -1.9314110634425135,
92  -1.4268663042616962, 1.0613942164863952, 0.9037643195141568, 1.835342100423069]
93 
94  def _set_target_random(self):
95  '''
96  @type self: moveit_commander.MoveGroupCommander
97  @param self: In this particular test script, the argument "self" is
98  either 'rarm' or 'larm'.
99  '''
100  global current, current2, target
101  current = self.get_current_pose()
102  print "*current*", current
103  target = self.get_random_pose()
104  print "*target*", target
105  self.set_pose_target(target)
106  self.go()
107  current2 = self.get_current_pose()
108  print "*current2*", current2
109 
110  # Associate a method to MoveGroupCommander class. This enables users to use
111  # the method on interpreter.
112  # Although not sure if this is the smartest Python code, this works fine from
113  # Python interpreter.
114  # #MoveGroupCommander._set_target_random = _set_target_random
115 
116  # ****** Usage ******
117  #
118  # See wiki tutorial
119  # https://code.google.com/p/rtm-ros-robotics/wiki/hironx_ros_bridge_en#Manipulate_Hiro_with_Moveit_via_Python
120 
122  # #rpy ver
123  target = [0.2035, -0.5399, 0.0709, 0, -1.6, 0]
124  self._ros.MG_RARM.set_pose_target(target)
125  self._ros.MG_RARM.plan()
126  self.assertTrue(self._ros.MG_RARM.go())
127 
129  target = [0.2035, -0.5399, 0.0709, 0.000427, 0.000317, -0.000384, 0.999999]
130  self._ros.MG_RARM.set_pose_target(target)
131  self._ros.MG_RARM.plan()
132  self.assertTrue(self._ros.MG_RARM.go())
133 
135  '''Comparing joint names.'''
136  self.assertItemsEqual(self._ros.MG_BOTHARMS.get_joints(), self._botharms_joints)
137 
139  '''
140  "both_arm" move group can't set pose target for now (July, 2015) due to
141  missing eef in the moveit config. Here checking if
142  MoveGroup.get_joint_values is working.
143  '''
144 
145  self._ros.MG_LARM.set_pose_target(self.banzai_pose_larm_goal)
146  self._ros.MG_LARM.plan()
147  self._ros.MG_LARM.go()
148  self._ros.MG_RARM.set_pose_target(self.banzai_pose_rarm_goal)
149  self._ros.MG_RARM.plan()
150  self._ros.MG_RARM.go()
151  # Comparing to the 3rd degree seems too aggressive; example output:
152  # x: array([ 1.35906843, -1.52695742, -1.52658066, -0.21309358,
153  # -0.19092542, -1.51707957, -0.70651268, -1.93170852,
154  # -1.42660669, 1.0629058, 0.90412021, 1.83650476])
155  # y: array([ 1.35914129, -1.52698103, -1.5263865 , -0.212939,
156  # -0.19093239, -1.51718648, -0.70667243, -1.93141106,
157  # -1.4268663 , 1.06139422, 0.90376432, 1.8353421 ])
158  numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
159  self.banzai_jointvals_goal, 2)
160 
162  '''
163  Test if moveit_commander.set_named_target brings the arms to
164  the init_rtm pose defined in HiroNx.srdf.
165  '''
166  # Move the arms to non init pose.
167  self._ros.MG_LARM.set_pose_target(self.banzai_pose_larm_goal)
168  self._ros.MG_LARM.plan()
169  self._ros.MG_LARM.go()
170  self._ros.MG_RARM.set_pose_target(self.banzai_pose_rarm_goal)
171  self._ros.MG_RARM.plan()
172  self._ros.MG_RARM.go()
173 
174  self._ros.MG_BOTHARMS.set_named_target('init_rtm')
175  self._ros.MG_BOTHARMS.plan()
176  self._ros.MG_BOTHARMS.go()
177 
178  # Raises AssertException when the assertion fails, which
179  # automatically be flagged false by unittest framework.
180  # http://stackoverflow.com/a/4319836/577001
181  numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
182  self.init_rtm_jointvals, 3)
183 
184 # def test_simple_unittest(self):
185 # self.assertEqual(1, 1)
186 
188  '''
189  Starting from https://github.com/start-jsk/rtmros_hironx/pull/422,
190  ROS_Client.py depends on moveit_commander.RobotCommander class.
191  This case tests the integration of ROS_Client.py and RobotCommander.
192 
193  Developers need to avoid testing moveit_commander.RobotCommander itself
194  -- that needs to be done upstream.
195  '''
196  # If the list of movegroups are not none, that can mean
197  # RobotCommander is working as expected.
198  groupnames = self._ros.get_group_names()
199  self.assertIsNotNone(groupnames)
200 
202  self._ros.goInitial()
203  numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
204  self.init_rtm_jointvals, 3)
205  self._ros.goInitial(init_pose_type=1)
206  numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
208 
210  self._ros.go_offpose()
211  numpy.testing.assert_almost_equal(self._ros.MG_UPPERBODY.get_current_joint_values(),
212  self.offpose_jointvals, 3)
213 
215  '''
216  Trying to capture issues like https://github.com/tork-a/rtmros_nextage/issues/244
217  '''
218  TRANS_RARM4_RARM5 = [-0.047, 0.000, -0.090] # Expected value.
219 
220  tflistener = tf.TransformListener()
221  (trans, rot) = tflistener.lookupTransform("/RARM_JOINT5_Link", "/RARM_JOINT4_Link", rospy.Time(0))
222  [self.assertAlmostEqual(v_trans, v_expected, 3) for v_trans, v_expected in zip(trans, TRANS_RARM4_RARM5)]
223 
224 
225 if __name__ == '__main__':
226  import rostest
227  rostest.rosrun(_PKG, 'test_hironx_moveit_run', TestHironxMoveit)


hironx_moveit_config
Author(s): Urko Esnaola , Isaac I.Y. Saito
autogenerated on Thu May 14 2020 03:52:17