PC and FANUC robot TCP/IP Communication

  • 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:

    1. FANUC Robot LR Mate 200iD/4S Educational Cell
    2. R30iA Mate Controller - Software version between 8.0 and 9.0 not sure
    3. 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.

    1. Snap image data (Not sure, this data is possible to extract or not)
    2. Positions of the detected object (as far as I understand from the manual, this information is available in the vision register)
    3. 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
    4. VR and PR data
    5. 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.

    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?

  • Place your Ad here!
  • That is a big project. You will have to spend time with the Fanuc manuals.


    I will give my advice

    Does this socket server-client is fine or there is some other easy method available?

    Its probably fine to use the socket connection. There are easier methods but they require purchasing additional software.



    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.

    Everything will need to be formatted as a string. This is sometimes done using JSON, CSV, or XML formatting or you can design your own format. So the process will be 1) Use KAREL commands to get the value and 2) format into a string to send to client

    Image data - not reasonable to send through socket connection. There is a KAREL command "V_SAVE_IMREG" which will save a snapped image to file. Then you could use FTP to get the image.

    Positions of objects in VR - VREG_FND_POS command

    System variables - GET_VAR command

    Search the KAREL manual for similar commands to get the other data that you need.


    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?

    In your code, isn't "loop1 = FALSE" executed inside the WHILE loop unconditionally? That will cause the loop to exit. To keep the KAREL program running you need to continue looping.

    WHILE (loop_condition)

    BYTES_AHEAD(...)

    IF (bytes_available > 0)

    #read data

    #process data and take action

    ENDIF

    DELAY 10

    ENDWHILE

  • There might be an easier way than socket communications.


    KAREL supports remote program calling via URLs, like so: HTTP://robbot_ip_address/KAREL/Karel_Program_Name?VariableName=string

    '?' marks off a variable to be sent to the robot, which must be declared as a string variable in the KAREL program. 'string' is the string that that KAREL variable will contain once this URL is called.


    The KAREL program can write a string and pass it back to the computer opening the URL. It's an .HTML file, but internally it's nothing but plain ASCII strings, no formatting codes.


    I was able to communicate with my Fanuc in this way, bidirectionally, using just this much Python code:

    Python
    from urllib.request import urlopen
    URL = 'http://192.168.1.250/KAREL/(karel program name)'
    Response = urlopen(URL)
    String = Response.read().decode('utf-8')
    print (String)

    That would cause a single run of the KAREL program. Variables could be added to the end of the URL call separated by '?', up to a maximum of 10, IIRC.


    Feedback from the KAREL program required:

    The CRs are KAREL keyword for carriage returns, and all the variables are strings. The CLOSE FILE command would return the string written into chOutFileName to the browser or program that called the URL.


    The filename written to must be TD:RESPONSE.HTM, this is a "handle" to the robot's internal web server for the exchange opened by the URL.

  • Thanks, JM for your response.


    I tried your suggestion, now the server is continuously running but client does not connect again and I received the following error on Python side:

    s.connect((HOST, PORT))

    ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

    Please put some light on the following:

    1- According to the KAREL manual(section 11.4.3), MSG_DISCO() is used for a closing socket if there is an error in file R/W operation or connection loss between server and client, i used it with byte_AHEAD() so python client can easily be connected again, but I got the following status code "Disconnect: 67208", what does this mean? Did I use this utility function in the right way?


    2- From where I can get the KAREL status code and their description?

    3- Do I need to call MSG_CONNECT() again after MSG_DISCO? i have tried this but got 67215.

    4-After receiving the data from the server, the python client closes the connection and BYTES_AHEAD() continuously called in the while loop and I notice for the first two iterations I got entry=0 and after that, I got data uninitialized warning on TP to avoid it I used UNITI() to close the connection. Why entry =0 for the first two loop iterations and an empty string after that?


    again many thatks

  • Hi,

    I modify the section inside the while like:

    Here is the result:

    just able to hamdle Uninitialized data and client still does not able to connect server again

  • Thanks skyfire,


    i will try your option too. Is this is feasible for my task? from where i can get more information about it?

    It's detailed in the "Internet Options Manual," Section 6.3.6 "Running KAREL programs from the Web Browser." If you sign up for the Fanuc CRC support portal, you can access these manuals.


    There is a note that the robot must have R626, the "Web Server Enhancement" option, for this to work.

  • It's detailed in the "Internet Options Manual," Section 6.3.6 "Running KAREL programs from the Web Browser." If you sign up for the Fanuc CRC support portal, you can access these manuals.


    There is a note that the robot must have R626, the "Web Server Enhancement" option, for this to work.

    Thanks Skyfire,


    I checked and R626 is installed. I am in conversation with FANUC about purchasing R648 and R632.

    Do I exchange data (mentioned in one of the previous threads) between python clients and robots using this approach.?


    Any light on thread 6, please

    thanks

  • MSG_CONNECT() is a blocking function call. In other words, the program will not continue to the next line of code until a client attempts to connect. So the only time your client can connect is when the KAREL program is on the line MSG_CONNECT.


    So you need to either keep the connection open on the client side or run MSG_DISCO and MSG_CONNECT on the server every time and have the client reconect everytime.


    For the error codes, you need to look in the Error Code manual from Fanuc. It will show how to interpret the decimal error code. For error code 67208, the 67 is the Facility Code. In the manual you will find that 67 = HOST. The error number is 208. Now you can find the error in the manual as HOST-208 SM: Not Yet Connected.

  • MSG_CONNECT() is a blocking function call. In other words, the program will not continue to the next line of code until a client attempts to connect. So the only time your client can connect is when the KAREL program is on the line MSG_CONNECT.


    So you need to either keep the connection open on the client side or run MSG_DISCO and MSG_CONNECT on the server every time and have the client reconect everytime.


    For the error codes, you need to look in the Error Code manual from Fanuc. It will show how to interpret the decimal error code. For error code 67208, the 67 is the Facility Code. In the manual you will find that 67 = HOST. The error number is 208. Now you can find the error in the manual as HOST-208 SM: Not Yet Connected.

    Thanks for JM for your response, let me try

  • I checked and R626 is installed. I am in conversation with FANUC about purchasing R648 and R632.

    Do I exchange data (mentioned in one of the previous threads) between python clients and robots using this approach.?

    It worked for me. To be clear, I wasn't trying to do high-speed cyclic exchanges -- I think the fastest I ever ran it was to repeat every 250ms.

  • Hi JM,


    Now client can join the server any time, thanks.

    I discover file must be closed before MSG_DICO() utility.

    I also notice that if the robot sends a message string using WRITE ARCHIVO2(TMP_STR) command and the client does not have any logic for receiving the server's message then READ ARCHIVO2 (TMP_STR1::n_bytes) operation is not successful and file_IO states generate the 2021 status code. What is the reason behind it? The client may be or may not be interested in messages from the server.

  • I don't know.


    IO status codes can be found in the KAREL manual under the IO_STATUS command.

    2021 is "End of file for RAM disk device". I don't know what this means. Maybe that there was no data in the buffer?


    You can use "READ file_id(cr)" to clear IO_STATUS errors.

  • Thanks,JM

    your so helpfull

  • There is a KAREL command "V_SAVE_IMREG" which will save a snapped image to file. Then you could use FTP to get the image.

    hI JM,


    I found the following vision commands in the KAREL manual,

    1. V_FIND_VIEW
    2. V_RUN_FIND
    3. V_GET_PASSFL
    4. V_GET_OFFSET
    5. V_RUN_FIND
    6. V_SAVE_IMREG
    7. V_SNAP_VIEW

    I have written a vision-based pick place TP program for FANUC Educational Cell and it is working perfectly. All the above commands except "V_SAVE_IMREG" are being used in TP program directly or indirectly (buried under TP commands, see picture). How I can use the "V_SAVE_IMREG" command in the KAREL program just for getting the image data of the currently snapped picture as TP program handling everything? OR Should I write the whole vision routine in KAREL and call it from TP program?


  • I don't have experience with iRVision in Karel.

    V_SAVE_IMREG may only be available in Karel. One option is to write a Karel program that only saves the image. Then you could keep your TP program and just add a call to your Karel program to save the image.

  • I don't have experience with iRVision in Karel.

    V_SAVE_IMREG may only be available in Karel. One option is to write a Karel program that only saves the image. Then you could keep your TP program and just add a call to your Karel program to save the image.

    Hi JM,

    thanks for your support.

  • There might be an easier way than socket communications.

    Hi SkyeFire,


    Can you please give some detailed insights, how this HTTP communication is used in my case (just consider App) and how I can I send the required data from the robot to an external PC? Does it is possible to change Digital output or user output from python script?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now

Advertising from our partners