
    ni                     Z   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSr   SS\R                  S\R                  \   S	\S
\R                  \   S\R                  \   S\R                  \   4S jjrS\R                  S	\4S jrS\R                  S	\4S jrS\R                  S	\4S jrg)z The inverse kinematic utilities.    )absolute_import)division)print_functionNr   r   r      robotlink_positionlink_id	joint_idsbase_translationbase_rotationc                 Z   U(       da  U R                  5       U R                  5       pU R                  R                  XxXV5      u  pxU R                  R                  XxU[        5      u  pOUn	SnU R                  R                  U R                  X)US9nU Vs/ s H  oU   PM	     nnU$ s  snf )ay  Uses Inverse Kinematics to calculate joint angles.

Args:
  robot: A robot instance.
  link_position: The (x, y, z) of the link in the body or the world frame,
    depending on whether the argument position_in_world_frame is true.
  link_id: The link id as returned from loadURDF.
  joint_ids: The positional index of the joints. This can be different from
    the joint unique ids.
  position_in_world_frame: Whether the input link_position is specified
    in the world frame or the robot's base frame.
  base_translation: Additional base translation.
  base_rotation: Additional base rotation.

Returns:
  A list of joint angles.
r   )solver)GetBasePositionGetBaseOrientationpybullet_clientmultiplyTransforms_IDENTITY_ORIENTATIONcalculateInverseKinematics	quadruped)r   r	   r
   r   position_in_world_framer   r   base_positionbase_orientationworld_link_pos_	ik_solverall_joint_anglesijoint_angless                  l/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/minitaur/robots/utilities/kinematics.pyjoint_angles_from_link_positionr!      s    2 
!&+&;&; '! $&+&;&;&N&N)9'J#M --@@8MONA #N)**EEoowy F B 099y!1%y,9	 :s   B(c                 |    [         R                  " U R                  R                  U R                  U5      S   5      $ )zComputes the link's position in the world frame.

Args:
  robot: A robot instance.
  link_id: The link id to calculate its position.

Returns:
  The position of the link in the world frame.
r   )nparrayr   getLinkStater   )r   r
   s     r    link_position_in_world_framer&   <   s6     
(('B1E
G G    c                 :   U R                  5       U R                  5       p2U R                  R                  X#5      u  pEU R                  R	                  U R
                  U5      nUS   nU R                  R                  XEUS5      u  p[        R                  " U5      $ )zComputes the link's local position in the robot frame.

Args:
  robot: A robot instance.
  link_id: The link to calculate its relative position.

Returns:
  The relative position of the link.
r   r   )	r   r   r   invertTransformr%   r   r   r#   r$   )
r   r
   r   r   inverse_translationinverse_rotation
link_stater	   link_local_positionr   s
             r    link_position_in_base_framer.   M   s     %*$9$9 %
 "*/*?*?*O*O+'' $$11%//7K*Q-- 00CC]LJ 
%	&&r'   c                    U R                    Vs/ s H  o"S   PM	     nnS/[        U5      -  nU R                  R                  U R                  USUXD5      u  pV[
        R                  " U5      nUR                  S   S:X  d   eU$ s  snf )a  Computes the Jacobian matrix for the given link.

Args:
  robot: A robot instance.
  link_id: The link id as returned from loadURDF.

Returns:
  The 3 x N transposed Jacobian matrix. where N is the total DoFs of the
  robot. For a quadruped, the first 6 columns of the matrix corresponds to
  the CoM translation and rotation. The columns corresponds to a leg can be
  extracted with indices [6 + leg_id * 3: 6 + leg_id * 3 + 3].
r   r   r   r      )joint_stateslenr   calculateJacobianr   r#   r$   shape)r   r
   stater   zero_vecjvr   jacobians           r    compute_jacobianr:   g   s    " -2,>,>?,>5Ah,>?S3'(((



1
1%//72;=M2:F%" XXb\(		a			/ @s   B)Fr0   r   )__doc__
__future__r   r   r   numpyr#   typingr   AnySequencefloatintr!   r&   r.   r:    r'   r    <module>rD      s    & &  %  $  "/8,8,::,??5), , s#	, ooe,, ??5),^G::GG"'::''4::r'   