nextage_ros_playpattern.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2017, Tokyo Opensource Robotics Kyokai Association
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Author: Yosuke Yamamoto
37 
38 import rospy
39 import geometry_msgs.msg
40 import copy
41 import tf
42 
43 from moveit_commander import MoveGroupCommander
44 
45 import nextage_rtm_playpattern as nxtpp
46 
47 
48 def setTargetPoseSequenceMoveIt(limb, pos_list, rpy_list, tm_list):
49  '''
50  Create a array of limb joint angles for the each waypoints
51  from data of the end effector postions and postures
52  using MoveIt!.
53 
54  @type limb : str
55  @param limb : limb to create a pattern, right arm 'rarm' or left arm 'larm'
56  @type pos_list : [[float,float,float],[float,float,float],...]
57  @param pos_list : Array of end effector positions (x,y,z) [m]
58  @type rpy_list : [[float,float,float],[float,float,float],...]
59  @param rpy_list : Array of end effector postures (r,p,y) [m]
60  @type tm_list : [float,float,...]
61  @param tm_list : Array of motion time lengths of the each pose [s]
62 
63  @rtype : RobotTrajectory, float
64  @return : Plan of limb waypoints motion and fraction of the path achieved as described by the waypoints
65  '''
66  wpose = geometry_msgs.msg.Pose()
67  waypoints = []
68 
69  for pos, rpy, tm in zip(pos_list, rpy_list, tm_list):
70  quaternion = tf.transformations.quaternion_from_euler(rpy[0], rpy[1], rpy[2])
71  wpose.position.x = pos[0]
72  wpose.position.y = pos[1]
73  wpose.position.z = pos[2]
74  wpose.orientation.x = quaternion[0]
75  wpose.orientation.y = quaternion[1]
76  wpose.orientation.z = quaternion[2]
77  wpose.orientation.w = quaternion[3]
78  waypoints.append(copy.deepcopy(wpose))
79 
80  (pln, frc) = limb.compute_cartesian_path(
81  waypoints, # waypoints to follow
82  0.01, # eef_step
83  0.0) # jump_threshold
84 
85  return pln, frc
86 
87 
88 if __name__ == '__main__':
89  '''
90  Main sequence for moving at waypoints
91  using MoveIt!.
92  '''
93  rospy.init_node('commander_example', anonymous=True)
94 
95  limb_name = "left_arm" # Limb 'right_arm', 'left_arm'
96  group = MoveGroupCommander(limb_name)
97 
98  rarm_initial_pose = group.get_current_pose().pose
99  rospy.loginfo("Got Initial Pose \n{}".format(rarm_initial_pose))
100 
101  pose_target = geometry_msgs.msg.Pose()
102  pose_target = copy.deepcopy(rarm_initial_pose)
103 
104  positions_arm = [] # All elements are lists. E.g. pos1 = [x1, y1, z1]
105  rpys_arm = [] # All elements are lists. E.g. rpy1 = [r1, p1, y1]
106  time_list = [] # Time list [t1, t2, t3,...]
107 
108  # Rectangular Positions, RPYs, Time List
109  rect_xyzs = nxtpp.rectangularPositions(dp_a=[0.25, 0.0, 0.1], dp_b=[0.45, 0.2, 0.1])
110  rect_rpys = nxtpp.samePostureRPY([-3.073437, -1.569023, 3.073247], len(rect_xyzs))
111  rect_time = nxtpp.equalTimeList(10.0, len(rect_xyzs))
112 
113  # Circular Positions, RPYs, Time List
114  circ_xyzs = nxtpp.circularPositions(center=[0.35, 0.1, 0.1], radius=0.1 ,steps=12)
115  circ_rpys = nxtpp.samePostureRPY([-3.073437, -1.569023, 3.073247], len(circ_xyzs))
116  circ_time = nxtpp.equalTimeList(10.0, len(circ_xyzs))
117 
118  # Adjust Transition Time
119  rect_time[0] += 1.0
120  circ_time[0] += 1.0
121 
122  # Combine Patterns
123  positions_arm = rect_xyzs + circ_xyzs
124  rpys_arm = rect_rpys + circ_rpys
125  time_list = rect_time + circ_time
126 
127  print('Limb: %s' % limb_name)
128  print('Positions (%d): %s' % (len(positions_arm), positions_arm))
129  print('RPY Pattern (%d): %s' % (len(rpys_arm), rpys_arm))
130  print('Time List (%d): %s' % (len(time_list), time_list))
131 
132  # plan waypoints
133  rospy.loginfo("Planing Waypoints")
134  plan, flaction = setTargetPoseSequenceMoveIt(group, positions_arm, rpys_arm, time_list)
135 
136  # wait for playing the plan on MoveIt
137  rospy.loginfo("Waiting while the plan is visualized on RViz")
138  rospy.sleep(20)
139 
140  # execute the plan
141  rospy.loginfo("Execute!!")
142  group.execute(plan)
143  rospy.loginfo("Executiion Done")
144  rospy.sleep(5)
145 
146  # move to the initial pose
147  rospy.loginfo("Move to Initial Pose")
148  pose_target = copy.deepcopy(rarm_initial_pose)
149  rospy.loginfo("set target to {}".format(pose_target))
150  group.set_pose_target(pose_target)
151  plan = group.plan()
152  ret = group.go()
def setTargetPoseSequenceMoveIt(limb, pos_list, rpy_list, tm_list)


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47