potential_field.py
Go to the documentation of this file.
00001 #
00002 #
00003 # Copyright (c) 2010, Georgia Tech Research Corporation
00004 # All rights reserved.
00005 # 
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of the Georgia Tech Research Corporation nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 # 
00017 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00018 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00025 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 
00029 # \author Advait Jain (Healthcare Robotics Lab, Georgia Tech.)
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) # signed
00056     bndry_dist_ee = smc.dist_from_boundary(curr_pos_tl, bndry, wrkspc_pts) # signed
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 # only interested in the translation. so junk values for circle
00072 # params are ok.
00073 def plot_eq_pt_motion_tl():
00074     vec_list = []
00075     for i in range(len(ee_tl.p_list)):
00076 #    for i in range(5):
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 #        rad_opt,cx_ts,cy_ts = at.fit_circle(rad_guess,x_guess,y_guess,pts_2d_ts,
00083 #                                         method='fmin_bfgs',verbose=False)
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 #        print 'time to segway_motion_repulse:',t1-t0
00095         nrm = np.linalg.norm(vt)
00096 #        if nrm > 0.005:
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 #calc_motion_all()
00173 #plot_eq_pt_motion_tl()
00174 


2010_icra_epc_pull
Author(s): Advait Jain, Charles C. Kemp (Healthcare Robotics Lab, Georgia Tech)
autogenerated on Wed Nov 27 2013 12:14:43