Java/LabView TCP Solution

So for this year’s game we were hoping to do video processing to target the backboard squares. We rewrote the Dashboard in LabView so we do all of our image processing on the Dashboard. We get coordinates of the rectangles and would like to use those numbers in Java, where we program the actual robot. After countless hours of trying various UDP and TCP combinations in both Java and LabView, we finally found a working solution!

The LabView end is pretty simple. First you need a TCP Listen.vi object, and then you need a TCP Write block inside a loop. Things on this end should be pretty clear, but if something isn’t, we can post screenshots or more detailed information. We’re using port 1180.

The Java end is a bit trickier. You attempt to open a connection to the port, and the LabView listener should accept the connection. Then we stream the data coming from LabView, and the InputStream reads it. We then output that data in Java. The code is from the FRC Iterative Robot Template, and we attached the main RobotTemplate.java file.

One important thing is, at the moment, the data streams faster than Java can process it. We’re going to have to slow it down so we don’t get a backlog of data when processing. Depending on your needs, this might be a thing to consider.

This code is free for anyone to use and it can be modified in any way. If anyone has a suggestion for improvements, please post them!

Hope this helps and good luck to all teams!!

-CRUSH 1011 Programmers

RobotTemplate.java (2.29 KB)

RobotTemplate.java (2.29 KB)


RobotTemplate.java (2.29 KB)

Can you not just use 127.0.0.1 as your IP?

To communicate with the cRIO you need your IP to be 10.XX.YY.Z. That’s how you’re supposed to set it up for the competition and it works.

127.0.01 is a standard loopback address. It points back at the computer.

TCP is great and all, except writing the client/server to handle a lot of excepts that could arise from network communication.

For anyone else who don’t want to write a server, you could just use a restful server with some queues and a kv store… These servers tends to be much more forgiving.

This is much easier than maintaining a connection, as you don’t need to maintain a connection.

However, there could be some lag, so I wouldn’t recommend using this in your robot’s main loop, although if you’re doing onboard computer, it shouldn’t be that bad, as long as your cables are all set. (a 1 second time out is recommended)

Here’s the server code that i whipped up in under 40 min. Other code running on your onboard computer/your DS could be just communicating with the server and the server acts as a message passer: https://github.com/FRCTeam4069/Mediator

Our team is having trouble getting the Dashboard to send TCP packets to our robot. Could you please post a screenshot of your relevant Dashboard code? We would much appreciate it.

Sorry to double-post, but we were able to get a TCP connection to the cRIO using the LabVIEW examples. Thanks for this post!

It’d be really cool if you could post a screenshot of the labview code. I’ve been trying to use the labview examples, however, this has not resulted in any progress.

We have also tried to run tcp communications between the robot and dashboard. The java side works fine on the robot, we have pretty much the same thing as 1011. Our labview side is causing problems though. I attached a picture of what we have been basicly doing, and it works in a blank vi with just tcp, but once you add the tracking in with the tcp it is extreamly slow. (If you run the tracking by its self on the dashboard it runs fine.) We also had problems with the loops in the labview but I think that is because we are reopening the connection each time it runs through the code. Could you please post a copy of your labview block diagram so we can see what is going wrong with ours.

Thanks,
Adam
1647

http://chiefdelphi.com/forums/attachment.php?attachmentid=12890&stc=1&d=1342560327

labview tcp.jpg


labview tcp.jpg

We are trying to use your example, but we are unable to get the code to run. The statement “import java.net” doesn’t work because java can’t find that package. How are you able to get java to recognize packages not included in the frc api?

I didn’t test the code, but when I pasted it into a new class in Netbeans it didn’t give me any errors. Where do you see " import java.net "? The only special imports he used were

import com.sun.squawk.io.BufferedReader;
import java.io.*;
import javax.microedition.io.*;

We’ve figured out our import problem, but now it is unable to the ServerSocket Class, the socket class, accept method of serversocket, the bufferedreader class, and so on. We can find the Socket Connection class but we can’t find any others. how did you guys get this to work?

I don’t remember using that, but as I am no longer on the team (I moved schools) and we did that last January, I might not remember that correctly. I will email the other programmer from last year. (And sorry for the late reply, it was his account that was subscribed to this thread.)