Exemplo n.º 1
0
  def testActivation(self):
    target_radius = 0.6
    prop_radius = 0.1
    target_height = 1

    arena = floors.Floor()
    target = target_sphere.TargetSphere(radius=target_radius,
                                        height_above_ground=target_height)
    prop = primitive.Primitive(geom_type='sphere', size=[prop_radius])
    arena.attach(target)
    arena.add_free_entity(prop)

    task = composer.NullTask(arena)
    task.initialize_episode = (
        lambda physics, random_state: prop.set_pose(physics, [0, 0, 2]))

    env = composer.Environment(task)
    env.reset()

    max_activated_height = target_height + target_radius + prop_radius

    while env.physics.bind(prop.geom).xpos[2] > max_activated_height:
      self.assertFalse(target.activated)
      self.assertEqual(env.physics.bind(target.material).rgba[-1], 1)
      env.step([])

    while env.physics.bind(prop.geom).xpos[2] > 0.2:
      self.assertTrue(target.activated)
      self.assertEqual(env.physics.bind(target.material).rgba[-1], 0)
      env.step([])

    # Target should be reset when the environment is reset.
    env.reset()
    self.assertFalse(target.activated)
    self.assertEqual(env.physics.bind(target.material).rgba[-1], 1)
Exemplo n.º 2
0
    def __init__(self,
                 walker,
                 maze_arena,
                 target=None,
                 target_reward_scale=1.0,
                 randomize_spawn_position=True,
                 randomize_spawn_rotation=True,
                 rotation_bias_factor=0,
                 aliveness_reward=0.0,
                 aliveness_threshold=DEFAULT_ALIVE_THRESHOLD,
                 contact_termination=True,
                 max_repeats=0,
                 enable_global_task_observables=False,
                 physics_timestep=DEFAULT_PHYSICS_TIMESTEP,
                 control_timestep=DEFAULT_CONTROL_TIMESTEP,
                 regenerate_maze_on_repeat=False):
        super(RepeatSingleGoalMaze, self).__init__(
            walker=walker,
            maze_arena=maze_arena,
            randomize_spawn_position=randomize_spawn_position,
            randomize_spawn_rotation=randomize_spawn_rotation,
            rotation_bias_factor=rotation_bias_factor,
            aliveness_reward=aliveness_reward,
            aliveness_threshold=aliveness_threshold,
            contact_termination=contact_termination,
            enable_global_task_observables=enable_global_task_observables,
            physics_timestep=physics_timestep,
            control_timestep=control_timestep)
        if target is None:
            target = target_sphere.TargetSphere()
        self._target = target
        self._rewarded_this_step = False
        self._maze_arena.attach(target)
        self._target_reward_scale = target_reward_scale
        self._max_repeats = max_repeats
        self._targets_obtained = 0
        self._regenerate_maze_on_repeat = regenerate_maze_on_repeat

        if enable_global_task_observables:
            xpos_origin_callable = lambda phys: phys.bind(walker.root_body
                                                          ).xpos

            def _target_pos(physics, target=target):
                return physics.bind(target.geom).xpos

            walker.observables.add_egocentric_vector(
                'target_0',
                observable_lib.Generic(_target_pos),
                origin_callable=xpos_origin_callable)
Exemplo n.º 3
0
 def __init__(self,
              walker,
              main_target,
              maze_arena,
              num_subtargets=20,
              target_reward_scale=10.0,
              subtarget_reward_scale=1.0,
              subtarget_colors=((0, 0, 0.4), (0, 0, 0.7)),
              randomize_spawn_position=True,
              randomize_spawn_rotation=True,
              rotation_bias_factor=0,
              aliveness_reward=0.0,
              aliveness_threshold=DEFAULT_ALIVE_THRESHOLD,
              contact_termination=True,
              physics_timestep=DEFAULT_PHYSICS_TIMESTEP,
              control_timestep=DEFAULT_CONTROL_TIMESTEP):
     super(RepeatSingleGoalMazeAugmentedWithTargets,
           self).__init__(walker=walker,
                          target=main_target,
                          maze_arena=maze_arena,
                          target_reward_scale=target_reward_scale,
                          randomize_spawn_position=randomize_spawn_position,
                          randomize_spawn_rotation=randomize_spawn_rotation,
                          rotation_bias_factor=rotation_bias_factor,
                          aliveness_reward=aliveness_reward,
                          aliveness_threshold=aliveness_threshold,
                          contact_termination=contact_termination,
                          physics_timestep=physics_timestep,
                          control_timestep=control_timestep)
     self._subtarget_reward_scale = subtarget_reward_scale
     self._subtargets = []
     for i in range(num_subtargets):
         subtarget = target_sphere.TargetSphere(
             radius=0.4,
             rgb1=subtarget_colors[0],
             rgb2=subtarget_colors[1],
             name='subtarget_{}'.format(i))
         self._subtargets.append(subtarget)
         self._maze_arena.attach(subtarget)
     self._subtarget_rewarded = None