(self, physics, random_state, site, target_pos,
                       target_quat=None, max_ik_attempts=10)
return success
Moves the arm so that a site occurs at the specified location.

    This function runs the inverse kinematics solver to find a configuration
    arm joints for which the pinch site occurs at the specified location in
    Cartesian coordinates.

    Args:
      physics: A `mujoco.Physics` instance.
      random_state: An `np.random.RandomState` instance.
      site: Either a `mjcf.Element` or a string specifying the full name
        of the site whose position is being set.
      target_pos: The desired Cartesian location of the site.
      target_quat: (optional) The desired orientation of the site, expressed
        as a quaternion. If `None`, the default orientation is to point
        vertically downwards.
      max_ik_attempts: (optional) Maximum number of attempts to make at finding
        a solution satisfying `target_pos` and `target_quat`. The joint
        positions will be randomized after each unsuccessful attempt.

    Returns:
      A boolean indicating whether the desired configuration is obtained.

    Raises:
      ValueError: If site is neither a string nor an `mjcf.Element`.
Moves the arm so that a site occurs at the specified location.
Moves the arm so that a site occurs at the specified location .
def set_site_to_xpos(self, physics, random_state, site, target_pos,
                       target_quat=None, max_ik_attempts=10):
    """Moves the arm so that a site occurs at the specified location.

    This function runs the inverse kinematics solver to find a configuration
    arm joints for which the pinch site occurs at the specified location in
    Cartesian coordinates.

    Args:
      physics: A `mujoco.Physics` instance.
      random_state: An `np.random.RandomState` instance.
      site: Either a `mjcf.Element` or a string specifying the full name
        of the site whose position is being set.
      target_pos: The desired Cartesian location of the site.
      target_quat: (optional) The desired orientation of the site, expressed
        as a quaternion. If `None`, the default orientation is to point
        vertically downwards.
      max_ik_attempts: (optional) Maximum number of attempts to make at finding
        a solution satisfying `target_pos` and `target_quat`. The joint
        positions will be randomized after each unsuccessful attempt.

    Returns:
      A boolean indicating whether the desired configuration is obtained.

    Raises:
      ValueError: If site is neither a string nor an `mjcf.Element`.
    """
    if isinstance(site, mjcf.Element):
      site_name = site.full_identifier
    elif isinstance(site, str):
      site_name = site
    else:
      raise ValueError('site should either be a string or mjcf.Element: got {}'
                       .format(site))
    if target_quat is None:
      target_quat = DOWN_QUATERNION
    lower, upper = self._get_joint_pos_sampling_bounds(physics)
    arm_joint_names = [joint.full_identifier for joint in self.joints]

    for _ in range(max_ik_attempts):
      result = inverse_kinematics.qpos_from_site_pose(
          physics=physics,
          site_name=site_name,
          target_pos=target_pos,
          target_quat=target_quat,
          joint_names=arm_joint_names,
          rot_weight=2,
          inplace=True)
      success = result.success

      # Canonicalise the angle to [0, 2*pi]
      if success:
        for arm_joint, low, high in zip(self.joints, lower, upper):
          arm_joint_mj = physics.bind(arm_joint)
          while arm_joint_mj.qpos >= high:
            arm_joint_mj.qpos -= 2*np.pi
          while arm_joint_mj.qpos < low:
            arm_joint_mj.qpos += 2*np.pi
            if arm_joint_mj.qpos > high:
              success = False
              break

      # If succeeded or only one attempt, break and do not randomize joints.
      if success or max_ik_attempts <= 1:
        break
      else:
        self.randomize_arm_joints(physics, random_state)

    return success
def set_site_to_xpos ( self , physics , random_state , site , target_pos , target_quat = None , max_ik_attempts = 10 ) : if isinstance ( site , mjcf . Element ) : site_name = site . full_identifier elif isinstance ( site , str ) : site_name = site else : raise ValueError ( 'site should either be a string or mjcf.Element: got {}' . format ( site ) ) if target_quat is None : target_quat = DOWN_QUATERNION lower , upper = self . _get_joint_pos_sampling_bounds ( physics ) arm_joint_names = [ joint . full_identifier for joint in self . joints ] for _ in range ( max_ik_attempts ) : result = inverse_kinematics . qpos_from_site_pose ( physics = physics , site_name = site_name , target_pos = target_pos , target_quat = target_quat , joint_names = arm_joint_names , rot_weight = 2 , inplace = True ) success = result . success # Canonicalise the angle to [0, 2*pi] if success : for arm_joint , low , high in zip ( self . joints , lower , upper ) : arm_joint_mj = physics . bind ( arm_joint ) while arm_joint_mj . qpos >= high : arm_joint_mj . qpos -= 2 * np . pi while arm_joint_mj . qpos < low : arm_joint_mj . qpos += 2 * np . pi if arm_joint_mj . qpos > high : success = False break # If succeeded or only one attempt, break and do not randomize joints. if success or max_ik_attempts <= 1 : break else : self . randomize_arm_joints ( physics , random_state ) return success