I have a call to a method that I call from robotInit(). The method reads some data from some text files and then prints the data with println and a call to SmartDashboard.putString(filename, buf) and a call to Shuffleboard.getTab(“Status”).add(filename, buf)
My problem is that the data always prints on the console with the correct information, however if I don’t exit from ShuffleBoard and restart it the data on the SmartDashboard tab sometimes shows old data and the data on the ShuffleBoard Status tab is almost always old data. When old data is displayed the field is usually shown slightly greyed out.
If I delete the Status tab and restart the robot a new Status tab appears but none of the fields appear.
I should mention that most of my testing has been with the Desktop Simulator, but the same behavior was observed when running on the actual robot.
Also I was wondering if there was any way to delete a tab from the robot code? At one point I thought the data was being carried over and the fields weren’t being updated, but I couldn’t find a way to delete a tab. I don’t think deleting the tab would help now, but it seems like an obvious missing piece.
Our time has made several attempts to switch to Shuffleboard over the years, but we have always abandoned it for this reason, the data shown is not reliably what the was sent from the robot.
I just tried restarting Shuffleboard after the robot was running, and the tab still showed old data. Using the outline viewer shows the old data in the Shuffleboard drop down section, but the correct data in the SmartDashboard section. Is it possible that these fields are being set to persistent by default and end up stored on the robot and then get restored to the old value?
You cant just write to a shuffleboard name again to update, you have to use networkTables like this
class VisionCalculator {
private ShuffleboardTab tab = Shuffleboard.getTab(“Vision”);
private NetworkTableEntry distanceEntry =
tab.add(“Distance to target”, 0)
.getEntry();
I am not trying to update a field. I have a class that calls getTab(tabname).add(fieldname,value) just once in robotInit(); The problem is that this information seems to be somewhat persistent, between calls to roboInit() and restarting Shuffleboard.
ShuffleboardTab#add(String, Object) sets the default value in the table and doesn’t overwrite any existing data, which probably explains the behavior you’re seeing. @Phlogiston was right - you’ll need to set the value on the NetworkTableEntry directly to change the value
There’s an open PR wpilibsuite/allwpilib#2340 that changes the behavior of add to more closely match the SmartDashboard API and overwrite existing data. TBD if this change will get in this season (or ever) - I’m mostly retired from WPILib work now
It is confusing with the Shuffleboard about when you can consider the state “clean”. I can use .add to create a field and set its value when called from roboInit(), but if I redeploy code without restarting Shuffleboard then even though I am running different code entirely the field doesn’t get updated. On the other hand, if I restart Shuffleboard the state is read from the robot and I still get the same problem. I suspect that the only safe way to use that idiom is if the robot and the Shuffleboard are both off at the same time, and even then if non of the fields are persistent.
Calling setString(buf) seems to have solved the problem, but the model for when you can and cannot just add a field seems to be lacking documentation at the least. I look forward to seeing #2340 fixed.
The intent of the API is, essentially, to build the layout the way you want and give a handle to the data (in the form of a NetworkTable Entry) at the end of the chain. It’s then up to the programmer to update/read/add callbacks/etc. to that handle; the API is only responsible for building the layout
It’s a different concept from the old SmartDashboard API. But there should probably be carryover to keep the basic stuff simple