pick_and_place.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2017 Svenzva Robotics
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of University of Arizona nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 
35 import rospy
36 import rospkg
37 import actionlib
38 import yaml
39 from std_msgs.msg import Bool
40 from svenzva_msgs.msg import *
41 from svenzva_msgs.srv import *
42 from trajectory_msgs.msg import JointTrajectoryPoint
43 from control_msgs.msg import JointTrajectoryAction, JointTrajectoryGoal, FollowJointTrajectoryAction, FollowJointTrajectoryGoal
44 from sensor_msgs.msg import JointState
45 from std_msgs.msg import Int32
46 
47 """
48 Plays back poses from an interaction file and controls the gripper as an Action
49 
50 """
51 
52 
53 #sends a j6 command as specified in the given yaml file.
54 #files must exist in the config directory of the demo package
55 def js_playback(filename, state_name):
56  global qmap, fkine
57 
58  #2 - execute action on yaml file
59  req = SvenzvaJointGoal()
60  if len(qmap[state_name]) < 6:
61  rospy.logerr("Could not find specified state. Configuration file ill-formed or missing. Aborting.")
62  return
63  req.positions = qmap[state_name]
64 
65  rospy.loginfo("Sending state command...")
66  fkine.send_goal_and_wait(req)
67 
68 def js_cb(data):
69  global joint_states
70  joint_states = data
71 
72 def setup():
73  rospy.init_node('svenzva_pick_place_demo', anonymous=False)
74  global qmap, fkine, joint_states
75 
76  record = True
77  joint_states = JointState()
78  gripper_client = actionlib.SimpleActionClient('/revel/gripper_action', GripperAction)
79  joint_states_sub = rospy.Subscriber('/joint_states', JointState, js_cb, queue_size=1)
80  #home_arm = rospy.ServiceProxy('home_arm_service', HomeArm)
81  fkine = actionlib.SimpleActionClient('/svenzva_joint_action', SvenzvaJointAction)
82  fkine.wait_for_server()
83  rospy.loginfo("Found Trajectory action server")
84 
85  gripper_client.wait_for_server()
86  rospy.loginfo("Found Revel gripper action server")
87 
88  goal = GripperGoal()
89 
90  filename = "book" #"pnp_demo"
91  fname=""
92  rospack = rospkg.RosPack()
93  path = rospack.get_path('svenzva_demo')
94  # load the yaml file that specifies the home position
95 
96  rospy.sleep(1)
97  if record:
98 
99  while(not rospy.is_shutdown()):
100  raw_input("Press Enter to save the current joint state to file...")
101  name = raw_input("What to name this point: ")
102  f = open(path+"/config/" + filename + ".yaml", "a")
103  ar = []
104  ar.append(joint_states.position[0])
105  ar.append(joint_states.position[1])
106  ar.append(joint_states.position[2])
107  ar.append(joint_states.position[3])
108  ar.append(joint_states.position[4])
109  ar.append(joint_states.position[5])
110  f.write(name + ": " + str(ar) + "\n")
111  f.close()
112 
113  f = open(path+"/config/" + filename + ".yaml")
114  qmap = yaml.safe_load(f)
115  f.close()
116 
117  #go to first position
118  js_playback(fname, "video_home")
119  rospy.sleep(2.0)
120 
121  #open gripper
122  goal.target_action = goal.OPEN
123  gripper_client.send_goal(goal)
124  rospy.sleep(0.5)
125 
126  js_playback(fname, "einstein_a1")
127  rospy.sleep(0.5)
128 
129  js_playback(fname, "einstein_p1")
130  rospy.sleep(0.5)
131 
132  goal.target_action = goal.CLOSE
133  goal.target_current = 50
134  gripper_client.send_goal(goal)
135  rospy.sleep(1.0)
136 
137  js_playback(fname, "einstein_i1")
138  #rospy.sleep(1.0)
139 
140  js_playback(fname, "einstein_i2")
141  #rospy.sleep(1.0)
142 
143 
144  js_playback(fname, "einstein_p2")
145  #rospy.sleep(1.0)
146 
147  goal.target_action = goal.OPEN
148  gripper_client.send_goal(goal)
149  rospy.sleep(0.25)
150 
151  js_playback(fname, "einstein_a2")
152  rospy.sleep(0.1)
153 
154  js_playback(fname, "einstein_i3")
155  rospy.sleep(0.1)
156 
157  js_playback(fname, "video_home")
158  rospy.sleep(2.0)
159 
160 
161  """
162  #open gripper
163  goal.target_action = gripper.OPEN
164  gripper_client.send_goal(goal)
165 
166  rospy.sleep(2.0)
167  #go forward to approach point
168  js_playback(fname, "a1")
169 
170  #close gripper
171  goal.target_action = gripper.CLOSE
172  goal.target_current = 50
173  gripper_client.send_goal(goal)
174  rospy.sleep(2.0)
175 
176  #point 2
177  js_playback(fname, "p2")
178 
179  goal.target_action = gripper.OPEN
180  gripper_client.send_goal(goal)
181 
182  rospy.sleep(2.0)
183  #point 2
184  js_playback(fname, "home")
185  rospy.loginfo("Arm homed. Demo complete")
186  """
187 
188 
189 if __name__ == '__main__':
190  try:
191  setup()
192  except rospy.ROSInterruptException:
193  pass
194 
195 
def js_playback(filename, state_name)
def js_cb(data)


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