41 from geometry_msgs.msg
import Pose
42 from moveit_commander
import MoveGroupCommander, MoveItCommanderException, RobotCommander
43 from moveit_msgs.msg
import RobotTrajectory
47 from tf.transformations
import quaternion_from_euler
50 _KINEMATICSOLVER_SAFE =
'RRTConnectkConfigDefault' 52 _MOVEGROUP_NAME_TORSO =
'torso' 53 _JOINTNAMES_TORSO = [
'CHEST_JOINT0']
55 _MOVEGROUP_ATTR_TORSO = [_MOVEGROUP_NAME_TORSO, _JOINTNAMES_TORSO]
57 _MOVEGROUP_NAME_LEFTARM =
'left_arm' 58 _JOINTNAMES_LEFTARM = [
'LARM_JOINT0',
'LARM_JOINT1',
'LARM_JOINT2',
'LARM_JOINT3',
'LARM_JOINT4',
'LARM_JOINT5']
59 _MOVEGROUP_ATTR_LEFTARM = [_MOVEGROUP_NAME_LEFTARM, _JOINTNAMES_LEFTARM]
61 _MOVEGROUP_NAME_RIGHTARM =
'right_arm' 62 _JOINTNAMES_RIGHTARM = [
'RARM_JOINT0',
'RARM_JOINT1',
'RARM_JOINT2',
'RARM_JOINT3',
'RARM_JOINT4',
'RARM_JOINT5']
63 _MOVEGROUP_ATTR_RIGHTARM = [_MOVEGROUP_NAME_RIGHTARM, _JOINTNAMES_RIGHTARM]
65 _MOVEGROUP_NAME_LEFTARM_TORSO =
'left_arm_torso' 66 _JOINTNAMES_LEFTARM_TORSO = _JOINTNAMES_TORSO +_JOINTNAMES_LEFTARM
67 _MOVEGROUP_ATTR_LEFTARM_TORSO = [_MOVEGROUP_NAME_LEFTARM_TORSO, _JOINTNAMES_LEFTARM_TORSO]
69 _MOVEGROUP_NAME_RIGHTARM_TORSO =
'right_arm_torso' 70 _JOINTNAMES_RIGHTARM_TORSO = _JOINTNAMES_TORSO + _JOINTNAMES_RIGHTARM
71 _MOVEGROUP_ATTR_RIGHTARM_TORSO = [_MOVEGROUP_NAME_RIGHTARM_TORSO, _JOINTNAMES_RIGHTARM_TORSO]
73 _MOVEGROUP_NAME_LEFTHAND =
'left_hand' 74 _JOINTNAMES_LEFTHAND = [
'LARM_JOINT5']
75 _MOVEGROUP_ATTR_LEFTHAND = [_MOVEGROUP_NAME_LEFTHAND, _JOINTNAMES_LEFTHAND]
77 _MOVEGROUP_NAME_RIGHTHAND =
'right_hand' 78 _JOINTNAMES_RIGHTHAND = [
'RARM_JOINT5']
79 _MOVEGROUP_ATTR_RIGHTHAND = [_MOVEGROUP_NAME_RIGHTHAND, _JOINTNAMES_RIGHTHAND]
81 _MOVEGROUP_NAME_HEAD =
'head' 82 _JOINTNAMES_HEAD = [
'HEAD_JOINT0',
'HEAD_JOINT1']
83 _MOVEGROUP_ATTR_HEAD = [_MOVEGROUP_NAME_HEAD, _JOINTNAMES_HEAD]
85 _MOVEGROUP_NAME_BOTHARMS =
'botharms' 87 _JOINTNAMES_BOTHARMS = _JOINTNAMES_LEFTARM + _JOINTNAMES_RIGHTARM
88 _MOVEGROUP_ATTR_BOTHARMS = [_MOVEGROUP_NAME_BOTHARMS, _JOINTNAMES_BOTHARMS]
90 _MOVEGROUP_NAME_UPPERBODY =
'upperbody' 91 _JOINTNAMES_UPPERBODY = _JOINTNAMES_TORSO + _JOINTNAMES_HEAD + _JOINTNAMES_LEFTARM + _JOINTNAMES_RIGHTARM
92 _MOVEGROUP_ATTR_UPPERBODY = [_MOVEGROUP_NAME_UPPERBODY, _JOINTNAMES_UPPERBODY]
95 _MOVEGROUP_NAMES = sorted([_MOVEGROUP_NAME_TORSO, _MOVEGROUP_NAME_HEAD,
96 _MOVEGROUP_NAME_LEFTARM, _MOVEGROUP_NAME_RIGHTARM,
97 _MOVEGROUP_NAME_LEFTARM_TORSO, _MOVEGROUP_NAME_RIGHTARM_TORSO,
98 _MOVEGROUP_NAME_LEFTHAND, _MOVEGROUP_NAME_RIGHTHAND,
99 _MOVEGROUP_NAME_BOTHARMS, _MOVEGROUP_NAME_UPPERBODY])
100 _MOVEGROUP_ATTRS = [_MOVEGROUP_ATTR_TORSO, _MOVEGROUP_ATTR_HEAD,
101 _MOVEGROUP_ATTR_LEFTARM, _MOVEGROUP_ATTR_RIGHTARM,
102 _MOVEGROUP_ATTR_LEFTARM_TORSO, _MOVEGROUP_ATTR_RIGHTARM_TORSO,
103 _MOVEGROUP_ATTR_LEFTHAND, _MOVEGROUP_ATTR_RIGHTHAND,
104 _MOVEGROUP_ATTR_BOTHARMS, _MOVEGROUP_ATTR_UPPERBODY]
106 _TARGETPOSE_LEFT = []
118 rospy.init_node(
'test_moveit')
126 mg = MoveGroupCommander(mg_attr[0])
130 mg.allow_replanning(
True)
132 mg.set_planning_time(30.0)
142 @return: Pose() with some values populated in. 145 pose_target.orientation.x = 0.00
146 pose_target.orientation.y = 0.00
147 pose_target.orientation.z = -0.20
148 pose_target.orientation.w = 0.98
149 pose_target.position.x = 0.18
150 pose_target.position.y = -0.00
151 pose_target.position.z = 0.94
156 Run `clear_pose_targets` at the beginning. 157 @rtype: RobotTrajectory http://docs.ros.org/api/moveit_msgs/html/msg/RobotTrajectory.html 159 self._mvgroup.clear_pose_targets()
162 self._mvgroup.set_pose_target(pose_target)
163 plan = self._mvgroup.plan()
164 rospy.loginfo(
' plan: {}'.format(plan))
168 '''Check if the defined move groups are loaded.''' 169 self.assertEqual(self.
_MOVEGROUP_NAMES, sorted(self.robot.get_group_names()))
172 '''Check if the defined joints in a move group are loaded.''' 174 self.assertEqual(mg_attr[1],
175 sorted(mg_attr[2].get_active_joints()))
179 @type movegroup: MoveGroupCommander 180 @rtype: RobotTrajectory http://docs.ros.org/api/moveit_msgs/html/msg/RobotTrajectory.html 182 movegroup.clear_pose_targets()
193 pose_target.orientation.x = -0.000556712307053
194 pose_target.orientation.y = -0.706576742941
195 pose_target.orientation.z = -0.00102461782513
196 pose_target.orientation.w = 0.707635461636
197 pose_target.position.x = 0.325471850974-0.01
198 pose_target.position.y = 0.182271241593+0.3
199 pose_target.position.z = 0.0676272396419+0.3
201 movegroup.set_pose_target(pose_target)
202 plan = movegroup.plan()
203 rospy.loginfo(
'Plan: {}'.format(plan))
207 '''Evaluate plan (RobotTrajectory)''' 212 self.assertNotEqual(0, plan.joint_trajectory.points)
216 Evaluate Plan and Execute works. 217 Currently no value checking is done (, which is better to be implemented) 223 self.assertTrue(mvgroup.go()
or mvgroup.go()
or mvgroup.go())
227 Check if http://wiki.ros.org/rtmros_nextage/Tutorials/Programming_Hiro_NEXTAGE_OPEN_MOVEIT works 233 rarm_initial_pose = rarm.get_current_pose().pose
234 print "=" * 10,
" Printing Right Hand initial pose: " 235 print rarm_initial_pose
238 larm_initial_pose = larm.get_current_pose().pose
239 print "=" * 10,
" Printing Left Hand initial pose: " 240 print larm_initial_pose
242 target_pose_r = Pose()
243 target_pose_r.position.x = 0.325471850974-0.01
244 target_pose_r.position.y = -0.182271241593-0.3
245 target_pose_r.position.z = 0.0676272396419+0.3
246 target_pose_r.orientation.x = -0.000556712307053
247 target_pose_r.orientation.y = -0.706576742941
248 target_pose_r.orientation.z = -0.00102461782513
249 target_pose_r.orientation.w = 0.707635461636
250 rarm.set_pose_target(target_pose_r)
252 print "=" * 10,
" plan1 ..." 253 self.assertTrue(rarm.go()
or rarm.go()
or rarm.go())
257 target_pose_r.position.x,
258 -target_pose_r.position.y,
259 target_pose_r.position.z,
260 target_pose_r.orientation.x,
261 target_pose_r.orientation.y,
262 target_pose_r.orientation.z,
263 target_pose_r.orientation.w
265 larm.set_pose_target(target_pose_l)
267 print "=" * 10,
" plan2 ..." 268 self.assertTrue(larm.go()
or larm.go()
or larm.go())
272 rarm.clear_pose_targets()
275 target_pose_r.position.x = 0.221486843301
276 target_pose_r.position.y = -0.0746407547512
277 target_pose_r.position.z = 0.642545484602
278 target_pose_r.orientation.x = 0.0669013615474
279 target_pose_r.orientation.y = -0.993519060661
280 target_pose_r.orientation.z = 0.00834224628291
281 target_pose_r.orientation.w = 0.0915122442864
282 rarm.set_pose_target(target_pose_r)
284 print "=" * 10,
" plan3..." 285 self.assertTrue(rarm.go()
or rarm.go()
or rarm.go())
288 print "=" * 10,
"Initial pose ..." 289 rarm.set_pose_target(rarm_initial_pose)
290 larm.set_pose_target(larm_initial_pose)
291 self.assertTrue(rarm.go()
or rarm.go()
or rarm.go())
292 self.assertTrue(larm.go()
or larm.go()
or larm.go())
297 target_pose_r = Pose()
298 target_pose_l = Pose()
299 q = quaternion_from_euler(0, -math.pi/2,0)
300 target_pose_r.position.x = 0.3
301 target_pose_r.position.y = 0.1
302 target_pose_r.position.z = 0.0
303 target_pose_r.orientation.x = q[0]
304 target_pose_r.orientation.y = q[1]
305 target_pose_r.orientation.z = q[2]
306 target_pose_r.orientation.w = q[3]
307 target_pose_l.position.x = 0.3
308 target_pose_l.position.y =-0.1
309 target_pose_l.position.z = 0.3
310 target_pose_l.orientation.x = q[0]
311 target_pose_l.orientation.y = q[1]
312 target_pose_l.orientation.z = q[2]
313 target_pose_l.orientation.w = q[3]
314 botharms.set_pose_target(target_pose_r,
'RARM_JOINT5_Link')
315 botharms.set_pose_target(target_pose_l,
'LARM_JOINT5_Link')
316 self.assertTrue(botharms.go()
or botharms.go()
or botharms.go())
319 target_pose_r.position.x = 0.3
320 target_pose_r.position.y =-0.2
321 target_pose_r.position.z = 0.0
322 target_pose_l.position.x = 0.3
323 target_pose_l.position.y = 0.2
324 target_pose_l.position.z = 0.0
325 botharms.set_pose_target(target_pose_r,
'RARM_JOINT5_Link')
326 botharms.set_pose_target(target_pose_l,
'LARM_JOINT5_Link')
327 self.assertTrue(botharms.go()
or botharms.go()
or botharms.go())
329 if __name__ ==
'__main__':
331 rostest.rosrun(
'nextage_ros_bridge',
'test_moveit', TestDualarmMoveit)
def test_plan_success(self)
string _KINEMATICSOLVER_SAFE
def _plan_leftarm(self, movegroup)
def test_list_movegroups(self)
list _MOVEGROUP_ATTR_RIGHTARM
def test_planandexecute(self)
def test_left_and_right_plan(self)
def _set_sample_pose(self)
def test_list_activejoints(self)
list _MOVEGROUP_ATTR_LEFTARM
def test_botharms_plan(self)
list _MOVEGROUP_ATTR_BOTHARMS