00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 import numpy
00041 import unittest
00042
00043 from geometry_msgs.msg import Pose, PoseStamped
00044 from moveit_commander import MoveGroupCommander
00045 import rospy
00046 import tf
00047
00048 from hironx_ros_bridge.ros_client import ROS_Client
00049
00050 _PKG = 'hironx_ros_bridge'
00051 _SEC_WAIT_BETWEEN_TESTCASES = 3
00052
00053
00054 class TestHironxMoveit(unittest.TestCase):
00055
00056 def __init__(self, *args, **kwargs):
00057 super(TestHironxMoveit, self).__init__(*args, **kwargs)
00058
00059 @classmethod
00060 def setUpClass(self):
00061
00062 self._ros = ROS_Client()
00063
00064 self._botharms_joints = ['LARM_JOINT0', 'LARM_JOINT1',
00065 'LARM_JOINT2', 'LARM_JOINT3',
00066 'LARM_JOINT4', 'LARM_JOINT5',
00067 'RARM_JOINT0', 'RARM_JOINT1',
00068 'RARM_JOINT2', 'RARM_JOINT3',
00069 'RARM_JOINT4', 'RARM_JOINT5']
00070
00071 self._ros.MG_RARM_current_pose = self._ros.MG_RARM.get_current_pose().pose
00072 self._ros.MG_LARM_current_pose = self._ros.MG_LARM.get_current_pose().pose
00073
00074
00075 self.init_rtm_jointvals = [0.010471975511965976, 0.0, -1.7453292519943295, -0.26529004630313807, 0.16406094968746698, -0.05585053606381855,
00076 -0.010471975511965976, 0.0, -1.7453292519943295, 0.26529004630313807, 0.16406094968746698, 0.05585053606381855]
00077
00078 self.init_rtm_jointvals_factory = [-1.3877787807814457e-17, 1.0842021724855044e-19, -2.2689280275926285, -4.440892098500626e-16, -2.220446049250313e-16, 0.0,
00079 0.0, 1.0842021724855044e-19, -2.2689280275926285, 2.220446049250313e-16, -1.1102230246251565e-16, 5.551115123125783e-17]
00080
00081 self.offpose_jointvals = [0.0, 0.0, 0.0,
00082 -0.4363323129985819, -2.4260076602721163, -2.7401669256310983, -0.7853981633974487, 0.0, 0.0,
00083 0.4363323129985819, -2.4260076602721163, -2.7401669256310983, 0.7853981633974487, 0.0, 0.0]
00084
00085
00086 self.banzai_pose_larm_goal = [-0.0280391167993, 0.558512828409, 0.584801820449,
00087 0.468552399035, -0.546097642377, -0.449475560632, 0.529346516701]
00088 self.banzai_pose_rarm_goal = [0.0765219167208, -0.527210000725, 0.638387081642,
00089 -0.185009037721, -0.683111796219, 0.184872589841, 0.681873929223]
00090 self.banzai_jointvals_goal = [1.3591412928962834, -1.5269810342586994, -1.5263864987632225, -0.212938998306429,
00091 -0.19093239258017988, -1.5171864827145887, -0.7066724299606867, -1.9314110634425135,
00092 -1.4268663042616962, 1.0613942164863952, 0.9037643195141568, 1.835342100423069]
00093
00094 def _set_target_random(self):
00095 '''
00096 @type self: moveit_commander.MoveGroupCommander
00097 @param self: In this particular test script, the argument "self" is
00098 either 'rarm' or 'larm'.
00099 '''
00100 global current, current2, target
00101 current = self.get_current_pose()
00102 print "*current*", current
00103 target = self.get_random_pose()
00104 print "*target*", target
00105 self.set_pose_target(target)
00106 self.go()
00107 current2 = self.get_current_pose()
00108 print "*current2*", current2
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 def test_set_pose_target_rpy(self):
00122
00123 target = [0.2035, -0.5399, 0.0709, 0, -1.6, 0]
00124 self._ros.MG_RARM.set_pose_target(target)
00125 self._ros.MG_RARM.plan()
00126 self.assertTrue(self._ros.MG_RARM.go())
00127
00128 def test_set_pose_target_quarternion(self):
00129 target = [0.2035, -0.5399, 0.0709, 0.000427, 0.000317, -0.000384, 0.999999]
00130 self._ros.MG_RARM.set_pose_target(target)
00131 self._ros.MG_RARM.plan()
00132 self.assertTrue(self._ros.MG_RARM.go())
00133
00134 def test_botharms_compare_joints(self):
00135 '''Comparing joint names.'''
00136 self.assertItemsEqual(self._ros.MG_BOTHARMS.get_joints(), self._botharms_joints)
00137
00138 def test_botharms_get_joint_values(self):
00139 '''
00140 "both_arm" move group can't set pose target for now (July, 2015) due to
00141 missing eef in the moveit config. Here checking if
00142 MoveGroup.get_joint_values is working.
00143 '''
00144
00145 self._ros.MG_LARM.set_pose_target(self.banzai_pose_larm_goal)
00146 self._ros.MG_LARM.plan()
00147 self._ros.MG_LARM.go()
00148 self._ros.MG_RARM.set_pose_target(self.banzai_pose_rarm_goal)
00149 self._ros.MG_RARM.plan()
00150 self._ros.MG_RARM.go()
00151
00152
00153
00154
00155
00156
00157
00158 numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
00159 self.banzai_jointvals_goal, 2)
00160
00161 def test_botharms_set_named_target(self):
00162 '''
00163 Test if moveit_commander.set_named_target brings the arms to
00164 the init_rtm pose defined in HiroNx.srdf.
00165 '''
00166
00167 self._ros.MG_LARM.set_pose_target(self.banzai_pose_larm_goal)
00168 self._ros.MG_LARM.plan()
00169 self._ros.MG_LARM.go()
00170 self._ros.MG_RARM.set_pose_target(self.banzai_pose_rarm_goal)
00171 self._ros.MG_RARM.plan()
00172 self._ros.MG_RARM.go()
00173
00174 self._ros.MG_BOTHARMS.set_named_target('init_rtm')
00175 self._ros.MG_BOTHARMS.plan()
00176 self._ros.MG_BOTHARMS.go()
00177
00178
00179
00180
00181 numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
00182 self.init_rtm_jointvals, 3)
00183
00184
00185
00186
00187 def test_rosclient_robotcommander(self):
00188 '''
00189 Starting from https://github.com/start-jsk/rtmros_hironx/pull/422,
00190 ROS_Client.py depends on moveit_commander.RobotCommander class.
00191 This case tests the integration of ROS_Client.py and RobotCommander.
00192
00193 Developers need to avoid testing moveit_commander.RobotCommander itself
00194 -- that needs to be done upstream.
00195 '''
00196
00197
00198 groupnames = self._ros.get_group_names()
00199 self.assertIsNotNone(groupnames)
00200
00201 def test_rosclient_goInitial(self):
00202 self._ros.goInitial()
00203 numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
00204 self.init_rtm_jointvals, 3)
00205 self._ros.goInitial(init_pose_type=1)
00206 numpy.testing.assert_almost_equal(self._ros.MG_BOTHARMS.get_current_joint_values(),
00207 self.init_rtm_jointvals_factory, 3)
00208
00209 def test_rosclient_go_offpose(self):
00210 self._ros.go_offpose()
00211 numpy.testing.assert_almost_equal(self._ros.MG_UPPERBODY.get_current_joint_values(),
00212 self.offpose_jointvals, 3)
00213
00214 def test_geometry_link_r4_r5(self):
00215 '''
00216 Trying to capture issues like https://github.com/tork-a/rtmros_nextage/issues/244
00217 '''
00218 TRANS_RARM4_RARM5 = [-0.047, 0.000, -0.090]
00219
00220 tflistener = tf.TransformListener()
00221 (trans, rot) = tflistener.lookupTransform("/RARM_JOINT5_Link", "/RARM_JOINT4_Link", rospy.Time(0))
00222 [self.assertAlmostEqual(v_trans, v_expected, 3) for v_trans, v_expected in zip(trans, TRANS_RARM4_RARM5)]
00223
00224
00225 if __name__ == '__main__':
00226 import rostest
00227 rostest.rosrun(_PKG, 'test_hironx_moveit_run', TestHironxMoveit)