-
Notifications
You must be signed in to change notification settings - Fork 3
/
arm_project_test.py
executable file
·277 lines (236 loc) · 9.75 KB
/
arm_project_test.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
##!/usr/bin/env python
#import roslib; roslib.load_manifest('trajectory_planner')
#import rospy
#import threading
#from trajectory_planner import *
#from HaoUtil import *
#key_hole_found = False
#def main():
# global global_data
# global_data, ftm, tm = start()
# rospy.loginfo('initialized')
# move_forward_to_contact(global_data, 0.05)
#def ip_thread():
# from IPython.Shell import IPShellEmbed
# ipshell = IPShellEmbed(argv='',banner = 'OpenRAVE Dropping into IPython, variables:' +
# 'env, robot',exit_msg = 'Leaving Interpreter and ' +
# 'closing program.')
# ipshell(local_ns=locals())
#def GrabKey():
# MoveHandSrv(1,array([1.6,1.6,1.65,1.57]))
# raw_input('Press enter to try with pelican case collisions turned off ...')
# MoveHandSrv(1,array([1.8,1.8,1.65,1.57]))
# pdb.set_trace()
#def InsertKey():
# '''
# move left and right
# move up and down
# push
# '''
# vdist = 0.002
# hdist = 0.002
# for i in range(5):
# #pdb.set_trace()
# #hit to the surface again
# #GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.001, 50, False)
# #move down
# distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([0,1,0]), array([0,0,-1]), 'PALM', vdist, 50, 20, False)
# if isMissed:
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.02, 200, False)
# hole_localized = True
# break
#
# #move to the right
# distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([1,0,0]), array([0,0,-1]), 'PALM', hdist, 50, 20, False)
# if isMissed:
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.02, 200, False)
# hole_localized = True
# break
#
# #hit to the surface again
# #GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.001, 50, False)
# #move up
# distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([0,-1,0]), array([0,0,-1]), 'PALM', vdist, 50, 20, False)
# if isMissed:
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.02, 200, False)
# hole_localized = True
# break
#
# #move to the left
# distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([-1,0,0]), array([0,0,-1]), 'PALM', hdist, 50, 20, False)
# if isMissed:
# GuardedMoveUntilHit(global_data, array([0,0,-1]),'PALM', 0.02, 200, False)
# hole_localized = True
#
#def LocalizeHole( vlevel, hlevel ):
# #move up and left
# MoveHand(global_data, array([0,-1,0]), 'PALM', vlevel/2)
# #we do not want to move to the left a lot
# MoveHand(global_data, array([-1,0,0]), 'PALM', hlevel/4)
#
# #hit to the surface of the key hole
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.1, 30)
# #scan using move until miss primitive
# hole_localized = False
# num_steps = 3
# for i in range(num_steps):
# #move down
# distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([0,1,0]), array([0,0,-1]), 'PALM', vlevel, 50, 20, False)
# if isMissed:
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.01, 100, False)
# hole_localized = True
# break
#
# #move to the right
# if not key_hole_found:
# MoveHand(global_data, array([0,0,-1]), 'PALM', 0.01)
# MoveHand(global_data, array([1,0,0]), 'PALM', hlevel/num_steps)
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.015, 30)
# ## distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([1,0,0]), array([0,0,-1]), 'PALM', hlevel/num_steps, 50, 20, False)
# ## if isMissed:
# ## GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.01, 100, False)
# ## hole_localized = True
# ## break
#
# #hit to the surface again
# #GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.001, 50, False)
# #move up
# distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([0,-1,0]), array([0,0,-1]), 'PALM', vlevel, 50, 20, False)
# if isMissed:
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.01, 100, False)
# hole_localized = True
# break
#
# #move to the right
# if not key_hole_found:
# MoveHand(global_data, array([0,0,-1]), 'PALM', 0.01)
# MoveHand(global_data, array([1,0,0]), 'PALM', hlevel/num_steps)
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.015, 30)
# ## distance, isMissed, isHit = GuardedMoveUntilMiss(global_data, array([1,0,0]), array([0,0,-1]), 'PALM', hlevel/num_steps, 50, 20, False)
# ## if isMissed:
# ## GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.01, 100, False)
# ## hole_localized = True
# return hole_localized
#def LocalizeHandle1():
# '''
# first version, move the hand to the left end of the handle
# '''
# #move forward to hit the door
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.15)
# rospy.loginfo('door hit')
# #move back
# MoveHand(global_data, array([0,0,-1]),'PALM', 0.045)
# #move down to hit the handle
# GuardedMoveUntilHit(global_data, array([0,1,0]),'PALM', 0.5)
# rospy.loginfo('handle hit')
# #move up 2 cm
# MoveHand(global_data, array([0,-1,0]),'PALM', 0.02)
# #move to the left
# MoveHand(global_data, array([-1,0,0]), 'PALM', 0.1)
# #move down to the handle range
# MoveHand(global_data, array([0,1,0]), 'PALM', 0.03)
# #move forward a little so that the knuckle hits the handle side
# MoveHand(global_data, array([0,0,1]), 'PALM', 0.03)
# #move to the right to hit the handle
# GuardedMoveUntilHit(global_data, array([1,0,0]),'PALM', 0.2)
# #move to the left again
# MoveHand(global_data, array([-1,0,0]), 'PALM', 0.01)
# #move back
# MoveHand(global_data, array([0,0,-1]), 'PALM', 0.06)
# #move to the right
# MoveHand(global_data, array([1,0,0]), 'PALM', 0.13)
#def LocalizeHandle2():
# '''
# second version, move the hand to the right end of the handle
# '''
#
# #move forward to hit the door
# GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.15)
# rospy.loginfo('door hit')
# #move back
# MoveHand(global_data, array([0,0,-1]),'PALM', 0.045)
# #move down to hit the handle
# GuardedMoveUntilHit(global_data, array([0,1,0]),'PALM', 0.5)
# rospy.loginfo('handle hit')
# #move up
# MoveHand(global_data, array([0,-1,0]),'PALM', 0.04)
# #move to the right
# MoveHand(global_data, array([1,0,0]),'PALM', 0.12)
# #move forward
# MoveHand(global_data, array([0,0,1]),'PALM', 0.035)
# #move to the left
# GuardedMoveUntilHit(global_data, array([-1,0,0]),'PALM', 0.1)
# #move to the right to get away from the contact
# MoveHand(global_data, array([1,0,0]), 'PALM', 0.01)
# #move down
# GuardedMoveUntilHit(global_data, array([0,1,0]),'PALM', 0.1)
# #retract
# MoveHand(global_data, array([0,0,-1]),'PALM', 0.08)
# #-x: -0.02201925
# MoveHand(global_data, array([-1,0,0]),'PALM', 0.032)
# #-y: 0.01447249
# MoveHand(global_data, array([0,1,0]),'PALM', 0.038)
#if __name__ == '__main__':
# NODE_NAME='test'
# #MoveHandSrv(1,[3.1,3.1,3.1,0])
# #rospy.init_node(NODE_NAME)
# #ipython_thread = threading.Thread(None, ip_thread)
# #ipython_thread.start()
# #rospy.spin()
# #global global_data
# global_data, ftm, tm = start()
# rospy.loginfo('initialized')
# #MoveHand(global_data, array([0,0,-1]),'PALM', 0.01)
# pdb.set_trace()
# ## return
# ## ReOrient2(global_data,20.*pi/180.)
# ## ReOrient2(global_data,20.*pi/180.)
#
# ## #key insertion
# ## #GrabKey()
# ## pdb.set_trace()
# ## LocalizeHandle2()
# ## LocalizeHole(0.01, 0.01)
# ## LocalizeHole(0.002, 0.005)
# ## InsertKey()
# ## while not rospy.is_shutdown():
# ## rospy.sleep(1.0)
#def NaiveScan():
# #let's begin the scanning
# dx = 0.0015
# dy = 0.0015
# done = False
# for x_steps in range(4):
# if done == True:
# break
# #scan horizontal lines
# MoveHand(global_data, array([1,0,0]), 'PALM', dx)
# MoveHand(global_data, array([0,-1,0]), 'PALM', 2*dy)
# for y_steps in range(4):
# #scan vertical lines
# MoveHand(global_data, array([0,1,0]), 'PALM', dy)
# #hit the hole
# dist, isHit = GuardedMoveUntilHit(global_data, array([0,0,1]),'PALM', 0.07, 150)
# rospy.loginfo('distance moved is: %s', dist)
# if dist > 0.04:
# rospy.logerr('I believe that I inserted the key')
# done = True
# break
# #move back a little bit
# MoveHand(global_data, array([0,0,-1]), 'PALM', 0.03)
# #move up the the original height
# MoveHand(global_data, array([0,-1,0]), 'PALM', 2*dy)
#def new_test( grasp_tran = [], visualize_openrave = True, object_name = 'flask' ):
# """ Move the hand to a pregrasp position. If no grasp is given, moves the hand 5 cm above the object with it's palm pointed down.
# """
# global_data = SetupStaubliEnv(visualize_openrave)
# object_name = file_name_dict['object_name']
# if not grasp_tran:
# grasp_tran = eye(4)
# grasp_tran[1,1] = -1
# grasp_tran[2,2] = -1
# grasp_tran[2,3] = get_object_height(global_data.or_env, 'object', file_name_dict[object_name])
# pregrasp_object(global_data, file_name_dict[object_name], grasp_tran, run_it = True)
# return
#
#