Example of FANUC Karel program

Call a KAREL program that behaves the same way as the Example of FANUC TP program from another TP program.

TP program

  1:  ! Call the karel program that does the pick and place scenario
  2:  CALL KAREL_EXAMPLE
[End]

KAREL program

PROGRAM KAREL_EXAMPLE
-- Environment file required to access registers
%ENVIRONMENT REGOPE

VAR
  reValue         : REAL
  isConfigured    : BOOLEAN
  boValue         : BOOLEAN
  inStatus        : INTEGER
  stIpAddress     : STRING[50]
  inClientNumber1 : INTEGER
  inClientNumber2 : INTEGER
  inPortNumber    : INTEGER
  stRecipeID      : STRING[10]
  errorCode       : INTEGER
  i               : INTEGER

-- Routine equivalent to EYE_CONFIGURE
ROUTINE Configure(stIpAddress : STRING; inPortNumber : INTEGER; inClientNumber1 : INTEGER; inClientNumber2 : INTEGER) : BOOLEAN FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_CHECK_LAST_ERROR
ROUTINE RaiseCheckLastError FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_START_PRODUCTION
ROUTINE MainRoutineStartProduction(stRecipeID : STRING) FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_GET_PART
ROUTINE MainRoutineGetPart FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_PREPARE_PART
ROUTINE MainRoutinePreparePart FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_RAW_COMMAND
ROUTINE MainRoutineRawCommand (stRawCommand : STRING; inClientNB : INTEGER) FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

BEGIN
    stIpAddress = '192.168.0.50'    -- ip address of your EYE+
    inPortNumber = 7171             -- port number of your EYE+
    inClientNumber1 = 1             -- First client reserved for plugin (1-8)
    inClientNumber2 = 2             -- Second client reserved for plugin (1-8)
    stRecipeID = '12345'            -- Recipe identifier

    -- Configure the communication using client C1: and C2:
    isConfigured = Configure(stIpAddress, inPortNumber, inClientNumber1, inClientNumber2)

    IF isConfigured THEN
      -- Start production using the right recipe identifier
      MainRoutineStartProduction(stRecipeID)
      -- Check no error occured (last error will be write into the default register R[21])
      RaiseCheckLastError
      -- Get the RaiseCheckLastError response in register R[21]
      GET_REG(21, boValue, errorCode, reValue, inStatus)
      IF errorCode <> 0 THEN
          -- Error when staring the production, abort the program
          ABORT
      ENDIF

      -- Loop to pick and place
      FOR i = 1 TO 50 DO
          -- Send a get_part command to retreive the part coordinates, the coordinates are saved in register PR[20].
          MainRoutineGetPart
          -- Check no error occured (last error will be write into the default register R[21])
          RaiseCheckLastError
          -- Get the RaiseCheckLastError response in register R[21]
          GET_REG(21, boValue, errorCode, reValue, inStatus)
          IF errorCode = 0 THEN
              -- Coordinates are saved in the default position register (P[20])
              -- Do your pick and place here
              -- ...
          ELSE
              -- Error occured while getting part coordinates
              -- Do something depending on the error raised
          ENDIF
      ENDFOR

      -- Stop EYE+ production state and the communication
      MainRoutineStop('production')
      RaiseCheckLastError
      -- Get the RaiseCheckLastError response in register R[21]
      GET_REG(21, boValue, errorCode, reValue, inStatus)
      IF errorCode <> 0 THEN
          -- Not well configured
          ABORT
      ENDIF
    ELSE
      -- Not well configured
      -- Read error that occured (last error will be write into the default register R[21])
      RaiseCheckLastError
      -- Get the RaiseCheckLastError response in register R[21]
      GET_REG(21, boValue, errorCode, reValue, inStatus)
      IF errorCode <> 0 THEN
        -- Not well configured: see errorCode value
      ENDIF
      ABORT
    ENDIF

END KAREL_EXAMPLE