Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 import mekabot.hrl_robot as hr
00033 import hrl_lib.util as ut, hrl_lib.transforms as tr
00034 
00035 import math, numpy as np
00036 import copy
00037 
00038 import sys
00039 sys.path.append('../')
00040 import compliant_trajectories as ct
00041 import segway_motion_calc as smc
00042 
00043 
00044 def compute_workspace(z, hook_angle):
00045     firenze = hr.M3HrlRobot(connect=False)
00046     rot_mat = tr.Rz(hook_angle)*tr.Rx(math.radians(0))*tr.Ry(math.radians(-90))
00047     delta_list = [math.radians(d) for d in [0.,0.,0.,0.,10.,10.,10.]]
00048     x_list,y_list = [],[]
00049     if z < -0.4:
00050         xmin = 0.10
00051         xmax = 0.65
00052     else:
00053         xmin = 0.15
00054         xmax = 0.65
00055 
00056     for x in np.arange(xmin,xmax,.01):
00057         for y in np.arange(-0.1,-0.50,-0.01):
00058             if x<0.3 and y>-0.2:
00059                 continue
00060             q = firenze.IK('right_arm',np.matrix([x,y,z]).T,rot_mat)
00061             if q != None and firenze.within_physical_limits_right(q,delta_list)==True:
00062                 x_list.append(x)
00063                 y_list.append(y)
00064     return np.matrix([x_list,y_list])
00065 
00066 def create_workspace_dict():
00067     dd = {}
00068     ha_list = [math.radians(d) for d in [0.,90.,-90.]]
00069     for ha in ha_list:
00070         d = {}
00071         for z in np.arange(-0.1,-0.55,-0.01):
00072             print 'z:',z
00073             pts2d = compute_workspace(z,hook_angle=ha)
00074             d[z] = pts2d
00075         dd[ha] = {}
00076         dd[ha]['pts'] = d
00077 
00078     ut.save_pickle(dd,'workspace_dict_'+ut.formatted_time()+'.pkl')
00079 
00080 
00081 def create_workspace_boundary(pkl_name):
00082     dd = ut.load_pickle(pkl_name)
00083     for ha in dd.keys():
00084         pts_dict = dd[ha]['pts']
00085         bndry_dict = {}
00086         for z in pts_dict.keys():
00087             print 'z:',z
00088             wrkspc = pts_dict[z]
00089             if wrkspc.shape[1] < 100:
00090                 pts_dict.pop(z)
00091                 continue
00092             bndry = smc.compute_boundary(wrkspc)
00093             bndry_dict[z] = bndry
00094         dd[ha]['bndry'] = bndry_dict
00095     ut.save_pickle(dd, pkl_name)
00096 
00097 
00098 
00099 create_workspace_dict()
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108