Communication between Matlab and FANUC Roboguide

  • Hello everyone,


    For my engineering school project I have to create a communication with MATLAB and ROBOGUIDE to be able to send informations from MATLAB to ROBOGUIDE so that the robot (i have an educational cell from FANUC with an LR Mate 200i) can move. I know that it is possible to do it with KAREL programmation and using TCP/IP connection between them but for now, i don't really know how. I heard some solutions with creating server with KAREL and client on matlab but it didn't work.

    Can someone help me for that ?


    Thank you by advance ! :)

  • AD
  • Hi jmd2777,


    I tried to connect Matlab and Roboguide with a program I found on internet. Roboguide create a server and Matlab is the client that communicate with the server but Matlab cannot connect to Roboguide.


    Here is my KAREL program to create the server :


    PROGRAM TestServer


    %STACKSIZE = 4000

    %NOLOCKGROUP

    %NOPAUSE=ERROR+COMMAND+TPENABLE

    %ENVIRONMENT uif

    %ENVIRONMENT sysdef

    %ENVIRONMENT kclop

    %ENVIRONMENT bynam

    %ENVIRONMENT fdev

    %ENVIRONMENT flbt

    %INCLUDE klevccdf

    %INCLUDE klevkeys

    %INCLUDE klevkmsk


    VAR

    file_var : FILE

    tmp_int : INTEGER

    tmp_str : STRING[128]

    status : INTEGER

    entry : INTEGER

    loop1 : BOOLEAN


    BEGIN


    SET_FILE_ATR(file_var, ATR_IA)

    SET_VAR(entry, '*SYSTEM*','$HOST_CFG[1].$SERVER_PORT',8000,status)

    WRITE(' VAR status = ',status,CR)

    -- Connect the tag


    MSG_CONNECT('C1:',status)

    WRITE(' Connect status = ',status,CR)


    MSG_DISCO('C1:',status)

    WRITE('Disconnect status=',status,CR)

    --loop1 = TRU


    END TestServeur


    I'm not sure if I have to do it like that or if I can just create a file .txt or an excel file and read informations on that excel file with Roboguide (maybe with a karel program or just with roboguide function, I don't know) but the thing is that I have to read these informations in real time. And I didn't found a function on roboguide to read file from my PC.


    Also just to be more precise, what I want to do is to move my robot with voice.

  • First, I have to warn you that this will not be easy. You will need to commit time to reading Fanuc manuals on Karel and User Socket Messaging just to get the communication working. To initiate robot motion from an external source is another entire challenge that you will need to tackle.

    Since you have a training cell from Fanuc, I would recommend trying to get as much help as possible from them. For example, they have software add-ons that provide "motion streaming".



    Also, RoboGuide is a simulation of a real robot. So you mentioned the possibility that RoboGuide could read motion commands from a file, thats not really possible. You have to approach it like an actual robot.

  • First, I have to warn you that this will not be easy. You will need to commit time to reading Fanuc manuals on Karel and User Socket Messaging just to get the communication working. To initiate robot motion from an external source is another entire challenge that you will need to tackle.

    Since you have a training cell from Fanuc, I would recommend trying to get as much help as possible from them. For example, they have software add-ons that provide "motion streaming".



    Also, RoboGuide is a simulation of a real robot. So you mentioned the possibility that RoboGuide could read motion commands from a file, thats not really possible. You have to approach it like an actual robot.

    Actually, I have already read the manual from FANUC on KAREL programmation but it didn't really help me for now, I saw things on KAREL Server/Client but they are only giving us a program and the program didn't work when I put it in on Roboguide, there is some issues when I try to switch it from .kl to .pc with roboguide

    And they are not explaining what all functions on the program are doing..

    And yes, the problem is that i can't setup the communication, i'm trying to use User socket messaging but, didn't found how..


    What do you mean about "motion streaming" ? Can you tell me more about it ?


    And about your last sentence, I though maybe like an actual real robot, it can read a file like if it was an I/O from a PLC and then it's starting a program ?

  • What do you mean about "motion streaming" ? Can you tell me more about it ?

    Fanuc has an add-on software package for nearly everything. This includes packages for sending motion instructions from external sources.


    "Stream Motion

    Streaming motion option allows for an external device to perform path trajectory planning, streaming the path trajectory to the robot in near-real time, allowing for highly flexible and dynamic applications."


    There is another package named Dynamic Path Modification.


    Dynamic control of FANUC Robot in Run-Time


    I am mentioning this because using a software add-on like this would be the standard way of accomplishing your goal. So if you have access to help from Fanuc as a training cell, maybe they would give you the software. That would combine the communication and motion into one. Otherwise you need to figure out the communication first. Then how to take the input and convert it into motion.


    I guess its important to know what your goal is for the motion. The options are:

    1. Matlab sends commands to robot to run a motion program. That means the robot program has positions recorded in it that do not change. All you are doing is deciding which program to run.

    2. Matlab sends positions to the robot and the robot moves to those positions.

  • Ok thanks, i will contact FANUC to know more about "Stream Motion" or "Dynamic Path Modification"!


    My goal is the one you said : Matlab sends commands to robot to run a motion program. Because i meant to have like 4 or 5 differents program and I just want to decide which program to run using matlab.

  • Ok. I misunderstood your goal.


    "Stream Motion" or "Dynamic Path Modification" is mostly for Option 2.

    If you only need Option 1, then the link below shows the typical way of starting programs remotely (PROGRAM NUMBER SELECT PNS). However, that requires a PLC.


    https://www.onerobotics.com/po…ing-fanuc-robots-in-auto/


    You can also create your own custom version of this using Karel and User Socket Messaging. Which is how you started before I got you off on a tangent. Sorry.

  • If Matlab can send http requests you can use those to start a program. But then you also need a small Karel program that handles those requests. There are examples in the Fanuc documentation for network interface.

  • If you can send HTTP then you don't even need Karel. HTTP can set register values. You can monitor them in BGLOGIC to start a main program. In your main program you can conditionally call subprograms based on the register values.

  • What are you guys meaning with HTTP ? I saw on the "Fanuc documentation for network" an option for HTML program but it's not what i want it's only to build new interface for the teach pendant.


  • Don't worry it's my bad.


    But yeah I think i can do it using Karel and User Socket Messaging but the connection didn't work and there is not a lot of documentation about that ... X/

  • For socket messaging you need to first have

    1. Configure the SM server in Host Comm in the robot. This is covered in the "Setting up a Server Tag" section of the Karel manual. Pay attention to the tag that you use. I recommend that you configure S3 because that is what the example in the Karel manual uses.

    2. Build and Run the Karel program. I think theres a problem with the program you posted previously. For example, it shows MSG_CONNECT('C1:',status). That would be used if the robot were the client (C1 means use the settings in Client 1 slot of Host Comm). You want the robot to be the server. Use the example program from the Karel manual for a server.


    Pay attention to 2 of the lines in the server example.


    1. When they set the system variable for $HOSTS_CFG[3].$SERVER_PORT, that value is the port used for socket messaging. So when you try to connect with your Matlab client you will need to know the port to use. Also the [3] means that you are setting the port for S3 connection.

    2. MSG_CONNECT('S3:', status) - the 'S3' means that its going to use the settings configured in Server 3 of Host Comm.

  • .. I saw on the "Fanuc documentation for network" an option for HTML program but it's not what i want..

    Those HTML pages can trigger put/get requests to the robot, this can also be done with many programming languages. And I think also with mathlab.

    With the correct put/get requests you can start a Karel program with different parameters, or set register values and so on.

  • Matlab can send an HTTP request. I think that would be the simplest option.


    HTTP is the communication protocol used by all web pages on the internet and is commonly used for computer applications to communicate to each other. Google it.

  • Ok guys well, I found the solution, matlab updates a .txt file and I succeeded with the KAREL to read or write in this file what allows me to launch a robot program according to what roboguide reads !


    Now I hope it will work in real-time ! ^^


    Thanks you guys, you help me a lot ! :)

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