KAREL programming

KAREL programs allows to create more complex task than TP programs can do. It is a more advanced way of programming Fanuc robots.

KAREL programs cannot be edited/started from the Table TP. To run the content of a KAREL program, it is required to compile the *.kl file into *.pc file. Then *.pc file can be imported into the Table TP and then be executed inside a TP program using a CALL or RUN instruction.

Important

ROBOGUIDE is required to compile KAREL programs into PC files.

It is possible to use the plugin in your KAREL program. Some routines defined in the program IPL_ASYRIL_EYE_CFG can be used.

Note

If you want to program only through KAREL programs, you only need to install the plugin programs that start with IPL_ASYRIL_EYE_*.

Here is the list of KAREL routines that can be used in your KAREL programs:

  • MainRoutineStartProduction

  • MainRoutineStop

  • MainRoutineGetPart

  • MainRoutinePreparePart

  • MainRoutineRawCommand

  • RaiseCheckLastError

MainRoutineStartProduction

Declaration

ROUTINE MainRoutineStartProduction(stRecipeID : STRING) FROM IPL_ASYRIL_EYE_CFG

Parameters

  • stRecipeID : STRING[10] - the recipe’s unique identifier. The parameter must be a string containing an integer between 1 and 65535.

Description

This command must be called to start EYE+ in production state using the right recipe.

Usage example

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

VAR
  reValue         : REAL
  boValue         : BOOLEAN
  inStatus        : INTEGER
  errorCode       : INTEGER

-- 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

BEGIN
    -- Start production using the right recipe identifier
    MainRoutineStartProduction('12345')
    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 0 THEN
      -- EYE+ is in production
    ENDIF

    -- Stop EYE+ production state AND the communication
    MainRoutineStop('production')

END KAREL_EXAMPLE_START_PRODUCTION

MainRoutineStop

Declaration

ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

Parameters

  • stParameter : STRING[20] - is an EYE+ states. The parameter must be a string.

Description

This command is used to stop an EYE+ state and stop the communication on both clients. You must always end your program with an MainRoutineStop('production').

Warning

If you miss the call at the end of your program, you will need to do a fnct > ABORT (ALL) with the IPendant touch to stop the communication when starting another program.

Usage example

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

VAR
  reValue         : REAL
  boValue         : BOOLEAN
  inStatus        : INTEGER
  errorCode       : INTEGER

-- 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

BEGIN
    -- Stop all EYE+ state AND the communication
    MainRoutineStop('recipe_edition')
    MainRoutineStop('camera_configuration')
    MainRoutineStop('handeye_calibration')
    MainRoutineStop('production')

    -- Start production using the right recipe identifier
    MainRoutineStartProduction('12345')
    --  ...

    -- Stop EYE+ production state AND the communication
    MainRoutineStop('production')

    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 0 THEN
      -- EYE+ is in ready state
    ENDIF
END KAREL_EXAMPLE_STOP

MainRoutineGetPart

Declaration

ROUTINE MainRoutineGetPart FROM IPL_ASYRIL_EYE_CFG

Returns

The returned part is stored in the input position register chosen in the Network Configuration page.

Only the X, Y and R components are overwritten in the specified position register. You have to add the other components (Z, W, P) yourself according to your robot setup. These missing components can be assigned by hand or by using the assignment operator in your program.

Warning

If you do not assign the last components, the position will not be reachable by your robot.

Description

This command is used to request one part from EYE+. This is a blocking command, meaning it will keep going until it gets a response from EYE+.

Usage example

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

VAR
  reValue         : REAL
  boValue         : BOOLEAN
  inStatus        : INTEGER
  errorCode       : INTEGER

-- 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

BEGIN
    -- Start production using the right recipe identifier
    MainRoutineStartProduction('12345')

    -- Send a get_part command to retreive the part coordinates
    MainRoutineGetPart

    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 0 THEN
      -- EYE+ found a part
    ENDIF

    -- Stop EYE+ production state AND the communication
    MainRoutineStop('production')
END KAREL_EXAMPLE_GET_PART

MainRoutinePreparePart

Declaration

ROUTINE MainRoutinePreparePart FROM IPL_ASYRIL_EYE_CFG

Description

This command is used to request one part from EYE+. This command is not a blocking command. The part coordinates can be retrieved later with the MainRoutineGetPart command.

Usage example

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

VAR
  reValue         : REAL
  boValue         : BOOLEAN
  inStatus        : INTEGER
  errorCode       : INTEGER

-- 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

BEGIN
    -- Start production using the right recipe identifier
    MainRoutineStartProduction('12345')

    -- Prepare one part
    MainRoutinePreparePart

    -- ..

    -- Send a get_part command to retreive the part coordinates
    MainRoutineGetPart

    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 0 THEN
      -- EYE+ found a part
    ENDIF

    -- Stop EYE+ production state AND the communication
    MainRoutineStop('production')
END KAREL_EXAMPLE_PREPARE_PART

MainRoutineRawCommand

Declaration

ROUTINE MainRoutineRawCommand (stRawCommand : STRING; inClientNB : INTEGER) FROM IPL_ASYRIL_EYE_CFG

Parameters

  • stRawCommand : STRING[127] - is the raw command to send to EYE+. This parameter must be a string.

  • inClientNB : INTEGER - is the client number that will be used to send the command. The parameter must be an integer whose value is equal to 1 or 2.

    Note

    inClientNB = 1 refers to the first client you selected in the Network Configuration page, and inClientNB = 2 refers to the second client you selected.

Returns

The raw response of the command is stored in the reserved string register chosen in the Network Configuration page.

Description

This function is used to send raw commands to EYE+. Refer to chapter Commands to know what kind of commands can be sent.

Usage example

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

VAR
  reValue         : REAL
  boValue         : BOOLEAN
  inStatus        : INTEGER
  errorCode       : INTEGER

-- 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_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
    -- Start production using the right recipe identifier
    MainRoutineStartProduction('12345')

    -- Set parameters to use multi-feeding feature
    MainRoutineRawCommand('set_parameter multi_part_quantity a 1', 1)
    MainRoutineRawCommand('set_parameter multi_part_quantity b 0', 1)

    -- Send a get_part command to retreive the part coordinates
    MainRoutineGetPart

    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 0 THEN
      -- EYE+ found a part
    ENDIF

    -- Stop EYE+ production state AND the communication
    MainRoutineStop('production')
END KAREL_EXAMPLE_RAW_COMMAND

RaiseCheckLastError

Declaration

ROUTINE RaiseCheckLastError FROM IPL_ASYRIL_EYE_CFG

Returns

The last error detected is stored in the reserved register chosen in the Network Configuration page.

Description

This function is used to check if an error has occurred.

  • If no error has occurred, the output is equal to 0.

  • If an EYE+ error has occurred, the output is equal to one of the error codes listed in Error codes (error type 4xx or 5xx).

  • If a plugin error has occurred, the output is one of the following errors displayed in section Plugin errors (error type 6xx).

Once the error is returned as output from the function, the error is cleared internally (value set to 0).

Note

A good practice is to use this function just after each plugin command. This way, you will be able to know on which command the last error occurred.

Usage example

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

VAR
  reValue         : REAL
  boValue         : BOOLEAN
  inStatus        : INTEGER
  errorCode       : INTEGER

-- Routine equivalent to EYE_CHECK_LAST_ERROR
ROUTINE RaiseCheckLastError FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_GET_PART
ROUTINE MainRoutineGetPart FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG

BEGIN
    -- Send a get_part command to retreive the part coordinates
    MainRoutineGetPart
    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 403 THEN
      -- Production subsystem has not been started
    ENDIF

    --  Read last error raised
    RaiseCheckLastError
    -- get the RaiseCheckLastError response in register R[21]
    GET_REG(21, boValue, errorCode, reValue, inStatus)
    IF errorCode = 0 THEN
      -- Now the error is cleared
    ENDIF

    -- 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
      -- An error occured while stopping the production
      ABORT
    ENDIF
END KAREL_EXAMPLE_RAISECHECKLASTERROR