Hello,
So my team is planning on using Vision Processing this year to help with the shooter, and a precursory step to this is manipulating Network Tables. Today I was working on a basic example between the RoboRIO (C++) and a Java Client on a Mac (Java). The basic scenario is that the roboRio creates a network table (Net) and posts to it the variable Test with the value of 10. The client program then connects to the RoboRIO, and attempts to read the Net/Test value from the RoboRIO. However, the client fails to read the value from the network table and I am not sure why as both programs have repeatedly been dumbed down until there is hardly anything left. Any advice/suggestions would be much appreciated.
Thanks a bunch,
Henry
Here are the logistics:
Setup:
- C++ Iterative Robot Code
- Java Client Program on Mac
- Links to the jar discussed in the screensteps tutorial
Result:
-
Server (RoboRIO Code) seems to run fine. The Network Table (Net) and it’s value for Test are displayed in the variables tab of the SmartDashboard.
-
Client (Java - Mac) does not run as hoped. The code cannot find the Net/Test value and thus returns -1. Meanwhile, the SmartDashboard Console is spammed with NT: server: client CONNECTED: 10.51.4.198 port 5**** with ever-increasing port numbers.
-
On the Client Side, the lines of “Test: -1” are split up by alternate outputs of…
edu.wpi.first.wpilibj.networktables2.client.ClientConnectionAdapter@b4c966a entered connection state: DISCONNECTED_FROM_SERVERand
edu.wpi.first.wpilibj.networktables2.client.ClientConnectionAdapter@b4c966a entered connection state: CONNECTED_TO_SERVER
- Disabling the robot continues these console outputs until the client program is terminated.
Below, I have stripped the programs down to the basics, eliminating extraneous print statements and empty functions. As there is so little code, I can’t imagine what is going wrong?
Server Code: (The Relevant Stuff)
#include “WPILib.h”
#include “NetworkTables/NetworkTable.h”
class Robot: public IterativeRobot {
public:
// Network Table Test
std::shared_ptr<NetworkTable> table;
Robot():
{
table = NetworkTable::GetTable("Net");
}
private:
void TeleopPeriodic(){
table->PutNumber("Test",10);
}
};
START_ROBOT_CLASS(Robot)
Client Code: (The Relevant Stuff)
import edu.wpi.first.wpilibj.networktables.NetworkTable;
public class Client {
public static void main(String] arg){
NetworkTable.setClientMode();
NetworkTable.setIPAddress("10.51.4.105");
NetworkTable table = NetworkTable.getTable("Net");
while (true){
double test = table.getNumber("Test", -1);
System.out.printf("Test: %f
",test);
}
}
}