Skip to content

Commit

Permalink
added dmc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
amsks committed Jul 14, 2023
1 parent c6f643d commit 4d778df
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 21 deletions.
10 changes: 10 additions & 0 deletions carl/envs/dmc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Headless Rendering
If you have problems with OpenGL, this helped:
Set this in your script
```python
os.environ['DISABLE_MUJOCO_RENDERING'] = '1'
os.environ['MUJOCO_GL'] = 'osmesa'
os.environ['PYOPENGL_PLATFORM'] = 'osmesa'
```

And set ErrorChecker to None in `OpenGL/raw/GL/_errors.py`.
4 changes: 2 additions & 2 deletions carl/envs/dmc/carl_dm_finger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from carl.utils.types import Context, Contexts

DEFAULT_CONTEXT = {
"gravity": -9.81, # Gravity is disabled via flag
"gravity": 9.81, # Gravity is disabled via flag
"friction_tangential": 1, # Scaling factor for tangential friction of all geoms (objects)
"friction_torsional": 1, # Scaling factor for torsional friction of all geoms (objects)
"friction_rolling": 1, # Scaling factor for rolling friction of all geoms (objects)
Expand All @@ -30,7 +30,7 @@
}

CONTEXT_BOUNDS = {
"gravity": (-np.inf, -0.1, float),
"gravity": (0.1, np.inf, float),
"friction_tangential": (0, np.inf, float),
"friction_torsional": (0, np.inf, float),
"friction_rolling": (0, np.inf, float),
Expand Down
4 changes: 2 additions & 2 deletions carl/envs/dmc/carl_dm_fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from carl.utils.types import Context, Contexts

DEFAULT_CONTEXT = {
"gravity": -9.81, # Gravity is disabled via flag
"gravity": 9.81, # Gravity is disabled via flag
"friction_tangential": 1, # Scaling factor for tangential friction of all geoms (objects)
"friction_torsional": 1, # Scaling factor for torsional friction of all geoms (objects)
"friction_rolling": 1, # Scaling factor for rolling friction of all geoms (objects)
Expand All @@ -26,7 +26,7 @@
}

CONTEXT_BOUNDS = {
"gravity": (-np.inf, -0.1, float),
"gravity": (0.1, np.inf, float),
"friction_tangential": (0, np.inf, float),
"friction_torsional": (0, np.inf, float),
"friction_rolling": (0, np.inf, float),
Expand Down
4 changes: 2 additions & 2 deletions carl/envs/dmc/carl_dm_quadruped.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from carl.utils.types import Context, Contexts

DEFAULT_CONTEXT = {
"gravity": -9.81,
"gravity": 9.81,
"friction_tangential": 1.0, # Scaling factor for tangential friction of all geoms (objects)
"friction_torsional": 1.0, # Scaling factor for torsional friction of all geoms (objects)
"friction_rolling": 1.0, # Scaling factor for rolling friction of all geoms (objects)
Expand All @@ -26,7 +26,7 @@
}

CONTEXT_BOUNDS = {
"gravity": (-np.inf, -0.1, float),
"gravity": (0.1, np.inf, float),
"friction_tangential": (0, np.inf, float),
"friction_torsional": (0, np.inf, float),
"friction_rolling": (0, np.inf, float),
Expand Down
4 changes: 2 additions & 2 deletions carl/envs/dmc/carl_dm_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from carl.utils.types import Context, Contexts

DEFAULT_CONTEXT = {
"gravity": -9.81,
"gravity": 9.81,
"friction_tangential": 1.0, # Scaling factor for tangential friction of all geoms (objects)
"friction_torsional": 1.0, # Scaling factor for torsional friction of all geoms (objects)
"friction_rolling": 1.0, # Scaling factor for rolling friction of all geoms (objects)
Expand All @@ -26,7 +26,7 @@
}

CONTEXT_BOUNDS = {
"gravity": (-np.inf, -0.1, float),
"gravity": (0.1, np.inf, float),
"friction_tangential": (0, np.inf, float),
"friction_torsional": (0, np.inf, float),
"friction_rolling": (0, np.inf, float),
Expand Down
Empty file.
28 changes: 19 additions & 9 deletions carl/envs/dmc/dmc_tasks/finger.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,34 @@ def check_constraints(
limb_length_1: float,
x_spinner: float = 0.2,
x_finger: float = -0.2,
) -> None:
raise_error: bool = False,
**kwargs: Any
) -> bool:
is_okay = True
spinner_half_length = spinner_length / 2
# Check if spinner collides with finger hinge
distance_spinner_to_fingerhinge = (x_spinner - x_finger) - spinner_half_length
if distance_spinner_to_fingerhinge < 0:
raise ValueError(
f"Distance finger to spinner ({distance_spinner_to_fingerhinge}) not big enough, "
f"spinner can't spin. Decrease spinner_length ({spinner_length})."
)
is_okay = False
if raise_error:
raise ValueError(
f"Distance finger to spinner ({distance_spinner_to_fingerhinge}) not big enough, "
f"spinner can't spin. Decrease spinner_length ({spinner_length})."
)

# Check if finger can reach spinner (distance should be negative)
distance_fingertip_to_spinner = (x_spinner - spinner_half_length) - (
x_finger + limb_length_0 + limb_length_1
)
if distance_fingertip_to_spinner > 0:
raise ValueError(
f"Finger cannot reach spinner ({distance_fingertip_to_spinner}). Increase either "
f"limb_length_0, limb_length_1 or spinner_length."
)
is_okay = False
if raise_error:
raise ValueError(
f"Finger cannot reach spinner ({distance_fingertip_to_spinner}). Increase either "
f"limb_length_0, limb_length_1 or spinner_length."
)

return is_okay


def get_finger_xml_string(
Expand Down Expand Up @@ -98,6 +107,7 @@ def get_finger_xml_string(
x_spinner=x_spinner,
x_finger=x_finger,
spinner_length=spinner_length,
raise_error=True
)

proximal_to = -limb_length_0
Expand Down
4 changes: 2 additions & 2 deletions carl/envs/dmc/dmc_tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def check_okay_to_set(context_feature: str | list[str]) -> bool:
gravity = option.get("gravity")
if gravity is not None:
g = gravity.split(" ")
gravity = " ".join([g[0], g[1], str(context["gravity"])])
gravity = " ".join([g[0], g[1], str(-context["gravity"])])
else:
gravity = " ".join(["0", "0", str(context["gravity"])])
gravity = " ".join(["0", "0", str(-context["gravity"])])
option.set("gravity", gravity)

if check_okay_to_set("wind"):
Expand Down
1 change: 1 addition & 0 deletions carl/envs/dmc/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def load_dmc_env(
environment_kwargs: Dict[str, bool] = None,
visualize_reward: bool = False,
) -> dm_env:

if domain_name in _DOMAINS:
domain = _DOMAINS[domain_name]
elif domain_name in suite._DOMAINS:
Expand Down
4 changes: 2 additions & 2 deletions carl/envs/dmc/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Any, Optional, Tuple, TypeVar, Union

import dm_env # type: ignore
import gymnasium as gym
import gym
import numpy as np
from dm_env import StepType
from gymnasium import spaces
from gym import spaces

ObsType = TypeVar("ObsType")
ActType = TypeVar("ActType")
Expand Down

0 comments on commit 4d778df

Please sign in to comment.