2 from __future__
import print_function
3 from __future__
import division
5 import roslib; roslib.load_manifest(
'velma_task_cs_ros_interface')
10 from velma_common
import *
11 from rcprg_ros_utils
import exitError
15 print(
"Moving to the required position...")
16 velma.moveJoint(q_dest, time, start_time=0.01, position_tol=15.0/180.0*math.pi)
17 error = velma.waitForJoint()
19 print(
"The action should have ended without error, but the error code is", error)
24 print(
"Switch to cart_imp mode (no trajectory)...")
26 if not velma.moveCartImpRightCurrentPos(start_time=0.5):
28 if velma.waitForEffectorRight(timeout_s=timeout) != 0:
30 elif (rORl ==
"left"):
31 if not velma.moveCartImpLeftCurrentPos(start_time=0.5):
33 if velma.waitForEffectorLeft(timeout_s=timeout) != 0:
36 diag = velma.getCoreCsDiag()
37 if not diag.inStateCartImp():
38 print(
"The core_cs should be in cart_imp state, but it is not")
43 print(
"Switch to jnt_imp mode (no trajectory)...")
44 velma.moveJointImpToCurrentPos(start_time=0.5)
45 error = velma.waitForJoint()
47 print(
"The action should have ended without error, but the error code is", error)
50 diag = velma.getCoreCsDiag()
51 if not diag.inStateJntImp():
52 print(
"The core_cs should be in jnt_imp state, but it is not")
58 print(
"move of right gripper:", dest_q)
59 velma.moveHandRight(dest_q, [1.5,1.5,1.5,1.5], [5000,5000,5000,5000], 2000, hold=
True)
60 if velma.waitForHandRight() != 0:
65 elif (rORl ==
"left"):
66 print(
"move of left gripper:", dest_q)
67 velma.moveHandLeft(dest_q, [1.5,1.5,1.5,1.5], [5000,5000,5000,5000], 2000, hold=
True)
68 if velma.waitForHandLeft() != 0:
76 print(
"Moving the right tool and equilibrium pose from 'wrist' to 'grip' frame...")
77 T_B_Wr = velma.getTf(
"B",
"Wr")
78 T_Wr_Gr = velma.getTf(
"Wr",
"Gr")
79 if not velma.moveCartImpRight([T_B_Wr*T_Wr_Gr], [0.5], [T_Wr_Gr], [0.5],
None,
None, PyKDL.Wrench(PyKDL.Vector(5,5,5), PyKDL.Vector(5,5,5)), start_time=0.5):
81 if velma.waitForEffectorRight() != 0:
83 print(
"The right tool is now in 'grip' pose")
84 elif (rORl ==
"left"):
85 print(
"Moving the left tool and equilibrium pose from 'wrist' to 'grip' frame...")
86 T_B_Wl = velma.getTf(
"B",
"Wl")
87 T_Wl_Gl = velma.getTf(
"Wl",
"Gl")
88 if not velma.moveCartImpLeft([T_B_Wl*T_Wl_Gl], [0.5], [T_Wl_Gl], [0.5],
None,
None, PyKDL.Wrench(PyKDL.Vector(5,5,5), PyKDL.Vector(5,5,5)), start_time=0.5):
90 if velma.waitForEffectorLeft() != 0:
92 print(
"The left tool is now in 'grip' pose")
97 max_wr = PyKDL.Wrench(PyKDL.Vector(5,5,5), PyKDL.Vector(5,5,5))
98 p_tol = PyKDL.Twist(PyKDL.Vector(pt_val,pt_val,pt_val), PyKDL.Vector(pt_val,pt_val,pt_val))
100 print(
"Moving right wrist to pose defined in world frame...")
101 if not velma.moveCartImpRight([T_frame], [time],
None,
None, [imp_list], [0.01], max_wrench = max_wr, start_time = t0, path_tol = p_tol):
103 if velma.waitForEffectorRight() != 0:
105 elif (rORl ==
"left"):
106 print(
"Moving left wrist to pose defined in world frame...")
107 if not velma.moveCartImpLeft([T_frame], [time],
None,
None, [imp_list], [0.01], max_wrench = max_wr, start_time = t0, path_tol = p_tol):
109 if velma.waitForEffectorLeft() != 0:
113 def identification_movements(rightORleft, imp_list, pt_val, dest_qGrasped, dest_qOpened, T_B_Trd, T_B_Trd2, T_B_Trd_Identif1, T_B_Trd_Identif2):
114 imp_list_id = PyKDL.Wrench(PyKDL.Vector(1000, 1000, 1000), PyKDL.Vector(400, 400, 400))
116 print(
"*** start of identification procedure ***")
117 move_cart_imp(rightORleft, T_B_Trd, imp_list_id, pt_val, 8.0)
121 q_hand = velma.getHandCurrentConfiguration(rightORleft)
122 dest_qChecked = [q_hand[1], q_hand[4], q_hand[6], 0]
123 print(
"[FingerOneKnuckleTwo, FingerTwoKnuckleTwo, FingerThreeKnuckleTwo, Spread]:", dest_qChecked)
126 print(
"Velma's", rightORleft,
"gripper opened")
133 print(
"Moving gripper to first given pose and take first identification measurement")
134 move_cart_imp(rightORleft, T_B_Trd_Identif1, imp_list_id, pt_val, 8.0)
137 velma.sendIdentificationMeasurementCommand(rightORleft, 1)
139 print(
"Moving gripper to second given pose and take second identification measurement")
140 move_cart_imp(rightORleft, T_B_Trd_Identif2, imp_list_id, pt_val, 8.0)
142 velma.sendIdentificationMeasurementCommand(rightORleft, 2)
144 move_cart_imp(rightORleft, T_B_Trd_Identif1, imp_list_id, pt_val, 8.0)
149 print(
"Velma's", rightORleft,
"gripper opened")
154 print(
"Moving gripper to pose before grasping object...")
155 move_cart_imp(rightORleft, T_B_Trd, imp_list_id, pt_val, 8.0)
163 print(
"Moving gripper up...")
165 print(
"Moving gripper to first given pose and take third identification measurement")
166 move_cart_imp(rightORleft, T_B_Trd_Identif1, imp_list_id, pt_val, 8.0)
168 velma.sendIdentificationMeasurementCommand(rightORleft, 3)
170 print(
"Moving gripper to second given pose and take fourth identification measurement")
171 move_cart_imp(rightORleft, T_B_Trd_Identif2, imp_list_id, pt_val, 12.0)
173 velma.sendIdentificationMeasurementCommand(rightORleft, 4)
175 move_cart_imp(rightORleft, T_B_Trd_Identif1, imp_list, pt_val, 8.0)
176 print(
"*** end of identification procedure ***")
179 if(rightORleft ==
'right'):
180 T_B_Trd = velma.getTf(
"B",
"Gr")
181 elif(rightORleft ==
'left'):
182 T_B_Trd = velma.getTf(
"B",
"Gl")
183 velma.setGraspedFlag(rightORleft, GRAV_OBJ_COMP)
187 print(
"Calculating difference between desiread and reached pose...")
188 if (rORl ==
"right"):
189 T_B_T_diff = PyKDL.diff(T_frame, velma.getTf(
"B",
"Tr"), 1.0)
190 elif (rORl ==
"left"):
191 T_B_T_diff = PyKDL.diff(T_frame, velma.getTf(
"B",
"Tl"), 1.0)
195 if (rORl ==
"right"):
196 T_Wo_grip = velma.getTf(
"Wo",
"Gr")
197 elif (rORl ==
"left"):
198 T_Wo_grip = velma.getTf(
"Wo",
"Gl")
202 if (rORl ==
"right"):
204 print(
"Object not grabbed")
207 print(
"Right gripper grabbed the object")
208 elif (rORl ==
"left"):
210 print(
"Object not grabbed")
213 print(
"Left gripper grabbed the object")
216 if (rORl ==
"right"):
217 q_mapR = {
'torso_0_joint':0,
218 'right_arm_0_joint':-0.3,
'left_arm_0_joint':0.3,
219 'right_arm_1_joint':-1.8,
'left_arm_1_joint':1.8,
220 'right_arm_2_joint':1.25,
'left_arm_2_joint':-1.25,
221 'right_arm_3_joint':2.0,
'left_arm_3_joint':-0.85,
222 'right_arm_4_joint':0,
'left_arm_4_joint':0,
223 'right_arm_5_joint':-0.5,
'left_arm_5_joint':0.5,
224 'right_arm_6_joint':0,
'left_arm_6_joint':0 }
226 elif (rORl ==
"left"):
227 q_mapL = {
'torso_0_joint':0,
228 'right_arm_0_joint':-0.3,
'left_arm_0_joint':0.3,
229 'right_arm_1_joint':-1.8,
'left_arm_1_joint':1.8,
230 'right_arm_2_joint':1.25,
'left_arm_2_joint':-1.25,
231 'right_arm_3_joint':0.85,
'left_arm_3_joint':-2.0,
232 'right_arm_4_joint':0,
'left_arm_4_joint':0,
233 'right_arm_5_joint':-0.5,
'left_arm_5_joint':0.5,
234 'right_arm_6_joint':0,
'left_arm_6_joint':0 }
238 if (rORl ==
"right"):
239 q_mapR = {
'torso_0_joint':torso_angle,
240 'right_arm_0_joint':0.6,
'left_arm_0_joint':0.3,
241 'right_arm_1_joint':-1.1,
'left_arm_1_joint':1.8,
242 'right_arm_2_joint':1.5,
'left_arm_2_joint':-1.25,
243 'right_arm_3_joint':1.8,
'left_arm_3_joint':-0.85,
244 'right_arm_4_joint':1.2,
'left_arm_4_joint':0,
245 'right_arm_5_joint':-1.05,
'left_arm_5_joint':0.5,
246 'right_arm_6_joint':0,
'left_arm_6_joint':0 }
248 elif (rORl ==
"left"):
249 q_mapL = {
'torso_0_joint':torso_angle,
250 'right_arm_0_joint':-0.3,
'left_arm_0_joint':-0.6,
251 'right_arm_1_joint':-1.8,
'left_arm_1_joint':1.1,
252 'right_arm_2_joint':1.25,
'left_arm_2_joint':-1.5,
253 'right_arm_3_joint':0.85,
'left_arm_3_joint':-1.8,
254 'right_arm_4_joint':0,
'left_arm_4_joint':-1.2,
255 'right_arm_5_joint':-0.5,
'left_arm_5_joint':1.05,
256 'right_arm_6_joint':0,
'left_arm_6_joint':0 }
260 if __name__ ==
"__main__":
263 q_map_starting = {
'torso_0_joint':0,
264 'right_arm_0_joint':-0.3,
'left_arm_0_joint':0.3,
265 'right_arm_1_joint':-1.8,
'left_arm_1_joint':1.8,
266 'right_arm_2_joint':1.25,
'left_arm_2_joint':-1.25,
267 'right_arm_3_joint':0.85,
'left_arm_3_joint':-0.85,
268 'right_arm_4_joint':0,
'left_arm_4_joint':0,
269 'right_arm_5_joint':-0.5,
'left_arm_5_joint':0.5,
270 'right_arm_6_joint':0,
'left_arm_6_joint':0 }
272 rospy.init_node(
'object_control_test')
276 rightORleft =
'right' 286 print(
"Chosen gripper:", rightORleft)
287 print(
"CART_TEST:", CART_TEST)
288 print(
"GRAV_OBJ_COMP:", GRAV_OBJ_COMP)
291 imp_list = PyKDL.Wrench(PyKDL.Vector(500, 500, 500), PyKDL.Vector(100, 100, 100))
294 dest_qOpened = [0, 0, 0, 0]
295 dest_qClosed = [90.0/180.0*math.pi, 90.0/180.0*math.pi, 90.0/180.0*math.pi, 0]
296 dest_qGrasped = [85.0/180.0*math.pi, 85.0/180.0*math.pi, 85.0/180.0*math.pi, 0]
299 print(
"Running python interface for Velma...")
300 velma = VelmaInterface()
301 print(
"Waiting for VelmaInterface initialization...")
302 if not velma.waitForInit(timeout_s=5.0):
303 print(
"Could not initialize VelmaInterface")
305 print(
"Initialization ok!")
312 diag = velma.getCoreCsDiag()
313 if not diag.motorsReady():
314 print(
"Motors must be homed and ready to use for this test.")
317 if velma.enableMotors() != 0:
321 velma.setGraspedFlag(
'right',
False)
322 velma.setGraspedFlag(
'left',
False)
327 print(
"Right gripper closed")
329 print(
"Left gripper closed")
345 print(
"Velma's", rightORleft,
"gripper opened")
350 print(
"Reset tools for both arms...")
351 T_B_Wr = velma.getTf(
"B",
"Wr")
352 T_B_Wl = velma.getTf(
"B",
"Wl")
353 if not velma.moveCartImpRight([T_B_Wr], [0.5], [PyKDL.Frame()], [0.5],
None,
None, PyKDL.Wrench(PyKDL.Vector(5,5,5), PyKDL.Vector(5,5,5)), start_time=0.5):
355 if not velma.moveCartImpLeft([T_B_Wl], [0.5], [PyKDL.Frame()], [0.5],
None,
None, PyKDL.Wrench(PyKDL.Vector(5,5,5), PyKDL.Vector(5,5,5)), start_time=0.5):
357 if velma.waitForEffectorRight() != 0:
359 if velma.waitForEffectorLeft() != 0:
367 if(rightORleft ==
'right'):
368 T_Wo_obj1_pos = PyKDL.Vector(0.95, -0.12, 1.3)
369 elif(rightORleft ==
'left'):
370 T_Wo_obj1_pos = PyKDL.Vector(0.95, 0.12, 1.3)
372 T_B_Trd = PyKDL.Frame(T_Wo_grip.M, T_Wo_obj1_pos + PyKDL.Vector(0.0, 0.0, 0.0))
373 T_B_Trd2 = PyKDL.Frame(T_Wo_grip.M, T_Wo_obj1_pos + PyKDL.Vector(0.0, 0.0, 0.05))
375 dr = (T_Wo_obj1_pos - T_Wo_grip.p)
376 drL = math.sqrt(dr[0]**2 + dr[1]**2)
377 T_B_Trd_Identif1 = PyKDL.Frame(T_Wo_grip.M, T_Wo_obj1_pos + PyKDL.Vector(-0.2*dr[0]/drL, -0.2*dr[1]/drL, 0.05))
378 if (rightORleft ==
"right"):
379 R_z = PyKDL.Rotation.RotZ(-math.pi/2)
380 elif (rightORleft ==
"left"):
381 R_z = PyKDL.Rotation.RotZ(math.pi/2)
382 T_B_Trd_Identif2 = PyKDL.Frame(T_Wo_grip.M*R_z, T_Wo_obj1_pos + PyKDL.Vector(-0.2*dr[0]/drL, -0.2*dr[1]/drL, 0.05))
385 identification_movements(rightORleft, imp_list, pt_val, dest_qGrasped, dest_qOpened, T_B_Trd, T_B_Trd2, T_B_Trd_Identif1, T_B_Trd_Identif2)
443 print(
"Moving gripper to object's destination")
450 [time, q_actual] = velma.getLastJointState()
451 velma.setGraspedFlag(rightORleft,
False)
454 print(
"Velma's", rightORleft,
"gripper opened")
459 print(
"Moving", rightORleft,
"gripper up...")
463 move_cart_imp(rightORleft, T_B_Trd_Identif1, imp_list, pt_val, 8.0)
468 print(
"Velma's", rightORleft,
"gripper closed")
def switch_weight_compensation(rightORleft, GRAV_OBJ_COMP, imp_list, pt_val)
def q_map_rORl(rORl, torso_angle)
def identification_movements(rightORleft, imp_list, pt_val, dest_qGrasped, dest_qOpened, T_B_Trd, T_B_Trd2, T_B_Trd_Identif1, T_B_Trd_Identif2)
def switch2cart_imp_mode(rORl, timeout)
def move_jnt_imp(q_dest, time)
def isHandConfigurationClose(current_q, dest_q, tolerance=0.1)
Check if two configurations of robot hand are close within tolerance.
def diff_calc(rORl, T_frame)
def isHandConfigClose_rORl(rORl)
def move_cart_imp(rORl, T_frame, imp_list, pt_val, time)
def closeORopen_gripper(rORl, dest_q)
def switch2jnt_imp_mode()