00001
00002
00003 import rospy
00004 import numpy
00005 from unittest import TestCase
00006 import logging
00007
00008 import sys
00009 from moveit_commander import RobotCommander, PlanningSceneInterface, MoveGroupCommander
00010 from moveit_msgs.msg import RobotState
00011 from moveit_msgs.msg import DisplayRobotState
00012 import geometry_msgs.msg
00013 import copy
00014
00015 PKG = "right_sr_ur10_moveit_config"
00016
00017 class TestPlanners(TestCase):
00018 """
00019 Test class for motion planners using moveit
00020 """
00021
00022 def setUp(self):
00023 group_id = str(sys.argv[1])
00024 planner_id = str(sys.argv[2])
00025
00026 rospy.init_node('moveit_test_planners', anonymous=True)
00027
00028 self.scene = PlanningSceneInterface()
00029 self.robot = RobotCommander()
00030 self.group = MoveGroupCommander(group_id)
00031 rospy.sleep(1)
00032
00033 self.group.set_planner_id(planner_id)
00034
00035
00036
00037
00038
00039
00040
00041
00042 def _add_walls_and_ground(self):
00043
00044 p = geometry_msgs.msg.PoseStamped()
00045 p.header.frame_id = self.robot.get_planning_frame()
00046
00047 p.pose.position.x = 0
00048 p.pose.position.y = 0
00049
00050 p.pose.position.z = -0.11
00051 p.pose.orientation.x = 0
00052 p.pose.orientation.y = 0
00053 p.pose.orientation.z = 0
00054 p.pose.orientation.w = 1
00055 self.scene.add_box("ground", p, (3, 3, 0.1))
00056
00057 p.pose.position.x = 0.4
00058 p.pose.position.y = 0.85
00059 p.pose.position.z = 0.4
00060 p.pose.orientation.x = 0.5
00061 p.pose.orientation.y = -0.5
00062 p.pose.orientation.z = 0.5
00063 p.pose.orientation.w = 0.5
00064 self.scene.add_box("wall_front", p, (0.8, 2, 0.01))
00065
00066 p.pose.position.x = 1.33
00067 p.pose.position.y = 0.4
00068 p.pose.position.z = 0.4
00069 p.pose.orientation.x = 0.0
00070 p.pose.orientation.y = -0.707388
00071 p.pose.orientation.z = 0.0
00072 p.pose.orientation.w = 0.706825
00073 self.scene.add_box("wall_right", p, (0.8, 2, 0.01))
00074
00075 p.pose.position.x = -0.5
00076 p.pose.position.y = 0.4
00077 p.pose.position.z = 0.4
00078 p.pose.orientation.x = 0.0
00079 p.pose.orientation.y = -0.707107
00080 p.pose.orientation.z = 0.0
00081 p.pose.orientation.w = 0.707107
00082 self.scene.add_box("wall_left", p, (0.8, 2, 0.01))
00083
00084
00085
00086 def _check_plan(self, plan):
00087 if len(plan.joint_trajectory.points) > 0:
00088
00089 return True
00090 else:
00091 return False
00092
00093 def _plan_joints(self, joints):
00094 self.group.clear_pose_targets()
00095 group_variable_values = self.group.get_current_joint_values()
00096 group_variable_values[0:6] = joints[0:6]
00097 self.group.set_joint_value_target(group_variable_values)
00098
00099
00100
00101
00102 plan = self.group.plan()
00103 return self._check_plan(plan)
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 def test_trajectories_empty_environment(self):
00118
00119 joints = [-0.000938865682661, -1.98674414251, 2.19198020153, 0.581030868484, -0.00190057368648, -0.785934528975]
00120 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00121
00122
00123 joints = [-1.67232, -2.39104, 0.264862, 0.43346, 2.44148, 2.48026]
00124 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00125
00126
00127
00128 joints = [-0.000348431194526, 0.397651011661, 0.0766181197394, -0.600353691727, -0.000441966540076, 0.12612019707]
00129 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00130
00131
00132 joints = [0.146182953165, -2.6791929848, -0.602721109682, -3.00575848765, 0.146075718452, 0.00420656698366]
00133 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00134
00135
00136 joints = [ 1.425279839, -0.110370375874, -1.52548746261, -1.50659865247, -1.42700242769, 3.1415450794]
00137 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00138
00139
00140 joints = [1.57542451065, 3.01734161219, 2.01043257686, -1.14647092839, 0.694689321451, -0.390769365032]
00141 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00142
00143
00144 joints = [-0.289797803762, 2.37263860495, 2.69118483159, 1.65486712181, 1.04235601797, -1.69730925867]
00145 self.assertFalse(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00146
00147 def test_waypoins(self):
00148
00149 joints = [-0.324590029242, -1.42602359749, -1.02523472017, -0.754761892979, 0.344227622185, -3.03250264451]
00150 current = RobotState()
00151 current.joint_state.name = self.robot.get_current_state().joint_state.name
00152 current_joints = list(self.robot.get_current_state().joint_state.position)
00153 current_joints[0:6] = joints
00154 current.joint_state.position = current_joints
00155
00156
00157 self.group.set_start_state(current)
00158
00159 waypoints = []
00160
00161 initial_pose = self.group.get_current_pose().pose
00162
00163 initial_pose.position.x = -0.301185959729
00164 initial_pose.position.y = 0.377069787724
00165 initial_pose.position.z = 1.20681710541
00166 initial_pose.orientation.x = 0.0207499700474
00167 initial_pose.orientation.y = -0.723943002716
00168 initial_pose.orientation.z = -0.689528413407
00169 initial_pose.orientation.w = 0.00515118111221
00170
00171
00172 waypoints.append(initial_pose)
00173
00174
00175 wpose = geometry_msgs.msg.Pose()
00176 wpose.orientation = waypoints[0].orientation
00177 wpose.position.x = waypoints[0].position.x
00178 wpose.position.y = waypoints[0].position.y
00179 wpose.position.z = waypoints[0].position.z - 0.20
00180 waypoints.append(copy.deepcopy(wpose))
00181
00182
00183 wpose.position.y += 0.20
00184 waypoints.append(copy.deepcopy(wpose))
00185
00186
00187 wpose.position.x -= 0.20
00188 waypoints.append(copy.deepcopy(wpose))
00189
00190
00191 wpose= waypoints[0]
00192 waypoints.append(copy.deepcopy(wpose))
00193
00194 (plan3, fraction) = self.group.compute_cartesian_path(waypoints, 0.01, 0.0)
00195 self.assertTrue(self._check_plan(plan3) and fraction > 0.8,msg="Unable to plan waypoints")
00196
00197 def test_trajectories_with_walls_and_ground(self):
00198 self._add_walls_and_ground()
00199
00200
00201 joints = [0.302173213174, 0.192487443763, -1.94298265002, 1.74920382275, 0.302143499777, 0.00130280337897]
00202 self.assertFalse(self._plan_joints(joints),msg="Able to plan to: "+str(joints))
00203
00204
00205 joints = [3.84825722288e-05, 0.643694953509, -1.14391175311, 1.09463824437, 0.000133883149666, -0.594498939239]
00206 self.assertFalse(self._plan_joints(joints),msg="Able to plan to: "+str(joints))
00207
00208
00209 joints = [1.22262556307, -2.22935714353, 1.94043810556, 0.288788732588, 1.22183316693, 0.0873097240233]
00210 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00211
00212
00213 joints =[0.354696232081, -0.982224980654, 0.908055961723, -1.92328051116, -1.3516255551, 2.8225061435]
00214 self.assertTrue(self._plan_joints(joints),msg="Unable to plan to: "+str(joints))
00215
00216 if __name__ == "__main__":
00217 import rostest
00218 rostest.rosrun(PKG, "test_planners", TestPlanners)
00219