Communication between UR and Cognex

Hi all,

I’m having some issues to create a communication between cognex camera and UR10 robot. Please see the same code in below:

Connected:=socket_open(“192.168.1.124”,30008,"socket0)
Wait:1.0
socket_send_string(“admin”,“socket0)
socket_send_byte([13,10],“socket0”)
wait:0.01
ustat2=socket_read_line(“socket0)
wait:0.01
socket_send_string(””,"socket0)
socket_send_byte([13,10],“socket0”)
wait:0.01
pstat=socket_read_line("socket0)
wait:0.01

but not able to login the camera. the screenshot of UR teachpendant screen:

It’s giving error that invalid password. But there is no password. Do you have any idea?

Thanks for your help.

I tried with 2 different Cognex cameras both have the same issue.

Hey Sibel,

Welcome to the forum. First of all let me advice you to use the UR Script instead of Polyscope for the connection. That makes things a lot easier. and readable. Script should be available under the advanced tab, and there you can choose between a single line of code or a file (choose the file).

Which firmware are you running? Below is an example script to connect to the Cognex, but it is designed for firmware version 3.3+.

Let me know if this works for you or if you still get any more problems. Take note that the port and IP should be replaced with the port and IP you setup on the camera.

#Connect to a cognex camera, tested on UR Firmware 3.3

### Configuration of camera settings, adjust where needed ###

port = 10000
ip = "192.168.0.10"
socket_name = "Cognex"


### Connect to camera and return status ###
socket = socket_open(ip, port, socket_name)	
textmsg("Connection successful?: ", socket)


### After connecting the camera first sends a welcome message and asks for username and password ###

receive = socket_read_string(socket_name)
textmsg(receive)

### Send username ###
socket_send_string("admin" , socket_name)
socket_send_byte([13,10], socket_name)

### Receive request for password ###
receive = socket_read_string(socket_name)
textmsg(receive)
	
### Send password ###

socket_send_string("", socket_name)
socket_send_byte(13, socket_name) # Empty string and list of bytes gave some problems in the past, sending them seperate
socket_send_byte(10, socket_name)

receive = socket_read_string(socket_name)
textmsg(receive)

socket_close(socket_name)

Hi Mathijs,

Thank you so much for your reply. I just managed to try it out. It worked. The communication is established but now I have another issue to read the values on the defined cell. It’s giving [0,nan,nan,nan,nan]. Am I missing anything?

Please see below code & in-sight settings in below:

@Mathijs

In-sight setting image

Hey Sibel,

This has to do with the way Cognex sends its data and how the UR Robot expects to receive it.

Because you haven’t shared the firmware version you are running the code below might not work, I am assuming firmware 3.3+ again.

The UR Code looks like it could be working, to be sure try to clear the TCP receive buffer by adding a socket_read_string after the socket_read_ascii_float.

    socket_send_string("GVA009", socket_name)
    socket_send_byte([13,10], socket_name)

    # Expected format of data string: “(x, y, z)” where x, y, and z are floats or integers
    value_count = 4
    timeout = 5
    receive_list = socket_read_ascii_float(value_count , socket_name, timeout)

    ### There is still some data remaining in the camera buffer, we should empty it.
    buf = socket_read_string(socket_name)

    ### Show the resulting list
    textmsg("Received list:", receive_list)

I think your problem probably has to do something with the formatting of your data in Cognex, see screenshot of UR script manual below. You have to add parentheses. You can add them to the Leading and Trailing text option in the In-Sight settings.

Hi @Mathijs,

Sorry I forgot to mention about the firmware version. It’s 3.10 . I added String command as per your suggestion. It worked. I managed to receive the data.

Thank you very much for your help & time.

No problem. I am glad things are working now!

1 Like

Hello!

I’m currently working on a similar project
I have an In-Sight 2800 Vision Sensor (COGNEX) and a UR10 (Universal Robots), and I want to inspect a few points of a part. To do this I need to trigger the camera in each point.

I’m using Ethernet/IP to communicate between both devices.
I will attached some images, so you can see what I have already done.
I opened the connection, and when I run the program It’s TRUE, but I didn’t managed to trigger the camera.

Can anyone help?

Regards,

Hi Vascodias, could you create a new topic for this?

When doing so, could you convert the PolyScope nodes to UR script with a minimal working code example and post it as code like this:


You will get a code block where you can put the code:
image

Could you also make a minimal working job file for the In-Sight Explorer? That way I can actually run some tests and figure out the problem pretty fast. If you create your own topic before the weekend I will gladly help you with this problem and you will have a reply / fix by Monday.

1 Like

I already create a new topic!

Thanks!

Hi, I am working with cognex 9000 series and ur 5, How do I connect cognex to ur-5 using TCP/IP or Ethernet/IP? How do I set up communication and do the script programming to receive data from cognex? please help me if there is any documentation

Hey, I also have the similar problem I am using the port 50000, and I have sent the command “DAT” to get the data from the cognex 9912M, In the cognex I have setup TCP/Ip with the host as cognex IP address, and sending data using WriteDevice() I am getting [0,Nan,nan]. I am not sure why? would you be able to help me with this?

@mathijs I think we should ask our students to write this How-to:

Yeah, that would be helpful. I tried serial native robot protocol in cognex and I sent GV commands from the ur-5, I got the value from the socket_read_string() but, when I use socket_read_ascii_float(), I am still getting[0,nan,nan,nan]

You are close!

The socket_read_ascii_float() function expects the data to be formatted like this:

(123.456, 12.34, 456.78)

you can use the Format String function and add the brackets as leading and trailing text.

You can get rid of the status code by using the socket_read_line function (if you have a CB3).

1 Like

Hey Mathijs, that was helpful. Now i can see the float values. I have one more doubt, If I have to move my ur-5 to these positions, do I need to do the hand eye calibration? I converted the pixel values to millimeters and tried to move to the position but, it did not move to the correct place. So I was wondering, If I have to do hand eye caibration?

I guess I got it, I did the hand eye calibration and then imported the file, the units were in millimeters now. Thank You for the support! It is very helpful.

Good to hear you solved the problem :smiling_face: