
    ni(                         S r SSKJrJrJrJrJrJrJr  SSK	J
r
  SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SrS
r\R2                   " S S\R4                  5      5       rg)zDA module that defines autonomous object class and related functions.    )AnyCallableDictOptionalSequenceTextUnion)loggingN)bullet_client)base_client)sensor)object_controller)
robot_basei  c            	       `   \ rS rSrSr   S,S\S\\R                     S\	R                  S\4S jjrS-S
 jrS\R                  S	S4S jrS\/ \4   S	S4S jr\S 5       rS\S\\\4   S	S4S jrS rS-S jr   S.S\\\      S\\\      S\\	R                     S	S4S jjrS-S jrS\S	\4S jrS\S	S4S jrS-S jr S-S jr!  S/S\"\\   \#RH                  4   S\"\\   \#RH                  4   4S  jjr%S\"\\   \#RH                  4   S\"\\   \#RH                  4   4S! jr&S0S" jr'\S	\\   4S# j5       r(\S	\\R                     4S$ j5       r)\S	\#RH                  4S% j5       r*\S	\#RH                  4S& j5       r+\S	\#RH                  4S' j5       r,\S( 5       r-\S) 5       r.\S	\/4S* j5       r0S+r1g)1AutonomousObject   zGAutonomous object that moves/acts in simulation guided by a controller.N	urdf_filesensors
controlleractuate_by_resetc                 "   Xl         U=(       d    [        R                  " 5       U l        X@l        U(       d  U R
                  OU R                  U l        [        U5      U l	        SU l
        SU l        SU l        SU l        U R                  5         g)a  Constructor.

Args:
  urdf_file: The path to urdf file of the object.
  sensors: A list of sensor objects to attach to autonomous object.
  controller: A controller object that governs autonomous object's motion.
    If not specified, StationaryController is used.
  actuate_by_reset: Use pybullet resetBasePositionAndOrientation to actuate
    the object. Default is False, which means actuate by constraint. In the
    actuate by constrained mode, be extra cautious when the position or
    orientation control is based on position or orientation sensor reading
    of the same object. This loop-back condition is known to be problematic
    and causes slower than expected motion.
N)
_urdf_filer   StationaryController_controller_actuate_by_reset_actuate_base_pose_reset_base_pose_actuate_functionlist_sensors
_object_id_constraint_id_pybullet_client_clock_init_internal_states)selfr   r   r   r   s        i/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/minitaur/robots/autonomous_object.py__init__AutonomousObject.__init__   s~    &  O!M%6%K%K%MD-   	%)%:%: 	 MDMDOD DDK     returnc                     SU l         0 U l        [        R                  " S5      U l        [        R
                  " / SQ5      U l        g )Nr      r   r   r      )_observations_time_since_reset_observationsnpzeros	_positionarray_orientationr'   s    r(   r&   &AutonomousObject._init_internal_states?   s2    *+D'DXXa[DN.Dr+   pybullet_clientc                 P    Xl         U R                  5         U R                  5         g)z-Sets new simulation client and reload assets.N)r$   r&   load)r'   r:   s     r(   set_sim_clientAutonomousObject.set_sim_clientE   s    + IIKr+   clockc                     Xl         g)z=Sets monotonic clock when adding into simulation environment.N)r%   )r'   r?   s     r(   	set_clockAutonomousObject.set_clockK   s    Kr+   c                     U R                   $ Nr"   r8   s    r(   sim_object_idAutonomousObject.sim_object_idO       ??r+   time_since_reset_secobservationsc                 n    XR                   :  a  [        SU R                   U4-  5      eXl         X l        g)zUpdates simulation time and observations.

This function should be called before apply_action in each simulation step.

Args:
  time_since_reset_sec: Time from start of simulation reset in seconds.
  observations: A dict of observations.
z5Time cannot go backwards. Current t = %f, new t = %f.N)r1   
ValueErrorr2   )r'   rI   rJ   s      r(   updateAutonomousObject.updateS   sE     AAA
A..0D
EFG G +?'%r+   c                      [        SU R                  5        U R                  R                  U R                  5      U l        g!   [        SU R                  5        SSKnUR                  S5         g= f)zLoads object URDF file.z	loading: zError: cannot load r   N)printr   r$   loadURDFr"   sysexit)r'   rR   s     r(   
_load_urdfAutonomousObject._load_urdfd   sU    K)--66tGdo!4??3	hhqks   A A -A2c                 6   U R                  5         U R                  (       dD  U R                  R                  U R                  SSSU R                  R
                  SSSSS9	U l        U R                   H  nUR                  U 5        M     U R                  5         g)z-Reconstructs the robot and resets its states.r   r   r   r   r/   )	parentBodyUniqueIdparentLinkIndexchildBodyUniqueIdchildLinkIndex	jointType	jointAxisparentFramePositionchildFramePositionchildFrameOrientationN)
rT   r   r$   createConstraintr"   JOINT_FIXEDr#   r!   	set_robotreset)r'   ss     r(   r<   AutonomousObject.loadn   s    OO!! 11BB!__))55'& , C 	.d ]]kk$  	JJLr+   base_positionbase_orientation_quaternionc                 H   Uc  Ub  [        S5      eUb  X0l        U R                  5         U R                  R                  [        R
                  U R                  5      u  U l        U l        nU R                  U R                  U R                  5        U R                  5         g)a]  Resets the states (e.g.

pose and sensor readings) of the robot.

This is called at the start of each episode by the environment.

Args:
  base_position: Robot base position after reset. Must be None.
  base_orientation_quaternion: Robot base orientation after reset. Must be
    None.
  controller: A new controller to replace original controller.
NzNReset position and orientation of AutonomousObject is specified in controller.)rL   r   r&   
get_actionr   	INIT_TIMEr2   r5   r7   r   receive_observation)r'   rg   rh   r   _s        r(   rd   AutonomousObject.reset   s    "  $?$K 2 3 3 # +/+;+;+F+F##T%7%7,9(DND%q 	$..$*;*;<r+   c                     g)z*Shuts down the robot, no-op in simulation.N r8   s    r(   	terminateAutonomousObject.terminate   s    r+   actionc                 .    U[         La  [        S5      eU$ )zProcesses the input action before the action repeat loop.

Args:
  action: expect it to be `AUTONOMOUS_ACTION` at present.

Returns:
  the action as is.
EAutonomousObject only accept AUTONOMOUS_ACTION as action value input.)AUTONOMOUS_ACTIONrL   )r'   rs   s     r(   pre_control_step!AutonomousObject.pre_control_step   s$     && - . .Mr+   c                     U[         La  [        S5      eU R                  R                  U R                  U R
                  5      u  p#nU R                  X#5        g)z Applies the action to the robot.ru   N)rv   rL   r   rj   r1   r2   r   )r'   rs   positionorientationrm   s        r(   apply_actionAutonomousObject.apply_action   s\     && - . .#//::++T-?-? AH1 	81r+   c                     U R                   R                  U R                  5      u  p[        R                  " U5      U l        [        R                  " U5      U l        g)z"Updates the robot sensor readings.N)r$   getBasePositionAndOrientationr"   r3   r6   r5   r7   )r'   rz   r{   s      r(   rl   $AutonomousObject.receive_observation   sD     	;;DOOL HXXh'DN-Dr+   c                     g)z=Updates internal variables. Not yet used in AutonomousObject.Nrp   r8   s    r(   post_control_step"AutonomousObject.post_control_step   s    r+   rz   orientation_quatc                     Uc  U R                   nUc  U R                  nU R                  R                  U R                  SS5        U R                  R                  U R                  X5        g)zResets the base to the desired position and orientation.

Args:
  position: The desired base position. If omitted, current location is used.
  orientation_quat: The desired base orientation in quaternion. If omitted,
    current orientation is used.
NrW   )r5   r7   r$   resetBaseVelocityr"   resetBasePositionAndOrientationr'   rz   r   s      r(   r   !AutonomousObject._reset_base_pose   sa     h**++DOOY,57995r+   c                 X    U R                   R                  U R                  UU[        S9  g)a<  Actuates the base to the desired position and orientation.

Difference of this function from _reset_base_pose() is that this function
considers dynamics along the path and collisions along the motion path.

Args:
  position: The desired base position.
  orientation_quat: The desired base orientation in quaternion.
)jointChildFrameOrientationmaxForceN)r$   changeConstraintr#   
_MAX_FORCEr   s      r(   r   #AutonomousObject._actuate_base_pose   s/     	**#3	 + r+   c                     Ag)z:Resets the joint angles. Not yet used in AutonomousObject.Nrp   )r'   joint_angless     r(   _reset_joint_angles$AutonomousObject._reset_joint_angles   s    r+   c                     g)zCReturns a sequence of action names. Always () for AutonomousObject.rp   rp   r8   s    r(   action_namesAutonomousObject.action_names   s     r+   c                     U R                   $ )z"Returns the sensors on this robot.)r!   r8   s    r(   r   AutonomousObject.sensors   s     ==r+   c                 6    U R                   R                  5       $ )z=Returns the base pose as a quaternion in format (x, y, z, w).)r7   copyr8   s    r(   rh   ,AutonomousObject.base_orientation_quaternion   s     !!##r+   c                 t    [         R                  " U R                  R                  U R                  5      5      $ )z8Returns the base roll, pitch, and yaw angles in radians.)r3   r6   r$   getEulerFromQuaternionr7   r8   s    r(   base_roll_pitch_yaw$AutonomousObject.base_roll_pitch_yaw  s1     8844T5F5FGI Ir+   c                 6    U R                   R                  5       $ )z1Returns the base cartesian coordinates in meters.)r5   r   r8   s    r(   rg   AutonomousObject.base_position
  s     >>  r+   c                 R    U R                   c  [        S5      eU R                  5       $ )zSimulation monotonic time.z1Must call set_clock() before accessing timestamp.)r%   RuntimeErrorr8   s    r(   	timestampAutonomousObject.timestamp  s&     {{LMM;;=r+   c                     U R                   $ rD   )r$   r8   s    r(   r:    AutonomousObject.pybullet_client  s       r+   c                     U R                   $ rD   rE   r8   s    r(   robot_idAutonomousObject.robot_id  rH   r+   )r   r   r%   r#   r   r"   r2   r1   r7   r5   r$   r!   r   )rp   NF)r,   N)NNN)NNrD   )2__name__
__module____qualname____firstlineno____doc__r   r   r   Sensorr   ControllerBaseboolr)   r&   r   BulletClientr=   r   floatrA   propertyrF   r   r   rM   rT   r<   r   rd   rq   rw   r|   rl   r   r	   r3   ndarrayr   r   r   r   r   rh   r   rg   r   r:   intr   __static_attributes__rp   r+   r(   r   r      s   O 35>B(-	 ! ! / ! -;; ! "&	 !D/M,F,F 4 Xb%i0 T   & &c	?&/3&". 26?C?C	huo. $,HUO#< ,;;<	 IM	>5S S 	2 	2 	2.	
 GK=A5!&x

'B!C5).x/1zz0: *;5,x

/J)K +0%"**1L+M" HTN   x.   $2:: $ $ I2:: I I
 !RZZ ! !   ! !   r+   r   )r   typingr   r   r   r   r   r   r	   abslr
   ginnumpyr3   pybullet_utilsr   pybullet_envs.minitaur.envs_v2r   &pybullet_envs.minitaur.envs_v2.sensorsr   pybullet_envs.minitaur.robotsr   r   rv   r   configurable	RobotBaser   rp   r+   r(   <module>r      sb    J G G G  
  ( 6 9 ; 4   

 Dz++ D Dr+   