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 time
00042 import unittest
00043
00044 from geometry_msgs.msg import Pose, PoseStamped
00045 from moveit_commander import MoveGroupCommander, conversions
00046 import rospy
00047
00048 _PKG = 'hironx_ros_bridge'
00049 _SEC_WAIT_BETWEEN_TESTCASES = 3
00050
00051 class TestHironxMoveit(unittest.TestCase):
00052
00053 def __init__(self, *args, **kwargs):
00054 super(TestHironxMoveit, self).__init__(*args, **kwargs)
00055
00056 @classmethod
00057 def setUpClass(self):
00058
00059 rospy.init_node("test_hironx_moveit")
00060
00061 self.rarm = MoveGroupCommander("right_arm")
00062 self.larm = MoveGroupCommander("left_arm")
00063 self.botharms = MoveGroupCommander("both_arm")
00064
00065
00066 safe_kinematicsolver = "RRTConnectkConfigDefault"
00067 self.larm.set_planner_id(safe_kinematicsolver)
00068 self.rarm.set_planner_id(safe_kinematicsolver)
00069 self.botharms.set_planner_id(safe_kinematicsolver)
00070
00071 self._botharms_joints = ['LARM_JOINT0', 'LARM_JOINT1',
00072 'LARM_JOINT2', 'LARM_JOINT3',
00073 'LARM_JOINT4', 'LARM_JOINT5',
00074 'RARM_JOINT0', 'RARM_JOINT1',
00075 'RARM_JOINT2', 'RARM_JOINT3',
00076 'RARM_JOINT4', 'RARM_JOINT5']
00077
00078 self.rarm_current_pose = self.rarm.get_current_pose().pose
00079 self.larm_current_pose = self.larm.get_current_pose().pose
00080
00081
00082 self.init_rtm_jointvals = [0.010471975511965976, 0.0, -1.7453292519943295, -0.26529004630313807, 0.16406094968746698, -0.05585053606381855, -0.010471975511965976, 0.0, -1.7453292519943295, 0.26529004630313807, 0.16406094968746698, 0.05585053606381855]
00083
00084
00085 self.banzai_pose_larm_goal = [-0.0280391167993, 0.558512828409, 0.584801820449, 0.468552399035, -0.546097642377, -0.449475560632, 0.529346516701]
00086 self.banzai_pose_rarm_goal = [0.0765219167208, -0.527210000725, 0.638387081642, -0.185009037721, -0.683111796219, 0.184872589841, 0.681873929223]
00087 self.banzai_jointvals_goal = [1.3591412928962834, -1.5269810342586994, -1.5263864987632225, -0.212938998306429, -0.19093239258017988, -1.5171864827145887,
00088 -0.7066724299606867, -1.9314110634425135, -1.4268663042616962, 1.0613942164863952, 0.9037643195141568, 1.835342100423069]
00089
00090 def _set_target_random(self):
00091 '''
00092 @type self: moveit_commander.MoveGroupCommander
00093 @param self: In this particular test script, the argument "self" is either
00094 'rarm' or 'larm'.
00095 '''
00096 global current, current2, target
00097 current = self.get_current_pose()
00098 print "*current*", current
00099 target = self.get_random_pose()
00100 print "*target*", target
00101 self.set_pose_target(target)
00102 self.go()
00103 current2 = self.get_current_pose()
00104 print "*current2*", current2
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 def test_set_pose_target_rpy(self):
00118
00119 target = [0.2035, -0.5399, 0.0709, 0,-1.6,0]
00120 self.rarm.set_pose_target(target)
00121 self.rarm.plan()
00122 self.assertTrue(self.rarm.go())
00123
00124 def test_set_pose_target_quarternion(self):
00125 target = [0.2035, -0.5399, 0.0709, 0.000427, 0.000317, -0.000384, 0.999999]
00126 self.rarm.set_pose_target(target)
00127 self.rarm.plan()
00128 self.assertTrue(self.rarm.go())
00129
00130 def test_botharms_compare_joints(self):
00131 '''Comparing joint names.'''
00132 self.assertItemsEqual(self.botharms.get_joints(), self._botharms_joints)
00133
00134 def test_botharms_get_joint_values(self):
00135 '''
00136 "both_arm" move group can't set pose target for now (July, 2015) due to
00137 missing eef in the moveit config. Here checking if MoveGroup.get_joint_values is working.
00138 '''
00139
00140 self.larm.set_pose_target(self.banzai_pose_larm_goal)
00141 self.larm.plan()
00142 self.larm.go()
00143 self.rarm.set_pose_target(self.banzai_pose_rarm_goal)
00144 self.rarm.plan()
00145 self.rarm.go()
00146
00147
00148
00149
00150
00151
00152
00153 numpy.testing.assert_almost_equal(self.botharms.get_current_joint_values(), self.banzai_jointvals_goal, 2)
00154
00155 def test_botharms_set_named_target(self):
00156 '''
00157 Test if moveit_commander.set_named_target brings the arms to the init_rtm pose defined in HiroNx.srdf.
00158 '''
00159
00160 self.larm.set_pose_target(self.banzai_pose_larm_goal)
00161 self.larm.plan()
00162 self.larm.go()
00163 self.rarm.set_pose_target(self.banzai_pose_rarm_goal)
00164 self.rarm.plan()
00165 self.rarm.go()
00166
00167 self.botharms.set_named_target('init_rtm')
00168 self.botharms.plan()
00169 self.botharms.go()
00170
00171
00172
00173 numpy.testing.assert_almost_equal(self.botharms.get_current_joint_values(), self.init_rtm_jointvals, 3)
00174
00175
00176
00177
00178
00179 if __name__ == '__main__':
00180 import rostest
00181 rostest.rosrun(_PKG, 'test_hironx_moveit_run', TestHironxMoveit)