(self,
               gym_config,
               robot_class=None,
               env_sensors=None,
               robot_sensors=None,
               task=None,
               env_randomizers=None)
Initializes the locomotion gym environment.

    Args:
      gym_config: An instance of LocomotionGymConfig.
      robot_class: A class of a robot. We provide a class rather than an
        instance due to hard_reset functionality. Parameters are expected to be
        configured with gin.
      sensors: A list of environmental sensors for observation.
      task: A callable function/class to calculate the reward and termination
        condition. Takes the gym env as the argument when calling.
      env_randomizers: A list of EnvRandomizer(s). An EnvRandomizer may
        randomize the physical property of minitaur, change the terrrain during
        reset(), or add perturbation forces during step().

    Raises:
      ValueError: If the num_action_repeat is less than 1.
Initializes the locomotion gym environment.
Initializes the locomotion gym environment .
def __init__(self,
               gym_config,
               robot_class=None,
               env_sensors=None,
               robot_sensors=None,
               task=None,
               env_randomizers=None):
    """Initializes the locomotion gym environment.

    Args:
      gym_config: An instance of LocomotionGymConfig.
      robot_class: A class of a robot. We provide a class rather than an
        instance due to hard_reset functionality. Parameters are expected to be
        configured with gin.
      sensors: A list of environmental sensors for observation.
      task: A callable function/class to calculate the reward and termination
        condition. Takes the gym env as the argument when calling.
      env_randomizers: A list of EnvRandomizer(s). An EnvRandomizer may
        randomize the physical property of minitaur, change the terrrain during
        reset(), or add perturbation forces during step().

    Raises:
      ValueError: If the num_action_repeat is less than 1.

    """

    self.seed()
    self._gym_config = gym_config
    self._robot_class = robot_class
    self._robot_sensors = robot_sensors

    self._sensors = env_sensors if env_sensors is not None else list()
    if self._robot_class is None:
      raise ValueError('robot_class cannot be None.')

    # A dictionary containing the objects in the world other than the robot.
    self._world_dict = {}
    self._task = task

    self._env_randomizers = env_randomizers if env_randomizers else []

    # This is a workaround due to the issue in b/130128505#comment5
    if isinstance(self._task, sensor.Sensor):
      self._sensors.append(self._task)

    # Simulation related parameters.
    self._num_action_repeat = gym_config.simulation_parameters.num_action_repeat
    self._on_rack = gym_config.simulation_parameters.robot_on_rack
    if self._num_action_repeat < 1:
      raise ValueError('number of action repeats should be at least 1.')
    self._sim_time_step = gym_config.simulation_parameters.sim_time_step_s
    self._env_time_step = self._num_action_repeat * self._sim_time_step
    self._env_step_counter = 0

    self._num_bullet_solver_iterations = int(_NUM_SIMULATION_ITERATION_STEPS /
                                             self._num_action_repeat)
    self._is_render = gym_config.simulation_parameters.enable_rendering

    # The wall-clock time at which the last frame is rendered.
    self._last_frame_time = 0.0
    self._show_reference_id = -1

    if self._is_render:
      self._pybullet_client = bullet_client.BulletClient(
          connection_mode=pybullet.GUI)
      pybullet.configureDebugVisualizer(
          pybullet.COV_ENABLE_GUI,
          gym_config.simulation_parameters.enable_rendering_gui)
      if hasattr(self._task, '_draw_ref_model_alpha'):
        self._show_reference_id = pybullet.addUserDebugParameter("show reference",0,1,
          self._task._draw_ref_model_alpha)
      self._delay_id = pybullet.addUserDebugParameter("delay",0,0.3,0)
    else:
      self._pybullet_client = bullet_client.BulletClient(
          connection_mode=pybullet.DIRECT)
    self._pybullet_client.setAdditionalSearchPath(pd.getDataPath())
    if gym_config.simulation_parameters.egl_rendering:
      self._pybullet_client.loadPlugin('eglRendererPlugin')

    # The action list contains the name of all actions.
    self._build_action_space()

    # Set the default render options.
    self._camera_dist = gym_config.simulation_parameters.camera_distance
    self._camera_yaw = gym_config.simulation_parameters.camera_yaw
    self._camera_pitch = gym_config.simulation_parameters.camera_pitch
    self._render_width = gym_config.simulation_parameters.render_width
    self._render_height = gym_config.simulation_parameters.render_height

    self._hard_reset = True
    self.reset()

    self._hard_reset = gym_config.simulation_parameters.enable_hard_reset

    # Construct the observation space from the list of sensors. Note that we
    # will reconstruct the observation_space after the robot is created.
    self.observation_space = (
        space_utils.convert_sensors_to_gym_space_dictionary(
            self.all_sensors()))
def __init__ ( self , gym_config , robot_class = None , env_sensors = None , robot_sensors = None , task = None , env_randomizers = None ) : self . seed ( ) self . _gym_config = gym_config self . _robot_class = robot_class self . _robot_sensors = robot_sensors self . _sensors = env_sensors if env_sensors is not None else list ( ) if self . _robot_class is None : raise ValueError ( 'robot_class cannot be None.' ) # A dictionary containing the objects in the world other than the robot. self . _world_dict = { } self . _task = task self . _env_randomizers = env_randomizers if env_randomizers else [ ] # This is a workaround due to the issue in b/130128505#comment5 if isinstance ( self . _task , sensor . Sensor ) : self . _sensors . append ( self . _task ) # Simulation related parameters. self . _num_action_repeat = gym_config . simulation_parameters . num_action_repeat self . _on_rack = gym_config . simulation_parameters . robot_on_rack if self . _num_action_repeat < 1 : raise ValueError ( 'number of action repeats should be at least 1.' ) self . _sim_time_step = gym_config . simulation_parameters . sim_time_step_s self . _env_time_step = self . _num_action_repeat * self . _sim_time_step self . _env_step_counter = 0 self . _num_bullet_solver_iterations = int ( _NUM_SIMULATION_ITERATION_STEPS / self . _num_action_repeat ) self . _is_render = gym_config . simulation_parameters . enable_rendering # The wall-clock time at which the last frame is rendered. self . _last_frame_time = 0.0 self . _show_reference_id = - 1 if self . _is_render : self . _pybullet_client = bullet_client . BulletClient ( connection_mode = pybullet . GUI ) pybullet . configureDebugVisualizer ( pybullet . COV_ENABLE_GUI , gym_config . simulation_parameters . enable_rendering_gui ) if hasattr ( self . _task , '_draw_ref_model_alpha' ) : self . _show_reference_id = pybullet . addUserDebugParameter ( "show reference" , 0 , 1 , self . _task . _draw_ref_model_alpha ) self . _delay_id = pybullet . addUserDebugParameter ( "delay" , 0 , 0.3 , 0 ) else : self . _pybullet_client = bullet_client . BulletClient ( connection_mode = pybullet . DIRECT ) self . _pybullet_client . setAdditionalSearchPath ( pd . getDataPath ( ) ) if gym_config . simulation_parameters . egl_rendering : self . _pybullet_client . loadPlugin ( 'eglRendererPlugin' ) # The action list contains the name of all actions. self . _build_action_space ( ) # Set the default render options. self . _camera_dist = gym_config . simulation_parameters . camera_distance self . _camera_yaw = gym_config . simulation_parameters . camera_yaw self . _camera_pitch = gym_config . simulation_parameters . camera_pitch self . _render_width = gym_config . simulation_parameters . render_width self . _render_height = gym_config . simulation_parameters . render_height self . _hard_reset = True self . reset ( ) self . _hard_reset = gym_config . simulation_parameters . enable_hard_reset # Construct the observation space from the list of sensors. Note that we # will reconstruct the observation_space after the robot is created. self . observation_space = ( space_utils . convert_sensors_to_gym_space_dictionary ( self . all_sensors ( ) ) )