Hello there,
Let me introduce myself, I am a student in the Factory Automaton program and new to robotics.
I am working on a project with the following equipment from FANUC:
- FANUC Robot LR Mate 200iD/4S Educational Cell
- R30iA Mate Controller - Software version between 8.0 and 9.0 not sure
- PC Windows 10 - Python app
The following picture tries to explain the use case of the project on which I am currently working
the aim is to control robot movement and picking tasks from the cloud and generating alerts if the robot is unable to approach a specified position. There are two apps in the work scene App1 and App2. App2 will be controlling the robot by processing the data obtained by App1.
As the robot operation is based on vision so App1 needs to pull some data from the robot related to image, vision registers, U/T frames, and position register which will be utilized by App2 for computing possible forward/inverse kinematics solutions, analyzes and reports the reachability of positions, and validate trajectories given by the AI algorithm running in App2 and based on selected trajectory movement instructions will be created and send to the App1 which command the robot to move to verified picking position.
Currently, my focus is to establish communication between robot and the Python app (App1) running on PC to get the following data from robot and sending movement instructions.
- Snap image data (Not sure, this data is possible to extract or not)
- Positions of the detected object (as far as I understand from the manual, this information is available in the vision register)
- status of system variables (specifically related to robot reachability), for example, if an object is placed at the corner of the solitaire board, where the robot cannot reach, and the robot does not move, and the user is warned by the alarm on teaching pendant
- VR and PR data
- UF and UT frames
Also, the FANUC manual and some posts from this site got a glimpse that this could be done using socket messaging. Based on my task I make the robot a socket server and App1 as a socket client and wrote a simple KAREL server code and was able to exchange strings between the robot(roboguide) and App1.
KAREL server code
PROGRAM send2Cliient
%STACKSIZE = 4000
%COMMENT = 'AheadUtilityr'
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
---------------------------------------------------------------------------------------------------------------
--DECLARACION DE VARIABLES
VAR
ARCHIVO2 : FILE
TMP_INT : INTEGER
TMP_INT1 : INTEGER
TMP_STR : STRING[128]
TMP_STR1 : STRING[128]
STATUS : INTEGER
ENTRY : INTEGER
loop1 : BOOLEAN
---------------------------------------------------------------------------------------------------------------
BEGIN
-- clear the TPERROR screen
WRITE TPERROR(CHR(128))
--WRITE(CR)
WRITE('DISCONNECTING..',CR)
MSG_DISCO('S3:',STATUS)
WRITE('DONE.',CR)
SET_FILE_ATR(ARCHIVO2, ATR_IA)
--SET THE SERVER PORT BEFORE DOING A CONNECT
SET_VAR(ENTRY, '*SYSTEM*', '$HOSTS_CFG[3].$SERVER_PORT', 1162, STATUS)
WRITE('CONNECTING..',CR)
--OPEN CONNECTION
MSG_CONNECT('S3:', STATUS)
WRITE(' CONNECT STATUS= ',STATUS,CR)
loop1 = TRUE
--connectted or not
IF STATUS = 0 THEN
WHILE loop1 = TRUE DO
WRITE('Opening File...',CR)
OPEN FILE ARCHIVO2 ('RW','S3:')
STATUS = IO_STATUS(ARCHIVO2)
WRITE('File_IO_Status=',STATUS,CR)
--FILE OPEN is success OR NOT
IF STATUS = 0 THEN
--send msg to client
TMP_STR = 'RunJob'
WRITE ARCHIVO2(TMP_STR)
WRITE('Wrote: ',TMP_STR,CR)
WRITE('Waiting to read from client...',CR)
WRITE('READING',CR)
--reading from client
BYTES_AHEAD( ARCHIVO2, ENTRY,STATUS)
READ ARCHIVO2 (TMP_STR::ENTRY)
status = IO_STATUS(ARCHIVO2)
WRITE('Read status: ',status,CR)
WRITE('Read: ',TMP_STR,CR)
loop1 = FALSE
WRITE('Closed file.',CR)
CLOSE FILE ARCHIVO2
ELSE
WRITE('Error opening file',CR)
loop1 = FALSE
ENDIF
ENDWHILE
ENDIF
--IF UNINIT(TMP_STR) THEN
--WRITE ('UNINT',CR)
--WRITE ARCHIVO2('result was UNINIT', CR)
--WRITE('CLOSING File...',CR)
--CLOSE FILE ARCHIVO2
--STATUS = IO_STATUS(ARCHIVO2)
--WRITE('File_Close_Status=',STATUS,CR)
--ELSE
--READ 10 BYTES
--READ ARCHIVO2 (TMP_STR::10)
--STATUS = IO_STATUS(ARCHIVO2)
--WRITE (STATUS,CR)
--WRITE 10 BYTES
--WRITE (TMP_STR::12,CR)
--STATUS= IO_STATUS(ARCHIVO2)
--WRITE (STATUS,CR)
-- ENDIF
-- CLOSE FILE ARCHIVO2
-- ENDIF
-- ENDFOR
--ENDIF
END send2Cliient
---------------------------------------------------
Python Client
import socket
HOST = '192.168.100.2' # The server's hostname or IP address
PORT = 1162 # The port used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b'Hello from Client!')
data = s.recv(126)
print('Received', repr(data))
Display More
Does this socket server-client is fine or there is some other easy method available?
How the above-mentioned date can be extracted from the robot using KAREL and send to APP1? sending of the string is easy through file read/write but the position and frame are tricky to send.
Regarding the KAREL server code, currently, it sends a string to the client and closes the communication but I want the server can listen to the client continuously but I am not able to do that, how I can achieve this functionality?