robocasa.utils package
Contents
robocasa.utils package¶
Subpackages¶
- robocasa.utils.model_zoo package
- Submodules
- robocasa.utils.model_zoo.file_utils module
- robocasa.utils.model_zoo.log_utils module
- robocasa.utils.model_zoo.mjcf_gen_utils module
- robocasa.utils.model_zoo.mjcf_obj module
- robocasa.utils.model_zoo.mtl_utils module
- robocasa.utils.model_zoo.object_play_env module
- robocasa.utils.model_zoo.parser_utils module
- Module contents
- robocasa.utils.usd package
Submodules¶
robocasa.utils.camera_utils module¶
Collection of constants for cameras / robots / etc in kitchen environments
robocasa.utils.config_utils module¶
- robocasa.utils.config_utils.is_stale_controller_config(config: dict)¶
Checks if a controller config is in the format from robosuite versions <= 1.4.1. Does not check for config validity, only the format type. :param config: Controller configuration :type config: dict
- Returns:
True if the config is in the old format, False otherwise
- Return type:
bool
- robocasa.utils.config_utils.refactor_composite_controller_config(controller_config, robot_type, arms)¶
Checks if a controller config is in the format from robosuite versions <= 1.4.1. If this is the case, converts the controller config to the new composite controller config format in robosuite versions >= 1.5. If the robot has a default controller config use that and override the arms with the old controller config. If not just use the old controller config for arms. :param old_controller_config: Old controller config :type old_controller_config: dict
- Returns:
New controller config
- Return type:
dict
robocasa.utils.dataset_registry module¶
- robocasa.utils.dataset_registry.get_ds_path(task, ds_type, return_info=False)¶
robocasa.utils.env_utils module¶
- robocasa.utils.env_utils.create_env(env_name, robots='PandaOmron', camera_names=['robot0_agentview_left', 'robot0_agentview_right', 'robot0_eye_in_hand'], camera_widths=128, camera_heights=128, seed=None, render_onscreen=False, obj_instance_split=None, generative_textures=None, randomize_cameras=False, layout_and_style_ids=None, layout_ids=None, style_ids=None)¶
- robocasa.utils.env_utils.run_random_rollouts(env, num_rollouts, num_steps, video_path=None)¶
robocasa.utils.object_utils module¶
- robocasa.utils.object_utils.check_obj_fixture_contact(env, obj_name, fixture_name)¶
check if object is in contact with fixture
- robocasa.utils.object_utils.check_obj_in_receptacle(env, obj_name, receptacle_name, th=None)¶
check if object is in receptacle object based on threshold
- robocasa.utils.object_utils.compute_rel_transform(A_pos, A_mat, B_pos, B_mat)¶
Gets B’s position and rotation relative to A’s frame
- robocasa.utils.object_utils.fixture_pairwise_dist(f1, f2)¶
Gets the distance between two fixtures by finding the minimum distance between their exterior bounding box points
- robocasa.utils.object_utils.get_fixture_to_point_rel_offset(fixture, point)¶
get offset relative to fixture’s frame, given a global point
- robocasa.utils.object_utils.get_pos_after_rel_offset(fixture, offset)¶
get global position of a fixture, after applying offset relative to center of fixture
- robocasa.utils.object_utils.get_rel_transform(fixture_A, fixture_B)¶
Gets fixture_B’s position and rotation relative to fixture_A’s frame
- robocasa.utils.object_utils.gripper_obj_far(env, obj_name='obj', th=0.25)¶
check if gripper is far from object based on distance defined by threshold
- robocasa.utils.object_utils.normalize_joint_value(raw, joint_min, joint_max)¶
normalize raw value to be between 0 and 1
- robocasa.utils.object_utils.obj_cos(env, obj_name='obj', ref=(0, 0, 1))¶
- robocasa.utils.object_utils.obj_in_region(obj, obj_pos, obj_quat, p0, px, py, pz=None)¶
check if object is in the region defined by the points. Uses either the objects bounding box or the object’s horizontal radius
- robocasa.utils.object_utils.obj_inside_of(env, obj_name, fixture_id, partial_check=False)¶
whether an object (another mujoco object) is inside of fixture. applies for most fixtures
- robocasa.utils.object_utils.objs_intersect(obj, obj_pos, obj_quat, other_obj, other_obj_pos, other_obj_quat)¶
check if two objects intersect
- robocasa.utils.object_utils.point_in_fixture(point, fixture, only_2d=False)¶
check if point is inside of the exterior bounding boxes of the fixture
- Parameters:
point (np.array) – point to check
fixture (Fixture) – fixture object
only_2d (bool) – whether to check only in 2D
- robocasa.utils.object_utils.project_point_to_line(P, A, B)¶
logic copied from here: https://stackoverflow.com/a/61342198
- robocasa.utils.object_utils.set_geom_dimensions(sizes, positions, geoms, rotated=False)¶
set the dimensions of geoms in a fixture
- Parameters:
sizes (dict) – dictionary of sizes for each side
positions (dict) – dictionary of positions for each side
geoms (dict) – dictionary of geoms for each side
rotated (bool) – whether the fixture is rotated. Fixture may be rotated to make texture appear uniform due to mujoco texture conventions
robocasa.utils.placement_samplers module¶
- class robocasa.utils.placement_samplers.MultiRegionSampler(name, regions, side='all', mujoco_objects=None, rotation=None, rotation_axis='z', ensure_object_boundary_in_range=True, ensure_valid_placement=True, rng=None, z_offset=0.0)¶
Bases:
ObjectPositionSampler
- sample(fixtures=None, reference=None, on_top=True)¶
Uniformly sample on a surface (not necessarily table surface).
- Parameters:
fixtures (dict) – dictionary of current object placements in the scene as well as any other relevant obstacles that should not be in contact with newly sampled objects. Used to make sure newly generated placements are valid. Should be object names mapped to (pos, quat, MujocoObject)
reference (str or 3-tuple or None) – if provided, sample relative placement. Can either be a string, which corresponds to an existing object found in @fixtures, or a direct (x,y,z) value. If None, will sample relative to this sampler’s ‘reference_pos’ value.
on_top (bool) – if True, sample placement on top of the reference object.
- Returns:
- dictionary of all object placements, mapping object_names to (pos, quat, obj), including the
placements specified in @fixtures. Note quat is in (w,x,y,z) form
- Return type:
dict
- class robocasa.utils.placement_samplers.ObjectPositionSampler(name, mujoco_objects=None, ensure_object_boundary_in_range=True, ensure_valid_placement=True, reference_pos=(0, 0, 0), reference_rot=0, z_offset=0.0, rng=None)¶
Bases:
object
Base class of object placement sampler.
- Parameters:
name (str) – Name of this sampler.
mujoco_objects (None or MujocoObject or list of MujocoObject) – single model or list of MJCF object models
ensure_object_boundary_in_range (bool) – If True, will ensure that the object is enclosed within a given boundary (should be implemented by subclass)
ensure_valid_placement (bool) – If True, will check for correct (valid) object placements
reference_pos (3-array) – global (x,y,z) position relative to which sampling will occur
z_offset (float) – Add a small z-offset to placements. This is useful for fixed objects that do not move (i.e. no free joint) to place them above the table.
- add_objects(mujoco_objects)¶
Add additional objects to this sampler. Checks to make sure there’s no identical objects already stored.
- Parameters:
mujoco_objects (MujocoObject or list of MujocoObject) – single model or list of MJCF object models
- reset()¶
Resets this sampler. Removes all mujoco objects from this sampler.
- sample(fixtures=None, reference=None, on_top=True)¶
Uniformly sample on a surface (not necessarily table surface).
- Parameters:
fixtures (dict) – dictionary of current object placements in the scene as well as any other relevant obstacles that should not be in contact with newly sampled objects. Used to make sure newly generated placements are valid. Should be object names mapped to (pos, quat, MujocoObject)
reference (str or 3-tuple or None) – if provided, sample relative placement. Can either be a string, which corresponds to an existing object found in @fixtures, or a direct (x,y,z) value. If None, will sample relative to this sampler’s ‘reference_pos’ value.
on_top (bool) – if True, sample placement on top of the reference object.
- Returns:
- dictionary of all object placements, mapping object_names to (pos, quat, obj), including the
placements specified in @fixtures. Note quat is in (w,x,y,z) form
- Return type:
dict
- property sides_combinations¶
- property valid_sides¶
- class robocasa.utils.placement_samplers.SequentialCompositeSampler(name, rng=None)¶
Bases:
ObjectPositionSampler
Samples position for each object sequentially. Allows chaining multiple placement initializers together - so that object locations can be sampled on top of other objects or relative to other object placements.
- Parameters:
name (str) – Name of this sampler.
- add_objects(mujoco_objects)¶
Override super method to make sure user doesn’t call this (all objects should implicitly belong to sub-samplers)
- add_objects_to_sampler(sampler_name, mujoco_objects)¶
Adds specified @mujoco_objects to sub-sampler with specified @sampler_name.
- Parameters:
sampler_name (str) – Existing sub-sampler name
mujoco_objects (MujocoObject or list of MujocoObject) – Object(s) to add
- append_sampler(sampler, sample_args=None)¶
Adds a new placement initializer with corresponding @sampler and arguments
- Parameters:
sampler (ObjectPositionSampler) – sampler to add
sample_args (None or dict) – If specified, should be additional arguments to pass to @sampler’s sample() call. Should map corresponding sampler’s arguments to values (excluding @fixtures argument)
- Raises:
AssertionError – [Object name in samplers]
- hide(mujoco_objects)¶
Helper method to remove an object from the workspace.
- Parameters:
mujoco_objects (MujocoObject or list of MujocoObject) – Object(s) to hide
- reset()¶
Resets this sampler. In addition to base method, iterates over all sub-samplers and resets them
- sample(placed_objects=None, reference=None, on_top=True)¶
Sample from each placement initializer sequentially, in the order that they were appended.
- Parameters:
placed_objects (dict) – dictionary of current object placements in the scene as well as any other relevant obstacles that should not be in contact with newly sampled objects. Used to make sure newly generated placements are valid. Should be object names mapped to (pos, quat, MujocoObject)
reference (str or 3-tuple or None) – if provided, sample relative placement. This will override each sampler’s @reference argument if not already specified. Can either be a string, which corresponds to an existing object found in @fixtures, or a direct (x,y,z) value. If None, will sample relative to this sampler’s ‘reference_pos’ value.
on_top (bool) – if True, sample placement on top of the reference object. This will override each sampler’s @on_top argument if not already specified. This corresponds to a sampled z-offset of the current sampled object’s bottom_offset + the reference object’s top_offset (if specified)
- Returns:
- dictionary of all object placements, mapping object_names to (pos, quat, obj), including the
placements specified in @fixtures. Note quat is in (w,x,y,z) form
- Return type:
dict
- Raises:
RandomizationError – [Cannot place all objects]
- class robocasa.utils.placement_samplers.UniformRandomSampler(name, mujoco_objects=None, x_range=(0, 0), y_range=(0, 0), rotation=None, rotation_axis='z', ensure_object_boundary_in_range=True, ensure_valid_placement=True, reference_pos=(0, 0, 0), reference_rot=0, z_offset=0.0, rng=None, side='all')¶
Bases:
ObjectPositionSampler
Places all objects within the table uniformly random.
- Parameters:
name (str) – Name of this sampler.
mujoco_objects (None or MujocoObject or list of MujocoObject) – single model or list of MJCF object models
x_range (2-array of float) – Specify the (min, max) relative x_range used to uniformly place objects
y_range (2-array of float) – Specify the (min, max) relative y_range used to uniformly place objects
rotation (None or float or Iterable) –
- None:
Add uniform random random rotation
- Iterable (a,b):
Uniformly randomize rotation angle between a and b (in radians)
- value:
Add fixed angle rotation
rotation_axis (str) – Can be ‘x’, ‘y’, or ‘z’. Axis about which to apply the requested rotation
ensure_object_boundary_in_range (bool) –
- True:
The center of object is at position: [uniform(min x_range + radius, max x_range - radius)], [uniform(min x_range + radius, max x_range - radius)]
- False:
[uniform(min x_range, max x_range)], [uniform(min x_range, max x_range)]
ensure_valid_placement (bool) – If True, will check for correct (valid) object placements
reference_pos (3-array) – global (x,y,z) position relative to which sampling will occur
z_offset (float) – Add a small z-offset to placements. This is useful for fixed objects that do not move (i.e. no free joint) to place them above the table.
- sample(placed_objects=None, reference=None, on_top=True)¶
Uniformly sample relative to this sampler’s reference_pos or @reference (if specified).
- Parameters:
placed_objects (dict) – dictionary of current object placements in the scene as well as any other relevant obstacles that should not be in contact with newly sampled objects. Used to make sure newly generated placements are valid. Should be object names mapped to (pos, quat, MujocoObject)
reference (str or 3-tuple or None) – if provided, sample relative placement. Can either be a string, which corresponds to an existing object found in @fixtures, or a direct (x,y,z) value. If None, will sample relative to this sampler’s ‘reference_pos’ value.
on_top (bool) – if True, sample placement on top of the reference object. This corresponds to a sampled z-offset of the current sampled object’s bottom_offset + the reference object’s top_offset (if specified)
- Returns:
- dictionary of all object placements, mapping object_names to (pos, quat, obj), including the
placements specified in @fixtures. Note quat is in (w,x,y,z) form
- Return type:
dict
- Raises:
RandomizationError – [Cannot place all objects]
AssertionError – [Reference object name does not exist, invalid inputs]
robocasa.utils.postprocess_xml_utils module¶
- robocasa.utils.postprocess_xml_utils.convert_xml(xml_str)¶
Postprocess xml string generated by robosuite to be compatible with robosuite v1.5 This script should not the xml string if it was already generated using robosuite v1.5 :param xml_str: xml string to process (from robosuite v1.4.1) :type xml_str: str
- robocasa.utils.postprocess_xml_utils.get_eef_panda_site(prefix)¶
Helper function for new element added in robosuite v1.5
- robocasa.utils.postprocess_xml_utils.update_gripper_name(gripper_name: str)¶
robocasa.utils.texture_swap module¶
- robocasa.utils.texture_swap.get_random_textures(rng, frac=1.0)¶
This function returns a dictionary of random textures for cabinet, counter top, floor, and wall.
- Parameters:
rng (np.random.Generator) – Random number generator used for texture selection
frac (float) – Fraction of textures to select from the list of available textures Default: 1.0 (select from all textures)
- Returns:
Dictionary of texture paths
- Return type:
textures (dict)
- robocasa.utils.texture_swap.replace_cab_textures(rng, initial_state: str, new_cab_texture_file: str | None = None)¶
This function replaces the cabinet and counter base textures during playback.
- Parameters:
rng (np.random.Generator) – Random number generator used for texture selection
initial_state (str) – Initial env XML string
new_cab_texture_file (str) – New texture file for counter base and cabinets: i.e “cabinet/…” If None (default), will replace with a random texture from flat or wood directories
- robocasa.utils.texture_swap.replace_counter_top_texture(rng, initial_state: str, new_counter_top_texture_file: str | None = None)¶
This function replaces the counter top textures during playback.
- Parameters:
rng (np.random.Generator) – Random number generator used for texture selection
initial_state (str) – Initial env XML string
new_counter_top_texture_file (str) – New texture file for counter top: i.e “marble/dark_marble.png” If None (default), will replace with a random texture from marble directory
- robocasa.utils.texture_swap.replace_floor_texture(rng, initial_state: str, new_floor_texture_file: str | None = None)¶
This function replaces the counter top textures during playback.
- Parameters:
rng (np.random.Generator) – Random number generator used for texture selection
initial_state (str) – Initial env XML string
new_floor_texture_file (str) – New texture file for counter top: i.e “wood/dark_wood_planks_2.png” If None (default), will replace with a random texture from wood directory
- robocasa.utils.texture_swap.replace_wall_texture(rng, initial_state: str, new_wall_texture_file: str | None = None)¶
This function replaces the counter top textures during playback.
- Parameters:
rng (np.random.Generator) – Random number generator used for texture selection
initial_state (str) – Initial env XML string
new_wall_texture_file (str) – New texture file for counter top: i.e “wood/dark_wood_planks_2.png” If None (default), will replace with a random texture from wood directory