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 IPendant touch. 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 IPendant touch 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:
Configure
MainRoutineStartProduction
MainRoutineStop
MainRoutineGetPart
MainRoutinePreparePart
MainRoutineRawCommand
RaiseCheckLastError
Configure
Declaration
ROUTINE Configure(stIpAddress : STRING; inPortNumber : INTEGER; inClientNumber1 :INTEGER; inClientNumber2 : INTEGER) : BOOLEAN FROM IPL_ASYRIL_EYE_CFG
Parameters
stIpAddress : STRING[50] - is the IP address of your EYE+. The parameter must be a string with the IP address format
x.x.x.x
.inPortNumber : INTEGER - is the port number of EYE+. The parameter must be an integer.
inClientNumber1 : INTEGER - is the number of the first client reserved for the communication. The parameter must be an integer in the range of 1-8 and different from
inClientNumber2
.inClientNumber2 : INTEGER - is the number of the first client reserved for the communication. The parameter must be an integer in the range of 1-8 and different from
inClientNumber1
.
Returns
BOOLEAN - True if configuration succeeded, else return False.
Description
This command must be called at least once to specify the clients used by the communication.
Usage example
PROGRAM KAREL_EXAMPLE_CONFIGURE
-- Environment file required to access registers
%ENVIRONMENT REGOPE
VAR
reValue : REAL
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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
BEGIN
-- Configure the communication using client C1: and C2:
-- using IP address 192.168.0.50 and port number 7171
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF NOT isConfigured THEN
-- Read last error raised
RaiseCheckLastError
-- get the RaiseCheckLastError response in register R[21]
GET_REG(21, boValue, errorCode, reValue, inStatus)
IF errorCode <> 0 THEN
-- Not well configured: see the error code
ENDIF
ELSE
-- Configuration succeeded
ENDIF
END KAREL_EXAMPLE_CONFIGURE
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
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG
BEGIN
-- Configure the communication using client C1: and C2:
-- using IP address 192.168.0.50 and port number 7171
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF isConfigured THEN
-- 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')
ELSE
-- Not well configured
ENDIF
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
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG
BEGIN
-- Configure the communication using client C1: and C2:
-- using IP address 192.168.0.50 and port number 7171
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF isConfigured THEN
-- 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
ELSE
-- Not well configured
ENDIF
END KAREL_EXAMPLE_STOP
MainRoutineGetPart
Declaration
ROUTINE MainRoutineGetPart FROM IPL_ASYRIL_EYE_CFG
Returns
The returned part is stored in the reserved position register PR[20]
. Refer to table
Table 1 for more information.
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
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG
BEGIN
-- Configure the communication using client C1: and C2:
-- using IP address 192.168.0.50 and port number 7171
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF isConfigured THEN
-- 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')
ELSE
-- Not well configured
ENDIF
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
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG
BEGIN
-- Configure the communication using client C1: and C2:
-- using IP address 192.168.0.50 and port number 7171
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF isConfigured THEN
-- 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')
ELSE
-- Not well configured
ENDIF
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
Client 1 is the first client you entered in the Configure command and client 2 is the second client you entered.
Returns
The raw response of the command is stored in the reserved string register SR[20]
. Refer to table
Table 1 for more information.
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
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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_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
-- Configure the communication using client C1: and C2:
-- using IP address 192.168.0.50 and port number 7171
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF isConfigured THEN
-- 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')
ELSE
-- Not well configured
ENDIF
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 R[21]
. Refer to table
Table 1 for more information.
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
or5xx
).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
isConfigured : BOOLEAN
boValue : BOOLEAN
inStatus : INTEGER
errorCode : 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_GET_PART
ROUTINE MainRoutineGetPart FROM IPL_ASYRIL_EYE_CFG
-- Routine equivalent to EYE_STOP
ROUTINE MainRoutineStop(stParameter : STRING) FROM IPL_ASYRIL_EYE_CFG
BEGIN
-- Configure the network
isConfigured = Configure('192.168.0.50', 7171, 1, 2)
IF isConfigured THEN
-- 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
ELSE
-- Not well configured
RaiseCheckLastError
-- get the RaiseCheckLastError response in register R[21]
GET_REG(21, boValue, errorCode, reValue, inStatus)
IF errorCode <> 0 THEN
-- An error occured while configured the clients
ABORT
ENDIF
ENDIF
END KAREL_EXAMPLE_RAISECHECKLASTERROR