Network Tables c++ Roborio Crash on PutNumber()

Our team is learning to use the Network Table library this year to handle transferring data from our co-processor to the roborio. We are running into an issue getting the network tables to actually work on the roborio.

We have gotten the network table setup on both systems. The Raspberry Pi using the python library: pynetworktables appears to be detecting the network table by returning a “true” with the NetworkTables.isConnected() command when the rio is on. To me this makes it seem like the rio is properly setting up the server and the pi is putting the values out onto the table.

Our issue comes when we try to implement a PutNumber() or GetNumber() on the roborio. when we attempt to do either GutNumber() or PutNumber() the roborio immediately crashes on enable, and disables then restarts the robot code. Does anyone have any idea what is going on here?

i have attached the network table code portions that we are trying to use below (i left out the code that deals with joystick commands and driving and only left the code that uses the network table stuff).

For some reason to get the code to build there are a number of things that we needed to add that are not shown in the example codes from the wpilib: 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

All of those changes that we needed to get the code to build and deploy are commented in the code below.


class Robot: public IterativeRobot
{
public:
   
 NetworkTable *table 
robot ():
 table() // not shown on examples from FRC but we get an error without
 {
 myRobot.setExpiration(0.1)
   
 //table = NetworkTable::GetTable("datatable");
 //above code does not work was directed from forums to use:
 //std::shared_ptr<NetworkTable>table = bla>
 std::shared_ptr<NetworkTable>table = NetworkTable::GetTable("datatable")
 }
private:
 void TeleopPeriodic()
 {
//any of the code with PutNumber() or GetNumber() crashes the roborio
//hitting enable instantly disables the robot... 
   double vision = table->GetNumber("X", 0.0);
    if (vision != 0.0){
     table->PutNumber("Y",1234);    
    }
 }
};

Your table pointer is not getting initialized correctly. If you actually debugged like you should be doing (never post on CD if you have not already tried diagnosing the problem fully. And when you do post, include the relevant information about what you found), I expect you’ll find that your program segfaults.

Try this


class Robot: public IterativeRobot {
public:
  std::shared_ptr<NetworkTable> table;
  
  Robot() {
    myRobot.setExpiration(0.1)
    table.reset(NetworkTable::GetTable("datatable"));
  }

private:
  void TeleopPeriodic() {
    double vision = table->GetNumber("X", 0.0);
    if (vision != 0.0){
      table->PutNumber("Y", 1234);    
    }
  }
};