Log in

View Full Version : Send Variables to Other Programs Besides SDB


Technologyman00
31-08-2016, 22:05
Is there anyway to send variables to another program besides Smart Dashboard or at least read off of smart dashboard with another program on the PC?

Thanks, Collin

414cnewq
31-08-2016, 22:07
You can create a socket within a roborio program and then you can write a client program listening to that socket and responding based on the data.
(Edit: Gross Oversimplification. I am no networking expert, someone else on this forum could help you substantially better with this than I can)

SndMndBdy
01-09-2016, 07:37
On team 3419, we've done what 414cnewq is suggesting (talk via a custom socket between the roboRIO and a program running on the laptop). Unless you're an experienced networking programmer, it can be a quite a bit tricky. That being said, if you want to learn about the low level details of how computers communicate with each other in the "real world", this is a great educational exercise. It's also a good approach if you need to do something very with very low-latency, like having a USB camera on the roboRIO and processing the images on the laptop.

If you want a simpler approach, you can use the NetworkTables. This is how the roboRIO and SmartDashboard talk to each other, and you can write code that acts like the SmartDashboard to read the data. Here's a java example:

-Import NetworkTables.jar (the location changes from year to year. last year it was C:\Users\<USERNAME>\wpilib\java\current\lib). You may also need to include SmartDashboard.jar but I don't think so.
-Create a NetworkTable member variable:


private NetworkTable mNetworkTable;

-Initialize it at startup. I forget if the first two lines here are necessary. I think they are in general, but might not be if you are running in the context of the smartdashboard (like a custom widget)

NetworkTable.setIPAddress("roborio-3419-frc.local");
NetworkTable.setClientMode();

mNetworkTable = NetworkTable.getTable("SmartDashboard");

-To read data out of it, use a line like this:

mNetworkTable.getNumber("SomeVariableThatYouSetOnTheRIO", aDefaultInCaseItHasntBeenSet);

There is also a .NET implementation of NetworkTables ( https://github.com/robotdotnet/NetworkTablesDotNet ). The similar lines of code in C# are:

Declare it:
private NetworkTables.NetworkTable mSmartDashboardTable;


Initialize it:
NetworkTable.SetIPAddress("roborio-3419-frc.local");
//Set Client Mode
NetworkTable.SetClientMode();
//Initialize the client
NetworkTable.Initialize();
mSmartDashboardTable = NetworkTable.GetTable("SmartDashboard");

Use it:
mSmartDashboardTable.GetNumber("SomeVariable", theDefault);


I think there is a C++ implementation as well.

Hope this helps.

adciv
01-09-2016, 08:13
I think there is a C++ implementation as well.

There's also a LabView implementation. I think using network tables is the recommended solution 99% of the time. The 1% comes down to high performance (lower latency) requirements.

virtuald
01-09-2016, 16:45
You can write a dashboard in HTML/Javascript that communicates via NetworkTables too.

https://github.com/robotpy/pynetworktables2js

euhlmann
01-09-2016, 17:05
The official repo is at https://github.com/wpilibsuite/ntcore
Building it will give you "desktop" versions of ntcore.lib and ntcore-windows.jar that you can use.
Documentation for NetworkTable is included in the standard wpilibc/j docs

(I've also started bindings for ntcore to node.js (https://github.com/erikuhlmann/ntcore_node), if anybody's interested)