Go to Post "git er done" but do it right. - CJO [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 22-01-2012, 19:47
Frky's Avatar
Frky Frky is offline
Programmers
FRC #1011 (CRUSH)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Arizona
Posts: 3
Frky is an unknown quantity at this point
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
Reply With Quote
  #2   Spotlight this post!  
Unread 22-01-2012, 20:07
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: Java/LabView TCP Solution

Can you not just use 127.0.0.1 as your IP?
Reply With Quote
  #3   Spotlight this post!  
Unread 22-01-2012, 21:15
Frky's Avatar
Frky Frky is offline
Programmers
FRC #1011 (CRUSH)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2011
Location: Arizona
Posts: 3
Frky is an unknown quantity at this point
Re: Java/LabView TCP Solution

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.
__________________
CRUSH 1011 Programmers
crush1011.org
Reply With Quote
  #4   Spotlight this post!  
Unread 22-01-2012, 21:47
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,079
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Java/LabView TCP Solution

127.0.01 is a standard loopback address. It points back at the computer.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #5   Spotlight this post!  
Unread 22-01-2012, 23:27
shuhao shuhao is offline
Registered User
FRC #4069 (Lo-Ellen Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Sudbury
Posts: 138
shuhao is an unknown quantity at this point
Re: Java/LabView TCP Solution

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
Reply With Quote
  #6   Spotlight this post!  
Unread 05-02-2012, 20:30
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
Re: Java/LabView TCP Solution

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.
Reply With Quote
  #7   Spotlight this post!  
Unread 06-02-2012, 22:33
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
Re: Java/LabView TCP Solution

Sorry to double-post, but we were able to get a TCP connection to the cRIO using the LabVIEW examples. Thanks for this post!
Reply With Quote
  #8   Spotlight this post!  
Unread 07-02-2012, 17:08
kingofirony kingofirony is offline
Registered User
FRC #0694
 
Join Date: May 2011
Location: New York City
Posts: 6
kingofirony is an unknown quantity at this point
Re: Java/LabView TCP Solution

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.
Reply With Quote
  #9   Spotlight this post!  
Unread 17-07-2012, 17:32
adam1647 adam1647 is offline
Registered User
FRC #1647
 
Join Date: Jul 2012
Location: USA
Posts: 1
adam1647 is an unknown quantity at this point
Re: Java/LabView TCP Solution

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/attach...d=13425603 27
Attached Thumbnails
Click image for larger version

Name:	labview tcp.jpg
Views:	166
Size:	5.9 KB
ID:	12890  
Reply With Quote
  #10   Spotlight this post!  
Unread 05-10-2012, 17:59
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Re: Java/LabView TCP Solution

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?
Reply With Quote
  #11   Spotlight this post!  
Unread 05-10-2012, 18:12
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Java/LabView TCP Solution

Quote:
Originally Posted by apples000 View Post
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

Code:
import com.sun.squawk.io.BufferedReader;
import java.io.*;
import javax.microedition.io.*;
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
Reply With Quote
  #12   Spotlight this post!  
Unread 06-10-2012, 07:32
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Re: Java/LabView TCP Solution

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?

Last edited by apples000 : 06-10-2012 at 07:49.
Reply With Quote
  #13   Spotlight this post!  
Unread 25-10-2012, 23:43
ktrobotcreator's Avatar
ktrobotcreator ktrobotcreator is offline
Programmer
FRC #1245 (Shazbots)
Team Role: Programmer
 
Join Date: Jul 2012
Rookie Year: 2007
Location: Colorado
Posts: 38
ktrobotcreator is an unknown quantity at this point
Re: Java/LabView TCP Solution

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.)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:49.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi