-
Notifications
You must be signed in to change notification settings - Fork 0
Network Tables
We're dealing with a distributed system:
- RoboRIO - Runs the robot code
- Laptop - Dashboard or similar display
- Raspberry Pi - Optionally, another computer that processes video
How can we display information from the RoboRIO on the laptop?
How can we send some information, for example a desired lift position, from the laptop to the RoboRIO?
How can the Pi send information to the RoboRIO or the laptop, for example suggestions where to go?
A NetworkTable
is a table on the network where you can put named items, for example:
Name | Value |
---|---|
"DesiredPosition" | 10.0 |
"ActualPosition" | 9.99 |
Happy | true |
"BatteryVoltage" | 12.87 |
Technically, a "server", by default the RoboRIO, holds the actual network table, and sends a copy to all "clients". When the robot code changes the table, the RoboRIO sends an updated table to all clients. When one client changes the table, it sends the changes to the server, which then sends that to all the other clients.
FRC actually supports a hierarchical network table, i.e. one big table can have multiple sub-tables.
One is named "SmartDashboard". We tend to only interact with the SmartDashboard section of the network tables because every item placed in this section is automatically displayed on the Laptop's dashboard ("Smart Dashboard", "Shuffleboard", ...).
The Outline Viewer displays the complete network table, i.e. the "SmartDashboard" sub-table as well as all the other items.
The Outline Viewer can be started from the VS Code "WPILib: Start Tool" command. In its opening dialog, you would typically pick
- Server Mode: Off
- Server Location: IP of RoboRIO
- Default Port: On
When running only a Raspberry Pi in standalone mode, and the Pi acts as a network table server, enter the IP of the Pi.
On the RoboRIO, we need to do nothing, it's automatically the network tables server.
On the Raspberry Pi, we typically connect as a client to the network tables served by the RoboRIO:
int team = 2393;
NetworkTableInstance.getDefault().startClientTeam(team);
When we run the Pi standalone, without a RIO, it can be the server:
NetworkTableInstance.getDefault().startServer();
To publish a number on the SmartDashboard:
SmartDashboard.putNumber("ActualPosition", 9.99);
SmartDashboard.putBoolean("Happy", true);
To publish some value that we can then change on the dashboard:
// In robotInit(), place the setting with initial value on the dashboard
SmartDashboard.setDefaultNumber("DesiredPosition", 10.0);
Later in the robot code, we can than use that number, which we may adjust on the laptop's dashboard:
// In some xxxPeriodic() method, get the latest value
double desired = SmartDashboard.getNumber("DesiredPosition", 10.0);
// Do something with it, for example compute PID:
double error = desired - actual;
...