Skip to content

Commit

Permalink
Update Pusher-v5 model to one that is compatible with mujoco>=3 (#1019
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Kallinteris-Andreas authored Apr 17, 2024
1 parent 43ce95b commit b6d7f51
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 8 deletions.
97 changes: 97 additions & 0 deletions gymnasium/envs/mujoco/assets/pusher_v5.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!--
Pusher model for `Pusher-v5`, based on openai/gym/Pusher
modified by @Kallinteris-Andreas
- reduced body.object cylinder density 0.00001 -> 0.01
- disabled body.object sphere
-->
<mujoco model="arm3d">
<compiler inertiafromgeom="true" angle="radian" coordinate="local"/>
<option timestep="0.01" gravity="0 0 0" iterations="20" integrator="Euler" />

<default>
<joint armature='0.04' damping="1" limited="true"/>
<geom friction=".8 .1 .1" density="300" margin="0.002" condim="1" contype="0" conaffinity="0"/>
</default>

<worldbody>
<light diffuse=".5 .5 .5" pos="0 0 3" dir="0 0 -1"/>
<geom name="table" type="plane" pos="0 0.5 -0.325" size="1 1 0.1" contype="1" conaffinity="1"/>

<body name="r_shoulder_pan_link" pos="0 -0.6 0">
<geom name="e1" type="sphere" rgba="0.6 0.6 0.6 1" pos="-0.06 0.05 0.2" size="0.05" />
<geom name="e2" type="sphere" rgba="0.6 0.6 0.6 1" pos=" 0.06 0.05 0.2" size="0.05" />
<geom name="e1p" type="sphere" rgba="0.1 0.1 0.1 1" pos="-0.06 0.09 0.2" size="0.03" />
<geom name="e2p" type="sphere" rgba="0.1 0.1 0.1 1" pos=" 0.06 0.09 0.2" size="0.03" />
<geom name="sp" type="capsule" fromto="0 0 -0.4 0 0 0.2" size="0.1" />
<joint name="r_shoulder_pan_joint" type="hinge" pos="0 0 0" axis="0 0 1" range="-2.2854 1.714602" damping="1.0" />

<body name="r_shoulder_lift_link" pos="0.1 0 0">
<geom name="sl" type="capsule" fromto="0 -0.1 0 0 0.1 0" size="0.1" />
<joint name="r_shoulder_lift_joint" type="hinge" pos="0 0 0" axis="0 1 0" range="-0.5236 1.3963" damping="1.0" />

<body name="r_upper_arm_roll_link" pos="0 0 0">
<geom name="uar" type="capsule" fromto="-0.1 0 0 0.1 0 0" size="0.02" />
<joint name="r_upper_arm_roll_joint" type="hinge" pos="0 0 0" axis="1 0 0" range="-1.5 1.7" damping="0.1" />

<body name="r_upper_arm_link" pos="0 0 0">
<geom name="ua" type="capsule" fromto="0 0 0 0.4 0 0" size="0.06" />

<body name="r_elbow_flex_link" pos="0.4 0 0">
<geom name="ef" type="capsule" fromto="0 -0.02 0 0.0 0.02 0" size="0.06" />
<joint name="r_elbow_flex_joint" type="hinge" pos="0 0 0" axis="0 1 0" range="-2.3213 0" damping="0.1" />

<body name="r_forearm_roll_link" pos="0 0 0">
<geom name="fr" type="capsule" fromto="-0.1 0 0 0.1 0 0" size="0.02" />
<joint name="r_forearm_roll_joint" type="hinge" limited="true" pos="0 0 0" axis="1 0 0" damping=".1" range="-1.5 1.5"/>

<body name="r_forearm_link" pos="0 0 0">
<geom name="fa" type="capsule" fromto="0 0 0 0.291 0 0" size="0.05" />

<body name="r_wrist_flex_link" pos="0.321 0 0">
<geom name="wf" type="capsule" fromto="0 -0.02 0 0 0.02 0" size="0.01" />
<joint name="r_wrist_flex_joint" type="hinge" pos="0 0 0" axis="0 1 0" range="-1.094 0" damping=".1" />

<body name="r_wrist_roll_link" pos="0 0 0">
<joint name="r_wrist_roll_joint" type="hinge" pos="0 0 0" limited="true" axis="1 0 0" damping="0.1" range="-1.5 1.5"/>
<body name="tips_arm" pos="0 0 0">
<geom name="tip_arml" type="sphere" pos="0.1 -0.1 0." size="0.01" />
<geom name="tip_armr" type="sphere" pos="0.1 0.1 0." size="0.01" />
</body>
<geom type="capsule" fromto="0 -0.1 0. 0.0 +0.1 0" size="0.02" contype="1" conaffinity="1" />
<geom type="capsule" fromto="0 -0.1 0. 0.1 -0.1 0" size="0.02" contype="1" conaffinity="1" />
<geom type="capsule" fromto="0 +0.1 0. 0.1 +0.1 0." size="0.02" contype="1" conaffinity="1" />
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>
</body>

<!--<body name="object" pos="0.55 -0.3 -0.275" >-->
<body name="object" pos="0.45 -0.05 -0.275" >
<!-- <geom rgba="1 1 1 0" type="sphere" size="0.05 0.05 0.05" density="0.001" conaffinity="0"/> -->
<geom rgba="1 1 1 1" type="cylinder" size="0.05 0.05 0.05" density="0.01" contype="1" conaffinity="0"/>
<joint name="obj_slidey" type="slide" pos="0 0 0" axis="0 1 0" range="-10.3213 10.3" damping="0.5"/>
<joint name="obj_slidex" type="slide" pos="0 0 0" axis="1 0 0" range="-10.3213 10.3" damping="0.5"/>
</body>

<body name="goal" pos="0.45 -0.05 -0.3230">
<geom rgba="1 0 0 1" type="cylinder" size="0.08 0.001 0.1" density='0.00001' contype="0" conaffinity="0"/>
<joint name="goal_slidey" type="slide" pos="0 0 0" axis="0 1 0" range="-10.3213 10.3" damping="0.5"/>
<joint name="goal_slidex" type="slide" pos="0 0 0" axis="1 0 0" range="-10.3213 10.3" damping="0.5"/>
</body>
</worldbody>

<actuator>
<motor joint="r_shoulder_pan_joint" ctrlrange="-2.0 2.0" ctrllimited="true" />
<motor joint="r_shoulder_lift_joint" ctrlrange="-2.0 2.0" ctrllimited="true" />
<motor joint="r_upper_arm_roll_joint" ctrlrange="-2.0 2.0" ctrllimited="true" />
<motor joint="r_elbow_flex_joint" ctrlrange="-2.0 2.0" ctrllimited="true" />
<motor joint="r_forearm_roll_joint" ctrlrange="-2.0 2.0" ctrllimited="true" />
<motor joint="r_wrist_flex_joint" ctrlrange="-2.0 2.0" ctrllimited="true" />
<motor joint="r_wrist_roll_joint" ctrlrange="-2.0 2.0" ctrllimited="true"/>
</actuator>
</mujoco>
16 changes: 9 additions & 7 deletions gymnasium/envs/mujoco/pusher_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,17 @@ class PusherEnv(MujocoEnv, utils.EzPickle):
env = gym.make('Pusher-v5', xml_file=...)
```
| Parameter | Type | Default |Description |
|-------------------------|------------|--------------|----------------------------------------------------------|
| `xml_file` | **str** |`"pusher.xml"`| Path to a MuJoCo model |
| `reward_near_weight` | **float** | `0.5` | Weight for _reward_near_ term (see `Rewards` section) |
| `reward_dist_weight` | **float** | `1` | Weight for _reward_dist_ term (see `Rewards` section) |
| `reward_control_weight` | **float** | `0.1` | Weight for _reward_control_ term (see `Rewards` section) |
| Parameter | Type | Default |Description |
|-------------------------|------------|-----------------|----------------------------------------------------------|
| `xml_file` | **str** |`"pusher_v5.xml"`| Path to a MuJoCo model |
| `reward_near_weight` | **float** | `0.5` | Weight for _reward_near_ term (see `Rewards` section) |
| `reward_dist_weight` | **float** | `1` | Weight for _reward_dist_ term (see `Rewards` section) |
| `reward_control_weight` | **float** | `0.1` | Weight for _reward_control_ term (see `Rewards` section) |
## Version History
* v5:
- Minimum `mujoco` version is now 2.3.3.
- Fixed bug: increased the density of the object to be higher than air (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium/issues/950)).
- Added `default_camera_config` argument, a dictionary for setting the `mj_camera` properties, mainly useful for custom environments.
- Added `frame_skip` argument, used to configure the `dt` (duration of `step()`), default varies by environment check environment documentation pages.
- Added `xml_file` argument.
Expand All @@ -151,6 +152,7 @@ class PusherEnv(MujocoEnv, utils.EzPickle):
- Fixed `info["reward_ctrl"]` not being multiplied by the reward weight.
- Added `info["reward_near"]` which is equal to the reward term `reward_near`.
* v4: All MuJoCo environments now use the MuJoCo bindings in mujoco >= 2.1.3.
- Warning: This version of the environment is not compatible with `mujoco>=3.0.0` (related [GitHub issue](https://github.com/Farama-Foundation/Gymnasium/issues/950)).
* v3: This environment does not have a v3 release.
* v2: All continuous control environments now use mujoco-py >= 1.50.
* v1: max_time_steps raised to 1000 for robot based tasks (not including pusher, which has a max_time_steps of 100). Added reward_threshold to environments.
Expand All @@ -167,7 +169,7 @@ class PusherEnv(MujocoEnv, utils.EzPickle):

def __init__(
self,
xml_file: str = "pusher.xml",
xml_file: str = "pusher_v5.xml",
frame_skip: int = 5,
default_camera_config: Dict[str, Union[float, int]] = DEFAULT_CAMERA_CONFIG,
reward_near_weight: float = 0.5,
Expand Down
5 changes: 4 additions & 1 deletion tests/envs/mujoco/test_mujoco_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,10 @@ def test_model_object_count(version: str):
else:
assert env.model.nbvh == 18
assert env.model.njnt == 11
assert env.model.ngeom == 21
if version == "v4":
assert env.model.ngeom == 21
else:
assert env.model.ngeom == 20
assert env.model.ntendon == 0

env = gym.make(f"Reacher-{version}").unwrapped
Expand Down

0 comments on commit b6d7f51

Please sign in to comment.