(
      self,
      robot: Any,
      stance_duration: Sequence[float] = _NOMINAL_STANCE_DURATION,
      duty_factor: Sequence[float] = _NOMINAL_DUTY_FACTOR,
      initial_leg_state: Sequence[gait_generator.LegState] = LAIKAGO_TROTTING,
      initial_leg_phase: Sequence[float] = (0, 0, 0, 0),
      contact_detection_phase_threshold:
      float = _NOMINAL_CONTACT_DETECTION_PHASE,
  )
Initializes the class.

    Args:
      robot: A quadruped robot that at least implements the GetFootContacts API
        and num_legs property.
      stance_duration: The desired stance duration.
      duty_factor: The ratio  stance_duration / total_gait_cycle.
      initial_leg_state: The desired initial swing/stance state of legs indexed
        by their id.
      initial_leg_phase: The desired initial phase [0, 1] of the legs within the
        full swing + stance cycle.
      contact_detection_phase_threshold: Updates the state of each leg based on
        contact info, when the current normalized phase is greater than this
        threshold. This is essential to remove false positives in contact
        detection when phase switches. For example, a swing foot at at the
        beginning of the gait cycle might be still on the ground.
Initializes the class.
Initializes the class .
def __init__(
      self,
      robot: Any,
      stance_duration: Sequence[float] = _NOMINAL_STANCE_DURATION,
      duty_factor: Sequence[float] = _NOMINAL_DUTY_FACTOR,
      initial_leg_state: Sequence[gait_generator.LegState] = LAIKAGO_TROTTING,
      initial_leg_phase: Sequence[float] = (0, 0, 0, 0),
      contact_detection_phase_threshold:
      float = _NOMINAL_CONTACT_DETECTION_PHASE,
  ):
    """Initializes the class.

    Args:
      robot: A quadruped robot that at least implements the GetFootContacts API
        and num_legs property.
      stance_duration: The desired stance duration.
      duty_factor: The ratio  stance_duration / total_gait_cycle.
      initial_leg_state: The desired initial swing/stance state of legs indexed
        by their id.
      initial_leg_phase: The desired initial phase [0, 1] of the legs within the
        full swing + stance cycle.
      contact_detection_phase_threshold: Updates the state of each leg based on
        contact info, when the current normalized phase is greater than this
        threshold. This is essential to remove false positives in contact
        detection when phase switches. For example, a swing foot at at the
        beginning of the gait cycle might be still on the ground.
    """
    self._robot = robot
    self._stance_duration = stance_duration
    self._duty_factor = duty_factor
    self._swing_duration = np.array(stance_duration) / np.array(
        duty_factor) - np.array(stance_duration)
    if len(initial_leg_phase) != self._robot.num_legs:
      raise ValueError(
          "The number of leg phases should be the same as number of legs.")
    self._initial_leg_phase = initial_leg_phase
    if len(initial_leg_state) != self._robot.num_legs:
      raise ValueError(
          "The number of leg states should be the same of number of legs.")
    self._initial_leg_state = initial_leg_state
    self._next_leg_state = []
    # The ratio in cycle is duty factor if initial state of the leg is STANCE,
    # and 1 - duty_factory if the initial state of the leg is SWING.
    self._initial_state_ratio_in_cycle = []
    for state, duty in zip(initial_leg_state, duty_factor):
      if state == gait_generator.LegState.SWING:
        self._initial_state_ratio_in_cycle.append(1 - duty)
        self._next_leg_state.append(gait_generator.LegState.STANCE)
      else:
        self._initial_state_ratio_in_cycle.append(duty)
        self._next_leg_state.append(gait_generator.LegState.SWING)

    self._contact_detection_phase_threshold = contact_detection_phase_threshold

    # The normalized phase within swing or stance duration.
    self._normalized_phase = None
    self._leg_state = None
    self._desired_leg_state = None

    self.reset(0)
def __init__ ( self , robot : Any , stance_duration : Sequence [ float ] = _NOMINAL_STANCE_DURATION , duty_factor : Sequence [ float ] = _NOMINAL_DUTY_FACTOR , initial_leg_state : Sequence [ gait_generator . LegState ] = LAIKAGO_TROTTING , initial_leg_phase : Sequence [ float ] = ( 0 , 0 , 0 , 0 ) , contact_detection_phase_threshold : float = _NOMINAL_CONTACT_DETECTION_PHASE , ) : self . _robot = robot self . _stance_duration = stance_duration self . _duty_factor = duty_factor self . _swing_duration = np . array ( stance_duration ) / np . array ( duty_factor ) - np . array ( stance_duration ) if len ( initial_leg_phase ) != self . _robot . num_legs : raise ValueError ( "The number of leg phases should be the same as number of legs." ) self . _initial_leg_phase = initial_leg_phase if len ( initial_leg_state ) != self . _robot . num_legs : raise ValueError ( "The number of leg states should be the same of number of legs." ) self . _initial_leg_state = initial_leg_state self . _next_leg_state = [ ] # The ratio in cycle is duty factor if initial state of the leg is STANCE, # and 1 - duty_factory if the initial state of the leg is SWING. self . _initial_state_ratio_in_cycle = [ ] for state , duty in zip ( initial_leg_state , duty_factor ) : if state == gait_generator . LegState . SWING : self . _initial_state_ratio_in_cycle . append ( 1 - duty ) self . _next_leg_state . append ( gait_generator . LegState . STANCE ) else : self . _initial_state_ratio_in_cycle . append ( duty ) self . _next_leg_state . append ( gait_generator . LegState . SWING ) self . _contact_detection_phase_threshold = contact_detection_phase_threshold # The normalized phase within swing or stance duration. self . _normalized_phase = None self . _leg_state = None self . _desired_leg_state = None self . reset ( 0 )