Karel server for constant input data updating

  • Hello there,


    I'm quite new to robot programing and specially to fanuc robots and I'm implementing an application where I need a server to run on the controller to get and update constantly the information coming from a python client. The info will then be used to give movement instructions to the robot.


    The python client gets the data from an USB device and process it and then sends an array of 8 variables (either -1/0/1 for each) by socket messaging to the controller. I've been through the Karel server example that's on the Karel Reference Manual but truth is I don't really understand what's going on there, mainly with the "Open/Close File" instructions and the two for cycles. In my case, I want to constantly (no need for huge frequency but I don't want lag neither) get the values of the 8 variables so I can with them instruct the robot to move to certain positions. Thing is, I don't know if I should open a file and then constantly cycle through the same file with multiple read statements or if I should open/close a file everytime I want to update that data.


    I thank you in advance for any help given! :smiling_face:

    Edited once, last by dcrb ().

  • dcrb

    Changed the title of the thread from “Karel Server for constant data updating doubts” to “Karel server for constant input data updating”.
  • You will need to thoroughly read the Socket Messaging section in the Karel manual. First you configure the Socket Messaging protocol in the Host Comm settings.

    Then in your Karel program you will use these commands to read from the socket:

    MSG_CONNECT

    OPEN FILE

    BYTES_AHEAD

    READ

    CLOSE FILE

    MSG_DISCO


    OPEN FILE and CLOSE FILE are actually opening/closing your socket. You can leave the socket open and continuously read. I found it worked better to use BYTES_AHEAD in a loop to check if there was data in the buffer before calling READ.


    A few notes:

    1. I was never able to find a good way of dealing with connection errors. If you call READ and the connection to your Python client has dropped out, you will get an error that will stop the Karel program.

    2. READ is a blocking call. It will wait forever until data is received. That is why I used BYTES_AHEAD.

  • Thanks for your input. I've been trying to simulate the connection with RoboGuide but while the Python Program connects to the roboguide IP (127.0.0.1) I'm unable to connect the karel server to the python program. It always fails at the MSG_Connect, giving status = 67216. Any idea or suggestion on what might be wrong? Which port should I use?

  • Usually it would be S3: as the first two servers are configured by default for FTP. In the server setup you can define the port. I believe it defaults to port 9000, but this is just a SWAG.

  • For RoboGuide, I believe that the SERVICES.TXT file, located in your RG computer in the specific robot subdirectory under the workcell directory (on default installs, RG creates a My Workcells directory in your My Documents directory, and every workcell you create has its own directory inside), shows the ports exposed by each service in the virtual robot.

  • For RoboGuide, I believe that the SERVICES.TXT file, located in your RG computer in the specific robot subdirectory under the workcell directory (on default installs, RG creates a My Workcells directory in your My Documents directory, and every workcell you create has its own directory inside), shows the ports exposed by each service in the virtual robot.

    Found that file, pretty useful, thanks! I've managed to establish a connection through the port 2000 (127.0.0.1:2000), even though that port doesn't appear on the services file or anywhere else.

Advertising from our partners