Skip to content

Commit

Permalink
Merge branch 'main' into feature/register_default_envs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaux1 authored Jun 28, 2024
2 parents db2d570 + a80594e commit 0297a52
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 39 deletions.
12 changes: 7 additions & 5 deletions deformable_gym/envs/base_env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import abc
from typing import Any

Expand All @@ -7,7 +9,6 @@
import pybullet as pb
import pytransform3d.rotations as pr
from gymnasium import spaces
from pybullet_utils import bullet_client as bc

from ..envs.bullet_simulation import BulletSimulation
from ..helpers.pybullet_helper import MultibodyPose
Expand Down Expand Up @@ -36,24 +37,25 @@ class BaseBulletEnv(gym.Env, abc.ABC):
robot: BulletRobot
observation_space: spaces.Box
action_space: spaces.Box
metadata = {"render_modes": ["human"]}

def __init__(
self,
gui: bool = True,
real_time: bool = False,
horizon: int = 100,
soft: bool = False,
verbose: bool = False,
time_delta: float = 0.001,
verbose_dt: float = 10.00,
pybullet_options: str = "",
render_mode: str | None = None,
):

self.gui = gui
self.verbose = verbose
self.horizon = horizon
self.render_mode = render_mode

mode = pb.GUI if gui else pb.DIRECT
mode = pb.GUI if render_mode == "human" else pb.DIRECT

self.simulation = BulletSimulation(
soft=soft,
Expand Down Expand Up @@ -129,7 +131,7 @@ def render(self, mode: str = "human"):
:param mode: Render mode. Only 'human' is allowed.
"""
if mode == "human":
assert self.gui
assert self.render_mode == "human"
else:
raise NotImplementedError(f"Render mode {mode} not supported")

Expand Down
3 changes: 1 addition & 2 deletions examples/floating_mia_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
This is an example of how to use the FloatingMiaGraspInsole environment. A
random policy is then used to generate ten episodes.
"""

env = gymnasium.make("FloatingMiaGraspInsole-v0")
env = gymnasium.make("FloatingMiaGraspInsole-v0", render_mode="human")

obs, info = env.reset()
episode_return = 0
Expand Down
3 changes: 1 addition & 2 deletions examples/floating_shadow_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
This is an example of how to use the FloatingShadowGraspInsole environment. A
random policy is then used to generate ten episodes.
"""

env = gymnasium.make("FloatingShadowGraspInsole-v0")
env = gymnasium.make("FloatingShadowGraspInsole-v0", render_mode="human")


obs, info = env.reset()
Expand Down
4 changes: 2 additions & 2 deletions examples/parallel_floating_mia_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

SEED = 0

env = gymnasium.make("FloatingMiaGraspInsole-v0", gui=False)
env2 = gymnasium.make("FloatingMiaGraspInsole-v0", gui=False)
env = gymnasium.make("FloatingMiaGraspInsole-v0")
env2 = gymnasium.make("FloatingMiaGraspInsole-v0")

obs, info = env.reset(seed=SEED)
num_steps = 0
Expand Down
4 changes: 3 additions & 1 deletion examples/uniform_initialisation_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
sampler = UniformSampler(low, high, seed=0)

env = gymnasium.make(
"FloatingMiaGraspInsole-v0", initial_state_sampler=sampler, gui=True
"FloatingMiaGraspInsole-v0",
initial_state_sampler=sampler,
render_mode="human",
)

obs, info = env.reset()
Expand Down
1 change: 1 addition & 0 deletions examples/ur10_shadow_grasp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

env = gym.make("URShadowGraspPillow-v0")


env.reset()
episode_return = 0
num_episodes = 0
Expand Down
1 change: 1 addition & 0 deletions examples/ur5_mia_grasp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

env = gym.make("URMiaGraspPillow-v0")


env.reset()
episode_return = 0
num_episodes = 0
Expand Down
32 changes: 17 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
with open("README.md", "r") as f:
long_description = f.read()

setup(name='deformable_gym',
version="0.3.3",
maintainer='Melvin Laux',
maintainer_email='[email protected]',
description='Gym environments for grasping deformable objects',
long_description=long_description,
long_description_content_type="text/markdown",
license='BSD-3-Clause',
packages=["deformable_gym"],
install_requires=[
"pybullet",
"gymnasium",
"numpy>=1.23.5,<2.0.0",
"pytransform3d"
])
setup(
name="deformable_gym",
version="0.3.4",
maintainer="Melvin Laux",
maintainer_email="[email protected]",
description="Gym environments for grasping deformable objects",
long_description=long_description,
long_description_content_type="text/markdown",
license="BSD-3-Clause",
packages=["deformable_gym"],
install_requires=[
"pybullet",
"gymnasium",
"numpy>=1.23.5,<2.0.0",
"pytransform3d",
],
)
3 changes: 0 additions & 3 deletions tests/envs/test_floating_mia_grasp_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
@pytest.fixture
def env():
return FloatingMiaGraspEnv(
gui=False,
verbose=False,
horizon=10,
object_name="insole_on_conveyor_belt/back",
# observable_object_pos=True,
)


Expand Down Expand Up @@ -59,7 +57,6 @@ def test_episode_reproducibility(env: FloatingMiaGraspEnv):
env = FloatingMiaGraspEnv(
verbose=False,
horizon=3,
gui=False,
object_name="insole_on_conveyor_belt/back",
)

Expand Down
2 changes: 0 additions & 2 deletions tests/envs/test_floating_shadow_grasp_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@pytest.fixture
def env():
return FloatingShadowGraspEnv(
gui=False,
verbose=False,
horizon=10,
object_name="insole",
Expand Down Expand Up @@ -60,7 +59,6 @@ def test_episode_reproducibility(env: FloatingShadowGraspEnv):
env = FloatingShadowGraspEnv(
verbose=False,
horizon=3,
gui=False,
object_name="insole_on_conveyor_belt/back",
)

Expand Down
4 changes: 2 additions & 2 deletions tests/envs/test_parallel_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


def test_parallel_envs():
env = gymnasium.make("FloatingMiaGraspInsole-v0", gui=False, horizon=10)
env2 = gymnasium.make("FloatingMiaGraspInsole-v0", gui=False, horizon=10)
env = gymnasium.make("FloatingMiaGraspInsole-v0", horizon=10)
env2 = gymnasium.make("FloatingMiaGraspInsole-v0", horizon=10)

obs, info = env.reset(seed=SEED)
num_steps = 0
Expand Down
2 changes: 0 additions & 2 deletions tests/envs/test_ur10_shadow_grasp_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@pytest.fixture
def env():
return UR10ShadowGraspEnv(
gui=False,
verbose=False,
horizon=10,
object_name="insole",
Expand Down Expand Up @@ -61,7 +60,6 @@ def test_episode_reproducibility(env: UR10ShadowGraspEnv):
env = UR10ShadowGraspEnv(
verbose=False,
horizon=3,
gui=False,
object_name="insole_on_conveyor_belt/back",
)

Expand Down
3 changes: 0 additions & 3 deletions tests/envs/test_ur5_mia_grasp_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
@pytest.fixture
def env():
return UR5MiaGraspEnv(
gui=False,
verbose=False,
horizon=10,
object_name="insole",
# observable_object_pos=True,
)


Expand Down Expand Up @@ -43,7 +41,6 @@ def test_episode_reproducibility(env: UR5MiaGraspEnv):
env = UR5MiaGraspEnv(
verbose=False,
horizon=3,
gui=False,
object_name="insole_on_conveyor_belt/back",
)

Expand Down

0 comments on commit 0297a52

Please sign in to comment.