forked from lihuang3/ur5_ROS-Gazebo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ur5_gripper.py
executable file
·238 lines (208 loc) · 7.36 KB
/
ur5_gripper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/env python
import rospy, sys, numpy as np
import geometry_msgs.msg
import moveit_msgs.msg
from ur5_notebook.msg import Tracker
from std_msgs.msg import Header
from std_msgs.msg import Bool
from std_srvs.srv import Empty
def gripper_status(msg):
if msg.data:
print('gripper status = {}'.format(msg.data))
def gripper_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper1_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper1/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper1/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper2_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper2/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper2/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper3_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper3/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper3/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper4_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper4/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper4/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper5_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper5/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper5/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper6_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper6/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper6/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper7_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper7/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper7/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper8_on():
# Wait till the srv is available
rospy.wait_for_service('/ur5/vacuum_gripper8/on')
try:
# Create a handle for the calling the srv
turn_on = rospy.ServiceProxy('/ur5/vacuum_gripper8/on', Empty)
# Use this handle just like a normal function and call it
resp = turn_on()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper_off():
rospy.wait_for_service('/ur5/vacuum_gripper/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper1_off():
rospy.wait_for_service('/ur5/vacuum_gripper1/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper1/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper2_off():
rospy.wait_for_service('/ur5/vacuum_gripper2/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper2/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper3_off():
rospy.wait_for_service('/ur5/vacuum_gripper3/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper3/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper4_off():
rospy.wait_for_service('/ur5/vacuum_gripper4/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper4/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper5_off():
rospy.wait_for_service('/ur5/vacuum_gripper5/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper5/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper6_off():
rospy.wait_for_service('/ur5/vacuum_gripper6/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper6/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper7_off():
rospy.wait_for_service('/ur5/vacuum_gripper7/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper7/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def gripper8_off():
rospy.wait_for_service('/ur5/vacuum_gripper8/off')
try:
turn_off = rospy.ServiceProxy('/ur5/vacuum_gripper8/off', Empty)
resp = turn_off()
return resp
except rospy.ServiceException, e:
print "Service call failed: %s" % e
def trigger(msg):
gripper_trigger = msg.flag2
if gripper_trigger:
gripper_on()
gripper1_on()
gripper2_on()
gripper3_on()
gripper4_on()
gripper5_on()
gripper6_on()
gripper7_on()
gripper8_on()
else:
gripper_off()
gripper1_off()
gripper2_off()
gripper3_off()
gripper4_off()
gripper5_off()
gripper6_off()
gripper7_off()
gripper8_off()
rospy.init_node("ur5_gripper", anonymous=False)
gripper_status_sub = rospy.Subscriber('/ur5/vacuum_gripper/grasping', Bool, gripper_status, queue_size=1)
cxy_sub = rospy.Subscriber('cxy1', Tracker, trigger, queue_size=1)
rospy.spin()