moveit_jointplayback.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2013, SRI International
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of SRI International nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 
36 import sys
37 import copy
38 import rospy
39 import moveit_commander
40 import moveit_msgs.msg
41 import geometry_msgs.msg
42 import rospkg
43 import yaml
44 import actionlib
45 
46 from std_msgs.msg import String
47 from svenzva_msgs.msg import *
48 
50 
51  def __init__(self, filename):
52  self.robot = moveit_commander.RobotCommander()
53  self.scene = moveit_commander.PlanningSceneInterface()
54  self.group = moveit_commander.MoveGroupCommander("svenzva_arm")
55  self.diaply_pub = rospy.Publisher('/move_group/display_planned_path', moveit_msgs.msg.DisplayTrajectory, queue_size=1)
56 
57  self.gripper_client = actionlib.SimpleActionClient('/revel/gripper_action', GripperAction)
58 
59  self.setup_filesys(filename)
60 
61  self.gripper_client.wait_for_server()
62  rospy.loginfo("Found Revel gripper action server")
63 
64 
65  def print_info(self):
66 
67  ## Getting Basic Information
68  ## ^^^^^^^^^^^^^^^^^^^^^^^^^
69 
71  print "============ Reference frame: %s" % self.group.get_planning_frame()
72 
73  ## We can also print the name of the end-effector link for this group
74  print "============ Reference frame: %s" % self.group.get_end_effector_link()
75 
76  ## We can get a list of all the groups in the robot
77  print "============ Robot Groups:"
78  print self.robot.get_group_names()
79 
80  ## Sometimes for debugging it is useful to print the entire state of the
81  ## robot.
82  print "============ Printing robot state"
83  print self.robot.get_current_state()
84  print "============"
85 
86 
87  def setup_filesys(self, filename):
88  rospack = rospkg.RosPack()
89  path = rospack.get_path('svenzva_demo')
90  # load the yaml file that specifies the home position
91 
92  f = open(path+"/config/" + filename + ".yaml")
93  self.qmap = yaml.safe_load(f)
94  f.close()
95 
96 
97  def joint_playback(self, state_name):
98  self.group.clear_pose_targets()
99 
100  ## Then, we will get the current set of joint values for the group
101  group_variable_values = self.group.get_current_joint_values()
102  print "============ Joint values: ", group_variable_values
103 
104  for i,val in enumerate(self.qmap[state_name]):
105  group_variable_values[i] = val
106 
107  self.group.set_joint_value_target(group_variable_values)
108  plan2 = self.group.plan()
109  self.group.go(wait=True)
110 
111  def quit(self):
112  moveit_commander.roscpp_shutdown()
113  rospy.loginfo("STOPPING playback")
114 
115 
116 if __name__=='__main__':
117  moveit_commander.roscpp_initialize(sys.argv)
118  rospy.set_param('/move_group/trajectory_execution/allowed_start_tolerance', 0.0)
119  rospy.init_node('svenzva_moveit_joint_playback', anonymous=True)
120 
121  playback = JointPlayBack("book")
122 
123  goal = GripperGoal()
124 
125  #open gripper
126  goal.target_action = goal.OPEN
127  playback.gripper_client.send_goal(goal)
128  rospy.sleep(0.5)
129 
130  playback.joint_playback("start1")
131  rospy.sleep(3.0)
132  playback.joint_playback("start2")
133  rospy.sleep(3.0)
134  playback.joint_playback("approach3")
135  rospy.sleep(3.0)
136  playback.joint_playback("reach4")
137  rospy.sleep(3.0)
138 
139  goal.target_action = goal.CLOSE
140  goal.target_current = 700
141  playback.gripper_client.send_goal(goal)
142  rospy.sleep(2.0)
143 
144  playback.joint_playback("grab5")
145  rospy.sleep(3.0)
146 
147 
148 
149  playback.joint_playback("pullback6")
150 
151  rospy.sleep(2.0)
152  playback.joint_playback("turn7")
153  rospy.sleep(2.0)
154  playback.joint_playback("move8")
155  rospy.sleep(2.0)
156 
157  #open gripper
158  goal.target_action = goal.OPEN
159  playback.gripper_client.send_goal(goal)
160  rospy.sleep(0.5)
161 
162  playback.quit()
def print_info(self)
We can get the name of the reference frame for this robot.


svenzva_demo
Author(s): Max Svetlik
autogenerated on Wed Oct 28 2020 03:31:24