Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update domain randomization wrapper to work with mujoco!=3.1.1 for some settings #585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions robosuite/demos/demo_domain_randomization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Script to showcase domain randomization functionality.
"""

import mujoco
import time

import robosuite.macros as macros
from robosuite.utils.input_utils import *
Expand All @@ -12,7 +12,6 @@
macros.USING_INSTANCE_RANDOMIZATION = True

if __name__ == "__main__":
assert mujoco.__version__ == "3.1.1", "Script requires mujoco-py version 3.1.1 to run"
# Create dict to hold options that will be passed to env creation call
options = {}

Expand Down Expand Up @@ -57,10 +56,17 @@
control_freq=20,
hard_reset=False, # TODO: Not setting this flag to False brings up a segfault on macos or glfw error on linux
)
env = DomainRandomizationWrapper(env)
env = DomainRandomizationWrapper(
env,
randomize_color=False, # randomize_color currently only works for mujoco==3.1.1
randomize_camera=False, # less jarring when visualizing
randomize_dynamics=False,
)
env.reset()
env.viewer.set_camera(camera_id=0)

max_frame_rate = 20 # Set the desired maximum frame rate

# Get action limits
low, high = env.action_spec

Expand All @@ -69,3 +75,4 @@
action = np.random.uniform(low, high)
obs, reward, done, _ = env.step(action)
env.render()
time.sleep(1 / max_frame_rate)
5 changes: 5 additions & 0 deletions robosuite/wrappers/domain_randomization_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file implements a wrapper for facilitating domain randomization over
robosuite environments.
"""
import mujoco
import numpy as np

from robosuite.utils.mjmod import CameraModder, DynamicsModder, LightingModder, TextureModder
Expand Down Expand Up @@ -154,6 +155,10 @@ def __init__(
self.modders = []

if self.randomize_color:
assert mujoco.__version__ == "3.1.1", (
"TextureModder requires mujoco version 3.1.1 to run. "
"Pending support for later versions. Alternatively, you can set randomize_color=False."
)
self.tex_modder = TextureModder(
sim=self.env.sim, random_state=self.random_state, **self.color_randomization_args
)
Expand Down