def default_terminal_condition_for_laikago_v2(
    env,
    max_roll: float = 1.2,
    max_pitch: float = 1.2,
    min_height: float = 0.15,
    enforce_foot_contacts: bool = False):
  """A default terminal condition for Laikago_v2.

  Laikago is considered as fallen if the base position is too low or the base
  tilts/rolls too much.

  Args:
    env: An instance of MinitaurGymEnv
    max_roll:  Max roll before the episode terminates.
    max_pitch:  Max pitch before the episode terminates.
    min_height:  Min height before the episode terminates.
    enforce_foot_contacts: Ensure that contacts are established with the feet.

  Returns:
    A boolean indicating if Minitaur is fallen.
  """
  # Make sure that contacts are only made with the robot's feet.
  unwanted_collision = False
  if enforce_foot_contacts:
    # Get list of foot and knee link ids. Sometimes, the simulation will
    # register a contact as having been made with the knee link, even though it
    # was actually the foot that made the contact. Checking both the foot and
    # knee links for contact accounts for that.
    foot_link_ids = list(
        env.robot.urdf_loader.get_end_effector_id_dict().values())
    knee_link_ids = [foot_link_id - 1 for foot_link_id in foot_link_ids]
    contacts = env.pybullet_client.getContactPoints(bodyA=env.robot.robot_id)
    for contact in contacts:
      # Two different bodies made contact (i.e. not a self-collision).
      if contact[1] != contact[2]:
        foot_contact = (contact[3] in foot_link_ids) or (
            contact[3] in knee_link_ids)
        unwanted_collision = unwanted_collision or not foot_contact

  roll, pitch, _ = env.robot.base_roll_pitch_yaw
  pos = env.robot.base_position
  return (abs(roll) > max_roll or abs(pitch) > max_pitch or
          pos[2] < min_height or unwanted_collision)