
    ni                         S r SSKJrJrJrJ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                  R                   -  rS
rSrSr\R*                   " S S\5      5       rg)z0The imagery client to connect to the camera job.    )AnyDictSequenceTextN)worker_builder)imagery_pb2)imagery_utils)fwassert)timeutil   zfwuri://VisionJob/StartCapturezfwuri://VisionJob/StopCapturezfwuri://VisionJob/GetFramec                       \ rS rSrSrS\SSS\\\4S\	S\	S\	4S jjr
S	\R                  4S
 jrSS\	4S jjrS rS\\	\\   4   4S jrSrg)ImageryClient   z0Sends commands and receives states from cameras.NFstart_capture_uristop_capture_uriget_frame_uric	                     X l         Uc  [        R                  " 5       nXl        Ub  U R                  R	                  X45        XPl        X`l        Xpl        Xl        g)a  Initializes the client.

Args:
  fw_worker: A FluxWorks worker instance.
  rpc_timeout_sec: The timeout for any RPC calls from this client.
  ip_address: The ip address of the camera/vision process. If vision job is
    also instantiated in the same FluxWorks worker, both ip address and port
    are not needed.
  port: The port of the camera/vision process.
  async_mode: Whether the RPC calls in this client are async or synchronous.
    Aync mode is only required when you have multiple workers communicating
    with each other in the same Python process. If worker A is calling
    worker B's RPC, worker B's RPC is trying to get GIL from it's thread but
    caller (worker A) already holds the GIL, and this will cause a dead lock
    if worker A's calls are synchronous. If worker A is calling its own RPC,
    the same GIL can be used so there is no dead lock, and there is no need
    for async mode. Async mode will require context switching and thus is a
    bit slower.
  start_capture_uri: The FluxWorks URI to start camera capture.
  stop_capture_uri: The FluxWorks URI to stop camera capture.
  get_frame_uri: The FluxWorks URI to get camera frames.
N)	_rpc_timeout_secr   GetDefaultWorker_workerConnectToWorker_async_mode_start_capture_uri_stop_capture_uri_get_frame_uri)	self	fw_workerrpc_timeout_sec
ip_addressport
async_moder   r   r   s	            f/home/james-whalen/.local/lib/python3.13/site-packages/pybullet_envs/minitaur/vision/imagery_client.py__init__ImageryClient.__init__   sV    B , 113iL 
ll"":4!/-'    camera_framec                     0 nUR                   R                  5        H  u  p4[        R                  " U5      nXRU'   M!     U$ )z1Converts the camera frame to an image dictionary.)imagesitemsr	   convert_image_to_array)r   r&   r(   
image_nameimage_protoimage_arrays         r"   #_convert_camera_frame_to_image_dict1ImageryClient._convert_camera_frame_to_image_dictF   sD    
 F#/#6#6#<#<#>
!88Ek&Z $? Mr%   run_idc                     [         R                  " 5       nXl        [        R                  R                  U R                  R                  U R                  UU R                  S95        g)zStarts the camera capture session.

Args:
  run_id: The capture session id. This id will determine the name of the
    image logs' sub-direcotry.
r!   N)
r   CaptureRequestr0   r
   FwAssertCheckErrorMessager   CallOnewayProtoRpcr   r   )r   r0   capture_requests      r"   start_captureImageryClient.start_captureQ   sX     "002O#''''##'' 	( 	)*r%   c                     [         R                  " 5       n[        R                  R	                  U R
                  R                  U R                  UU R                  S95        g)z&Concludes the current capture session.r2   N)	r   r3   r
   r4   r5   r   r6   r   r   )r   r7   s     r"   stop_captureImageryClient.stop_capture`   sP    !002O''''""'' 	( 	)*r%   returnc           
         [         R                  " 5       n[         R                  " 5       n[        R                  R                  U R                  R                  U R                  UUU R                  U R                  S95        0 nUR                   HL  nUR                  nXS;   a$  X5   R                  U R                  U5      5        M8  U R                  U5      /X5'   MN     U$ )aQ  Gets the latest camera images.

Camera images can only be obtained after self.start_capture() is called.

Returns:
  A dictionary of camera frames, with the camera id as the key. Each camera
  frame may contain multiple streams. For example, on a realsense camera we
  may have "rgb" and "depth" streams, depending on the configuration.
r2   )r   GetFrameRequestCameraFrameCollectionr
   r4   r5   r   CallRoundtripProtoRpcr   r   r   frames	camera_idappendr.   )r   get_frame_requestframe_collectionimages_by_camerar&   rC   s         r"   get_camera_imagesImageryClient.get_camera_imagesi   s     $335"88:''**!!'' 	+ 	)* (//((i 
	&#**44\B	D 44\B'
# 0 r%   )r   r   r   r   r   r   )vision)__name__
__module____qualname____firstlineno____doc___RPC_TIMEOUT_URI_START_CAPTURE_URI_STOP_CAPTURE_URI_GET_FRAMEr   r#   r   CameraFramer.   r8   r;   r   r   r   rH   __static_attributes__ r%   r"   r   r      s    8 " 20*-( -( -( -(^	%11	*$ ** dHSM&9!:  r%   r   )rO   typingr   r   r   r   gin pybullet_envs.minitaur.fw_bridger   pybullet_envs.minitaur.visionr   r	   Bgoogle3.third_party.fluxworks.core.fluxworks.python.genericutil_pyr
   r   TimeUtilSECrP   rQ   rR   rS   configurableobjectr   rV   r%   r"   <module>r`      sk    6 , , 
 ; 5 7 W W8$$(((5 3 - uF u ur%   