| Sensor Model | All |
| Firmware Version (Classic and GoPxL) | 3.x, 4.x, 5.x, 6.x, 1.x |
| SDK Version | 3.x, 4.x, 5.x, 6.x, 1.x |
Overview
This document outlines how to establish ASCII communication between a FANUC robot controller and Gocator using Karel programming. This integration works for both Gocator Classic and GoPxL. The advantage of this integration is that it allows direct communication between the Fanuc controller and the sensor. Eliminating the need for a "middle man" such as a PLC.
The best method for KAREL development is to use RoboGuide as an IDE. Development can be tricky without this software to debug.
Sensor Setup
Our sensor is set up in the following manner.
- Sensor IP: 192.168.1.30
- Protocol: ASCII (Custom Config)
Fig 1. Gocator Classic ASCII sensor settings.
Fig 1.1. GoPxL ASCII sensor settings.
Fig 1.2.. Ensure we have the proper outputs added in out GoPxL settings.
Fig 2 & 2.1. Script tool simulating measurements, output 0 through 5 for Gocator Classic/GoPxL ASCII
The travel speed that the robot will be running at needs to match the travel speed set in the Gocator. Below shows how to set the travel speed in both software's.
Fig 3. How to set travel speed in Gocator Classic GUI.
Fig 3.1. How to set travel speed in GoPxL GUI.
Fig 4 & 4.1. Setting proper trigger settings.
FANUC Settings Setup
To establish communication with the Gocator sensor, we need to create a client tag on the FANUC robot. This is outlined in the FANUC Karel manual, section 12.2.2, "Setting up a Client Tag". We will create a client tag that contains our sensor's IP address and the correct port information. For ASCII communication, we will use port 8190. Our Gocator 2490 is at IP address 192.168.1.30. The FANUC Robots IP is at address 192.168.1.100.
Fig 5. Settings in FANUC robot for client tag “C3”
Next, we need to set up our host configuration system variable in our robot. We need to specify the correct port information (8190) here. These variables can be changed within a FANUC script, but it is recommended to change them beforehand.
Fig 6 & 7. Settings for "$HOSTC_CFG" on FANUC Robot
After these settings have been changed, the controller will need to be restarted for the setting to take effect.
Additional Robot Dependent Settings
Depending on your robot and robot controller there are some additional settings that could need to be changed. Furthermore, if the robot was used in previous deployments there are settings that can interfere with this integration.
Firstly, UI signals may need to be set to false. This is present at item 7 in the system configuration.
Fig 7.1. UI Signals Setup Configuration
Secondly, in the system config, item 42 may need to be changed from Local to Remote. Users have reported needing to change this to remote for this integration to function normally. However, this is not the case for FANUC Co-Bots.
Fig 7.2. Remote/Local Setup Configuration
After these settings have been changed, the controller will need to be restarted for the setting to take effect.
KAREL Socket Program
This program will accomplish the following:
- Establish socket communication to Gocator
- Start the Gocator Sensor
- Wait for results
- Print results to FANUC USER screen
- Set Registers 1-9 to results
- Close socket communication to Gocator
Fig 8. TP Program calling Karel program "GOATORCONNECT", New register values, and the information printed to the user screen. This screenshot was taken in Roboguide.
Karel Code
-- Gocator FANUC ASCII Integration Example
--Febuary 7th, 2025
---------------------------------------------------------------------
PROGRAM GocatorConnect -- Program name in TP
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%ENVIRONMENT REGOPE
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
--Define Varriables
---------------------------------------------------------------------
VAR
file_var : FILE
tmp_int : INTEGER
tmp_str : STRING[128]
status : INTEGER
entry : INTEGER
loop1 : BOOLEAN
parts: ARRAY[10] OF STRING[20] -- up to 10 items. Stamp into and measuremnts.
current_pos: INTEGER
part_index: INTEGER
char: STRING[1]
temp_str: STRING[20]
str_length: INTEGER
tempReal: REAL
--------------------------------------------------------
-- Begin Program
BEGIN
--Sets the attributes of a file before it is opened
--ATR_IA = Interactively write
--ATR_PIPWAIT = Wait For Data
SET_FILE_ATR(file_var, ATR_IA)
--Set System IP and Server Port -- 8190 Gocator ASCII port
SET_VAR(entry,'*SYSTEM*','$HOSTC_CFG[2].$SERVER_PORT',8190,status)
-- Connect the tag
WRITE('Connecting..',CR)
--Connect to Gocator via ASCII
MSG_CONNECT('C3:',status)
--Write Connection Status (0 = Sucess)
WRITE(' Connect Status = ',status,CR)
--Check Status before opening
IF status = 0 THEN
--Open Connection for Client 3 "rw" = read/write
OPEN FILE file_var('rw','C3:')
--return status of IO connection
status = IO_STATUS(file_var)
IF status = 0 THEN
--String to start the sensor
tmp_str = 'Start' + CHR(13) + CHR(10)
--Send string command to sensor
WRITE file_var(tmp_str)
--Recieve Command Reply From Sensor
READ file_var(tmp_str)
--Return status of IO connection
status = IO_STATUS(file_var)
--Check status of IO connection
IF status <> 0 THEN
WRITE ( 'Error sending command', CR)
ENDIF
--Read 100 Characters of Data into "tmp_str" from Gocator
READ file_var(tmp_str)
--Return status of IO connection
status = IO_STATUS(file_var)
--Check status of IO connection
IF status <> 0 THEN
WRITE ( 'Error recieving command', CR)
ENDIF
--The below code will delmit the ASCII results. All results are espected to have a
-- " , " acting as the delimiter between measurements. EX (Value1,Value2,Value3,)
-------------------------------------------------------------------------------------------------------------------------------------
--get total string length
str_length = STR_LEN(tmp_str)
current_pos = 1
part_index = 1
temp_str = ''
-- Parse string character by character
WHILE current_pos <= str_length DO
-- Get current character
char = SUB_STR(tmp_str, current_pos, 1)
-- Check if character is a comma or we're at the end
IF (char = ',') OR (current_pos = str_length) THEN
-- If at end and not comma, include last character
IF (current_pos = str_length) AND (char <> ',') THEN
temp_str = temp_str + char
ENDIF
-- Store completed part
IF part_index <= ARRAY_LEN(parts) THEN
parts[part_index] = temp_str
part_index = part_index + 1
temp_str = ''
ENDIF
ELSE
-- Add character to current part
temp_str = temp_str + char
ENDIF
current_pos = current_pos + 1
ENDWHILE
-- Print stamp and measurement results after parse
FOR current_pos = 1 TO ARRAY_LEN(parts) -1 DO
--Print to user screen
WRITE('Value ', current_pos, ': ', parts[current_pos], CR)
--convert from string to real
CNV_STR_REAL(parts[current_pos], tempReal)
--Set to data registers 51-59, current pos = 1 initially
SET_REAL_REG(current_pos + 50, tempReal, status)
ENDFOR
-------------------------------------------------------------------------------------------------------------------------------------
--String to stop the sensor 'Stop/r/n
tmp_str = 'Stop' + CHR(13) + CHR(10)
--Send string command to sensor
WRITE file_var(tmp_str)
--Recieve Command Reply From Sensor
READ file_var(tmp_str)
--Return status of IO connection
status = IO_STATUS(file_var)
--Check status of IO connection
IF status <> 0 THEN
WRITE ( 'Error recieving command', CR)
ENDIF
--Close Connection for Client 3
CLOSE FILE file_var
--Else if connection is not establiched to sensor
ELSE
WRITE('Connection Error',CR)
ENDIF
--Disconnect from client three
MSG_DISCO('C3:',status)
ENDIF
END GocatorConnect
Example TP Program
This is an example of how the above Karel code can be used in a teach pendant program with a Gocator line profiler. On line 8, the motion instruction utilizes TA (time-after) to make sure the robot is up to speed before the sensor is turned on. The sensor cannot be accelerating while scanning; this will tarnish image quality. The Gocator must be traveling at a constant speed while in time-based triggering mode.
Fig 9. Teach Pendent program on FANUC CRX-10iA
Advanced TP Program
This is a more advanced TP program that uses the extra Karel code below. This program will perform two scans over a part with a defined X-offset. This program assumes a proper TCP and Tool Frame to accomplish this.
Notice this advanced TP program MUST use all three Karel programs present to operate.
CALL CONNECTGOCATORK - Connects to sensor, opens socket connection
CALL SCANGOCATORK - Will scan and save results to robot controller. This file is dependent on CONNECTGOCATORK running first. This file cannot operate independently.
CALL DISCONNECTGOCATORK - Disconnects from sensor, closes socket connection.
Fig 10 & 11. Teach Pendent program on FANUC CRX-10iA
Additional KAREL Socket Program's
Extra Karel Code (Connect to Gocator)
PROGRAM CONNECTGOCATORK-- Program name
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%ENVIRONMENT REGOPE
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
--Define Varriables
---------------------------------------------------------------------
VAR
file_var : FILE
tmp_int : INTEGER
tmp_str : STRING[128]
status : INTEGER
entry : INTEGER
--------------------------------------------------------
-- Begin Program
BEGIN
--Sets the attributes of a file before it is opened
--ATR_IA = Interactively write
--ATR_PIPWAIT = Wait For Data
SET_FILE_ATR(file_var, ATR_IA)
--Set System IP and Server Port -- 8190 Gocator ASCII port
SET_VAR(entry,'*SYSTEM*','$HOSTC_CFG[2].$SERVER_PORT',8190,status)
-- Connect the tag
WRITE('Connecting..',CR)
--Connect to Gocator via ASCII
MSG_CONNECT('C3:',status)
--Write Connection Status (0 = Sucess)
WRITE(' Connect Status = ',status,CR)
--Check Status before opening
IF status = 0 THEN
WRITE('Connection Success', CR)
--Else if connection is not establiched to sensor
ELSE
WRITE('Connection Error',CR)
ENDIF
END CONNECTGOCATORK
Extra Karel Code (Scan With Gocator & Collect Data)
PROGRAM SCANGOCATORK -- Program name
%STACKSIZE = 8000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%ENVIRONMENT REGOPE
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
--Define Varriables
---------------------------------------------------------------------
VAR
file_var : FILE
tmp_int : INTEGER
tmp_str : STRING[128]
status : INTEGER
entry : INTEGER
loop1 : BOOLEAN
parts: ARRAY[20] OF STRING[20] -- up to 20 items. Stamp info and measuremnts.
current_pos: INTEGER
reg_start_index: INTEGER
part_index: INTEGER
char: STRING[1]
temp_str: STRING[20]
str_length: INTEGER
tempReal: REAL
--------------------------------------------------------
-- Begin Program
BEGIN
SET_FILE_ATR(file_var, ATR_IA)
OPEN FILE file_var('rw','C3:')
--return status of IO connection
status = IO_STATUS(file_var)
IF status = 0 THEN
--String to start the sensor
tmp_str = 'Start' + CHR(13) + CHR(10)
--Send string command to sensor
WRITE file_var(tmp_str)
--Recieve Command Reply From Sensor
READ file_var(tmp_str)
--Return status of IO connection
status = IO_STATUS(file_var)
--Check status of IO connection
IF status <> 0 THEN
WRITE ( 'Error sending command', CR)
ENDIF
WRITE ( 'Ready to read data', CR)
--Read 100 Characters of Data into "tmp_str" from Gocator
READ file_var(tmp_str)
--Return status of IO connection
status = IO_STATUS(file_var)
--Check status of IO connection
IF status <> 0 THEN
WRITE ( 'Error recieving command', CR)
ENDIF
--The below code will delmit the ASCII results. All results are espected to have a
-- " , " acting as the delimiter between measurements. EX (Value1,Value2,Value3,)
-------------------------------------------------------------------------------------------------------------------------------------
--get total string length
str_length = STR_LEN(tmp_str)
current_pos = 1
part_index = 1
temp_str = ''
-- Parse string character by character
WHILE current_pos <= str_length DO
-- Get current character
char = SUB_STR(tmp_str, current_pos, 1)
-- Check if character is a comma or we're at the end
IF (char = ',') OR (current_pos = str_length) THEN
-- If at end and not comma, include last character
IF (current_pos = str_length) AND (char <> ',') THEN
temp_str = temp_str + char
ENDIF
-- Store completed part
IF part_index <= ARRAY_LEN(parts) THEN
parts[part_index] = temp_str
part_index = part_index + 1
temp_str = ''
ENDIF
ELSE
-- Add character to current part
temp_str = temp_str + char
ENDIF
current_pos = current_pos + 1
ENDWHILE
--START AR REGISTER 50------------------
reg_start_index = 50
-- Print stamp and measurement results after parse
FOR current_pos =1 TO ARRAY_LEN(parts) - 1 DO
--Print to user screen
WRITE('Value ', (current_pos), ': ', parts[current_pos], CR)
--convert from string to real
CNV_STR_REAL(parts[current_pos], tempReal)
--Set to data registers 1-9
SET_REAL_REG(reg_start_index, tempReal, status)
WRITE('Status of reg write ', status, CR)
reg_start_index = reg_start_index + 1
ENDFOR
-------------------------------------------------------------------------------------------------------------------------------------
--STRING TO STOP the sensor 'Stop/r/n
tmp_str = 'Stop' + CHR(13) + CHR(10)
--Send string command to sensor
WRITE file_var(tmp_str)
--Recieve Command Reply From Sensor
READ file_var(tmp_str)
--Return status of IO connection
status = IO_STATUS(file_var)
--Check status of IO connection
IF status <> 0 THEN
WRITE ( 'Error recieving command', CR)
ENDIF
--Close Connection for Client 3
CLOSE FILE file_var
ENDIF
END SCANGOCATORK
Extra Karel Code (Disconnect from Gocator)
PROGRAM DISCONNECTGOCATORK-- Program name
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%ENVIRONMENT REGOPE
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
--Define Variables
---------------------------------------------------------------------
VAR
file_var : FILE
tmp_int : INTEGER
tmp_str : STRING[128]
status : INTEGER
entry : INTEGER
--------------------------------------------------------
-- Begin Program
BEGIN
-- Connect the tag
WRITE('Disconnecting..',CR)
--Disconnect from client three
MSG_DISCO('C3:',status)
--Write Connection Status (0 = Sucess)
WRITE(' Disconnect Status = ',status,CR)
--Check Status before opening
IF status = 0 THEN
WRITE('Disconnect Success', CR)
--Else if connection is not establiched to sensor
ELSE
WRITE('Disconnect Error',CR)
ENDIF
END DISCONNECTGOCATORKTroubleshooting
The "USER" screen on your FANUC is going to be your best friend in terms of understanding why things are going wrong. We always want the status of our connection to be 0. If you see your status is anything other than 0, connection problems have occurred. Most commonly, trying to connect to the sensor while already connected. Or trying to disconnect from the sensor while not connected.
Fig 12. Location of "USER" Screen On Fanuc Robot
Fig 13. Example of successful communication. Success is always indicated by 0.
If you receive an "uninitialized" error on the robot side, this is because you are not sending any data or enough data over to the robot. A great sanity check is to send fixed values for testing.
Fig 14.1. Example of sending fixed integer values "222" through ASCII and Gocator.
Fig 14.2. What is received on the robot side for above 14.1 testing.
Video Demo
A video of a robot running the Advanced TP program from this article can be found at the below link:
Video Demo Data/Results
One important note to highlight is that Gocator data will only be as good as your motion source. The motion out of the FANUC robot is not perfect (aka not perfect linear motion). This imperfection in the movement can be seen within the data collection.
Even if the Robot appears to be moving perfectly straight, the slightest vibrations and disturbances will impact image quality. The image below was taken on a wooden table top, as shown in the above YouTube video.
Fig 15. Flat surface appears wavy because of imperfect robot motion.
Comments
0 comments
Please sign in to leave a comment.