Go to Post Every year, 118 inspires our team to dream for the stars, and land on mars. If 118 wasn't there we wouldn't be off the ground. Think about it every superstar has critics. Keep doing what you do 118. - xSAWxBLADEx [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 24-01-2012, 23:48
Sunstroke Sunstroke is offline
Programmer
AKA: Joe Grinstead
FRC #3504 (Girls of Steel)
Team Role: Mentor
 
Join Date: Apr 2009
Rookie Year: 2009
Location: New England
Posts: 49
Sunstroke is an unknown quantity at this point
Communication code between robot and computer provided by WPI

Hello Everyone,

There are a lot of people trying to figure out how to do TCP or UDP connections between the robot and a random computer. WPI has already provided the tools to do this, in the form of "NetworkTables". While the robot has NetworkTable code in C++ and Java, the computer version has only been written in Java. In fact, NetworkTable is what the SmartDashboard uses to communicate with the robot (which is why it can both read data and write data).

Do you know about hash tables? The NetworkTable is a hash table shared between the robot and any other computer (even multiple computers at the same time). Both the robot and the computers can write to the table, and the change will be sent to everyone that is connected.

Let's say that you wanted to process images on some other computer, and wanted to send data back for the x and y values. You start by coming up with a name for your table, we could call it something clear like "camera".

Then on the computer, put the NetworkTable.jar jar in your project (you can download the project from the SmartDashboard project, or you can use the .jar in C:\\Program Files\SmartDashboard\lib if you installed the SmartDashboard using the installer).

The computer code is very simple. To start, you need to put the line:
Code:
NetworkTable.setTeam(3504); // <-- put your own team number here
Then, when you want to send data, you can do this:
Code:
NetworkTable.getTable("camera").putInt("x", 50);
NetworkTable.getTable("camera").putInt("y", 60);
and that's all the network code you need for the computer! It will automatically link up with the robot, sync the data, and reconnect if the robot goes down.

For the robot, you don't need to specify your team number, just use:
Code:
NetworkTable.getTable("camera").getInt("x", 0);  // <-- the second number is the default value you want if their is no number there already
NetworkTable.getTable("camera").getInt("y", 0);
 


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 23:22.

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