예제 #1
0
    def plotting(id_vehicle, vehicle):  # @UnusedVariable
        id_world = 'SBox2_10a'
        world = get_conftools_worlds().instance(id_world)
        simulation = VehicleSimulation(vehicle, world)
        simulation.new_episode()
        simulation.compute_observations()
        sim_state = simulation.to_yaml()

        plot_params = dict(grid=2,
                           zoom=vehicle.radius * 1.5,
                           width=400,
                           height=400,
                           show_sensor_data=True)

        f = tempfile.NamedTemporaryFile(suffix='.png', delete=True)
        vehicles_cairo_display_png(filename=f.name,
                                   sim_state=sim_state,
                                   **plot_params)

        f = tempfile.NamedTemporaryFile(suffix='.pdf', delete=True)
        vehicles_cairo_display_pdf(filename=f.name,
                                   sim_state=sim_state,
                                   **plot_params)

        f = tempfile.NamedTemporaryFile(suffix='.svg', delete=True)
        vehicles_cairo_display_svg(filename=f.name,
                                   sim_state=sim_state,
                                   **plot_params)
예제 #2
0
    def plotting(id_vehicle, vehicle):  # @UnusedVariable
        id_world = 'SBox2_10a'
        world = get_conftools_worlds().instance(id_world)
        simulation = VehicleSimulation(vehicle, world)
        simulation.new_episode()
        simulation.compute_observations()
        sim_state = simulation.to_yaml()

        plot_params = dict(grid=2,
                           zoom=vehicle.radius * 1.5,
                           width=400, height=400,
                           show_sensor_data=True)

        f = tempfile.NamedTemporaryFile(suffix='.png', delete=True)
        vehicles_cairo_display_png(filename=f.name, sim_state=sim_state,
                                   **plot_params)

        f = tempfile.NamedTemporaryFile(suffix='.pdf', delete=True)
        vehicles_cairo_display_pdf(filename=f.name, sim_state=sim_state,
                                   **plot_params)

        f = tempfile.NamedTemporaryFile(suffix='.svg', delete=True)
        vehicles_cairo_display_svg(filename=f.name, sim_state=sim_state,
                                   **plot_params)
예제 #3
0
def main():
    if not vehicles_has_cairo:
        logger.error('This program cannot be run if Cairo is not installed.')
        return
    from vehicles_cairo import (vehicles_cairo_display_pdf,
                                vehicles_cairo_display_png,
                                vehicles_cairo_display_svg)

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--vehicle",
                      default='d_SE2_rb_v-rf360',
                      help="ID vehicle [%default].")
    parser.add_option("--world",
                      default='stochastic_box_10',
                      help="ID world [%default].")
    parser.add_option("-n",
                      default=1,
                      type='int',
                      help="number of simulations [%default].")
    parser.add_option("--outdir",
                      "-o",
                      default='display_demo',
                      help="output directory [%default]")
    parser.add_option("--figsize",
                      default=10,
                      type='float',
                      help="figsize (inches) [%default]")
    parser.add_option("-z",
                      "--zoom",
                      default=0,
                      type='float',
                      help="zoom in meters; 0 for full view [%default]")
    parser.add_option("-g",
                      "--grid",
                      default=1,
                      type='float',
                      help="grid size in meters; 0 for no grid [%default]")

    parser.add_option("--cairo", default=False, action='store_true')

    parser.add_option("--seed", default=None, type='int')

    (options, args) = parser.parse_args()
    if args:
        raise Exception()

    id_vehicle = options.vehicle
    id_world = options.world

    logger.info('id_vehicle: %s' % id_vehicle)
    logger.info('  id_world: %s' % id_world)

    if options.seed is None:
        options.seed = np.random.randint(1000000)

    np.random.seed(seed=options.seed)
    logger.info('Using seed %s (your lucky number is %s)' %
                (options.seed, np.random.randint(1000)))

    vehicle = VehiclesConfig.vehicles.instance(
        id_vehicle)  # @UndefinedVariable
    world = VehiclesConfig.worlds.instance(id_world)  # @UndefinedVariable

    simulation = VehicleSimulation(vehicle, world)

    from reprep import Report, MIME_PDF
    basename = 'display-%s-%s' % (id_vehicle, id_world)
    r = Report(basename)
    r.text('seed', 'Seed = %s' % options.seed)
    for i in range(options.n):
        sec = r.node('simulation%d' % i)
        f = sec.figure()

        simulation.new_episode()
        simulation.compute_observations()

        sim_state = simulation.to_yaml()

        plot_params = dict(grid=options.grid,
                           zoom=options.zoom,
                           show_sensor_data=True)
        #            with f.plot('start', figsize=(options.figsize,
        #                                                options.figsize)) as pylab:
        #                    display_all(pylab, sim_state, **plot_params)

        with f.data_file('start_cairo_png', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                                       width=800,
                                       height=800,
                                       sim_state=sim_state,
                                       **plot_params)

        with f.data_file('start_cairo_pdf', MIME_PDF) as filename:
            vehicles_cairo_display_pdf(filename,
                                       width=800,
                                       height=800,
                                       sim_state=sim_state,
                                       **plot_params)

        with f.data_file('start_cairo_svg', MIME_SVG) as filename:
            vehicles_cairo_display_svg(filename,
                                       width=800,
                                       height=800,
                                       sim_state=sim_state,
                                       **plot_params)

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)
예제 #4
0
def main():
    if not vehicles_has_cairo:
        logger.error('This program cannot be run if Cairo is not installed.')
        return
    from vehicles_cairo import (vehicles_cairo_display_pdf,
                                vehicles_cairo_display_png,
                                vehicles_cairo_display_svg)

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--vehicle", default='d_SE2_rb_v-rf360',
                      help="ID vehicle [%default].")
    parser.add_option("--world", default='stochastic_box_10',
                       help="ID world [%default].")
    parser.add_option("-n", default=1, type='int',
                    help="number of simulations [%default].")
    parser.add_option("--outdir", "-o", default='display_demo',
                    help="output directory [%default]")
    parser.add_option("--figsize", default=10, type='float',
                    help="figsize (inches) [%default]")
    parser.add_option("-z", "--zoom", default=0, type='float',
                    help="zoom in meters; 0 for full view [%default]")
    parser.add_option("-g", "--grid", default=1, type='float',
                    help="grid size in meters; 0 for no grid [%default]")

    parser.add_option("--cairo", default=False, action='store_true')

    parser.add_option("--seed", default=None, type='int')

    (options, args) = parser.parse_args()
    if args:
        raise Exception()

    id_vehicle = options.vehicle
    id_world = options.world

    logger.info('id_vehicle: %s' % id_vehicle)
    logger.info('  id_world: %s' % id_world)

    if options.seed is None:
        options.seed = np.random.randint(1000000)

    np.random.seed(seed=options.seed)
    logger.info('Using seed %s (your lucky number is %s)' % 
                (options.seed, np.random.randint(1000)))

    vehicle = VehiclesConfig.vehicles.instance(id_vehicle)  # @UndefinedVariable
    world = VehiclesConfig.worlds.instance(id_world)  # @UndefinedVariable

    simulation = VehicleSimulation(vehicle, world)

    from reprep import Report, MIME_PDF
    basename = 'display-%s-%s' % (id_vehicle, id_world)
    r = Report(basename)
    r.text('seed', 'Seed = %s' % options.seed)
    for i in range(options.n):
        sec = r.node('simulation%d' % i)
        f = sec.figure()

        simulation.new_episode()
        simulation.compute_observations()

        sim_state = simulation.to_yaml()

        plot_params = dict(grid=options.grid,
                           zoom=options.zoom, show_sensor_data=True)
#            with f.plot('start', figsize=(options.figsize,
#                                                options.figsize)) as pylab:
#                    display_all(pylab, sim_state, **plot_params)

        with f.data_file('start_cairo_png', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename, width=800, height=800,
                        sim_state=sim_state, **plot_params)

        with f.data_file('start_cairo_pdf', MIME_PDF) as filename:
            vehicles_cairo_display_pdf(filename, width=800, height=800,
                        sim_state=sim_state, **plot_params)

        with f.data_file('start_cairo_svg', MIME_SVG) as filename:
            vehicles_cairo_display_svg(filename, width=800, height=800,
                        sim_state=sim_state, **plot_params)

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)
예제 #5
0
def main():
    from vehicles_cairo import vehicles_has_cairo
    if not vehicles_has_cairo:
        logger.error('This program cannot be run if Cairo is not installed.')
        return

    from vehicles_cairo import (vehicles_cairo_display_pdf,
                                vehicles_cairo_display_png,
                                vehicles_cairo_display_svg,
                                cairo_plot_circle2)

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--vehicles", default='*',
                      help="ID vehicle [%default].")
    parser.add_option("--world", default='SBox2_10a',
                      # default='empty_fixed',
                       help="ID world [%default].")
    parser.add_option("--outdir", "-o",
                      default='vehicles_demo_display_vehicles',
                    help="output directory [%default]")
    parser.add_option("--figsize", default=10, type='float',
                    help="figsize (inches) [%default]")
    parser.add_option("-g", "--grid", default=1, type='float',
                    help="grid size in meters; 0 for no grid [%default]")
    parser.add_option("-d", dest="config", default=".",
                      help="Config directory")
    parser.add_option("--scale", default=False, action='store_true',
                    help="If given, displays the scale with a red circle")

    (options, args) = parser.parse_args()
    if args:
        raise Exception()  # XXX

    id_world = options.world

    logger.info('  id_world: %s' % id_world)

    from reprep import Report, MIME_PDF
    basename = 'vehicles_demo'
    r = Report(basename)

    logger.info('Loading configuration from %s' % options.config)
    VehiclesConfig.load(options.config)

    # TODO: selection
    all_vehicles = VehiclesConfig.vehicles.keys()
    if options.vehicles is None:
        vehicles = all_vehicles
    else:
        vehicles = expand_string(options.vehicles, all_vehicles)

    print('Plotting vehicles: %s' % vehicles)

    f0 = r.figure(cols=6)
    f0_data = r.figure(cols=6)

    for id_vehicle in sorted(vehicles):
        sec = r.node(id_vehicle)
        f = sec.figure(cols=6)

        world = VehiclesConfig.specs['worlds'].instance(id_world)
        vehicle = VehiclesConfig.specs['vehicles'].instance(id_vehicle)
        simulation = VehicleSimulation(vehicle, world)
        simulation.new_episode()
        simulation.compute_observations()
        sim_state = simulation.to_yaml()

        def draw_scale(cr):
            if options.scale:
                cairo_plot_circle2(cr, 0, 0,
                               vehicle.radius, fill_color=(1, .7, .7))

        plot_params = dict(grid=options.grid,
                           zoom=1.5,
                           zoom_scale_radius=True,
                           width=500, height=500,
                           show_sensor_data=True,
                           show_sensor_data_compact=True,
                           extra_draw_world=draw_scale,
                           bgcolor=None,
                           show_world=False)

        with f.data_file('png_with', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                        sim_state=sim_state, **plot_params)

        f0_data.sub(f.last(), caption=id_vehicle)

        plot_params['show_sensor_data'] = False
        with f.data_file('png_without', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                        sim_state=sim_state, **plot_params)

        f0.sub(f.last(), caption=id_vehicle)

        with f.data_file('svg', MIME_SVG) as filename:
            vehicles_cairo_display_svg(filename,
                        sim_state=sim_state, **plot_params)

        plot_params['grid'] = 0
        plot_params['extra_draw_world'] = None
        with sec.data_file('pdf', MIME_PDF) as filename:
            vehicles_cairo_display_pdf(filename,
                        sim_state=sim_state, **plot_params)

        plot_params['show_robot_body'] = True
        plot_params['show_robot_sensors'] = False
        with f.data_file('png_only_body', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                        sim_state=sim_state, **plot_params)

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)