Sensor Model | All |
Firmware Version | 3.x, 4.x, 5.x, 6.x |
SDK Version | 3.x, 4.x, 5.x, 6.x |
Overview
This document outlines how to establish ASCII communication between a FANUC robot and Gocator using Karel programming.
Sensor Setup
Our sensor is set up in the following manner.
- Sensor IP: 192.168.1.30
- Protocol: ASCII (Custom Config)
Fig 1. Gocator ASCII sensor settings.
Fig 2. Script tool simulating measurements, output 0 through 5 for Gocator 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 the Gocator.
Fig 3. How to set travel speed in Gocator GUI.
Fig 4. Setting trigger settings in Gocator.
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 2330 is at IP address 192.168.1.30.
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.
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 1-9
SET_REAL_REG(current_pos, 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. As if the sensor is accelerating, this will tarnish image quality.
Fig 9. Teach Pendent program on FANUC CRX-10iA
Comments
0 comments
Please sign in to leave a comment.