I’m a software mentor with a procedural programming background. I have minimal experience with Object Oriented design and I don’t know Java. I’m doing my best reading the docs and trying to follow the examples. I’ve run into many things I don’t understand. Here’s one of them.
In the GearsBot example code I would like to understand how the data on the SmartDashboard is updated. I can see that RobotContainer is called once and only once when instantiated in RobotInit. But in RobotContainer I see lines of code such as:
SmartDashboard.putData(m_claw);
m_wrist.log();
which look like they should be run periodically in order to update the dashboard during runtime. But I can’t figure out how this would happen.
I’m new, too, but from what I understand from tinkering is that whatever m_claw is i.e. number ,string… That will be put into the Smart dashboard. We are using . putNumber to track our Driver’s X and Y axis. This is just a guess since I haven’t looked into it but I would assume .log will put whatever the literall is inside of the variable to the driver station console. Take that with a grain of salt, though.
You don’t have to update SmartDashboard or Shuffleboard because they are automatically updated in BaseIterativeRobot or something similar(that name my not be correct).
For Sendables put on the dashboard with putData() like Subsystem, Command, and other Objects that is probably correct, but I do not believe that to be the case with putNumber(), putBoolean() and the like that put primitive type values.
Perhaps if we were sending a lambda function or something, but otherwise, we are sending a single immutable value unless something behind the scenes is regularly calling the log() method of the subsystems that I cannot find.
So putData accepts a Sendable implementation, which just has an initSendable method that takes a SendableBuilder that the Sendable uses associate getter and setter properties with the sendable. When the Sendable is put on the smartdashboard, its added to the SendableRegistry which saves the getters and setters as suppliers and consumers that periodically calls them to get and update the values to/from the driverstation (how does it do that? Something about SendableBuilderImpl and a hashmap of “components” but that’s not important idk I definitely did not spend hours looking at the source for no reason). Basically it’s saving a reference of whatever methods you specify in the Sendable and calling them every periodically.
The Sendable system makes it really easy for a programmer to add values to the LiveWindow. just implement Sendable and add properties to the SendableBuilder in initSendable. Then just add the Sendable to the SendableRegistry and viola! I believe the pid classes do this, the base wpilib speedcontroller classes do this, and the subsystems do this (they basically just display the current command running on that subsystem afaik. I could be wrong. All of this could be wrong.)
As already described in a bit of detail, whether or not SmartDashboard updates is based on the data that is on the SmartDashboard. There are many very useful ways to use Shuffleboard/SmartDashboard, especially during the build season. One of which, is viewing the commands and subsystems that are being tested. Other ways are to plot things like motor current, encoder values, gyro headings, etc.
Things that implement Sendable (Commands and Subsystems) will automatically update their SmartDashboard status. Primitives (doubles, ints, etc) need to be manually updated.
If you’re using Command-Based programming in the new framework, you can use the Subsystem’s periodic() method to repeatedly put the numbers (or strings) you want updated.
Thanks for all the responses. I appreciate that. Has anyone found any documentation which describes this behavior? I like to point students to actual written documentation rather than just saying it’s “tribal knowledge”.