isaac-sim/OmniIsaacGymEnvs

Contact Sensors on Humanoid

HiPatil opened this issue · 4 comments

I am using a custom environment, where I have a humanoid in a room. I want to check when humanoid collides with room walls. How can I do this? I tried using force sensor, but it is giving weird values, and also tried adding contact sensors in post_reset function, and tried to read those sensors in get_observation. But I am getting empty list.

Additionally I also get the following error, but simulation continues to run.

[Error] [omni.physx.plugin] Transformation change on non-root links is not supported.

Would appreciate if someone could help me solve this problem.

Hi, I think the recommended way of doing this is by creating RigidPrimViews for all of the humanoids prims. ie feet, hands etc. I can give you an example from a qaudruped:

NB! Remeber to set track_contact_forces=True,prepare_contact_sensors=True. And for speed if you are using GPU set the config flag "disable_contact_processing=True" Else you get a massive CPU overhead somewhere.

class OlympusView(ArticulationView):
def init(
self,
prim_paths_expr: str,
name: Optional[str] = "OlympusView",
track_contact_forces=True,
prepare_contact_sensors=True,
) -> None:
"""[summary]"""

    super().__init__(
        prim_paths_expr=prim_paths_expr, name=name, reset_xform_properties=False
    )

    self.Base = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/Body",
        name="Base",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )

    self.MotorHousing_FL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/MotorHousing_FL",
        name="MotorHousing_FL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterThigh_FL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontThigh_FL",
        name="FrontThigh_FL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerThigh_FL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackThigh_FL",
        name="BackThigh_FL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterShank_FL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontShank_FL",
        name="FrontShank_FL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerShank_FL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackShank_FL",
        name="BackShank_FL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=track_contact_forces,
    )
    self.Paw_FL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/Paw_FL",
        name="Paw_FL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
        # contact_filter_prim_paths_expr= ["/World/defaultGroundPlane"],
    )
    self.MotorHousing_FR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/MotorHousing_FR",
        name="MotorHousing_FR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterThigh_FR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontThigh_FR",
        name="FrontThigh_FR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerThigh_FR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackThigh_FR",
        name="BackThigh_FR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterShank_FR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontShank_FR",
        name="FrontShank_FR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerShank_FR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackShank_FR",
        name="BackShank_FR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.Paw_FR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/Paw_FR",
        name="Paw_FR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
        # contact_filter_prim_paths_expr= ["/World/defaultGroundPlane"],
    )

    self.MotorHousing_BL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/MotorHousing_BL",
        name="MotorHousing_BL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerThigh_BL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontThigh_BL",
        name="FrontThigh_BL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterThigh_BL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackThigh_BL",
        name="BackThigh_BL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerShank_BL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontShank_BL",
        name="FrontShank_BL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterShank_BL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackShank_BL",
        name="BackShank_BL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.Paw_BL = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/Paw_BL",
        name="Paw_BL",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
        # contact_filter_prim_paths_expr= ["/World/defaultGroundPlane"],
    )

    self.MotorHousing_BR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/MotorHousing_BR",
        name="MotorHousing_BR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerThigh_BR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontThigh_BR",
        name="FrontThigh_BR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterThigh_BR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackThigh_BR",
        name="BackThigh_BR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.InnerShank_BR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/FrontShank_BR",
        name="FrontShank_BR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.OuterShank_BR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/BackShank_BR",
        name="BackShank_BR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
    )
    self.Paw_BR = RigidPrimView(
        prim_paths_expr="/World/envs/.*/Olympus/Paw_BR",
        name="Paw_BR",
        reset_xform_properties=False,
        track_contact_forces=track_contact_forces,
        prepare_contact_sensors=prepare_contact_sensors,
        # contact_filter_prim_paths_expr= ["/World/defaultGroundPlane"],
    )

    self.rigid_prims = [
        self.Base,
        self.MotorHousing_FL,
        self.OuterThigh_FL,
        self.InnerThigh_FL,
        self.OuterShank_FL,
        self.InnerShank_FL,
        self.Paw_FL,
        self.MotorHousing_FR,
        self.OuterThigh_FR,
        self.InnerThigh_FR,
        self.OuterShank_FR,
        self.InnerShank_FR,
        self.Paw_FR,
        self.MotorHousing_BL,
        self.InnerThigh_BL,
        self.OuterThigh_BL,
        self.InnerShank_BL,
        self.OuterShank_BL,
        self.Paw_BL,
        self.MotorHousing_BR,
        self.InnerThigh_BR,
        self.OuterThigh_BR,
        self.InnerShank_BR,
        self.OuterShank_BR,
        self.Paw_BR,
    ]
    self._paws = [self.Paw_FL, self.Paw_FR, self.Paw_BL, self.Paw_BR]
    


def add_to_scene(self, scene) -> None:
    scene.add(self)
    for rigid_prim in self.rigid_prims:
        scene.add(rigid_prim)

def get_collision_buf(self) -> Tensor:
    coll_buf = torch.zeros(self._count, dtype=torch.bool, device=self._device)
    for rigid_prim in self.rigid_prims:
        if "Paw" in rigid_prim.name:
            continue
        forces: Tensor = rigid_prim.get_net_contact_forces(clone=True)
        prim_in_collision = (forces.abs() > 1e-5).any(dim=-1)
        coll_buf = coll_buf.logical_or(prim_in_collision)
    return coll_buf

@larsrpe Thanks a lot!

In case of Humanoid, can we combine two or more prims? Like combining upper_arm on both left and right, thigh on left and right and so on into one Rigid Prim View?

Does have more contact forces (Rigid Prim View) affect the speed of training?

You can do this by encapsulating more prims in the view. You have to do something like this:

UpperArms= RigidPrimView(prim_path_expr="/World/envs/.*/MyHumanoid/.*UpperArm", ...

Performance vice I dont think it matters much, but you can just test both!

Great, thanks!