Skip to content

simulo.ContactSensor

Contact force sensor using PhysX contact reporting.

Measures contact forces between bodies and the environment. Commonly used for foot contact detection in locomotion tasks.

Attributes:

  • history_length — Number of past contact states to store
  • track_air_time — Whether to track time since last contact
  • filter_prim_paths — Optional list of prims to filter contacts with

Example:

import simulo
# Create contact sensor for robot feet
contact = simulo.ContactSensor(
history_length=6,
track_air_time=True,
debug_vis=True,
)
# Add to scene (supports regex patterns)
scene.add(contact, at="/World/Robot/.*_FOOT")
# Read data
forces = contact.read_net_forces() # (num_envs, num_bodies, 3)
air_time = contact.read_air_time() # (num_envs, num_bodies)

Note: The path can include regex patterns (e.g., “.*_FOOT”) to match multiple bodies. Contact reporting must be enabled on the rigid bodies (done automatically for articulation feet).

simulo.ContactSensor(
path: Optional[str] = None,
update_period: float = 0.0,
history_length: int = 1,
track_air_time: bool = False,
filter_prim_paths: Optional[List[str]] = None,
enabled: bool = True,
debug_vis: bool = False,
)
ContactSensor.read_net_forces() -> torch.Tensor

Get net contact forces in world frame.

Returns:

Force tensor of shape (num_envs, num_bodies, 3). Each row is (fx, fy, fz) force vector in Newtons.

Raises:

  • RuntimeError — If sensor not initialized
ContactSensor.read_force_matrix() -> torch.Tensor

Get contact force matrix (forces with history).

Returns:

Force matrix of shape (num_envs, num_bodies, history_length, 3).

Raises:

  • RuntimeError — If sensor not initialized
ContactSensor.read_air_time() -> torch.Tensor

Get time bodies have been in air (not in contact).

Returns:

Air time tensor of shape (num_envs, num_bodies). Values are float32 in seconds.

Raises:

  • RuntimeError — If sensor not initialized or track_air_time is False
ContactSensor.is_in_contact(threshold: float = 1.0) -> torch.Tensor

Check if bodies are in contact.

Args:

  • threshold — Force threshold for contact detection (Newtons)

Returns:

Boolean tensor of shape (num_envs, num_bodies). True if contact force magnitude exceeds threshold.