00001
00002
00003 import sys
00004 import numpy as np, math
00005 import copy
00006 import matplotlib.pyplot as pp
00007
00008 import roslib; roslib.load_manifest('hrl_common_code_darpa_m3')
00009 import hrl_lib.util as ut
00010 import hrl_lib.matplotlib_util as mpu
00011 import hrl_common_code_darpa_m3.software_simulation_setup.viz as sssv
00012
00013
00014
00015
00016 if __name__ == '__main__':
00017 import optparse
00018 p = optparse.OptionParser()
00019
00020 p.add_option('--nr', action='store', dest='nr',type='int',
00021 default=3, help='number of goals in radial direction')
00022 p.add_option('--nt', action='store', dest='nt',type='int',
00023 default=3, help='number of goals in theta direction')
00024
00025 p.add_option('--rmin', action='store', dest='rmin',type='float',
00026 default=0.5, help='min radial distance for goal')
00027 p.add_option('--rmax', action='store', dest='rmax',type='float',
00028 default=0.7, help='max x radial distance for goal')
00029
00030 p.add_option('--tmin', action='store', dest='tmin',type='float',
00031 default=-30, help='min theta for goal (DEGREES)')
00032 p.add_option('--tmax', action='store', dest='tmax',type='float',
00033 default=30, help='max theta for goal (DEGREES)')
00034
00035 p.add_option('--pkl', action='store', dest='pkl', default=None,
00036 help='pkl with obstacle locations')
00037
00038 p.add_option('--save_figure', '--sf', action='store_true', dest='sf',
00039 help='save the figure')
00040 p.add_option('--sim3', action='store_true', dest='sim3',
00041 help='three link planar (torso, upper arm, forearm)')
00042 p.add_option('--sim3_with_hand', action='store_true', dest='sim3_with_hand',
00043 help='three link planar (upper arm, forearm, hand)')
00044
00045 p.add_option('--grid_goal', action='store', dest='grid_resol', type='float',
00046 default=0.0, help='Grid Goal resolution for equaly distributed goals')
00047 p.add_option('--xmin', action='store', dest='xmin',type='float',
00048 default=0.2, help='min x coord for goals')
00049 p.add_option('--xmax', action='store', dest='xmax',type='float',
00050 default=0.6, help='max x coord for goals')
00051 p.add_option('--ymin', action='store', dest='ymin',type='float',
00052 default=-0.3, help='min y coord for goals')
00053 p.add_option('--ymax', action='store', dest='ymax',type='float',
00054 default=0.3, help='max y coord for goals')
00055
00056 opt, args = p.parse_args()
00057
00058 if opt.pkl == None:
00059 raise RuntimeError('Please specify a reach_problem_dict pkl')
00060
00061 rpd = ut.load_pickle(opt.pkl)
00062 nm = '.'.join(opt.pkl.split('.')[0:-1])
00063 g_list = []
00064
00065 if opt.grid_resol:
00066
00067 x = opt.xmin
00068 y = opt.ymin
00069
00070 arGridX = []
00071 while x <= opt.xmax:
00072 arGridX.append(x)
00073 x += opt.grid_resol
00074
00075 arGridY = []
00076 while y <= opt.ymax:
00077 arGridY.append(y)
00078 y += opt.grid_resol
00079
00080 for i in range(len(arGridX)):
00081 for j in range(len(arGridY)):
00082 rpd['goal'] = [arGridX[i], arGridY[j], 0]
00083 ut.save_pickle(rpd, nm + '_x%02d'%i + '_y%02d'%j + '.pkl')
00084 g_list.append(copy.copy(rpd['goal']))
00085
00086 else:
00087
00088 if opt.nr != 1 :
00089 r_step = (opt.rmax - opt.rmin) / (opt.nr - 1)
00090 else:
00091 r_step = 0
00092
00093 if opt.nt != 1 :
00094 t_step = math.radians((opt.tmax - opt.tmin) / (opt.nt - 1))
00095 else:
00096 t_step = 0
00097
00098 t_start = math.radians(opt.tmin)
00099 nt = opt.nt
00100
00101 for r in range(opt.nr):
00102 for t in range(nt):
00103 rad = opt.rmin + r_step * r
00104 theta = t_start + t_step * t
00105 rpd['goal'] = [rad * math.cos(theta), rad * math.sin(theta), 0]
00106 ut.save_pickle(rpd, nm + '_r%02d'%r + '_t%02d'%t + '.pkl')
00107 g_list.append(copy.copy(rpd['goal']))
00108
00109 if r%2 == 0:
00110 t_start = t_start + t_step/2
00111 nt = nt - 1
00112 else:
00113 t_start = t_start - t_step/2
00114 nt = nt + 1
00115
00116 if opt.sf:
00117
00118
00119 roslib.load_manifest('hrl_software_simulation_darpa_m3')
00120 import hrl_software_simulation_darpa_m3.gen_sim_arms as gsa
00121
00122 if opt.sim3:
00123 import hrl_common_code_darpa_m3.robot_config.three_link_planar_capsule as d_robot
00124 elif opt.sim3_with_hand:
00125 import hrl_common_code_darpa_m3.robot_config.three_link_with_hand as d_robot
00126
00127 mpu.set_figure_size(6,4)
00128 pp.figure()
00129 kinematics = gsa.RobotSimulatorKDL(d_robot)
00130 sssv.draw_obstacles_from_reach_problem_dict(rpd)
00131 g_arr = np.array(g_list)
00132 pp.scatter(-g_arr[:,1], g_arr[:,0], s=50, c='g', marker='x', lw=1, edgecolor='g')
00133
00134 q = [0.,0,0]
00135 ee,_ = kinematics.FK(q)
00136 rad = np.linalg.norm(ee)
00137 sa = -math.radians(45)
00138 ea = math.radians(45)
00139 mpu.plot_circle(0., 0., rad, sa, ea, color='b', linewidth=0.5)
00140 mpu.plot_radii(0., 0., rad, sa, ea, 2*math.pi, color='b', linewidth=0.5)
00141
00142 pp.xlim(-0.7, 0.7)
00143 mpu.reduce_figure_margins(left=0.02, bottom=0.02, right=0.98, top=0.98)
00144 pp.savefig(nm+'.pdf')
00145
00146
00147