Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   We got Sockets working (http://www.chiefdelphi.com/forums/showthread.php?t=100675)

sand500 19-01-2012 20:42

We got Sockets working
 
http://www.youtube.com/watch?v=N0xvqxRKCKg

What we have is the computer with the driver station has the PS3 controller connected to it. We then get input from the left stick of the joystick to the CRIO with the regular Joystick Class. Now to send that to the 2nd computer, we use java sockets with the CRIO running the socket server code and the computer running the client socket code. So far, we are just experimenting with sockets with last years robot.

Patrickwhite 19-01-2012 20:51

Re: We got Sockets working
 
Neat!

Your custom dashboard looks a lot like the Smart Dashboard - for what reasons did you decide to make your own, instead of using the Smart Dashboard?

neal 19-01-2012 21:10

Re: We got Sockets working
 
Is that possible to do with SmartDashboard? I'd really love to get those bars for joysticks and the Gyro thing as well!

theNerd 19-01-2012 21:17

Re: We got Sockets working
 
Wow. I've been trying to lean how to do that in LabView. Since I switched over to java I still wonder how to do that. Could you explain in detail how you got the comms to work?

Patrickwhite 19-01-2012 21:17

Re: We got Sockets working
 
Absolutely that's possible with the SmartDashboard.

The SmartDashboard package is edu.wpi.first.wpilibj.smartdashboard.

Data sent has a name and a value. The name is used to tie a set of values to a certain widget - if you send "Heading" as 90, then set up a widget to listen to that key, then subsequent sendings of "Heading" will go straight to that widget.

You can send booleans, ints, doubles, and Strings, as well as any class that implements SmartDashboardData. You can even make your own SmartDashboardData-implementing class, though doing so is a bit complicated.

You can make your own widget to display data received any way you like.

neal 19-01-2012 21:22

Re: We got Sockets working
 
Quote:

Originally Posted by Patrickwhite (Post 1109386)
Absolutely that's possible with the SmartDashboard.

The SmartDashboard package is edu.wpi.first.wpilibj.smartdashboard.

Data sent has a name and a value. The name is used to tie a set of values to a certain widget - if you send "Heading" as 90, then set up a widget to listen to that key, then subsequent sendings of "Heading" will go straight to that widget.

You can send booleans, ints, doubles, and Strings, as well as any class that implements SmartDashboardData. You can even make your own SmartDashboardData-implementing class, though doing so is a bit complicated.

Oh, cool! I was wondering what putint() and other methods did. But I won't have access to the robot until Saturday. Glad you explained!

How do you make the widgets, though?

Patrickwhite 19-01-2012 22:27

Re: We got Sockets working
 
http://firstforge.wpi.edu/sf/wiki/do...iki/Extensions

Great set of tutorials on how to write a widget.

The SmartDashboard itself can be downloaded from the same project, under File Releases.

sand500 20-01-2012 09:50

Re: We got Sockets working
 
Quote:

Originally Posted by Patrickwhite (Post 1109363)
Neat!

Your custom dashboard looks a lot like the Smart Dashboard - for what reasons did you decide to make your own, instead of using the Smart Dashboard?

Well we are still messing around at this point, but based on how our bot turns out, we will make our Dashboard to fit the bot.

ProgrammerMatt 28-01-2012 19:25

Re: We got Sockets working
 
Mind sharing how to use sockets im trying to send my vision tracking data to our robot with no luck :(

Sunstroke 28-01-2012 20:43

Re: We got Sockets working
 
Quote:

Originally Posted by ProgrammerMatt (Post 1115455)
Mind sharing how to use sockets im trying to send my vision tracking data to our robot with no luck :(

Might I suggest looking at this thread? It takes away all the little obnoxious parts of sockets and does it for you.

ProgrammerMatt 28-01-2012 23:44

Re: We got Sockets working
 
Quote:

Originally Posted by sand500 (Post 1109353)
http://www.youtube.com/watch?v=N0xvqxRKCKg

What we have is the computer with the driver station has the PS3 controller connected to it. We then get input from the left stick of the joystick to the CRIO with the regular Joystick Class. Now to send that to the 2nd computer, we use java sockets with the CRIO running the socket server code and the computer running the client socket code. So far, we are just experimenting with sockets with last years robot.

Could you possibly share this code because of the lack of examples?

Sunstroke 29-01-2012 00:10

Re: We got Sockets working
 
Quote:

Originally Posted by ProgrammerMatt (Post 1115455)
Mind sharing how to use sockets im trying to send my vision tracking data to our robot with no luck :(

I would consider using the code provided by WPI.

ProgrammerMatt 31-01-2012 15:32

Re: We got Sockets working
 
Quote:

Originally Posted by Sunstroke (Post 1115679)
I would consider using the code provided by WPI.

The problem with that is i have a program for vision tracking and it sends out TCP data on its own...

derekwhite 01-02-2012 08:35

Re: We got Sockets working
 
Here's one quick example:

Code:

// connect to “echo” server:
SocketConnection sc = (SocketConnection) Connector.open("socket://host.com:79");
InputStream is = sc.openInputStream();
OutputStream os = sc.openOutputStream();

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


derekwhite 01-02-2012 08:36

Re: We got Sockets working
 
More examples here:

http://developers.sun.com/mobility/m.../midp2network/

ProgrammerMatt 02-02-2012 17:33

Re: We got Sockets working
 
This is more for derek but when i send data to my robot using this code http://pastebin.com/x2KZepNR that i made i get a thread error and null pointer any ideas?
here is error

Code:

[cRIO] Default disabled() method running, consider providing your own
[cRIO] Uncaught exception in Thread.run():
[cRIO]    on thread Thread-6
[cRIO] java.lang.NullPointerException
[cRIO]    at edu.wpi.first.wpilibj.templates.Socket.run(Socket.java:40)
[cRIO]    in virtual method #47 of com.sun.squawk.VMThread(bci=42)
[cRIO]    in static method #3 of com.sun.squawk.VM(bci=6)


derekwhite 03-02-2012 09:38

Re: We got Sockets working
 
That stack trace suggests that the variable "you" is null at line 40. But it looks like that would only happen if acceptAndOpen() throw an exception, and no exception was printed in the output you showed.

An aside about NullPointerExceptions - for how common these are, they can really only be created by:
  • Trying to get or set a field using an object reference that is null:
    thisIsNull.field = 1;
  • Trying to get or set an array element using an object reference that is null:
    thisIsNull[0] = 1;
  • Trying to get the array length using an object reference that is null:
    thisIsNull.length;
  • Trying to call a non-static method on an object reference that is null:
    thisIsNull.toString();
  • Trying to synchronize an object reference that is null:
    synchronize(thisIsNull) ...
  • Throwing a NullPointerException! This is not too common, but some likely cases are:
    System.arraycopy(), Hashtable.contains().
    In Java SE (not on robot), native methods may throw a NullPointerException. It depends on the method.

For now I suggest adding code that explicitly checks for "you" being null or not.

I hope this helps track down the bug.

ProgrammerMatt 03-02-2012 09:51

Re: We got Sockets working
 
Ok i did figure it out and i can recive data but i see a bunch of exceptions being thrown even know i can send and recive data. any idea why?


All times are GMT -5. The time now is 13:02.

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