20 import pyride_synchronizer
21 import pyride_interpreter
as pint
23 from math_tools
import general_math
as gen
33 array([ -1.26299826e-01, 1.77046412e+00, -1.02862191e+00,
34 -1.36864905e+00, -2.31195189e+00, -1.29253137e+00,
35 1.71195615e-01, 8.02176174e-01, -2.12167293e-03,
36 2.32811863e-04, 7.05358701e-03, 4.01010384e-01,
37 2.44565260e+00, 7.10476515e-01, -1.30808585e+00,
38 1.15357810e+00, -4.49485156e-01, -2.46943329e+00])
42 super(Skilled_PR2, self).
__init__(run_magiks = run_magiks)
75 Sets the configuration given by q as the reference configuration
76 If q is not given, it reads the robot arm joints and sets them as reference configuration
81 keep_config = np.copy(self.
q)
82 assert self.set_config(q),
"Error from Skilled_PR2.set_reference(): Given joints are not feasible"
84 self.
q = np.copy(keep_config)
88 qr = self.rarm.config.q
89 ql = self.larm.config.q
90 pint.take_rarm_to(qr, time_to_reach = ttr)
91 pint.take_larm_to(ql, time_to_reach = ttr)
94 assert False,
"This should not happen"
98 qr = np.array([ 0.08842831, 2.34773988, 0.07718497, -1.32087472, -0.71994221, -1.02121596, -1.56155048])
99 self.rarm.set_config(qr)
102 self.
say(
"Please, put the bord in my right hand")
105 self.
say(
"Thank you")
110 self.
say(
"Please, put the pen in my left hand")
113 self.
say(
"Thank you")
116 self.
say(
"Let's draw something. Show me a board")
118 pint.activate_tilt_laser()
119 while pint.tl_dist ==
None:
122 N = len(pint.tl_dist)/2
132 pint.deactivate_tilt_laser()
135 ql = np.array([ 1.1742804 , 2.04188103, 1.35847037, -1.99603627, -1.22890376, -1.16233047, 0.80086808])
136 self.larm.set_config(ql)
138 qr = np.array([-0.37128888, 2.08050452, -1.08169936, -1.27411378, 0.92031194, -1.3185062 , 1.23221083])
139 self.rarm.set_config(qr)
142 self.
say(
"How was it?")
145 qr = np.array([ 0.08842831, 2.34773988, 0.07718497, -1.32087472, -0.71994221, -1.02121596, -1.56155048])
146 self.rarm.set_config(qr)
172 def get_ready(self, only_orientation = True, reverse = False):
175 ori = self.rarm.wrist_orientation()
176 pos = self.rarm_end_position()
178 ori = self.larm.wrist_orientation()
179 pos = self.larm_end_position()
182 ori = rot.reverse(ori)
183 R = rot.orthogonal(ori)
187 p = arm.wrist_position()
197 self.set_target(p, R)
210 print "Left Arm is not calibrated!"
214 ori = ps.rot.point_forward_orientation
227 x = x/np.linalg.norm(x)
230 ori = np.append(np.append([y],[z],axis = 0), [x], axis = 0).T
231 assert gen.equal(np.linalg.det(ori), 1.0)
233 self.larm.set_target(pos - self.
depth*n, ori)
236 print "Right Arm is not calibrated!"
240 ori = ps.rot.point_forward_orientation
252 x = x/np.linalg.norm(x)
255 ori = np.append(np.append([y],[z],axis = 0), [x], axis = 0).T
256 assert gen.equal(np.linalg.det(ori), 1.0)
258 self.rarm.set_target(pos-self.
depth*n, ori)
262 pint.wait_until_finished(target_list = [
'rarm',
'larm'])
270 arm.dt = shape_trajectory.phi_end/100
271 jt = arm.js_project(shape_trajectory, relative =
False, traj_type =
'polynomial')
274 jt.consistent_velocities()
276 if not gen.equal(jt.phi_end, shape_trajectory.phi_end):
277 print "Warning from PyRide_PR2.draw_shape(): All the shape is not in the workspace. Part of it will be drawn !"
279 L = sum(shape_trajectory.points_dist())
281 shape_trajectory.plot3d()
283 jt.plot(axis = j, show_points = True)
293 def draw_from_canvas(self, canvas_shapes, width_pixels = 640, height_pixels = 480, plot = False, silent=True):
296 ori_l = self.larm.wrist_orientation()
297 ori_r = self.rarm.wrist_orientation()
314 for cs
in canvas_shapes:
319 pr = traj.Trajectory_Polynomial(dimension = 3)
320 pr.add_point(0.0, np.copy(pos0), np.zeros(3))
321 for (x,y)
in cs.pts[1:]:
323 pr.add_point(phi, pos)
327 pr.consistent_velocities()
335 pl = traj.Trajectory_Polynomial(dimension = 3)
336 pl.add_point(0.0, np.copy(pos0), np.zeros(3))
337 for (x,y)
in cs.pts[1:]:
339 pl.add_point(phi, pos)
343 pl.consistent_velocities()
361 while ((ir < nrt)
or (il < nlt))
and (
not pint.rarm_failed)
and (
not pint.larm_failed):
364 if (ir < nrt)
and (step_r == 0):
367 print "Trajectory: ", ir,
" Step 0 for Right Arm"
369 pos = np.copy(pr.segment[0].point[0].pos)
370 pos = pos - self.
depth*nr
371 self.rarm.set_target(pos, ori_r)
372 assert self.rarm.goto_target(optimize =
True)
373 pint.take_rarm_to(self.rarm.config.q, time_to_reach = 2.0)
376 if (il < nlt)
and (step_l == 0):
379 print "Trajectory: ", il,
" Step 0 for Left Arm"
381 pos = np.copy(pl.segment[0].point[0].pos)
382 pos = pos - self.
depth*nl
383 self.larm.set_target(pos, ori_l)
384 assert self.larm.goto_target(optimize =
True)
385 pint.take_larm_to(self.larm.config.q, time_to_reach = 2.0)
388 if (pint.rarm_reached)
and (step_r == 1):
391 print "Trajectory: ", ir,
" Step 1 for Right Arm"
392 pos = np.copy(pr.segment[0].point[0].pos)
393 self.rarm.set_target(pos, ori_r)
394 assert self.rarm.goto_target(optimize =
True)
395 pint.take_rarm_to(self.rarm.config.q, time_to_reach = 1.0)
398 if (pint.larm_reached)
and (step_l == 1):
401 print "Trajectory: ", il,
" Step 1 for Left Arm"
402 pos = np.copy(pl.segment[0].point[0].pos)
403 self.larm.set_target(pos, ori_l)
404 assert self.larm.goto_target(optimize =
True)
405 pint.take_larm_to(self.larm.config.q, time_to_reach = 1.0)
409 if (pint.rarm_reached)
and (step_r == 2):
412 print "Trajectory: ", ir,
" Step 2 for Right Arm"
418 if (pint.larm_reached)
and (step_l == 2):
421 print "Trajectory: ", il,
" Step 2 for Left Arm"
424 nseg = len(pl.segment)
435 if (pint.rarm_reached)
and (step_r == 3):
438 print "Trajectory: ", ir,
" Step 3 for Right Arm"
441 pos = self.rarm.wrist_position() - nr*self.
depth
442 self.rarm.set_target(pos, ori_r)
443 assert self.rarm.goto_target(optimize =
True)
444 pint.take_rarm_to(self.rarm.config.q, time_to_reach = 1.0)
447 if (pint.larm_reached)
and (step_l == 3):
450 print "Trajectory: ", il,
" Step 3 for Left Arm"
453 pos = self.larm.wrist_position() - nl*self.
depth
454 self.larm.set_target(pos, ori_l)
455 assert self.larm.goto_target(optimize =
True)
456 pint.take_larm_to(self.larm.config.q, time_to_reach = 1.0)
458 self.larm_reference = True
459 self.arm_back(dx = self.depth, relative = True)
463 if (pint.rarm_reached)
and (step_r == 4):
466 print "Trajectory: ", ir,
" Step 4 for Right Arm"
470 if (pint.larm_reached)
and (step_l == 4):
473 print "Trajectory: ", il,
" Step 4 for Left Arm"
485 print "Action not completed! Time Out!"
write_from_shape_complete
def sync_robot
Synchronizes the real robot or robot in simulation with the object.
def sync_object
Synchronizes the object with the robot and verifies the equity of forward kinematics for both the rig...
def larm_target
Solves the Inverse Kinematics for the left arm with given redundant parameter and takes the right ar...
This class introduces a data structure for complete kinematics of a PR2 robot which can sychronize it...
def say
Use this function if you want the robot to say something.
def arm_target
Solves the Inverse Kinematics for the reference arm with given redundant parameter The instructions ...
arm_speed
A float specifying the speed of arm gripper in the operational space in m/sec.
def rarm_target
Solves the Inverse Kinematics for the right arm with given redundant parameter and takes the right a...