コード例 #1
0
    def init_plan(self):
        '''
        load parameters from ROS parameter server and activate a online planner 
        from the given parameters.
        '''
        print('init_plan...')
        config_path = rospy.get_param(self.node_name + '/config_path')
        
        config = DiffeoplanConfigMaster()
        config.load(config_path)
        set_current_config(config)
        print('...')
        
        id_discdds = rospy.get_param(self.node_name + '/id_discdds')
        id_algo = rospy.get_param(self.node_name + '/id_algo')
        print('...')
#        pdb.set_trace()
        self.discdds = config.discdds.instance(id_discdds)
        self.algo = config.algos.instance(id_algo)
        self.algo.plan_time = 0.5 / self.system['frequency']
        self.algo.init(id_discdds, self.discdds)
        print('...') 
        
        size = self.discdds.actions[0].diffeo.get_shape()
        self.size = (size[1], size[0]) 
        print('planner initiated')
コード例 #2
0
def testconfig():
    if Storage.config is None:
        config = DiffeoplanConfigMaster()
        config.load()
        set_current_config(config)
        
    return get_current_config()
コード例 #3
0
    def init_plan(self):
        '''
        load parameters from ROS parameter server and activate a online planner 
        from the given parameters.
        '''
        print('init_plan...')
        config_path = rospy.get_param(self.node_name + '/config_path')

        config = DiffeoplanConfigMaster()
        config.load(config_path)
        set_current_config(config)
        print('...')

        id_discdds = rospy.get_param(self.node_name + '/id_discdds')
        id_algo = rospy.get_param(self.node_name + '/id_algo')
        print('...')
        #        pdb.set_trace()
        self.discdds = config.discdds.instance(id_discdds)
        self.algo = config.algos.instance(id_algo)
        self.algo.plan_time = 0.5 / self.system['frequency']
        self.algo.init(id_discdds, self.discdds)
        print('...')

        size = self.discdds.actions[0].diffeo.get_shape()
        self.size = (size[1], size[0])
        print('planner initiated')
コード例 #4
0
def report_dds(config, id_discdds, discdds, image='lena'):
    set_current_config(config)
    r = Report('dds-%s' % (id_discdds))
    image = config.images.instance(image)
    y0 = UncertainImage(image)
    discdds.display(r, y0)
    return r
コード例 #5
0
def init_algorithm(config, id_algo, id_discdds, discdds):
    """ Returns the instanced DiffeoPlanninAlgorithm """
    # instance the algorithm
    set_current_config(config)
    algo = config.algos.instance(id_algo)    
    # initialize the algorithm with the dynamics
    # TODO: add computation time
    #t0 = time.clock()
    algo.set_name_for_log(id_algo)
    algo.init(id_discdds, discdds) 
    #init_time = time.clock() - t0
    return algo
コード例 #6
0
def visualize_result(config, id_tc, id_algo, stats):
    """ Returns a report """
    set_current_config(config)
    
    result = stats['result']
    r = Report('%s-%s' % (id_tc, id_algo))
#    tc = config.testcases.instance(id_tc)
#    discdds = config.discdds.instance(tc.id_discdds)
    algo = stats['algo']
    tc = stats['tc']
    discdds = algo.get_dds()
    
    tc.display(r.section('testcase'), discdds=discdds)
    
    if not result.success:
        r.text('warning', 'Plannning unsuccesful')
    else:
        rsol = r.section('solution')
        rsol.text('plan', 'Plan: %s' % str(result.plan))
    
        y0 = tc.y0
        y1 = tc.y1
        y1plan = discdds.predict(y0, result.plan)
        mismatch = np.abs(y1.get_values() - y1plan.get_values()).sum(axis=2)
        
        f = rsol.figure(cols=4)
        zoom = lambda x: rgb_zoom(x, 8)
        
        f.data_rgb('y1plan', zoom(y1plan.get_rgb()),
                   caption='plan prediction (certain)')
        f.data_rgb('y1plan_certain', zoom(y1plan.get_rgb_uncertain()),
                   caption='certainty of prediction')
        
        f.data_rgb('mismatch', zoom(scale(mismatch)),
                   caption='Mismatch value pixel by pixel '
                            '(zero for synthetic testcases...)')
    
    
    algo.plan_report(r.section('planning'), result, tc)
    
    extra = result.extra
    
    write_log_lines(r, extra)
    
    return r
コード例 #7
0
def visualize_result(config, id_tc, id_algo, stats):
    """ Returns a report """
    set_current_config(config)

    result = stats["result"]
    r = Report("%s-%s" % (id_tc, id_algo))
    #    tc = config.testcases.instance(id_tc)
    #    discdds = config.discdds.instance(tc.id_discdds)
    algo = stats["algo"]
    tc = stats["tc"]
    discdds = algo.get_dds()

    tc.display(r.section("testcase"), discdds=discdds)

    if not result.success:
        r.text("warning", "Plannning unsuccesful")
    else:
        rsol = r.section("solution")
        rsol.text("plan", "Plan: %s" % str(result.plan))

        y0 = tc.y0
        y1 = tc.y1
        y1plan = discdds.predict(y0, result.plan)
        mismatch = np.abs(y1.get_values() - y1plan.get_values()).sum(axis=2)

        f = rsol.figure(cols=4)
        zoom = lambda x: rgb_zoom(x, 8)

        f.data_rgb("y1plan", zoom(y1plan.get_rgb()), caption="plan prediction (certain)")
        f.data_rgb("y1plan_certain", zoom(y1plan.get_rgb_uncertain()), caption="certainty of prediction")

        f.data_rgb(
            "mismatch",
            zoom(scale(mismatch)),
            caption="Mismatch value pixel by pixel " "(zero for synthetic testcases...)",
        )

    algo.plan_report(r.section("planning"), result, tc)

    extra = result.extra

    write_log_lines(r, extra)

    return r
コード例 #8
0
    def load_diffeoplan(self):
        '''
        load parameters from ROS parameter server and activate a online planner 
        from the given parameters.
        '''
        config_path = rospy.get_param(self.node_name + '/config_path')
        
        config = DiffeoplanConfigMaster()
        config.load(config_path)
        set_current_config(config)
        
        id_discdds = rospy.get_param(self.node_name + '/id_discdds')
        id_algo = rospy.get_param(self.node_name + '/id_algo')

        diffeo_structure_threshold = 0.2
        
        # Check for threshold params, if evaluated to a list of tuple, then 
        # give the list or tuple as thresholds.
        thresholds = rospy.get_param(self.node_name + '/planning_thresholds')
        try:
            if eval(thresholds).__class__ in [list, tuple]:
                get_planning_thresholds = eval(thresholds)
            else:
                get_planning_thresholds = thresholds
        except:
            get_planning_thresholds = thresholds
        
        # dummy variables
        plan_length = 0
        num_tests = 0
        plans = [] 

        self.online_planner = OnlinePlanning(id_discdds,
                 diffeo_structure_threshold,
                 id_algo,
                 plan_length,
                 num_tests,
                 get_planning_thresholds,
                 plans)
        
        self.state = WAIT_GOAL
コード例 #9
0
def instantiate_testcase(config, id_tc):
    set_current_config(config)
    return config.testcases.instance(id_tc)
コード例 #10
0
def instantiate_discdds(config, id_discdds):
    set_current_config(config)
    return config.discdds.instance(id_discdds)
コード例 #11
0
def report_tc(config, id_tc, tc):
    set_current_config(config)
    r = Report('tc-%s' % (id_tc))
    tc.display(r)
    return r
コード例 #12
0
ファイル: online_plan.py プロジェクト: AndreaCensi/diffeoplan
def main():
    logger.info('Starting online planning')
    parser = OptionParser()
    parser.add_option("-t", "--id_otc",
                      help="", default=None)
    parser.add_option("-e", "--env",
                      help="environment name", default='default')
    parser.add_option("-o", "--result",
                      help="Result storage file", default=None)
    parser.add_option("-r", "--report",
                      help="Specify output reports", default='')
    (options, _) = parser.parse_args()

    config = DiffeoplanConfigMaster()
    config.load('default:/home/adam/diffeo-data/')
    
    report_opt = options.report.split(',')
    
    set_current_config(config)
    if options.id_otc is not None:
        testcases = options.id_otc.split(',')
    else:
        testcases = []
        
        
    if options.result is not None:
        data_files = options.result.split(',')
    else:
        data_files = []
        
    try:
        all_stats = []
        for data_file in data_files:
            all_stats += pickle.load(open(data_file))
    except:
        pass
        
    for tc in testcases:
        logger.info('Starting up tests with : %s' % tc)
        planning_module = config.online_testcases.instance(tc)
        all_stats += planning_module.run_all_tests(options.env)
    
    pickle.dump(all_stats, open(options.result, 'wb'))

    rm = ReportManager('out/online')
    
    if 'vis' in report_opt:
        for i, stat in enumerate(all_stats):
            report = comp(report_tools.run_report, stat)
            kwargs = dict(env=stat.labels['env'])
            rm.add(report, 'online_run_' + str(i), **kwargs)
    
    stats_file = yaml.load(open('/home/adam/git/boot12env/src/surf12adam/orbit.online_report.yaml'))

    stats_def = []
    for i in range(len(stats_file)):
        if stats_file[i]['id'] in report_opt:
            stats_def.append(stats_file[i])
    
    kwargs = {'summary':'summary'}
    report = comp(report_tools.stat_report, stats_def, all_stats)
    rm.add(report, 'summary_stats', **kwargs)
    
    kwargs = {'summary':'empty'}
    report = comp(report_tools.empty_report)
    rm.add(report, 'empty', **kwargs)
    
    rm.create_index_job()
    compmake_console()
コード例 #13
0
def main():
    logger.info('Starting online planning')
    parser = OptionParser()
    parser.add_option("-t", "--id_otc", help="", default=None)
    parser.add_option("-e",
                      "--env",
                      help="environment name",
                      default='default')
    parser.add_option("-o",
                      "--result",
                      help="Result storage file",
                      default=None)
    parser.add_option("-r",
                      "--report",
                      help="Specify output reports",
                      default='')
    (options, _) = parser.parse_args()

    config = DiffeoplanConfigMaster()
    config.load('default:/home/adam/diffeo-data/')

    report_opt = options.report.split(',')

    set_current_config(config)
    if options.id_otc is not None:
        testcases = options.id_otc.split(',')
    else:
        testcases = []

    if options.result is not None:
        data_files = options.result.split(',')
    else:
        data_files = []

    try:
        all_stats = []
        for data_file in data_files:
            all_stats += pickle.load(open(data_file))
    except:
        pass

    for tc in testcases:
        logger.info('Starting up tests with : %s' % tc)
        planning_module = config.online_testcases.instance(tc)
        all_stats += planning_module.run_all_tests(options.env)

    pickle.dump(all_stats, open(options.result, 'wb'))

    rm = ReportManager('out/online')

    if 'vis' in report_opt:
        for i, stat in enumerate(all_stats):
            report = comp(report_tools.run_report, stat)
            kwargs = dict(env=stat.labels['env'])
            rm.add(report, 'online_run_' + str(i), **kwargs)

    stats_file = yaml.load(
        open('/home/adam/git/boot12env/src/surf12adam/orbit.online_report.yaml'
             ))

    stats_def = []
    for i in range(len(stats_file)):
        if stats_file[i]['id'] in report_opt:
            stats_def.append(stats_file[i])

    kwargs = {'summary': 'summary'}
    report = comp(report_tools.stat_report, stats_def, all_stats)
    rm.add(report, 'summary_stats', **kwargs)

    kwargs = {'summary': 'empty'}
    report = comp(report_tools.empty_report)
    rm.add(report, 'empty', **kwargs)

    rm.create_index_job()
    compmake_console()