GRIPLINK CRX - Example Programs
================================

This folder contains FANUC TP/LS example programs that demonstrate typical
usage patterns of the GRIPLINK CRX plugin. Each example can be loaded directly
into a RoboGuide workcell or a real CRX controller.

NOTE: All programs require the GRIPLINK CRX Plugin installed on your robot.


OVERVIEW
--------

Program                 Description
---------------------------------------------------------------------------------------
GRIPLINK_CRX_DEMO       Minimal grip/release loop - entry-level example
SIMPLE_GRIP_RELEASE     Blocking grip/release cycle with full state checking and fault handler
MULTI_GRIP_RELEASE      Simultaneous operation of multiple grippers across ports 0-3
ASYNC_PREPOSITION       Asynchronous pre-positioning during robot motion
FLEXGRIP_CYCLE          Full FlexGrip/FlexRelease cycle with speed, force, and no-part detection
CHECK_WORKPIECE         Workpiece size measurement and acceptance check


PROGRAM DETAILS
---------------

GRIPLINK_CRX_DEMO
  The most basic example. Connects to the GRIPLINK controller, homes the gripper
  on port 0, and runs three consecutive GRIP/RELEASE cycles using a FOR loop.
  The device state (R[10]) is evaluated after each GRIP to distinguish HOLDING
  from no part, but no fault recovery is implemented. Intended as a first
  functional test after installation.

  Key calls: CONNECT -> HOME -> RELEASE -> ( GRIP -> RELEASE ) x3 -> BYE


SIMPLE_GRIP_RELEASE
  Basic GRIP/RELEASE demonstration with complete error handling. 
  After each operation the device state is read and checked:

    State 5 (HOLDING)  -> part gripped successfully
    State 4 (NO PART)  -> gripper closed but nothing detected
    Any other state    -> fault, jumps to LBL[99] which calls BYE and aborts

  Key calls: CONNECT -> HOME -> RELEASE -> GRIP -> STATE -> RELEASE -> BYE


MULTI_GRIP_RELEASE
  Demonstrates parallel operation of multiple grippers. The program first
  scans ports 0-3 with DEVSTATE to auto-detect how many grippers are connected
  (R[2] stores the last active port index). Each detected gripper is homed and
  released.

  The grip phase issues GRIP without waiting (wait-flag = 0) for all ports in
  sequence, then uses a second loop with WAITSTATE to synchronize all grippers
  at once. The same pattern is repeated for release. This minimises total cycle
  time when multiple grippers must act simultaneously.

  Key calls: CONNECT -> DEVSTATE/HOME/RELEASE per port
             -> GRIP (no-wait) x N -> WAITSTATE x N
             -> RELEASE (no-wait) x N -> WAITSTATE x N -> BYE


ASYNC_PREPOSITION
  Shows how to pipeline gripper preposition with robot motion. FLEXRELEASE is
  called with the wait-flag set to 0, so the controller returns immediately and
  the robot can start moving towards the pick/place position while the gripper
  is opening in parallel. After the robot motion (WAIT 1.0 sec simulated here),
  WAITSTATE is called to confirm the gripper has reached its target state
  (3 = RELEASED) before the robot arrives.

  Key calls: CONNECT -> HOME -> FLEXRELEASE (no-wait) -> robot motion
             -> WAITSTATE -> BYE

  Register usage:
    R[1]   Target finger position for FLEXRELEASE (50 mm)
    R[10]  Device state return value


FLEXGRIP_CYCLE
  A complete FlexGrip/FlexRelease cycle that exercises all major parameters
  of the flexible grip commands.

    FLEXRELEASE(port, position=100 mm, speed=200, force=500, wait=1, retReg=10)
      Opens fingers to 100 mm.

    FLEXGRIP(port, noPart=-20 mm, speed=150, force=50, zeroForce=0, wait=1, retReg=10)
      Closes until contact; if fingers reach -20 mm without resistance,
      the result is NO PART.

  After gripping, the state is evaluated:
    5 (HOLDING)  -> part gripped
    4 (NO PART)  -> gripper closed without contact
    other        -> FAULT, exit via LBL[99]

  After a 2-second hold the gripper is released again and the release state
  is verified.

  Key calls: CONNECT -> HOME -> FLEXRELEASE -> FLEXGRIP -> state check
             -> wait -> FLEXRELEASE -> state check -> BYE

  Register usage:
    R[1]   No-part limit (-20 mm)
    R[2]   Release position (100 mm)
    R[10]  Device state return value


CHECK_WORKPIECE
  Demonstrates in-process workpiece size measurement. After a standard GRIP
  the actual finger spread is read with IPL_WR_GRIPLINK_VALUE into R[5].
  The measured value is compared against a configurable tolerance window
  (R[1]-R[2], default 79.9-80.1 mm):

    Within tolerance  -> MESSAGE[WORKPIECE ACCEPTED]
    Out of tolerance  -> MESSAGE[WORKPIECE REJECTED]

  If the gripper reports a state other than 5 (HOLDING) after the GRIP
  command, the measurement is skipped entirely.

  Key calls: CONNECT -> HOME -> RELEASE -> GRIP -> state check
             -> VALUE -> size check -> RELEASE -> BYE

  Register usage:
    R[1]   Lower size limit (79.9 mm)
    R[2]   Upper size limit (80.1 mm)
    R[5]   Measured workpiece size (mm)
    R[10]  Device state return value


DEVICE STATE REFERENCE
----------------------

Code  Name      Description
----  --------  ----------------------------------------
  3   RELEASED  Gripper fully open / released
  4   NO PART   Grip completed, no workpiece detected
  5   HOLDING   Workpiece gripped successfully
  7   FAULT     Error condition
