Skip to content

Commit e03a8aa

Browse files
committed
Extends haptic scene and set defaults
1 parent 1e31b49 commit e03a8aa

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

examples/assets/haptics.xml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
<texture name='groundplane' type='2d' builtin='checker' rgb1='.2 .3 .4' rgb2='.1 .2 .3' width='300' height='300' mark='edge' markrgb='.8 .8 .8'/>
55
<material name='groundplane' texture='groundplane' texrepeat='5 5' texuniform='true' reflectance='.2'/>
66
</asset>
7-
8-
<!-- Always initialize the free camera to point at the origin. -->
9-
<statistic center='0 0 0'/>
107
<default>
118
<geom solimp="0.9 0.95 0.001 0.5 2" solref="0.005 1" condim="6" />
129
</default>
1310
<worldbody>
11+
<camera name="default_view" mode="targetbody" target="panda/panda_gripper/panda_rightfinger" pos="1.244 -0.603 1.202"/>
1412
<geom name='ground' type='plane' size='2 2 2' material='groundplane'
1513
friction='0.4'/>
1614
<light directional='true' diffuse='.7 .7 .7' pos='1 .1 2' dir='0 -.1 -2' specular='.3 .3 .3' castshadow='true'/>
@@ -21,16 +19,32 @@
2119
</body>
2220
<body pos="0.45 0 0.4" >
2321
<geom type="box" size=".025 .025 .025" rgba="1 0 0 1" />
24-
<joint type="slide" axis="0 1 0" range="-0.075 0.075" />
25-
<joint type="slide" axis="1 0 0" range="-0.125 0.025" />
22+
<joint type="slide" damping="50" axis="0 1 0" range="-0.075 0.075" />
23+
<joint type="slide" damping="50" axis="1 0 0" range="-0.125 0.025" />
2624
</body>
27-
<body pos="0.4 0.4 0.355">
28-
<geom type="box" size="0.1 0.1 0.005" rgba="1 1 0 1"/>
25+
<body pos="0.4 0.25 0.355">
26+
<geom type="box" size="0.1 0.1 0.005" rgba="0 0 1 1"/>
2927
</body>
30-
<body pos="0.4 0.4 0.4">
31-
<geom type="sphere" size="0.04" rgba="1 1 0 1" />
28+
<body pos="0.4 0.25 0.4">
29+
<geom type="sphere" size="0.04" rgba="0 0 1 1" />
3230
<joint type="slide" axis="0 1 0" range="-0.1 0.1" />
3331
<joint type="slide" axis="1 0 0" range="-0.1 0.1" />
3432
</body>
33+
34+
<body pos="0.5 -0.2 0.355">
35+
<geom type="box" size="0.05 0.05 0.005" rgba="0 1 0 1"/>
36+
<geom type="cylinder" pos="0 0 0.02" size="0.03 0.02" rgba="0.5 1 0.5 0.3" contype="0" conaffinity="0" group="1"/>
37+
</body>
38+
<body pos="0.5 -0.2 0.4">
39+
<geom type="cylinder" size="0.028 0.02" rgba="0 1 0 1" />
40+
<joint type="slide" axis="0 0 1" range="-0.02 0" damping="10.0" stiffness="100"/>
41+
</body>
42+
43+
<body pos="0.3 -0.2 0.4">
44+
<geom type="capsule" fromto="-0.08 0 0 0.08 0 0" size="0.015" rgba="0 0.5 0 1"/>
45+
<geom type="cylinder" size="0.02 0.03" rgba="0 1 0 1"/>
46+
<joint type="hinge" axis="0 0 1" damping="10" armature="0.01"/>
47+
</body>
48+
3549
</worldbody>
3650
</mujoco>

examples/haptics.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import numpy as np
1010
from dm_control import composer, mjcf
1111
from dm_env import specs
12+
from dm_control.viewer import user_input, application
1213

1314
from dm_robotics.panda import arm_constants, environment
1415
from dm_robotics.panda import parameters as params
@@ -28,6 +29,31 @@ def step(self, timestep: dm_env.TimeStep) -> np.ndarray:
2829
return action
2930

3031

32+
class Obs(utils.ObservationPlot):
33+
"""Selects torque observation to render by default."""
34+
def _init_buffer(self):
35+
super()._init_buffer()
36+
self._obs_idx = self._obs_keys.index('panda_torque')
37+
self.reset_data()
38+
self.update_title()
39+
40+
41+
class App(utils.ApplicationWithPlot):
42+
"""Sets default window size, camera and observation plot."""
43+
def __init__(self):
44+
super().__init__('Haptic Demo', 1920, 1080)
45+
46+
def _perform_deferred_reload(self, params):
47+
application.Application._perform_deferred_reload(self, params)
48+
cmp = Obs(self._runtime)
49+
self._renderer.components += cmp
50+
self._renderer.components += utils.ActionPlot(self._runtime)
51+
self._renderer.components += utils.RewardPlot(self._runtime)
52+
self._input_map.bind(cmp.next_obs, user_input.KEY_F4)
53+
self._input_map.bind(cmp.prev_obs, user_input.KEY_F3)
54+
self._viewer._camera_select.select_next()
55+
56+
3157
if __name__ == '__main__':
3258
# We initialize the default configuration for logging
3359
# and argument parsing. These steps are optional.
@@ -54,5 +80,5 @@ def step(self, timestep: dm_env.TimeStep) -> np.ndarray:
5480
# Initialize the agent.
5581
agent = Agent(env.action_spec())
5682
# Visualize the simulation to confirm physical interaction.
57-
app = utils.ApplicationWithPlot()
83+
app = App()
5884
app.launch(env, policy=agent.step)

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ authors = [
1919
{ name = "Jean Elsner", email = "[email protected]" },
2020
]
2121
dependencies = [
22-
"dm-robotics-moma>=0.6.0",
23-
"dm-robotics-controllers>=0.6.0",
24-
"dm-robotics-agentflow>=0.6.0",
25-
"dm-robotics-manipulation>=0.6.0",
26-
"dm-robotics-geometry>=0.6.0",
27-
"dm-robotics-transformations>=0.6.0",
22+
"dm-robotics-moma>=0.9.0",
23+
"dm-robotics-controllers>=0.9.0",
24+
"dm-robotics-agentflow>=0.9.0",
25+
"dm-robotics-manipulation>=0.9.0",
26+
"dm-robotics-geometry>=0.9.0",
27+
"dm-robotics-transformations>=0.9.0",
2828
"dm_env",
2929
"panda-python>=0.7.4",
3030
]

0 commit comments

Comments
 (0)