Go to Post This is probably one of the most important robots in FRC history and it never even was in an official event. - gyroscopeRaptor [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 27-08-2014, 20:47
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
FRC Java TCP client

I need help. I need to make a TCP socket client to read and write data to a socket server in the back end. The Java ME in the cRIO seems quite limited (I don't have enough experience to back myself though), and I can't figure out the default socket library. Java.net is absent so I cannot use the Java native functions.

The socket server is written in C++. It is meant to communicate data between the cRIO and my coprocessor, mostly, but to also allow me to tap into the datastream from a remote computer!

I have been searching in Google and CD for a while and I am only coming across solutions for Java SE and above!
Have a good day
  #2   Spotlight this post!  
Unread 27-08-2014, 21:27
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,835
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: FRC Java TCP client

Well, it doesn't help right now... but in our Alpha and Beta testing of the new control system, the RoboRio uses full Java 8 SE. So, if you're looking to create something that could possibly be used in the future, you can work with the full SE and get it working on the RoboRio when your team gets one.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
  #3   Spotlight this post!  
Unread 27-08-2014, 21:37
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: FRC Java TCP client

That really doesn't help too much, though. There is a chance that the Java SE might not be released in time. While that unfortunate chance is quite slim, I want to get started now. I want to get myself in a position in which I can calculate all the info I want on a separate computer with a lot of power, and send back the data to the cRIO. I guess that if I cannot get a network interface started, I might need to use a Raspberry Pi to convert these requests into a serial interface so I can use the serial I/O in the cRIO.

I would rather tend to avoid that method because it means that I will need to add another step in the data transfer, which will make the system prone to lag. With the level of AI I have planned, I need to do whatever I can to reduce lag! . Thanks for your answer, and I hope I can get this sorted out sometime soon!
  #4   Spotlight this post!  
Unread 27-08-2014, 21:56
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 544
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: FRC Java TCP client

Quote:
Originally Posted by yash101 View Post
With the level of AI I have planned, I need to do whatever I can to reduce lag! .
Keep in mind that sending packets is a <sarcasm>bit</sarcasm> easier than writing AI scripts...

Also, remember the golden rule of efficiency, write the code first then determine if you have an issue. A thought-based AI will have no problem from the added delay by having a hardwired pie.

Also, I hope this is a stupid question but have you looked into NetworkTables?

Last edited by Arhowk : 27-08-2014 at 22:01.
  #5   Spotlight this post!  
Unread 27-08-2014, 22:04
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: FRC Java TCP client

Quote:
Originally Posted by Arhowk View Post
Keep in mind that sending packets is a <sarcasm>bit</sarcasm> easier than writing AI scripts...

Also, remember the golden rule of efficiency, write the code first then determine if you have an issue. A thought-based AI will have no problem from the added delay by having a hardwired pie.

As far as the actual question is concerned, do you have to use TCP? The only class I know of in Java 5 would be DatagramSocket which sends UDP.
I am using a library to make socket programming extremely easy. However, the easiest to implement protocol that it supports is TCP. Also, I want a constant bi-directional data transfer. I basically want to have some request system, where the cRIO can request some data from the coprocessor, and vice-versa. This would also allow me to use the same socket server to send data to a UI, etc.

UDP is my last choice. For some basic path-planning, I will need to ensure that all the requests complete in a structured order!

I guess that if I can implement NetworkTables on the coprocessor, that would make things extremely simple! However, I don't think NetTables were built to be as portable as I want them to be!
  #6   Spotlight this post!  
Unread 27-08-2014, 22:07
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 544
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: FRC Java TCP client

Quote:
Originally Posted by yash101 View Post
I am using a library to make socket programming extremely easy. However, the easiest to implement protocol that it supports is TCP. Also, I want a constant bi-directional data transfer. I basically want to have some request system, where the cRIO can request some data from the coprocessor, and vice-versa. This would also allow me to use the same socket server to send data to a UI, etc.

UDP is my last choice. For some basic path-planning, I will need to ensure that all the requests complete in a structured order!

I guess that if I can implement NetworkTables on the coprocessor, that would make things extremely simple! However, I don't think NetTables were built to be as portable as I want them to be!

What dont you understand about the Packet class?

write data to the PacketOutputStream and send it to the server..

found this in the SocketConnection class (which seems to be the well documented class around packets and sockets)

Code:
 SocketConnection sc = (SocketConnection)
 Connector.open("socket://host.com:79");
 sc.setSocketOption(SocketConnection.LINGER, 5);

 InputStream is = sc.openInputStream(); OutputStream os =
 sc.openOutputStream();

 os.write("\r\n".getBytes()); int ch = 0; while(ch != -1) { ch = is.read(); }

 is.close(); os.close(); sc.close();

Last edited by Arhowk : 27-08-2014 at 22:09.
  #7   Spotlight this post!  
Unread 27-08-2014, 22:21
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: FRC Java TCP client

Yes, but I can't use that in FRC Java. It is in java.net, which is not present on the cRIO Java!
My main purpose of this thread is to find solutions that work in the current Java ME environment that the cRIOs run!

Last edited by yash101 : 27-08-2014 at 22:26.
  #8   Spotlight this post!  
Unread 27-08-2014, 22:29
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 544
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: FRC Java TCP client

Quote:
Originally Posted by yash101 View Post
Yes, but I can't use that in FRC Java. It is in java.net, which is not present on the cRIO Java!
My main purpose of this thread is to find solutions that work in the current Java ME environment that the cRIOs run!
According to the javadocs it's in javax.microedition.io.

E/ please fact check >.> just pasted that into my 2013 bot code and it worked fine (except for an uncaught exception)

Last edited by Arhowk : 27-08-2014 at 22:31.
  #9   Spotlight this post!  
Unread 27-08-2014, 22:31
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: FRC Java TCP client

That was exactly what I was looking for. Now, I need to figure out how to implement it!
  #10   Spotlight this post!  
Unread 27-08-2014, 22:40
SteveGarward's Avatar
SteveGarward SteveGarward is offline
Red 5, standing by...
AKA: 7 years already
FRC #0111 (WildStang), FRC #3132 (Thunder Down Under)
Team Role: Mentor
 
Join Date: Dec 2009
Rookie Year: 2010
Location: Gurnee, IL
Posts: 173
SteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud ofSteveGarward has much to be proud of
Re: FRC Java TCP client

One of the best places to start is still the Java Tutorial. Here's the page on socket programming:
http://docs.oracle.com/javase/tutori...rking/sockets/
__________________
FRC Team 111 - WildStang (Mentor, Drive Coach)
FTC Team 7458 - Full Force! (Mentor, Coach)
FRC Team 3132 - Australia's FIRST FRC Team! (Holy crazy first year, Batman!)

  #11   Spotlight this post!  
Unread 27-08-2014, 23:34
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,835
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: FRC Java TCP client

Quote:
Originally Posted by yash101 View Post
That really doesn't help too much, though. There is a chance that the Java SE might not be released in time. While that unfortunate chance is quite slim, I want to get started now. I want to get myself in a position in which I can calculate all the info I want on a separate computer with a lot of power, and send back the data to the cRIO. I guess that if I cannot get a network interface started, I might need to use a Raspberry Pi to convert these requests into a serial interface so I can use the serial I/O in the cRIO.

I would rather tend to avoid that method because it means that I will need to add another step in the data transfer, which will make the system prone to lag. With the level of AI I have planned, I need to do whatever I can to reduce lag! . Thanks for your answer, and I hope I can get this sorted out sometime soon!
In time for what? While nothing is official until the season starts, Alpha teams have been using Java SE on the RoboRio successfully since last fall, and they didn't make any changes when they moved into Beta... I'd say you'd be pretty safe moving forward with that path - just mock out the RoboRio part on another computer for now.

When I'm working on a project at work, I seldom have a production-equivalent environment I can do my development on. We set things up so we can do development where we need to do development, then deploy to system environments (scaled down production hardware), and eventually to something that is actually production equivalent and then production. Is it possible to adopt a similar approach here? It'll save you a lot of headaches in the long run, as you can do development and some amount of testing without needing to monopolize time on the robot (or last years bot or practice bot or whatever). That time with the robot can probably be better spent with driver practice or build improvements.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
  #12   Spotlight this post!  
Unread 28-08-2014, 14:14
orangelight's Avatar
orangelight orangelight is offline
Registered User
AKA: Alex
FRC #0548 (Robostangs)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Northville
Posts: 168
orangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to beholdorangelight is a splendid one to behold
Re: FRC Java TCP client

I am making one for my team here
https://github.com/orangelight/Robos...ation-Protocol
__________________


  #13   Spotlight this post!  
Unread 28-08-2014, 20:42
NotInControl NotInControl is offline
Controls Engineer
AKA: Kevin
FRC #2168 (Aluminum Falcons)
Team Role: Engineer
 
Join Date: Oct 2011
Rookie Year: 2004
Location: Groton, CT
Posts: 261
NotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond reputeNotInControl has a reputation beyond repute
Re: FRC Java TCP client

You can definitely use streams on the Java cRIO. We have been using TCP for years on our robot.

Here is some code to help you get started

Code:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.ServerSocketConnection;
import javax.microedition.io.StreamConnection;
import org.team2168.utils.Util;


private int port;
private String messageOut;


private volatile boolean clientConnected;


// A TCP Socket Connection
private ServerSocketConnection conn = null;

// TCP Socket Stream
private StreamConnection sc = null;


// Address Variable
private String addressIn = "socket://:" + port;


// Opens a socket to listen for incoming connections
try{
	try {
		conn = (ServerSocketConnection) Connector
				.open(addressIn);

	} catch (IOException e) {
		e.printStackTrace();
	}

	// wait for a client to connect, this blocks until a connect
	// is made
	System.out.println("Listening on: "
			+ conn.getLocalAddress() + " on port: "
			+ conn.getLocalPort());
	sc = conn.acceptAndOpen();
	System.out.println("Client Connected");

} catch (IOException e) {

}

//To get the input stream
try {
	InputStream is = null;
	is = sc.openInputStream();
}catch (IOException x) {
	x.printStackTrace();
}


//Example to get the output stream
OutputStream os = null;
try {
	os = sc.openOutputStream();

	while (true) {
		//keep sending some message
		messageOut = "Some Message";

		buf = messageOut.getBytes("US_ASCII");

		try {
			os.write(buf);
		} catch (IOException e) {
			// e.printStackTrace();
			System.out.println("Appears Client Closed "
					+ "the Connection");

			// close streams
			os.close();
			sc.close();
			conn.close();

		}
	}
} catch (IOException e) {
	e.printStackTrace();
}

For 2015: Instead of using ServerSocketConnection and SocketConnection, just use ServerSocket and Socket classes to create TCP streams. It is much simpler to create a server in JavaSE

Here is an example for 2015 roboRio:

Code:
	// A TCP Socket Connection for RoboRio
	private ServerSocket listener = null;

	// TCP Socket Stream connection
	private Socket client = null;

        private int port;


        try {
		listener = new ServerSocket(port);
	} catch (IOException e) {
		e.printStackTrace();
	}

	// wait for a client to connect, this blocks the current thread until a connect
	// is made
	System.out.println("Listening on port: " + listener.getLocalPort());
	client = listener.accept();
        System.out.println("Client Connected");

//For the input stream, try the following:

try {
	DataInputStream is = new DataInputStream(client.getInputStream());
      } catch (IOException e) {
	 e.printStackTrace();
      }


//And for the outputstream try the following

try {
        DataOutputStream os = new DataOutputStream(client.getOutputStream());
     } catch (IOException e) {
         e.printStackTrace();
     }
__________________
Controls Engineer, Team 2168 - The Aluminum Falcons
[2016 Season] - World Championship Controls Award, District Controls Award, 3rd BlueBanner
-World Championship- #45 seed in Quals, World Championship Innovation in Controls Award - Curie
-NE Championship- #26 seed in Quals, winner(195,125,2168)
[2015 Season] - NE Championship Controls Award, 2nd Blue Banner
-NE Championship- #26 seed in Quals, NE Championship Innovation in Controls Award
-MA District Event- #17 seed in Quals, Winner(2168,3718,3146)
[2014 Season] - NE Championship Controls Award & Semi-finalists, District Controls Award, Creativity Award, & Finalists
-NE Championship- #36 seed in Quals, SemiFinalist(228,2168,3525), NE Championship Innovation in Controls Award
-RI District Event- #7 seed in Quals, Finalist(1519,2168,5163), Innovation in Controls Award
-Groton District Event- #9 seed in Quals, QuarterFinalist(2168, 125, 5112), Creativity Award
[2013 Season] - WPI Regional Winner - 1st Blue Banner
  #14   Spotlight this post!  
Unread 29-08-2014, 09:54
JesseK's Avatar
JesseK JesseK is offline
Expert Flybot Crasher
FRC #1885 (ILITE)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 2005
Location: Reston, VA
Posts: 3,722
JesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond reputeJesseK has a reputation beyond repute
Re: FRC Java TCP client

I would say I could help, but our team has used a C++ server on the robot for as long as I can remember - the client on the display was in Java. There are some 'tricks' to getting performance enhancements, but if you're going for full AI then you should focus on that specifically since that is by far the longest lead time to your goal.

I'd also recommend your robot be the server so you can control how often a client attempts re-connects at game time. You get 2-way comms if it's a TCP socket.
  #15   Spotlight this post!  
Unread 30-08-2014, 17:12
gblake's Avatar
gblake gblake is offline
6th Gear Developer; Mentor
AKA: Blake Ross
no team (6th Gear)
Team Role: Mentor
 
Join Date: May 2006
Rookie Year: 2006
Location: Virginia
Posts: 1,942
gblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond reputegblake has a reputation beyond repute
Re: FRC Java TCP client

OBTW,

UDP's is unreliablity only results in lost messages when resource contention exists. I doubt there will be much of that in a well-designed version of a specialized appliance like a co-processor communicating with a robot controller.

To remove the possibility of lost or out-of-order messages, if the other solutions (already posted) hadn't been available, you could implement a simple user-code handshake to ensure reliable, ordered delivery of UDP messages between the two processors.

I know that an efficient off-the-shelf TCP implementation is almost always the proper way to avoid reinventing the wheel; but one shouldn't be scared of reinventing parts of it, if (and only if) necessary.

Ensuring reliable (in the connection-oriented communication sense) and ordered delivery isn't all that hard, and wouldn't add much overhead to an intra-robot comm link.
__________________
Blake Ross, For emailing me, in the verizon.net domain, I am blake
VRC Team Mentor, FTC volunteer, 5th Gear Developer, Husband, Father, Triangle Fraternity Alumnus (ky 76), U Ky BSEE, Tau Beta Pi, Eta Kappa Nu, Kentucky Colonel
Words/phrases I avoid: basis, mitigate, leveraging, transitioning, impact (instead of affect/effect), facilitate, programmatic, problematic, issue (instead of problem), latency (instead of delay), dependency (instead of prerequisite), connectivity, usage & utilize (instead of use), downed, functionality, functional, power on, descore, alumni (instead of alumnus/alumna), the enterprise, methodology, nomenclature, form factor (instead of size or shape), competency, modality, provided(with), provision(ing), irregardless/irrespective, signage, colorized, pulsating, ideate
Closed Thread


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 03:00.

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