예제 #1
0
 def step(self, action, action_dot):
     self._last_base_position = self.minitaur.GetTrueBasePosition()
     if self._is_render:
         time_spent = time.time() - self._last_frame_time
         self._last_frame_time = time.time()
         time_to_sleep = self.control_time_step - time_spent
         if time_to_sleep > 0:
             time.sleep(time_to_sleep)
         base_pos = self.minitaur.GetTrueBasePosition()
         [yaw, pitch,
          dist] = self._pybullet_client.getDebugVisualizerCamera()[8:11]
         self._pybullet_client.resetDebugVisualizerCamera(
             dist, yaw, pitch, base_pos)
     for env_randomizer in self._env_randomizers:
         env_randomizer.randomize_step(self)
     self.minitaur.Step(action, action_dot)
     self._get_true_observation()
     done = self._termination()
     if self._log_path is not None:
         minitaur_logging.update_episode_proto(self._episode_proto,
                                               self.minitaur, action,
                                               self._env_step_counter)
     self._env_step_counter += 1
     if done:
         self.minitaur.Terminate()
     return np.array(self._get_true_observation())
예제 #2
0
    def _step_old_robot_class(self, action):
        self._last_base_position = self._robot.GetBasePosition()
        self._last_action = action

        if self._is_render:
            self._wait_for_rendering()

        for env_randomizer in self._env_randomizers:
            env_randomizer.randomize_step(self)

        self._robot.Step(action)

        if self._profiling_slot >= 0:
            self._profiling_counter -= 1
            if self._profiling_counter == 0:
                self._pybullet_client.stopStateLogging(self._profiling_slot)

        if self._log_path is not None:
            minitaur_logging.update_episode_proto(self._episode_proto,
                                                  self._robot, action,
                                                  self._env_step_counter)
        reward = self._reward()

        for s in self.all_sensors():
            s.on_step(self)

        if self._task and hasattr(self._task, 'update'):
            self._task.update(self)  # TODO(b/154635313): resolve API mismatch

        done = self._termination()
        self._env_step_counter += 1
        # TODO(b/161941829): terminate removed for now, change terminate to other
        # names.
        return self._get_observation(), reward, done, {}
예제 #3
0
    def _step_new_robot_class(self, action):
        self._last_base_position = self._robot.base_position
        self._last_action = action

        if self._is_render:
            self._wait_for_rendering()

        for env_randomizer in self._env_randomizers:
            env_randomizer.randomize_step(self)

        action = self._robot.pre_control_step(action, self._env_time_step)
        for obj in self._dynamic_objects():
            obj.pre_control_step(autonomous_object.AUTONOMOUS_ACTION)
        for _ in range(self._num_action_repeat):
            for env_randomizer in self._env_randomizers:
                env_randomizer.randomize_sub_step(self, i,
                                                  self._num_action_repeat)
            self._robot.apply_action(action)
            for obj in self._dynamic_objects():
                obj.update(self.get_time_since_reset(), self._observation_dict)
                obj.apply_action(autonomous_object.AUTONOMOUS_ACTION)

            self._pybullet_client.stepSimulation()
            self._sim_step_counter += 1

            self._robot.receive_observation()
            for obj in self._dynamic_objects():
                obj.receive_observation()

            for s in self.all_sensors():
                s.on_new_observation()

        self._robot.post_control_step()
        for obj in self._dynamic_objects():
            obj.post_control_step()

        if self._profiling_slot >= 0:
            self._profiling_counter -= 1
            if self._profiling_counter == 0:
                self._pybullet_client.stopStateLogging(self._profiling_slot)

        if self._log_path is not None:
            minitaur_logging.update_episode_proto(self._episode_proto,
                                                  self._robot, action,
                                                  self._env_step_counter)
        reward = self._reward()

        for s in self.all_sensors():
            s.on_step(self)

        if self._task and hasattr(self._task, 'update'):
            self._task.update(self)  # TODO(b/154635313): resolve API mismatch

        done = self._termination()
        self._env_step_counter += 1
        # TODO(b/161941829): terminate removed for now, change terminate to other
        # names.
        return self._get_observation(), reward, done, {}
예제 #4
0
    def step(self, action):
        """Step forward the simulation, given the action.

    Args:
      action: A list of desired motor angles for eight motors.

    Returns:
      observations: The angles, velocities and torques of all motors.
      reward: The reward for the current state-action pair.
      done: Whether the episode has ended.
      info: A dictionary that stores diagnostic information.

    Raises:
      ValueError: The action dimension is not the same as the number of motors.
      ValueError: The magnitude of actions is out of bounds.
      :param control_m:
    """
        self._last_base_position = self.minitaur.GetBasePosition()

        if self._is_render:
            # Sleep, otherwise the computation takes less time than real time,
            # which will make the visualization like a fast-forward video.
            time_spent = time.time() - self._last_frame_time
            self._last_frame_time = time.time()
            time_to_sleep = self.control_time_step - time_spent
            if time_to_sleep > 0:
                time.sleep(time_to_sleep)
            base_pos = self.minitaur.GetBasePosition()
            # Keep the previous orientation of the camera set by the user.
            [yaw, pitch,
             dist] = self._pybullet_client.getDebugVisualizerCamera()[8:11]
            self._pybullet_client.resetDebugVisualizerCamera(
                dist, yaw, pitch, base_pos)

        for env_randomizer in self._env_randomizers:
            env_randomizer.randomize_step(self)

        action = self._transform_action_to_motor_command(action)
        self.minitaur.Step(action)

        reward = self._reward()
        done = self._termination()
        if self._log_path is not None:
            minitaur_logging.update_episode_proto(self._episode_proto,
                                                  self.minitaur, action,
                                                  self._env_step_counter)
        self._env_step_counter += 1
        if done:
            self.minitaur.Terminate()
        return np.array(self._get_observation()), reward, done, {}
예제 #5
0
  def _step(self, action):
    """Step forward the simulation, given the action.

    Args:
      action: A list of desired motor angles for eight motors.

    Returns:
      observations: The angles, velocities and torques of all motors.
      reward: The reward for the current state-action pair.
      done: Whether the episode has ended.
      info: A dictionary that stores diagnostic information.

    Raises:
      ValueError: The action dimension is not the same as the number of motors.
      ValueError: The magnitude of actions is out of bounds.
    """
    self._last_base_position = self.minitaur.GetBasePosition()

    if self._is_render:
      # Sleep, otherwise the computation takes less time than real time,
      # which will make the visualization like a fast-forward video.
      time_spent = time.time() - self._last_frame_time
      self._last_frame_time = time.time()
      time_to_sleep = self.control_time_step - time_spent
      if time_to_sleep > 0:
        time.sleep(time_to_sleep)
      base_pos = self.minitaur.GetBasePosition()
      # Keep the previous orientation of the camera set by the user.
      [yaw, pitch,
       dist] = self._pybullet_client.getDebugVisualizerCamera()[8:11]
      self._pybullet_client.resetDebugVisualizerCamera(dist, yaw, pitch,
                                                       base_pos)

    for env_randomizer in self._env_randomizers:
      env_randomizer.randomize_step(self)

    action = self._transform_action_to_motor_command(action)
    self.minitaur.Step(action)
    reward = self._reward()
    done = self._termination()
    if self._log_path is not None:
      minitaur_logging.update_episode_proto(self._episode_proto, self.minitaur,
                                            action, self._env_step_counter)
    self._env_step_counter += 1
    if done:
      self.minitaur.Terminate()
    return np.array(self._get_observation()), reward, done, {}
    def _step(self, action):
        """Step forward the simulation, given the action.

    Args:
      action: A list of desired motor angles for eight motors.

    Returns:
      observations: Roll, pitch of the base, and roll, pitch rate.
      reward: The reward for the current state-action pair.
      done: Whether the episode has ended.
      info: A dictionary that stores diagnostic information.

    Raises:
      ValueError: The action dimension is not the same as the number of motors.
      ValueError: The magnitude of actions is out of bounds.
    """
        if self._is_render:
            # Sleep, otherwise the computation takes less time than real time,
            # which will make the visualization like a fast-forward video.
            time_spent = time.time() - self._last_frame_time
            self._last_frame_time = time.time()
            time_to_sleep = self.control_time_step - time_spent
            if time_to_sleep > 0:
                time.sleep(time_to_sleep)
            base_pos = self.minitaur.GetBasePosition()
            # Keep the previous orientation of the camera set by the user.
            [yaw, pitch,
             dist] = self._pybullet_client.getDebugVisualizerCamera()[8:11]
            self._pybullet_client.resetDebugVisualizerCamera(
                dist, yaw, pitch, base_pos)
        action = self._transform_action_to_motor_command(action)
        t = self._env_step_counter % MOVING_FLOOR_TOTAL_STEP
        if t == 0:
            self._seed()
            orientation_x = random.uniform(-0.2, 0.2)
            self._seed()
            orientation_y = random.uniform(-0.2, 0.2)
            _, self._cur_ori = self._pybullet_client.getBasePositionAndOrientation(
                0)
            self._goal_ori = self._pybullet_client.getQuaternionFromEuler(
                [orientation_x, orientation_y, 0])
        t = float(float(t) / float(MOVING_FLOOR_TOTAL_STEP))
        ori = map(operator.add, [x * (1.0 - t) for x in self._cur_ori],
                  [x * t for x in self._goal_ori])
        ori = list(ori)
        print("ori=", ori)
        self._pybullet_client.resetBasePositionAndOrientation(
            0, [0, 0, 0], ori)
        if self._env_step_counter % PERTURBATION_TOTAL_STEP == 0:
            self._perturbation_magnitude = random.uniform(0.0, 0.0)
            if self._sign < 0.5:
                self._sign = 1.0
            else:
                self._sign = 0.0
        self._pybullet_client.applyExternalForce(
            objectUniqueId=1,
            linkIndex=-1,
            forceObj=[self._sign * self._perturbation_magnitude, 0.0, 0.0],
            posObj=[0.0, 0.0, 0.0],
            flags=self._pybullet_client.LINK_FRAME)
        self.minitaur.Step(action)
        self._env_step_counter += 1
        done = self._termination()
        obs = self._get_true_observation()
        reward = self._reward(action, obs)
        if self._log_path is not None:
            minitaur_logging.update_episode_proto(self._episode_proto,
                                                  self.minitaur, action,
                                                  self._env_step_counter)
        if done:
            self.minitaur.Terminate()
        return np.array(self._get_observation()), reward, done, {}
  def step(self, action):
    """Step forward the simulation, given the action.

    Args:
      action: A list of desired motor angles for eight motors.

    Returns:
      observations: Roll, pitch of the base, and roll, pitch rate.
      reward: The reward for the current state-action pair.
      done: Whether the episode has ended.
      info: A dictionary that stores diagnostic information.

    Raises:
      ValueError: The action dimension is not the same as the number of motors.
      ValueError: The magnitude of actions is out of bounds.
    """
    if self._is_render:
      # Sleep, otherwise the computation takes less time than real time,
      # which will make the visualization like a fast-forward video.
      time_spent = time.time() - self._last_frame_time
      self._last_frame_time = time.time()
      time_to_sleep = self.control_time_step - time_spent
      if time_to_sleep > 0:
        time.sleep(time_to_sleep)
      base_pos = self.minitaur.GetBasePosition()
      # Keep the previous orientation of the camera set by the user.
      [yaw, pitch,
       dist] = self._pybullet_client.getDebugVisualizerCamera()[8:11]
      self._pybullet_client.resetDebugVisualizerCamera(dist, yaw, pitch,
                                                       base_pos)
    action = self._transform_action_to_motor_command(action)
    t = self._env_step_counter % MOVING_FLOOR_TOTAL_STEP
    if t == 0:
      self.seed()
      orientation_x = random.uniform(-0.2, 0.2)
      self.seed()
      orientation_y = random.uniform(-0.2, 0.2)
      _, self._cur_ori = self._pybullet_client.getBasePositionAndOrientation(0)
      self._goal_ori = self._pybullet_client.getQuaternionFromEuler(
          [orientation_x, orientation_y, 0])
    t = float(float(t) / float(MOVING_FLOOR_TOTAL_STEP))
    ori = map(operator.add, [x * (1.0 - t) for x in self._cur_ori],
              [x * t for x in self._goal_ori])
    ori=list(ori)
    print("ori=",ori)
    self._pybullet_client.resetBasePositionAndOrientation(0, [0, 0, 0], ori)
    if self._env_step_counter % PERTURBATION_TOTAL_STEP == 0:
      self._perturbation_magnitude = random.uniform(0.0, 0.0)
      if self._sign < 0.5:
        self._sign = 1.0
      else:
        self._sign = 0.0
    self._pybullet_client.applyExternalForce(
        objectUniqueId=1,
        linkIndex=-1,
        forceObj=[self._sign * self._perturbation_magnitude, 0.0, 0.0],
        posObj=[0.0, 0.0, 0.0],
        flags=self._pybullet_client.LINK_FRAME)
    self.minitaur.Step(action)
    self._env_step_counter += 1
    done = self._termination()
    obs = self._get_true_observation()
    reward = self._reward()
    if self._log_path is not None:
      minitaur_logging.update_episode_proto(self._episode_proto, self.minitaur,
                                            action, self._env_step_counter)
    if done:
      self.minitaur.Terminate()
    return np.array(self._get_observation()), reward, done, {}