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 sys,time
00033 import hrl_lib.util as ut, hrl_lib.transforms as tr
00034 import matplotlib_util.util as mpu
00035 import numpy as np, math
00036
00037 sys.path.append('../')
00038 import segway_motion_calc as smc
00039 import arm_trajectories as at
00040
00041 def plot_hook_translation(curr_pos_tl,cx_tl,cy_tl,cy_ts,
00042 start_pos_ts,eq_pt_tl,bndry,wrkspc_pts):
00043 vt,a = smc.segway_motion_repulse(curr_pos_tl,cx_tl,cy_tl,cy_ts,
00044 start_pos_ts,eq_pt_tl,bndry,wrkspc_pts)
00045
00046
00047 mpu.plot_yx(eq_pt_tl[1,:].A1, eq_pt_tl[0,:].A1, linewidth=2,
00048 color='g', scatter_size=15, label='Eq Pt')
00049 mpu.plot_yx(curr_pos_tl[1,:].A1, curr_pos_tl[0,:].A1, linewidth=0,
00050 color='b', scatter_size = 15, label = 'FK')
00051 mpu.plot_yx(bndry[1,:].A1, bndry[0,:].A1, linewidth=0, color='y',
00052 scatter_size=8)
00053 mpu.plot_yx([-0.2], [0.], linewidth=0, color='b', scatter_size=2)
00054
00055 bndry_dist_eq = smc.dist_from_boundary(eq_pt_tl, bndry, wrkspc_pts)
00056 bndry_dist_ee = smc.dist_from_boundary(curr_pos_tl, bndry, wrkspc_pts)
00057 if bndry_dist_ee < bndry_dist_eq:
00058 p = curr_pos_tl
00059 else:
00060 p = eq_pt_tl
00061 pts_close = smc.pts_within_dist(p[0:2,:],bndry,0.01,0.1)
00062 mpu.plot_yx(pts_close[1,:].A1, pts_close[0,:].A1, linewidth=0,
00063 color='r', scatter_size = 8)
00064
00065 nrm = np.linalg.norm(vt)
00066 vt = vt/nrm
00067 mpu.plot_quiver_yxv(p[1,:].A1, p[0,:].A1, vt, scale=12)
00068
00069 mpu.show()
00070
00071
00072
00073 def plot_eq_pt_motion_tl():
00074 vec_list = []
00075 for i in range(len(ee_tl.p_list)):
00076
00077 curr_pos_tl = np.matrix(ee_tl.p_list[i]).T
00078 eq_pt_tl = np.matrix(eq_tl.p_list[i]).T
00079
00080 pts_ts = np.matrix(ee_ts.p_list[0:i+1]).T
00081 pts_2d_ts = pts_ts[0:2,:]
00082
00083
00084 rad_opt = 1.0
00085 cx_ts,cy_ts = 0.5,-1.3
00086 c_ts = np.matrix([cx_ts,cy_ts,0.]).T
00087 x,y,a = st.x_list[i],st.y_list[i],st.a_list[i]
00088 c_tl = smc.tlTts(c_ts,x,y,a)
00089 cx_tl,cy_tl = c_tl[0,0],c_tl[1,0]
00090 t0 = time.time()
00091 vt,a = smc.segway_motion_repulse(curr_pos_tl,cx_tl,cy_tl,cy_ts,
00092 start_pos_ts,eq_pt_tl,bndry,wrkspc_pts)
00093 t1 = time.time()
00094
00095 nrm = np.linalg.norm(vt)
00096
00097 vt = vt/nrm
00098 vec_list.append(vt.A1.tolist())
00099
00100 v = np.matrix(vec_list).T
00101
00102 eq_pts = np.matrix(eq_tl.p_list).T
00103 ee_pts = np.matrix(ee_tl.p_list).T
00104 mpu.plot_yx(eq_pts[1,:].A1,eq_pts[0,:].A1,linewidth=1,color='g',label='eq')
00105 mpu.plot_yx(ee_pts[1,:].A1,ee_pts[0,:].A1,linewidth=1,color='b',label='FK')
00106 mpu.plot_yx(bndry[1,:].A1,bndry[0,:].A1,linewidth=0,color='y')
00107 mpu.plot_quiver_yxv(eq_pts[1,:].A1,eq_pts[0,:].A1,v,scale=30)
00108 mpu.legend()
00109 mpu.show()
00110
00111 def plot_single_point():
00112 n_pts = 115
00113 pts_ts = np.matrix(ee_ts.p_list[0:n_pts]).T
00114 pts_2d_ts = pts_ts[0:2,:]
00115 rad_opt,cx_ts,cy_ts = at.fit_circle(rad_guess,x_guess,y_guess,pts_2d_ts,
00116 method='fmin_bfgs',verbose=False)
00117 print 'rad_opt,cx_ts,cy_ts:',rad_opt,cx_ts,cy_ts
00118
00119 c_ts = np.matrix([cx_ts,cy_ts,0.]).T
00120 x,y,a = st.x_list[n_pts-1],st.y_list[n_pts-1],st.a_list[n_pts-1]
00121 c_tl = smc.tlTts(c_ts,x,y,a)
00122 cx_tl,cy_tl = c_tl[0,0],c_tl[1,0]
00123
00124 curr_pos_tl = np.matrix(ee_tl.p_list[n_pts-1]).T
00125 eqpt_tl = np.matrix(eq_tl.p_list[n_pts-1]).T
00126
00127 plot_hook_translation(curr_pos_tl,cx_tl,cy_tl,cy_ts,start_pos_ts,
00128 eqpt_tl,bndry,wrkspc_pts)
00129
00130
00131 def calc_motion_all():
00132 for i in range(len(ee_tl.p_list)):
00133 curr_pos_tl = np.matrix(ee_tl.p_list[i]).T
00134 eq_pt_tl = np.matrix(eq_tl.p_list[i]).T
00135
00136 pts_ts = np.matrix(ee_ts.p_list[0:i+1]).T
00137 pts_2d_ts = pts_ts[0:2,:]
00138 rad_opt,cx_ts,cy_ts = at.fit_circle(rad_guess,x_guess,y_guess,pts_2d_ts,
00139 method='fmin_bfgs',verbose=False)
00140 c_ts = np.matrix([cx_ts,cy_ts,0.]).T
00141 x,y,a = st.x_list[i],st.y_list[i],st.a_list[i]
00142 c_tl = smc.tlTts(c_ts,x,y,a)
00143 cx_tl,cy_tl = c_tl[0,0],c_tl[1,0]
00144 vt,a = smc.segway_motion_repulse(curr_pos_tl,cx_tl,cy_tl,cy_ts,
00145 start_pos_ts,eq_pt_tl,bndry)
00146 print 'angle:',math.degrees(a)
00147
00148
00149
00150 argv = sys.argv
00151
00152 fname = argv[1]
00153 d = ut.load_pickle(fname)
00154
00155 st = d['segway']
00156
00157 ee_tl = at.joint_to_cartesian(d['actual'])
00158 ee_ts = at.account_segway_motion(ee_tl,st)
00159
00160 eq_tl = at.joint_to_cartesian(d['eq_pt'])
00161 eq_ts = at.account_segway_motion(eq_tl,st)
00162
00163 bndry = d['bndry']
00164 wrkspc_pts = d['wrkspc']
00165
00166 rad_guess = 1.0
00167 start_pos_ts = np.matrix(ee_ts.p_list[0]).T
00168 x_guess = start_pos_ts[0,0]
00169 y_guess = start_pos_ts[1,0] - rad_guess
00170
00171 plot_single_point()
00172
00173
00174