Log in

View Full Version : C++ Network Tables


IDKnow
03-02-2013, 20:07
I am attempting to use the network tables class to pass values from my SmartDashboard extensions to the robot.

This thread describes the process using Java
http://www.chiefdelphi.com/forums/showthread.php?t=103352
but it seems to imply near the end that the same process will not work for C++

In my code and in the windows API I could find equivalent commands though- for everything other than begin and end transaction.

Without these, the robot crashes as soon an i try TableName->GetNumber("",0);

Am I missing something?


//declarations:
NetworkTable *Vision;
float d;
//initialization
Vision->GetTable("VisionTable");//should create table if does not exist
//control loop (where it crashes)
if (Vision->IsConnected())
{
//Vision->beginTransaction();
d = Vision->GetNumber("d",0);//where 0 is default if "d" does not exist
//Vision->endTransaction();
}

nightpool
04-02-2013, 08:49
Hmm... Normally when interacting with the SmartDashboard one uses the static functions from the SmartDashboard class. Like SmartDashboard::GetNumber("d"), for your example.

As far as I know, the smart dashboard class does not support defaults, because you should initialize variables before you try retrieving them.

virtuald
04-02-2013, 11:07
If you examine the source code for NetworkTables, you will notice that it throws an exception when you do a GetNumber() without first doing a PutNumber() (only the first PutNumber() is required).

They got rid of Begin/End transaction in this year's implementation of NetworkTables, thus why you can't find it. :)

IDKnow
04-02-2013, 21:22
Thanks guys! You're advice and a little trial and error provided me with the fix:

Putting this before the GetTable command keeps the code from crashing.
I haven't tested getting values yet though because I'm having issues with the SmartDashboard. Also, the put function causes a crash but this is progress! : )


NetworkTable::SetIPAddress("10.16.71.20");//driverstation IP
NetworkTable::SetClientMode();
NetworkTable::SetTeam(1671);
NetworkTable::Initialize();

virtuald
05-02-2013, 00:01
Keep in mind that the 'client' is the driver station, and the 'server' is the robot. Also, you should only call SetIPAddress or SetTeam, not both. SetTeam is used to determine the IP address of the robot when in client mode. Read the code. :)

IDKnow
06-02-2013, 00:49
http://wpilib.screenstepslive.com/s/3120/m/7912/l/80205-writing-a-simple-networktables-program-in-c-and-java-with-a-java-client-pc-side

That's helpful. Still having trouble with the client side but I need to make it work a little differently and I'll get to fixing that tomorrow. Thanks again guys!