예제 #1
0
def isActionStable_multiproc(args):
    name, cells, x, y, yaw, action, name_actor, type_actor, dims_actor = args

    sim = SimBullet(gui=False)
    sim.addObject('plane','plane')
    sim.addObject(name, cells, [0,0,0,1], 0,0,0)
    sim.addObject(name_actor,type_actor,[0,0,0,1])
    sim.setObjectPose(name,x,y,yaw)

    (x0,y0,z0),q0 = sim.getObjectPose(name,ndims=3)
    KinoPlanner.applyAction(sim, name,x,y,yaw, \
                            action,name_actor,dims_actor)
    (x1,y1,z1),q1 = sim.getObjectPose(name,ndims=3)

    q0 = q0.normalised
    q1 = q1.normalised
    dist_q = 1 - np.dot(q0.q,q1.q)**2

    return z1>0 or dist_q<0.003 # <10degree
예제 #2
0
def draw_result(fp_label,
                fp_res,
                fp_massmap,
                fp_posres,
                setups,
                masses_gt=[1, 1, 1, 1],
                iters=[
                    -1,
                    0,
                    1,
                    2,
                ]):

    cmap = matplotlib.cm.coolwarm
    #cnorm = matplotlib.colors.Normalize(vmin=0.1,vmax=4.9)

    obj = os.path.split(fp_label)[1].split('_')[0]

    sim = SimBullet(gui=False)
    #sim._p.setGravity(0,0,-9.8)
    sim.addObject('table_rect', 'table_rect', [1, 1, 1, 0])
    sim.setupRendering(0.75, -90, -60, 500, 500)
    img_label = cv2.imread(fp_label, cv2.IMREAD_UNCHANGED)
    labels = np.unique(img_label)
    cells = CellPhysicsBase.createCells(img_label, masses_gt, 0.53 / 640.0)
    sim.addObject(obj, cells, [0, 0, 1, 1])
    sim.setObjectPose(obj, 0, 0, 0)

    cellinfos = sim.getCellBodyProperties(obj)
    vmax = max([info['mass'] for info in cellinfos])
    vmin = min([info['mass'] for info in cellinfos])
    cnorm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax)
    for info in cellinfos:
        info['color'] = cmap(cnorm(info['mass']))
    sim.setCellBodyProperties(obj, cellinfos)
    img = sim.draw()
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    cv2.imwrite(fp_massmap % -3, img)

    f = open(fp_res, 'rb')
    res = pickle.load(f)
    f.close()

    # estimation example
    cellinfos = res['history'][-1]['cellinfos']
    #cnorm = matplotlib.colors.Normalize(vmin=0.1,vmax=5)
    for info in cellinfos[obj]:
        info['color'] = cmap(cnorm((vmax - vmin) * 0.5))
    sim.setCellBodyProperties(obj, cellinfos[obj])
    img = sim.draw()

    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    cv2.imwrite(fp_massmap % -2, img)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    for it in iters:

        if it >= len(res['history']):
            continue

        cellinfos = res['history'][it]['cellinfos']
        #vmax = max([info['mass'] for info in cellinfos[obj]])
        #vmin = min([info['mass'] for info in cellinfos[obj]])
        #cnorm = matplotlib.colors.Normalize(vmin=vmin,vmax=vmax)
        for info in cellinfos[obj]:
            info['color'] = cmap(cnorm(info['mass']))
        sim.setCellBodyProperties(obj, cellinfos[obj])
        img = sim.draw()
        img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
        cv2.imwrite(fp_massmap % it, img)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    return

    # debug image
    sim.setupRendering(0.75, 90, -90, 500, 500)

    sim.addObject('finger1', 'finger', [1, 1, 0.9, 1])
    sim.addObject('finger2', 'finger', [1, 1, 0.6, 1])
    sim.addObject('finger3', 'finger', [1, 1, 0.3, 1])

    sim.addObject('init', cells, [0.7, 0.7, 0.7, 1])
    pos, rot = sim.getPosRot(sim.objects['init']['shape'], 0, 0, 0)
    pos[2] = pos[2] - 0.002
    sim._p.resetBasePositionAndOrientation(sim.objects['init']['bodyId'], pos,
                                           rot)

    sim.addObject('gt', cells, [0, 1, 0, 1])
    for i in range(len(res['history'][-1]['test_poses'])):

        if 'real' not in setups:
            pixel2meter(cells, setups['test'][i])
            sim.resetObject('finger1',setups['test'][i]['finger']['pos'][0] - 0.03,\
                                      setups['test'][i]['finger']['pos'][1],0)
            sim.resetObject('finger2',setups['test'][i]['finger']['pos'][0] + setups['test'][i]['finger']['velocity'][0]*0.40 - 0.03,\
                                      setups['test'][i]['finger']['pos'][1] + setups['test'][i]['finger']['velocity'][1]*0.40,0)
            sim.resetObject('finger3',setups['test'][i]['finger']['pos'][0] + setups['test'][i]['finger']['velocity'][0]*0.90 - 0.03,\
                                      setups['test'][i]['finger']['pos'][1] + setups['test'][i]['finger']['velocity'][1]*0.90,0)
        else:
            sim.resetObject('finger1',setups['real'][i]['finger']['pos'][0] - 0.03,\
                                      setups['real'][i]['finger']['pos'][1],0)
            sim.resetObject('finger2',setups['real'][i]['finger']['pos'][0] + setups['real'][i]['finger']['velocity'][0]*0.40 - 0.03,\
                                      setups['real'][i]['finger']['pos'][1] + setups['real'][i]['finger']['velocity'][1]*0.40,0)
            sim.resetObject('finger3',setups['real'][i]['finger']['pos'][0] + setups['real'][i]['finger']['velocity'][0]*0.90 - 0.03,\
                                      setups['real'][i]['finger']['pos'][1] + setups['real'][i]['finger']['velocity'][1]*0.90,0)

        pose_gt = res['history'][-1]['test_poses'][i]['gt']

        #sim.resetObject(obj,100,100,0)
        sim.resetObject('gt', pose_gt[obj]['x'], pose_gt[obj]['y'],
                        pose_gt[obj]['yaw'])
        #img = sim.draw()
        #img = cv2.cvtColor(img,cv2.COLOR_RGB2BGR)
        #cv2.imwrite(fp_posres % (i+20),img)
        #img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)

        #sim.resetObject('gt',100,100,0)
        pose_est = res['history'][-1]['test_poses'][i]['estimation']
        sim.resetObject(obj, pose_est[obj]['x'], pose_est[obj]['y'],
                        pose_est[obj]['yaw'])

        pos, rot = sim.getPosRot(sim.objects['gt']['shape'], pose_gt[obj]['x'],
                                 pose_gt[obj]['y'], pose_gt[obj]['yaw'])
        pos[0] = pos[0] - 0.001
        pos[2] = pos[2] - 0.001
        sim._p.resetBasePositionAndOrientation(sim.objects['gt']['bodyId'],
                                               pos, rot)

        img = sim.draw()
        img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
        cv2.imwrite(fp_posres % i, img)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
예제 #3
0
                    n_plans = 1

            # create planner
            planner = ProbPhysicsPlanner(obj,fp_label,models,meter_per_pixel,
                                         setup=setup,
                                         contact_resolution=0.02, \
                                         pushing_dists=[0.20,0.10,0.05,0.04,0.03,0.02,0.01])

            # select goals
            goals_sel = planner.selectGoals(obj, goals)
            print('Selected Goals: ', goals_sel)

            sim = SimBullet(gui=args.debug)
            sim.setupCamera(0.75,-90,-89.99, 0.63,0,0)
            sim.addObject('table_round','table_round',[1,1,1,1])
            sim.setObjectPose('table_round',0.63,0,0)
            sim.addObject('finger','finger',[1,1,0,1])
            sim.setObjectPose('finger',10,0,0)
            cells = CellPhysicsBase.createCells(fp_label,gts[obj]['masses'],meter_per_pixel=meter_per_pixel)
            sim.addObject(obj, cells, [0.5,0.5,0.5,1], 0, 0, 0)

            succs = []
            plans = []
            n_actions = []
            for i in args.inits:
                init = inits[i]
                print('method:%s obj:%s init#:%d'%(method,obj,i))

                fp_save = os.path.join(args.outdir,'%s_%s_init%d.pkl'%(method,obj,i))
                if args.skip and os.path.isfile(fp_save):
                    print('[SKIP] %s' % fp_save)
예제 #4
0
            'book', 'box', 'crimp', 'hammer', 'ranch', 'snack', 'toothpaste',
            'windex'
    ]:

        if not os.path.isdir(dir_sav + '/fig'):
            os.makedirs(dir_sav + '/fig')

        fp_label = '../../dataset/objects/%s_label.pgm' % obj
        img_label = cv2.imread(fp_label, cv2.IMREAD_UNCHANGED)
        cells = CellPhysicsBase.createCells(img_label, [1, 1, 1, 1],
                                            0.53 / 640.0)

        sim = SimBullet(gui=False)
        sim.setupRendering(0.75, -90, -60, 500, 500)
        sim.addObject(obj, cells, [0, 0, 1, 1])
        sim.setObjectPose(obj, 0, 0, 0)

        files = glob.glob(dir_sav + '/' + obj + '*.pkl')
        for file in files:

            filename = os.path.split(file)[1].split('.')[0]

            f = open(file, 'rb')
            sav = pickle.load(f)
            f.close()

            cellinfo = sav['cellinfo']
            error_cell = sav['error_cell']

            masses = []
            frics = []
예제 #5
0
                    print(file)
                    print('push_x:', push_x)
                    print('push_y:', push_y)

                    sim = SimBullet(gui=False)
                    sim._p.setGravity(0, 0, -9.8)
                    sim.setupRendering(0.75, -90, -89.99, 500, 500)
                    sim.addObject('finger0', 'finger', [1, 1, 0, 1])
                    sim.addObject('finger1', 'finger', [1, 0, 1, 1])
                    sim.addObject('table_rect', 'table_rect', [1, 1, 1, 1])
                    img_label = cv2.imread(fp_label, cv2.IMREAD_UNCHANGED)
                    cells = CellPhysicsBase.createCells(
                        img_label, [0, 0, 0, 0], meter_per_pixel=0.53 / 640.0)
                    sim.addObject(obj + '0', cells, [0, 0, 1, 1])
                    sim.addObject(obj + '1', cells, [1, 0, 0, 1])
                    sim.setObjectPose('finger0', push_x, push_y, 0)
                    sim.setObjectPose('finger1',
                                      push_x + float(node['push']['vec']['x']),
                                      push_y, 0)
                    sim.setObjectPose(obj + '0', 0, 0, 0)
                    sim.setObjectPose(obj + '1', x_res, y_res, yaw_res)

                    draw = sim.draw()
                    plt.imshow(draw)
                    plt.show()

            if True:
                engine = get_engine(args.method)
                engine.setup(setup, n_group=-1)
                n_group = len(engine.meta_targets[obj]['cells']['cells'])
예제 #6
0
                        if args.skip and os.path.isfile(fp_save):
                            print('[SKIP] %s' % fp_save)
                            continue

                        print('method: {}, param: {}, init: {}, goal: {}'.format(method,param,init,goal))
                        time_beg = time.time()

                        planner = CellPhysicsPlanner(obj, img, [5-0.1]*4, meter_per_pixel)

                        sim = SimBullet(gui=False)
                        sim.setupCamera(0.75,-90,-89.99, 0.63,0,0)
                        sim.addObject('plane','plane',[1,1,1,1])
                        sim.addObject('finger','finger',[1,1,0,1])
                        cells = CellPhysicsBase.createCells(img,param['masses'],meter_per_pixel=meter_per_pixel)
                        sim.addObject(obj, cells, [0.5,0.5,0.5,1], 0,0,0)
                        sim.setObjectPose(obj,goal[0],goal[1],goal[2])
                        cellpos_goal = sim.getCellBodyPose(obj)
                        sim.setObjectPose(obj,init[0],init[1],init[2])
    
                        history = {'path':[], 'actions':[]}
                        while True:
                            x0,y0,yaw0 = sim.getObjectPose(obj)
                            cellpos0 = sim.getCellBodyPose(obj)
                            err_xy = np.linalg.norm([goal[0]-x0,goal[1]-y0])
                            err_yaw = distance_angle(goal[2],yaw0)
                            err_cell = CellPhysicsBase.distanceCellPos(cellpos_goal, cellpos0)
                            cellinfos = planner.getProperties()
                            cellinfos_copy = [info.copy() for info in cellinfos]
                            history['path'].append({'x':x0,'y':y0,'yaw':yaw0,'cellinfos':cellinfos_copy, 
                                                    'err_xy':err_xy,'err_yaw':err_yaw,'err_cell':err_cell})