
    ni                     T    S r SSKrSSKrSSKrSSKrSSKrSSKr " S S\5      r	S r
g)zYThis file implements the functionalities of an example simulated system using pybullet.

    Nc                   x    \ rS rSrSr\R                  " 5       S4S jrSS jrS r	S r
S rS	 rS
 rS rS rSrg)BoxStackPyBulletSim   zhThe ExamplePyBulletSim class that adds some objects to the scene, steps the sim and return a reward.

  g{Gz?c                 b    Xl         X l        SU l        X0l        SU l        U R                  SS9  g)zConstructs an example simulation and reset it to the initial states.

Args:
  pybullet_client: The instance of BulletClient to manage different
    simulations.
  urdf_root: The path to the urdf folder.
  time_step: The time step of the simulation.
r   T)reload_urdfN)_pybullet_client
_urdf_rootm_actions_taken_since_reset	time_stepstateIdReset)selfpybullet_client	urdf_rootr   s       h/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/prediction/boxstack_pybullet_sim.py__init__BoxStackPyBulletSim.__init__   s1     ,O'(D$NDLJJ4J     c                    SU l         SnSnSnU(       Ga  U R                  R                  5       nUS   n[        SUS   5        [        SUS   5        [        SUS	   5        [        S
US   5        U R                  R	                  SUS   US   US	   S9  U R                  R                  S5      nU R                  R                  S5      nU R                  R                  USUS9  SU l        / U l	        / SQn	/ SQn
/ SQn/ SQnXX/n[        U R                  5       H  nSSXNS-  U-  -   /nU R                  R                  / SQ5      n/ SQnU R                  R                  SUU5      nU R                  R                  USX   S9  U R                  R                  U5        M     U R                  R                  SSS5        U R                  R                  5       U l        O5U R                  S:  a%  U R                  R!                  U R                  5        SnU R                   H  n["        R$                  " U* U5      n["        R$                  " U* U5      n["        R$                  " [&        R(                  * [&        R(                  5      nUUUUS-  U-  -   /nUS-  nU R                  R                  SSU/5      nU R                  R+                  XU5        M     g)zReset the minitaur to its initial states.

Args:
  reload_urdf: Whether to reload the urdf file. If not, Reset() just place
    the minitaur back to its starting position.
r   g?
   z
cameraYaw=   zcameraPitch=	   z
camtarget=   zprojectionMatrix=   g333333?)cameraDistance	cameraYawcameraPitchcameraTargetPositionz
plane.urdfzchecker_blue.pngr   )textureUniqueId   )g
ףp=
?      ?r"      )g=
ףp=?g(\?gףp=
?r#   )gq=
ףp?g\(\?r   r#   )r   g?gQ?r#      )r   r   r   )r   r   r   r#   zcube_small.urdf)	rgbaColorir#   N)r   r	   getDebugVisualizerCameraprintresetDebugVisualizerCameraloadURDFloadTexturechangeVisualShape_numObjects_cubesrangegetQuaternionFromEulerappend
setGravity	saveStater   restoreStaterandomuniformmathpiresetBasePositionAndOrientation)r   r   	xPosRange	yPosRangeboxHalfExtentscamInfor   planetexUidredgreenyellowbluecolorsiposorncubeindexposXposYyaws                         r   r   BoxStackPyBulletSim.Reset!   s    ()D$IIN%%>>@gr{nL'!*%NGAJ'L'"+&,
66cAHCJ1:LSTVK 7 Y
 ##,,\:e$$001CDf
--eR-Pddk!c#e!fdF)fT%%&!!^!en&<<=##::9E$$--.?cJ//bFI/N4  ' &&q!S1**446dl
,,!
**4<<8E[[^^YJ	2d^^YJ	2dNNDGG8TWW-c4%!)n*DDEcqje!!88!QEc
;;ACH r   c                     g)zNGet the length of the action list.

Returns:
  The length of the action list.
r!    r   s    r   GetActionDimension&BoxStackPyBulletSim.GetActionDimension^   s     r   c                 `    [         R                  " S/U R                  5       -  5      nSUSS& U$ )zGet the upper bound of the observation.

Returns:
  The upper bound of an observation. See GetObservation() for the details
    of each element of an observation.
g        g      ?r   N)nparrayGetObservationDimension)r   upper_bounds     r   GetObservationUpperBound,BoxStackPyBulletSim.GetObservationUpperBoundf   s3     ((C54#?#?#AABKKOr   c                 $    U R                  5       * $ )z'Get the lower bound of the observation.)rW   rO   s    r   GetObservationLowerBound,BoxStackPyBulletSim.GetObservationLowerBoundq   s    ))+++r   c                 P    [        U R                  5       5      n[        SU5        U$ )zXGet the length of the observation list.

Returns:
  The length of the observation list.
zsz=)lenGetObservationr'   )r   szs     r   rU   +BoxStackPyBulletSim.GetObservationDimensionu   s&     
T  "	#B	%Ir   c                     / nU R                    HT  nU R                  R                  U5      u  p4UR                  [	        U5      5        UR                  [	        U5      5        MV     U$ )zGet the observations of minitaur.

Returns:
  The observation list. observation[0:4] is the base orientation in quaternion form.
)r-   r	   getBasePositionAndOrientationextendlist)r   observationrD   rE   rF   s        r   r^   "BoxStackPyBulletSim.GetObservation   s[     K[[&&DDQGhcc#c#  r   c                 .    U =R                   S-  sl         g)zSet the desired action.
    r#   Nr   )r   actions     r   ApplyActionBoxStackPyBulletSim.ApplyAction   s     	$$)$r   c                      U R                   S:  $ )N   rh   rO   s    r   TerminationBoxStackPyBulletSim.Termination   s    ++s22r   )r-   r,   r	   r
   r   r   r   N)F)__name__
__module____qualname____firstlineno____doc__pybullet_datagetDataPathr   r   rP   rW   rZ   rU   r^   rj   rn   __static_attributes__rN   r   r   r   r      sG     1>0I0I0KW[ ! ;Iz	,*
3r   r   c                     [        U UUS9nU$ )N)r   r   r   )r   )r   r   r   sims       r   	CreateSimrz      s    O&/&/	1# 
*r   )rt   copyr6   numpyrS   osru   r4   objectr   rz   rN   r   r   <module>r      s2       	  F3& F3Rr   