
    *ij                     f    d Z ddlZddlmZmZ ddlmZ ddlmZ erddl	m
Z
  G d de          ZdS )	z4Abstract base class for teleoperation input methods.    N)ABCabstractmethod)TYPE_CHECKING)try_open_footpedal)RobotControllerc                   4   e Zd ZdZeedefd                        Zedd            Zedd            Z	edd	            Z
eedefd
                        ZddZddZddZdddZdddefdZdddefdZddZedefd            Zedefd            ZdS )TeleopInterfacezShared interface for all teleoperation input methods.

    To add a new input method, subclass this, implement all abstract methods,
    and instantiate it from the CLI or calling code.
    returnc                     dS )z@Short identifier used in metadata (e.g. 'leader', 'spacemouse').N selfs    1/home/robot-lab/raiden_cmu/raiden/control/base.pynamezTeleopInterface.name             robot_controllerr   Nc                     dS )zQDevice-specific setup after robots are ready (attach hardware, warm up IK, etc.).Nr   r   r   s     r   setupzTeleopInterface.setup   r   r   c                     dS )zStart the control loop threads.Nr   r   s     r   startzTeleopInterface.start   r   r   c                     dS )zStop the control loop threads.Nr   r   s     r   stopzTeleopInterface.stop!   r   r   c                     dS )z9Status message printed when teleoperation becomes active.Nr   r   s    r   bannerzTeleopInterface.banner%   r   r   c                 .    |                                   dS )a(  Open session-level peripherals (footpedal, etc.).

        Called once per session before the first episode.  Default: opens
        the foot pedal with subtask-boundary semantics.  Subclasses that
        need additional session-level setup should call ``super().open()``
        first.
        N)#_open_footpedal_for_subtask_latchesr   s    r   openzTeleopInterface.open.   s     	0022222r   c                 l    t          | dd          "| j                                         d| _        dS dS )zClose session-level peripherals.

        Called once at session end.  Default: closes the foot pedal if it
        was opened by ``open()``.
        
_footpedalN)getattrr!   closer   s    r   r#   zTeleopInterface.close8   s=     4t,,8O!!###"DOOO 98r   c                      t          j                     _        d _        t	                       _         j        dS dt          ddf fd} j                            |            j                                         t          d           dS )a  Initialise the subtask Event and bind the pedal callback.

        A single ``threading.Event`` is set on each press; the recorder
        thread polls it, captures the camera clock once, and fans the
        timestamp out to ``add_event_marker`` and (when audio is enabled)
        to ``AudioRecorder.mark_boundary``.  The callback is gated on
        ``_recording_controller is not None`` so presses outside an
        active recording are ignored (no soft-pause, no start/stop).
        N_coder
   c                 L    j         j                                         d S d S N)_recording_controller_pedal_subtaskset)r%   r   s    r   _cbz@TeleopInterface._open_footpedal_for_subtask_latches.<locals>._cbT   s/    )5#''))))) 65r   u7     ✓ FootPedal ready: press to mark a subtask boundary)
	threadingEventr)   r(   r   r!   inton_pressr   print)r   r+   s   ` r   r   z3TeleopInterface._open_footpedal_for_subtask_latchesB   s     (o// &*",..?"F	*s 	*t 	* 	* 	* 	* 	* 	* 	  %%%GHHHHHr   c                     || _         dS )a  Notify the interface whether a recording episode is active.

        Pass the controller when an episode starts; pass None when it ends.
        Used by interfaces that want to gate pedal latches on the
        recording-active state.  Default: no-op.
        N)r(   r   s     r   set_active_recordingz$TeleopInterface.set_active_recording\   s     &6"""r   c                 n    | j                                         r| j                                          dS dS )a  Return True if the operator pressed the subtask-boundary pedal
        during an active recording.

        Consumed by the recorder to capture a timestamp once (passed to
        both ``add_event_marker`` and ``AudioRecorder.mark_boundary`` so
        the two consumers see bit-identical timestamps).  Default
        implementation drains ``_pedal_subtask`` (initialised in
        ``open()``).
        TF)r)   is_setclearr   s     r   poll_subtaskzTeleopInterface.poll_subtaske   s:     %%'' 	%%'''4ur   c                     dS )zReturn True on a session-level trigger event (leader-arm button,
        etc.).  Used to start/stop episodes on interfaces with hardware
        buttons.  Default: never triggers.Fr   r   s     r   pollzTeleopInterface.pollt   s	     ur   c                 Z    |                      |           |                     |           dS )a#  Discard any latched pedal events so they don't bleed across phases.

        ``threading.Event``-backed pedal latches stay set until polled;
        without an explicit drain at episode boundaries a stray press
        queued during a previous wait would auto-mark the next episode.
        N)r8   r6   r   s     r   drain_pedal_eventsz"TeleopInterface.drain_pedal_eventsz   s2     			"###*+++++r   c                     dS )z9True if this mode requires leader arms to be initialised.Fr   r   s    r   uses_leaderszTeleopInterface.uses_leaders   s	     ur   c                     | j         S )zTrue if recording should start on a leader-arm button press.

        False means keyboard / Enter key is used instead.
        )r<   r   s    r   waits_for_button_startz&TeleopInterface.waits_for_button_start   s       r   )r   r   r
   N)r
   Nr'   )__name__
__module____qualname____doc__propertyr   strr   r   r   r   r   r   r#   r   r2   boolr6   r8   r:   r<   r>   r   r   r   r	   r	      s         Oc O O O ^ XO ` ` ` ^` . . . ^. - - - ^- H H H H ^ XH3 3 3 3# # # #I I I I46 6 6 6 6-> 4    %6 4    , , , , d    X ! ! ! ! X! ! !r   r	   )rB   r,   abcr   r   typingr   raiden.robot.footpedalr   raiden.robot.controllerr   r	   r   r   r   <module>rJ      s    : :     # # # # # # # #             5 5 5 5 5 5 8777777B! B! B! B! B!c B! B! B! B! B!r   