Skip to content

Commit 61a6de9

Browse files
committed
support anymal d rough terrain
1 parent 90e0486 commit 61a6de9

File tree

4 files changed

+112
-52
lines changed

4 files changed

+112
-52
lines changed

source/isaaclab/isaaclab/envs/mdp/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ __all__ = [
6060
"randomize_rigid_body_material",
6161
"randomize_rigid_body_scale",
6262
"randomize_visual_color",
63+
"randomize_visual_color_instanced",
6364
"randomize_visual_texture_material",
6465
"reset_joints_by_offset",
6566
"reset_joints_by_scale",
@@ -138,6 +139,8 @@ __all__ = [
138139
"joint_pos_out_of_manual_limit",
139140
"joint_vel_out_of_limit",
140141
"joint_vel_out_of_manual_limit",
142+
"body_lin_vel_out_of_limit",
143+
"body_ang_vel_out_of_limit",
141144
"root_height_below_minimum",
142145
"time_out",
143146
]
@@ -201,6 +204,7 @@ from .events import (
201204
randomize_rigid_body_material,
202205
randomize_rigid_body_scale,
203206
randomize_visual_color,
207+
randomize_visual_color_instanced,
204208
randomize_visual_texture_material,
205209
reset_joints_by_offset,
206210
reset_joints_by_scale,
@@ -287,6 +291,8 @@ from .terminations import (
287291
joint_pos_out_of_manual_limit,
288292
joint_vel_out_of_limit,
289293
joint_vel_out_of_manual_limit,
294+
body_lin_vel_out_of_limit,
295+
body_ang_vel_out_of_limit,
290296
root_height_below_minimum,
291297
time_out,
292298
)

source/isaaclab/isaaclab/envs/mdp/terminations.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,41 @@ def joint_effort_out_of_limit(
150150
return torch.any(out_of_limits, dim=1)
151151

152152

153+
"""
154+
Body velocity terminations.
155+
"""
156+
157+
158+
def body_lin_vel_out_of_limit(
159+
env: ManagerBasedRLEnv,
160+
max_velocity: float,
161+
asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
162+
) -> torch.Tensor:
163+
"""Terminate when any body's linear velocity magnitude exceeds the limit [m/s].
164+
165+
Also terminates on NaN velocities, which indicate a solver singularity.
166+
"""
167+
asset: Articulation = env.scene[asset_cfg.name]
168+
body_vel = wp.to_torch(asset.data.body_lin_vel_w)[:, asset_cfg.body_ids]
169+
speed = torch.linalg.norm(body_vel, dim=-1)
170+
return torch.any((speed > max_velocity) | torch.isnan(speed), dim=1)
171+
172+
173+
def body_ang_vel_out_of_limit(
174+
env: ManagerBasedRLEnv,
175+
max_velocity: float,
176+
asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"),
177+
) -> torch.Tensor:
178+
"""Terminate when any body's angular velocity magnitude exceeds the limit [rad/s].
179+
180+
Also terminates on NaN velocities, which indicate a solver singularity.
181+
"""
182+
asset: Articulation = env.scene[asset_cfg.name]
183+
body_vel = wp.to_torch(asset.data.body_ang_vel_w)[:, asset_cfg.body_ids]
184+
speed = torch.linalg.norm(body_vel, dim=-1)
185+
return torch.any((speed > max_velocity) | torch.isnan(speed), dim=1)
186+
187+
153188
"""
154189
Contact sensor.
155190
"""

source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/config/anymal_d/rough_env_cfg.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55

6+
from isaaclab_newton.physics import MJWarpSolverCfg, NewtonCfg, NewtonCollisionPipelineCfg
7+
from isaaclab_physx.physics import PhysxCfg
8+
9+
from isaaclab.sim import SimulationCfg
610
from isaaclab.utils import configclass
711

8-
from isaaclab_tasks.manager_based.locomotion.velocity.velocity_env_cfg import (
9-
EventsCfg,
10-
LocomotionVelocityRoughEnvCfg,
11-
StartupEventsCfg,
12-
)
12+
from isaaclab_tasks.manager_based.locomotion.velocity.velocity_env_cfg import LocomotionVelocityRoughEnvCfg
1313
from isaaclab_tasks.utils import PresetCfg
1414

1515
##
@@ -19,28 +19,33 @@
1919

2020

2121
@configclass
22-
class AnymalDPhysxEventsCfg(EventsCfg, StartupEventsCfg):
23-
pass
24-
25-
26-
@configclass
27-
class AnymalDEventsCfg(PresetCfg):
28-
default = AnymalDPhysxEventsCfg()
29-
newton = EventsCfg()
22+
class RoughPhysicsCfg(PresetCfg):
23+
default = PhysxCfg(gpu_max_rigid_patch_count=10 * 2**15)
24+
newton = NewtonCfg(
25+
solver_cfg=MJWarpSolverCfg(
26+
njmax=200,
27+
nconmax=100,
28+
cone="pyramidal",
29+
impratio=1.0,
30+
integrator="implicitfast",
31+
use_mujoco_contacts=False,
32+
),
33+
collision_cfg=NewtonCollisionPipelineCfg(max_triangle_pairs=2_500_000),
34+
num_substeps=1,
35+
debug_mode=False,
36+
)
3037
physx = default
3138

32-
3339
@configclass
3440
class AnymalDRoughEnvCfg(LocomotionVelocityRoughEnvCfg):
35-
events: AnymalDEventsCfg = AnymalDEventsCfg()
41+
sim: SimulationCfg = SimulationCfg(physics=RoughPhysicsCfg())
3642

3743
def __post_init__(self):
3844
# post init of parent
3945
super().__post_init__()
4046
# switch robot to anymal-d
4147
self.scene.robot = ANYMAL_D_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot")
4248

43-
4449
@configclass
4550
class AnymalDRoughEnvCfg_PLAY(AnymalDRoughEnvCfg):
4651
def __post_init__(self):

source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/velocity_env_cfg.py

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
from isaaclab.utils.assets import ISAAC_NUCLEUS_DIR, ISAACLAB_NUCLEUS_DIR
2727
from isaaclab.utils.noise import UniformNoiseCfg as Unoise
2828

29+
2930
import isaaclab_tasks.manager_based.locomotion.velocity.mdp as mdp
30-
from isaaclab_tasks.utils import PresetCfg
31+
from isaaclab_tasks.utils import PresetCfg, preset
3132

3233
##
3334
# Pre-defined configs
@@ -161,6 +162,49 @@ def __post_init__(self):
161162
@configclass
162163
class EventsCfg:
163164
"""Configuration for events."""
165+
# startup
166+
physics_material = EventTerm(
167+
func=mdp.randomize_rigid_body_material,
168+
mode="startup",
169+
params={
170+
"asset_cfg": SceneEntityCfg("robot", body_names=".*"),
171+
"static_friction_range": (0.8, 0.8),
172+
"dynamic_friction_range": (0.6, 0.6),
173+
"restitution_range": (0.0, 0.0),
174+
"num_buckets": 64,
175+
},
176+
)
177+
178+
add_base_mass = EventTerm(
179+
func=mdp.randomize_rigid_body_mass,
180+
mode="startup",
181+
params={
182+
"asset_cfg": SceneEntityCfg("robot", body_names="base"),
183+
"mass_distribution_params": (-5.0, 5.0),
184+
"operation": "add",
185+
},
186+
)
187+
188+
base_com = preset(
189+
default=EventTerm(
190+
func=mdp.randomize_rigid_body_com,
191+
mode="startup",
192+
params={
193+
"asset_cfg": SceneEntityCfg("robot", body_names="base"),
194+
"com_range": {"x": (-0.05, 0.05), "y": (-0.05, 0.05), "z": (-0.01, 0.01)},
195+
},
196+
),
197+
newton=None
198+
)
199+
200+
collider_offsets = EventTerm(
201+
func=mdp.randomize_rigid_body_collider_offsets,
202+
mode="startup",
203+
params={
204+
"asset_cfg": SceneEntityCfg("robot", body_names=".*"),
205+
"contact_offset_distribution_params": (0.01, 0.01)
206+
},
207+
)
164208

165209
# reset
166210
base_external_force_torque = EventTerm(
@@ -207,40 +251,6 @@ class EventsCfg:
207251
)
208252

209253

210-
@configclass
211-
class StartupEventsCfg:
212-
# startup
213-
physics_material = EventTerm(
214-
func=mdp.randomize_rigid_body_material,
215-
mode="startup",
216-
params={
217-
"asset_cfg": SceneEntityCfg("robot", body_names=".*"),
218-
"static_friction_range": (0.8, 0.8),
219-
"dynamic_friction_range": (0.6, 0.6),
220-
"restitution_range": (0.0, 0.0),
221-
"num_buckets": 64,
222-
},
223-
)
224-
225-
add_base_mass = EventTerm(
226-
func=mdp.randomize_rigid_body_mass,
227-
mode="startup",
228-
params={
229-
"asset_cfg": SceneEntityCfg("robot", body_names="base"),
230-
"mass_distribution_params": (-5.0, 5.0),
231-
"operation": "add",
232-
},
233-
)
234-
235-
base_com = EventTerm(
236-
func=mdp.randomize_rigid_body_com,
237-
mode="startup",
238-
params={
239-
"asset_cfg": SceneEntityCfg("robot", body_names="base"),
240-
"com_range": {"x": (-0.05, 0.05), "y": (-0.05, 0.05), "z": (-0.01, 0.01)},
241-
},
242-
)
243-
244254

245255
@configclass
246256
class RewardsCfg:
@@ -287,6 +297,10 @@ class TerminationsCfg:
287297
func=mdp.illegal_contact,
288298
params={"sensor_cfg": SceneEntityCfg("contact_forces", body_names="base"), "threshold": 1.0},
289299
)
300+
body_lin_vel = DoneTerm(
301+
func=mdp.body_lin_vel_out_of_limit,
302+
params={"max_velocity": 20.0, "asset_cfg": SceneEntityCfg("robot", body_names=".*")},
303+
)
290304

291305

292306
@configclass
@@ -314,7 +328,7 @@ class LocomotionVelocityRoughEnvCfg(ManagerBasedRLEnvCfg):
314328
# MDP settings
315329
rewards: RewardsCfg = RewardsCfg()
316330
terminations: TerminationsCfg = TerminationsCfg()
317-
events: EventsCfg = MISSING
331+
events: EventsCfg = EventsCfg()
318332
curriculum: CurriculumCfg = CurriculumCfg()
319333

320334
def __post_init__(self):

0 commit comments

Comments
 (0)