Terminations#

Termination functions for the Genesis environment. Each of these should return a boolean tensor indicating which environments should terminate, in the tensor shape (num_envs,).

genesis_forge.mdp.terminations.bad_orientation(env: GenesisEnv, limit_angle: float = 40.0, entity_attr: str = 'robot', entity_manager: EntityManager = None, grace_steps: int = 0) torch.Tensor[source]#

Terminate the environment if the robot is tipping over too much.

This function uses projected gravity to detect when the robot has tilted beyond a safe threshold. When the robot is perfectly upright, projected gravity should be [0, 0, -1] in the body frame. As the robot tilts, the x,y components increase, indicating roll and pitch angles.

Parameters:
  • env – The Genesis environment containing the robot

  • limit_angle – Maximum allowed tilt angle in degrees (default: 40 degrees)

  • entity_manager – The entity manager for the entity.

  • entity_attr – The attribute name of the entity in the environment. This isn’t necessary if entity_manager is provided.

  • grace_steps – Number of steps at episode start to ignore tilt detection (default: 0) This gives the robot a chance to stabilize before tilt detection is active.

Returns:

Boolean tensor indicating which environments should terminate

Return type:

torch.Tensor

genesis_forge.mdp.terminations.base_height_below_minimum(env: GenesisEnv, minimum_height: float = 0.05, entity_attr: str = 'robot', entity_manager: EntityManager = None) torch.Tensor[source]#

Terminate the environment if the robot’s base height falls below a minimum threshold.

Parameters:
  • env – The Genesis environment containing the robot

  • minimum_height – Minimum allowed base height in meters

  • entity_manager – The entity manager for the entity.

  • entity_attr – The attribute name of the entity in the environment. This isn’t necessary if entity_manager is provided.

Returns:

Boolean tensor indicating which environments should terminate

Return type:

torch.Tensor

genesis_forge.mdp.terminations.contact_force(_env: GenesisEnv, contact_manager: ContactManager, threshold: float = 1.0) torch.Tensor[source]#

Terminate if any link in the contact manager is in contact with something with a force greater than the threshold.

Parameters:
  • env – The Genesis environment containing the robot

  • contact_manager – The contact manager to check for contact

  • threshold – The force threshold for contact detection (default: 1.0 N)

Returns:

The total force for the contact manager for each environment

genesis_forge.mdp.terminations.contact_force_with_grace_period(env: GenesisEnv, contact_manager: ContactManager, threshold: float = 100.0, grace_steps: int = 10) torch.Tensor[source]#

Terminate if contact force exceeds threshold, with a grace period at episode start.

This is useful for quadrupeds that may start in slightly unstable positions and need a few steps to stabilize before fall detection becomes active.

Parameters:
  • env – The Genesis environment containing the robot

  • contact_manager – The contact manager to check for contact

  • threshold – The force threshold for contact detection (default: 100.0 N)

  • grace_steps – Number of steps at episode start to ignore contacts (default: 10)

Returns:

Boolean tensor indicating which environments should terminate

genesis_forge.mdp.terminations.has_contact(_env: GenesisEnv, contact_manager: ContactManager, threshold=1.0, min_contacts=1) torch.Tensor[source]#

One or more links in the contact manager are in contact with something.

Parameters:
  • env – The Genesis environment containing the robot

  • contact_manager – The contact manager to check for contact

  • threshold – The force threshold, per contact, for contact detection (default: 1.0)

  • min_contacts – The minimum number of contacts required to terminate (default: 1)

Returns:

True for each environment that has contact

genesis_forge.mdp.terminations.out_of_bounds(env: GenesisEnv, terrain_manager: TerrainManager, subterrain: str | None = None, border_margin: float = 0.5, entity_attr: str = 'robot') torch.Tensor[source]#

Terminate if the entity’s base position is outside of the terrain.

Parameters:
  • env – The Genesis environment containing the robot

  • terrain_manager – The terrain manager to check for out of bounds

  • subterrain – The subterrain to keep the robot inside of

  • border_margin – The margin (in meters) to add to the terrain bounds This terminates the episode before the robot falls off the terrain.

  • entity_attr – The attribute name of the entity in the environment. This isn’t necessary if entity_manager is provided.

genesis_forge.mdp.terminations.timeout(env: GenesisEnv) torch.Tensor[source]#

Terminate the environment if the episode length exceeds the maximum episode length.