Unverified Commit e83f79e3 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Switches to events for Anymal-C direct environment (#990)

# Description

The previous implementation in ANYmal-C environment randomly sampled the
friction material. This sometimes led to an overflow of a number of
materials possible from the PhysX side. This MR switches to using events
for the ANYmal Direct RL environment implementation.

Fixes [#941](https://github.com/isaac-sim/IsaacLab/issues/941)

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
parent ac4751fe
......@@ -7,7 +7,10 @@ from __future__ import annotations
import torch
import omni.isaac.lab.envs.mdp as mdp
import omni.isaac.lab.sim as sim_utils
from omni.isaac.lab.managers import EventTermCfg as EventTerm
from omni.isaac.lab.managers import SceneEntityCfg
from omni.isaac.lab.assets import Articulation, ArticulationCfg
from omni.isaac.lab.envs import DirectRLEnv, DirectRLEnvCfg
from omni.isaac.lab.scene import InteractiveSceneCfg
......@@ -23,6 +26,33 @@ from omni.isaac.lab_assets.anymal import ANYMAL_C_CFG # isort: skip
from omni.isaac.lab.terrains.config.rough import ROUGH_TERRAINS_CFG # isort: skip
@configclass
class EventCfg:
"""Configuration for randomization."""
physics_material = EventTerm(
func=mdp.randomize_rigid_body_material,
mode="startup",
params={
"asset_cfg": SceneEntityCfg("robot", body_names=".*"),
"static_friction_range": (0.8, 0.8),
"dynamic_friction_range": (0.6, 0.6),
"restitution_range": (0.0, 0.0),
"num_buckets": 64,
},
)
add_base_mass = EventTerm(
func=mdp.randomize_rigid_body_mass,
mode="startup",
params={
"asset_cfg": SceneEntityCfg("robot", body_names="base"),
"mass_distribution_params": (-5.0, 5.0),
"operation": "add",
},
)
@configclass
class AnymalCFlatEnvCfg(DirectRLEnvCfg):
# env
......@@ -63,6 +93,9 @@ class AnymalCFlatEnvCfg(DirectRLEnvCfg):
# scene
scene: InteractiveSceneCfg = InteractiveSceneCfg(num_envs=4096, env_spacing=4.0, replicate_physics=True)
# events
events: EventCfg = EventCfg()
# robot
robot: ArticulationCfg = ANYMAL_C_CFG.replace(prim_path="/World/envs/env_.*/Robot")
contact_sensor: ContactSensorCfg = ContactSensorCfg(
......@@ -152,19 +185,7 @@ class AnymalCEnv(DirectRLEnv):
# Get specific body indices
self._base_id, _ = self._contact_sensor.find_bodies("base")
self._feet_ids, _ = self._contact_sensor.find_bodies(".*FOOT")
self._underisred_contact_body_ids, _ = self._contact_sensor.find_bodies(".*THIGH")
# Randomize robot friction
env_ids = self._robot._ALL_INDICES
mat_props = self._robot.root_physx_view.get_material_properties()
mat_props[:, :, :2].uniform_(0.6, 0.8)
self._robot.root_physx_view.set_material_properties(mat_props, env_ids.cpu())
# Randomize base mass
base_id, _ = self._robot.find_bodies("base")
masses = self._robot.root_physx_view.get_masses()
masses[:, base_id] += torch.zeros_like(masses[:, base_id]).uniform_(-5.0, 5.0)
self._robot.root_physx_view.set_masses(masses, env_ids.cpu())
self._undesired_contact_body_ids, _ = self._contact_sensor.find_bodies(".*THIGH")
def _setup_scene(self):
self._robot = Articulation(self.cfg.robot)
......@@ -245,7 +266,7 @@ class AnymalCEnv(DirectRLEnv):
# undersired contacts
net_contact_forces = self._contact_sensor.data.net_forces_w_history
is_contact = (
torch.max(torch.norm(net_contact_forces[:, :, self._underisred_contact_body_ids], dim=-1), dim=1)[0] > 1.0
torch.max(torch.norm(net_contact_forces[:, :, self._undesired_contact_body_ids], dim=-1), dim=1)[0] > 1.0
)
contacts = torch.sum(is_contact, dim=1)
# flat orientation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment