robosuite.environments package#
Subpackages#
- robosuite.environments.manipulation package
- Submodules
- robosuite.environments.manipulation.door module
- robosuite.environments.manipulation.lift module
- robosuite.environments.manipulation.manipulation_env module
- robosuite.environments.manipulation.nut_assembly module
- robosuite.environments.manipulation.pick_place module
- robosuite.environments.manipulation.single_arm_env module
- robosuite.environments.manipulation.stack module
- robosuite.environments.manipulation.two_arm_env module
- robosuite.environments.manipulation.two_arm_handover module
- robosuite.environments.manipulation.two_arm_lift module
- robosuite.environments.manipulation.two_arm_peg_in_hole module
- robosuite.environments.manipulation.wipe module
- Module contents
Submodules#
robosuite.environments.base module#
- class robosuite.environments.base.EnvMeta(name, bases, class_dict)#
Bases:
type
Metaclass for registering environments
- class robosuite.environments.base.MujocoEnv(has_renderer=False, has_offscreen_renderer=True, render_camera='frontview', render_collision_mesh=False, render_visual_mesh=True, render_gpu_device_id=-1, control_freq=20, lite_physics=True, horizon=1000, ignore_done=False, hard_reset=True, renderer='mjviewer', renderer_config=None, seed=None)#
Bases:
object
Initializes a Mujoco Environment. :param has_renderer: If true, render the simulation state in
a viewer instead of headless mode.
- Parameters:
has_offscreen_renderer (bool) – True if using off-screen rendering.
render_camera (str) – Name of camera to render if has_renderer is True. Setting this value to ‘None’ will result in the default angle being applied, which is useful as it can be dragged / panned by the user using the mouse
render_collision_mesh (bool) – True if rendering collision meshes in camera. False otherwise.
render_visual_mesh (bool) – True if rendering visual meshes in camera. False otherwise.
render_gpu_device_id (int) – corresponds to the GPU device id to use for offscreen rendering. Defaults to -1, in which case the device will be inferred from environment variables (GPUS or CUDA_VISIBLE_DEVICES).
control_freq (float) – how many control signals to receive in every simulated second. This sets the amount of simulation time that passes between every action input.
lite_physics (bool) – Whether to optimize for mujoco forward and step calls to reduce total simulation overhead. Set to False to preserve backward compatibility with datasets collected in robosuite <= 1.4.1.
horizon (int) – Every episode lasts for exactly @horizon timesteps.
ignore_done (bool) – True if never terminating the environment (ignore @horizon).
hard_reset (bool) – If True, re-loads model, sim, and render object upon a reset call, else, only calls sim.reset and resets all robosuite-internal variables
renderer (str) – string for the renderer to use
renderer_config (dict) – dictionary for the renderer configurations
seed (int) – environment seed. Default is None, where environment is unseeded, ie. random
- Raises:
ValueError – [Invalid renderer selection]
- property action_dim#
Size of the action space :returns: Action space dimension :rtype: int
- property action_spec#
Action specification should be implemented in subclasses. Action space is represented by a tuple of (low, high), which are two numpy vectors that specify the min/max action limits per dimension.
- property active_observables#
Grabs all names of active observables for this environment. An observable is considered active if its value is being returned in the observation dict from _get_observations() call or from the step() call (assuming this observable is enabled). :returns: All active observation names :rtype: set
- add_observable(observable)#
Adds an observable to this environment. :param observable: Observable instance. :type observable: Observable
- check_contact(geoms_1, geoms_2=None)#
Finds contact between two geom groups. :param geoms_1: an individual geom name or list of geom names or a model. If
a MujocoModel is specified, the geoms checked will be its contact_geoms
- Parameters:
geoms_2 (str or list of str or MujocoModel or None) – another individual geom name or list of geom names. If a MujocoModel is specified, the geoms checked will be its contact_geoms. If None, will check any collision with @geoms_1 to any other geom in the environment
- Returns:
True if any geom in @geoms_1 is in contact with any geom in @geoms_2.
- Return type:
bool
- clear_objects(object_names)#
Clears objects with the name @object_names out of the task space. This is useful for supporting task modes with single types of objects, as in @self.single_object_mode without changing the model definition. :param object_names: Name of object(s) to remove from the task workspace :type object_names: str or list of str
- close()#
Do any cleanup necessary here.
- close_renderer()#
Closes the renderer
- edit_model_xml(xml_str)#
This function edits the model xml with custom changes, including resolving relative paths, applying changes retroactively to existing demonstration files, and other custom scripts. Environment subclasses should modify this function to add environment-specific xml editing features. :param xml_str: Mujoco sim demonstration XML file as string :type xml_str: str
- Returns:
Edited xml file as string
- Return type:
str
- property enabled_observables#
Grabs all names of enabled observables for this environment. An observable is considered enabled if its values are being continually computed / updated at each simulation timestep. :returns: All enabled observation names :rtype: set
- get_contacts(model)#
Checks for any contacts with @model (as defined by @model’s contact_geoms) and returns the set of geom names currently in contact with that model (excluding the geoms that are part of the model itself). :param model: Model to check contacts for. :type model: MujocoModel
- Returns:
Unique geoms that are actively in contact with this model.
- Return type:
set
- Raises:
AssertionError – [Invalid input type]
- get_ep_meta()#
Returns a dictionary containing episode metadata :returns: episode metadata :rtype: dict
- get_pixel_obs()#
Gets the pixel observations for the environment from the specified renderer
- initialize_renderer()#
- initialize_time(control_freq)#
Initializes the time constants used for simulation. :param control_freq: Hz rate to run control loop at within the simulation :type control_freq: float
- modify_observable(observable_name, attribute, modifier)#
Modifies observable with associated name @observable_name, replacing the given @attribute with @modifier. :param observable_name: Observable to modify :type observable_name: str :param attribute: Observable attribute to modify.
Options are {‘sensor’, ‘corrupter’,`’filter’, `’delayer’, ‘sampling_rate’, ‘enabled’, ‘active’}
- Parameters:
modifier (any) – New function / value to replace with for observable. If a function, new signature should match the function being replaced.
- property observation_modalities#
Modalities for this environment’s observations :returns: All observation modalities :rtype: set
- property observation_names#
Grabs all names for this environment’s observables :returns: All observation names :rtype: set
- observation_spec()#
Returns an observation as observation specification. An alternative design is to return an OrderedDict where the keys are the observation names and the values are the shapes of observations. We leave this alternative implementation commented out, as we find the current design is easier to use in practice. :returns: Observations from the environment :rtype: OrderedDict
- render()#
Renders to an on-screen window.
- reset()#
Resets simulation. :returns: Environment observation space after reset occurs :rtype: OrderedDict
- reset_from_xml_string(xml_string)#
Reloads the environment from an XML description of the environment. :param xml_string: Filepath to the xml file that will be loaded directly into the sim :type xml_string: str
- reward(action)#
Reward should be a function of state and action :param action: Action to execute within the environment :type action: np.array
- Returns:
Reward from environment
- Return type:
float
- set_ep_meta(meta)#
Set episode meta data :param meta: containing episode metadata :type meta: dict
- set_xml_processor(processor)#
Sets the processor function that xml string will be passed to inside _initialize_sim() calls. :param processor: If set, processing method should take in a xml string and
return no arguments.
- step(action)#
Takes a step in simulation with control command @action. :param action: Action to execute within the environment :type action: np.array
- Returns:
(OrderedDict) observations from the environment
(float) reward from the environment
(bool) whether the current episode is completed or not
(dict) misc information
- Return type:
4-tuple
- Raises:
ValueError – [Steps past episode termination]
- unset_ep_meta()#
Unset episode meta data
- update_state()#
update internal state of environment (can be called after resetting simulation or after step)
- visualize(vis_settings)#
Do any needed visualization here :param vis_settings: Visualization keywords mapped to T/F, determining whether that specific
component should be visualized. Should have “env” keyword as well as any other relevant options specified.
- robosuite.environments.base.make(env_name, *args, **kwargs)#
Instantiates a robosuite environment. This method attempts to mirror the equivalent functionality of gym.make in a somewhat sloppy way. :param env_name: Name of the robosuite environment to initialize :type env_name: str :param *args: Additional arguments to pass to the specific environment class initializer :param **kwargs: Additional arguments to pass to the specific environment class initializer
- Returns:
Desired robosuite environment
- Return type:
- Raises:
Exception – [Invalid environment name]
- robosuite.environments.base.register_env(target_class)#
robosuite.environments.robot_env module#
- class robosuite.environments.robot_env.RobotEnv(robots, env_configuration='default', base_types='default', controller_configs=None, initialization_noise=None, use_camera_obs=True, has_renderer=False, has_offscreen_renderer=True, render_camera='frontview', render_collision_mesh=False, render_visual_mesh=True, render_gpu_device_id=-1, control_freq=20, lite_physics=True, horizon=1000, ignore_done=False, hard_reset=True, camera_names='agentview', camera_heights=256, camera_widths=256, camera_depths=False, camera_segmentations=None, robot_configs=None, renderer='mjviewer', renderer_config=None, seed=None)#
Bases:
MujocoEnv
Initializes a robot environment in Mujoco.
- Parameters:
robots – Specification for specific robot(s) to be instantiated within this env
env_configuration (str) – Specifies how to position the robot(s) within the environment. Default is “default”, which should be interpreted accordingly by any subclasses.
controller_configs (str or list of dict) – If set, contains relevant controller parameters for creating a custom controller. Else, uses the default controller for this specific task. Should either be single dict if same controller is to be used for all robots or else it should be a list of the same length as “robots” param
mount_types (None or str or list of str) – type of mount, used to instantiate mount models from mount factory. Default is “default”, which is the default mount associated with the robot(s) the ‘robots’ specification. None results in no mount, and any other (valid) model overrides the default mount. Should either be single str if same mount type is to be used for all robots or else it should be a list of the same length as “robots” param
initialization_noise (dict or list of dict) –
Dict containing the initialization noise parameters. The expected keys and corresponding value types are specified below:
- ’magnitude’:
The scale factor of uni-variate random noise applied to each of a robot’s given initial joint positions. Setting this value to None or 0.0 results in no noise being applied. If “gaussian” type of noise is applied then this magnitude scales the standard deviation applied, If “uniform” type of noise is applied then this magnitude sets the bounds of the sampling range
- ’type’:
Type of noise to apply. Can either specify “gaussian” or “uniform”
Should either be single dict if same noise value is to be used for all robots or else it should be a list of the same length as “robots” param
- Note:
Specifying “default” will automatically use the default noise settings. Specifying None will automatically create the required dict with “magnitude” set to 0.0.
use_camera_obs (bool) – if True, every observation includes rendered image(s)
has_renderer (bool) – If true, render the simulation state in a viewer instead of headless mode.
has_offscreen_renderer (bool) – True if using off-screen rendering
render_camera (str) – Name of camera to render if has_renderer is True. Setting this value to ‘None’ will result in the default angle being applied, which is useful as it can be dragged / panned by the user using the mouse
render_collision_mesh (bool) – True if rendering collision meshes in camera. False otherwise.
render_visual_mesh (bool) – True if rendering visual meshes in camera. False otherwise.
render_gpu_device_id (int) – corresponds to the GPU device id to use for offscreen rendering. Defaults to -1, in which case the device will be inferred from environment variables (GPUS or CUDA_VISIBLE_DEVICES).
control_freq (float) – how many control signals to receive in every second. This sets the amount of simulation time that passes between every action input.
lite_physics (bool) – Whether to optimize for mujoco forward and step calls to reduce total simulation overhead. Set to False to preserve backward compatibility with datasets collected in robosuite <= 1.4.1.
horizon (int) – Every episode lasts for exactly @horizon timesteps.
ignore_done (bool) – True if never terminating the environment (ignore @horizon).
hard_reset (bool) – If True, re-loads model, sim, and render object upon a reset call, else, only calls sim.reset and resets all robosuite-internal variables
camera_names (str or list of str) –
name of camera to be rendered. Should either be single str if same name is to be used for all cameras’ rendering or else it should be a list of cameras to render.
- Note:
At least one camera must be specified if @use_camera_obs is True.
- Note:
To render all robots’ cameras of a certain type (e.g.: “robotview” or “eye_in_hand”), use the convention “all-{name}” (e.g.: “all-robotview”) to automatically render all camera images from each robot’s camera list).
camera_heights (int or list of int) – height of camera frame. Should either be single int if same height is to be used for all cameras’ frames or else it should be a list of the same length as “camera names” param.
camera_widths (int or list of int) – width of camera frame. Should either be single int if same width is to be used for all cameras’ frames or else it should be a list of the same length as “camera names” param.
camera_depths (bool or list of bool) – True if rendering RGB-D, and RGB otherwise. Should either be single bool if same depth setting is to be used for all cameras or else it should be a list of the same length as “camera names” param.
camera_segmentations (None or str or list of str or list of list of str) –
Camera segmentation(s) to use for each camera. Valid options are:
None: no segmentation sensor used ‘instance’: segmentation at the class-instance level ‘class’: segmentation at the class level ‘element’: segmentation at the per-geom level
If not None, multiple types of segmentations can be specified. A [list of str / str or None] specifies [multiple / a single] segmentation(s) to use for all cameras. A list of list of str specifies per-camera segmentation setting(s) to use.
robot_configs (list of dict) – Per-robot configurations set from any subclass initializers.
seed (int) – environment seed. Default is None, where environment is unseeded, ie. random
- Raises:
ValueError – [Camera obs require offscreen renderer]
ValueError – [Camera name must be specified to use camera obs]
- property action_dim#
Size of the action space
- Returns:
Action space dimension
- Return type:
int
- property action_spec#
Action space (low, high) for this environment
- Returns:
(np.array) minimum (low) action values
(np.array) maximum (high) action values
- Return type:
2-tuple
- reward(action)#
Runs superclass method by default
- visualize(vis_settings)#
In addition to super call, visualizes robots.
- Parameters:
vis_settings (dict) – Visualization keywords mapped to T/F, determining whether that specific component should be visualized. Should have “robots” keyword as well as any other relevant options specified.