Пример #1
0
    def __init__(self,
                 world=None,
                 id_world=None,
                 vehicle=None,
                 id_vehicle=None,
                 dt=VehiclesConstants.DEFAULT_SIMULATION_DT,
                 **kwargs):
        self.dt = dt

        if not ((world is not None) ^ (id_world is not None)):
            raise ValueError('Specify exactly one of "world" and "id_world".')
        if not ((vehicle is not None) ^ (id_vehicle is not None)):
            raise ValueError('Specify exactly one of "vehicle" '
                             'and "id_vehicle".')

        vehicles = get_conftools_vehicles()
        worlds = get_conftools_worlds()

        # TODO: user shortcuts
        if vehicle is not None:
            id_vehicle = vehicle['id']
            vehicle_spec = vehicle
            # TODO: check well formed
            vehicle = vehicles.instance_spec(vehicle)
        else:
            vehicle_spec = vehicles[id_vehicle]
            vehicle = vehicles.instance(id_vehicle)

        if world is not None:
            id_world = world['id']
            # TODO: check well formed
            world_spec = world
            world = worlds.instance_spec(world)
        else:
            world_spec = worlds[id_world]
            world = worlds.instance(id_world)

        VehicleSimulation.__init__(self, vehicle, world, **kwargs)

        cmd_spec = StreamSpec.from_yaml(
                                self.vehicle.dynamics.get_commands_spec())

        self.last_commands = cmd_spec.get_default_value()

        if len(self.vehicle.sensors) == 0:
            raise Exception('Vehicle %r has no sensors defined.' % id_vehicle)

        obs_spec = create_obs_spec(self.vehicle)
        self._boot_spec = BootSpec(obs_spec=obs_spec, cmd_spec=cmd_spec,
                                   id_robot=id_vehicle)
        # XXX: id, desc, extra?
        self.commands_source = BootOlympicsConstants.CMD_SOURCE_REST

        self.boot_episode_started = False

        # Save for later
        self.id_world = id_world
        self.id_vehicle = id_vehicle
        self.world_spec = world_spec
        self.vehicle_spec = vehicle_spec
Пример #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 __init__(self, id_worlds):
        self.id_worlds = id_worlds
        self.worlds = [get_conftools_worlds().instance(id_world) 
                       for id_world in id_worlds] 

        wb = [w.bounds for w in self.worlds]

        bounds = [[np.min([b[0][0] for b in wb]),
                   np.max([b[0][1] for b in wb])],
                  [np.min([b[1][0] for b in wb]),
                   np.max([b[1][1] for b in wb])],
                  [np.min([b[2][0] for b in wb]),
                   np.max([b[2][1] for b in wb])]]
        bounds = np.array(bounds).tolist()
        World.__init__(self, bounds)
Пример #4
0
    def __init__(self, id_worlds):
        self.id_worlds = id_worlds
        self.worlds = [
            get_conftools_worlds().instance(id_world) for id_world in id_worlds
        ]

        wb = [w.bounds for w in self.worlds]

        bounds = [
            [np.min([b[0][0] for b in wb]),
             np.max([b[0][1] for b in wb])],
            [np.min([b[1][0] for b in wb]),
             np.max([b[1][1] for b in wb])],
            [np.min([b[2][0] for b in wb]),
             np.max([b[2][1] for b in wb])]
        ]
        bounds = np.array(bounds).tolist()
        World.__init__(self, bounds)
Пример #5
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)
Пример #6
0
    def __init__(self,
                 world=None,
                 id_world=None,
                 vehicle=None,
                 id_vehicle=None,
                 dt=VehiclesConstants.DEFAULT_SIMULATION_DT,
                 **kwargs):
        self.dt = dt

        if not ((world is not None) ^ (id_world is not None)):
            raise ValueError('Specify exactly one of "world" and "id_world".')
        if not ((vehicle is not None) ^ (id_vehicle is not None)):
            raise ValueError('Specify exactly one of "vehicle" '
                             'and "id_vehicle".')

        vehicles = get_conftools_vehicles()
        worlds = get_conftools_worlds()

        # TODO: user shortcuts
        if vehicle is not None:
            id_vehicle = vehicle['id']
            vehicle_spec = vehicle
            # TODO: check well formed
            vehicle = vehicles.instance_spec(vehicle)
        else:
            vehicle_spec = vehicles[id_vehicle]
            vehicle = vehicles.instance(id_vehicle)

        if world is not None:
            id_world = world['id']
            # TODO: check well formed
            world_spec = world
            world = worlds.instance_spec(world)
        else:
            world_spec = worlds[id_world]
            world = worlds.instance(id_world)

        VehicleSimulation.__init__(self, vehicle, world, **kwargs)

        cmd_spec = StreamSpec.from_yaml(
            self.vehicle.dynamics.get_commands_spec())

        self.last_commands = cmd_spec.get_default_value()

        if len(self.vehicle.sensors) == 0:
            raise Exception('Vehicle %r has no sensors defined.' % id_vehicle)

        obs_spec = create_obs_spec(self.vehicle)
        self._boot_spec = BootSpec(obs_spec=obs_spec,
                                   cmd_spec=cmd_spec,
                                   id_robot=id_vehicle)
        # XXX: id, desc, extra?
        self.commands_source = BootOlympicsConstants.CMD_SOURCE_REST

        self.boot_episode_started = False

        # Save for later
        self.id_world = id_world
        self.id_vehicle = id_vehicle
        self.world_spec = world_spec
        self.vehicle_spec = vehicle_spec
Пример #7
0
# 
#     try:
#         function(*arguments)
#     except:
#         msg = ('Error detected when running test (%s); displaying debug info.'
#                % function.__name__)
#         if dynamics is not None:
#             msg += '\ndynamics: %s' % dynamics
#         # TODO: write other info
#         logger.error(msg)
#         raise


for_all_dynamics = comptests_for_all(get_conftools_dynamics())
for_all_vehicles = comptests_for_all(get_conftools_vehicles())
for_all_worlds = comptests_for_all(get_conftools_worlds())
for_all_sensors = comptests_for_all(get_conftools_sensors())
for_all_skins = comptests_for_all(get_conftools_skins())
for_all_world_vehicle_pairs = comptests_for_all_pairs(get_conftools_worlds(),
                                                      get_conftools_vehicles())

# 
# for_all_dynamics = fancy_test_decorator(lister=all_dynamics,
#             arguments=lambda x: (x, get_dynamics(x)),
#             attributes=lambda x: dict(dynamics=x))
# 
# for_all_worlds = fancy_test_decorator(lister=all_worlds,
#             arguments=lambda x: (x, get_world(x)),
#             attributes=lambda x: dict(world=x))
# 
# for_all_vehicles = fancy_test_decorator(lister=all_vehicles,
Пример #8
0
#         if an exception is detected. '''
#
#     try:
#         function(*arguments)
#     except:
#         msg = ('Error detected when running test (%s); displaying debug info.'
#                % function.__name__)
#         if dynamics is not None:
#             msg += '\ndynamics: %s' % dynamics
#         # TODO: write other info
#         logger.error(msg)
#         raise

for_all_dynamics = comptests_for_all(get_conftools_dynamics())
for_all_vehicles = comptests_for_all(get_conftools_vehicles())
for_all_worlds = comptests_for_all(get_conftools_worlds())
for_all_sensors = comptests_for_all(get_conftools_sensors())
for_all_skins = comptests_for_all(get_conftools_skins())
for_all_world_vehicle_pairs = comptests_for_all_pairs(get_conftools_worlds(),
                                                      get_conftools_vehicles())

#
# for_all_dynamics = fancy_test_decorator(lister=all_dynamics,
#             arguments=lambda x: (x, get_dynamics(x)),
#             attributes=lambda x: dict(dynamics=x))
#
# for_all_worlds = fancy_test_decorator(lister=all_worlds,
#             arguments=lambda x: (x, get_world(x)),
#             attributes=lambda x: dict(world=x))
#
# for_all_vehicles = fancy_test_decorator(lister=all_vehicles,