Skip to content

Commit 344dc69

Browse files
committed
[fix] fix sapien maniksill new verison compatbility issue
1 parent e3ca5b2 commit 344dc69

File tree

3 files changed

+127
-108
lines changed

3 files changed

+127
-108
lines changed

example/sapien/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ python run_sapien_viz.py
3333

3434
This will start the simulation, and you should be able to visualize it in your web browser via the provided link.
3535

36+
Please be aware that the errors `[svulkan2] [error] GLFW error: X11: The DISPLAY environment variable is missing`
37+
and `[svulkan2] [warning] Continue without GLFW.` can be **disregarded** if you are operating on a headless server
38+
without a screen. Despite SAPIEN triggering an error when the DISPLAY variable is absent, both SAPIEN and the visualizer
39+
can function normally in such a situation.
40+
3641
## Limitations
3742

3843
Currently, the rendering of soft body simulation is not support for SAPIEN ManiSkill.

example/sapien/run_sapien_viz.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@
77
Original mani-skill2 code without the web visualization
88
# Reference: https://haosulab.github.io/ManiSkill2/getting_started/quickstart.html
99
10-
import gym
11-
import mani_skill2.envs # import to register all environments in gym
10+
import gymnasium as gym
11+
import mani_skill2.envs
1212
13-
env = gym.make("PickCube-v0", obs_mode="rgbd", control_mode="pd_ee_delta_pose")
13+
env = gym.make("PickCube-v0", obs_mode="rgbd", control_mode="pd_joint_delta_pos", render_mode="human")
1414
print("Observation space", env.observation_space)
1515
print("Action space", env.action_space)
1616
17-
env.seed(0) # specify a seed for randomness
18-
obs = env.reset()
19-
done = False
20-
while not done:
17+
obs, _ = env.reset(seed=0) # reset with a seed for randomness
18+
terminated, truncated = False, False
19+
while not terminated and not truncated:
2120
action = env.action_space.sample()
22-
obs, reward, done, info = env.step(action)
21+
obs, reward, terminated, truncated, info = env.step(action)
2322
env.render() # a display is required to render
2423
env.close()
2524
"""
2625

2726
from typing import Optional
2827

29-
import gym
28+
import gymnasium as gym
3029
# import to register all environments in gym
3130
# noinspection PyUnresolvedReferences
3231
import mani_skill2.envs # pylint: disable=unused-import
@@ -51,7 +50,10 @@ def wrapped_setup_viewer(self):
5150
self._viewer.toggle_camera_lines(False)
5251

5352

54-
create_sapien_visualizer(port=6000, host="localhost", keep_default_viewer=True)
53+
# Set to True if you want to keep both the original viewer and the web visualizer. A display is needed for True
54+
keep_on_screen_renderer = False
55+
56+
create_sapien_visualizer(port=6000, host="localhost", keep_default_viewer=keep_on_screen_renderer)
5557
sapien_env.BaseEnv._setup_scene = wrapped_setup_scene
5658

5759
sapien_env.BaseEnv._setup_viewer = wrapped_setup_viewer
@@ -60,20 +62,24 @@ def wrapped_setup_viewer(self):
6062
"AssemblingKits-v0", "PlugCharger-v0", "PegInsertionSide-v0", "PickClutterYCB-v0", "PickSingleEGAD-v0",
6163
"StackCube-v0"]
6264
control_mode = ["base_pd_joint_vel_arm_pd_joint_vel"] * 3 + ["pd_joint_delta_pos"] * 8
65+
66+
# You can try different task_num to visualize different tasks
6367
task_num = 1
6468

6569
env = gym.make(task_names[task_num], obs_mode="rgbd", control_mode=control_mode[task_num])
6670
# print("Observation space", env.observation_space)
6771
print("Action space", env.action_space)
6872

69-
env.seed(1) # specify a seed for randomness
70-
7173
while True:
72-
obs = env.reset()
73-
done = False
74-
for _ in range(500):
75-
action = env.action_space.sample()
76-
obs, reward, done, info = env.step(action)
77-
# env.render() # a display is required to render
74+
try:
75+
obs = env.reset()
76+
done = False
77+
for _ in range(100):
78+
action = env.action_space.sample()
79+
obs, reward, terminated, truncated, info = env.step(action)
80+
if keep_on_screen_renderer:
81+
env.render() # a display is required to render
82+
except KeyboardInterrupt:
83+
break
7884

7985
env.close()

0 commit comments

Comments
 (0)