Class BuildConstantsPublisher
The "build constants" are metadata related to the state of the code at the time it was built, e.g, git branch, git commit, build time, etc. This information can be very valuable when troubleshooting issues with the live code of the robot.
BuildConstantsPublisher receives this information from a specially built (as explained below)
BuildConstants class at build time. It provides an interface to publish it to NetworkTables
(publish(NetworkTableInstance)) or print it to the robot console (log()) - at
runtime. Build constants need to be published only once, typically during robot initialization.
The constants are published under the "/Metadata" table in NetworkTables. This is a
special NetworkTables table. Some tools have special support for the "/Metadata" table. For
instance, Advantage Scope has a dedicated Metadata tab that loads information like Build
Constants in a well formated table view.
To instantiate a BuildConstantsPublisher, a build constants class, BuildConstants, is
needs to be generated for the robot library by enabling the `gversion` plugin in the gradle build
file. Instructions can be found in
the WPILib documentation.
With the BuildConstants generation enabled, the publisher is initialized and used like this:
BuildConstantsPublisher buildConstantsPublisher(frc.robot.BuildConstants.class);
// Publish the build constants to "/Metadata" on the NetworkTables
buildConstantsPublisher.publish(NetworkTableInstance.getDefault());
// Log the build constants in the robot console as well.
buildConstantsPublisher.log();
- Since:
- 2.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the NetworkTable under which the build constants are published. -
Constructor Summary
ConstructorsConstructorDescriptionBuildConstantsPublisher(Class<?> buildConstantsClass) Constructs a BuildConstantsPublisher. -
Method Summary
Modifier and TypeMethodDescriptionGets the build constants extracted from the publisher.voidlog()Logs the build constants to the console.voidpublish(NetworkTableInstance ntInstance) Publishes the build constants to NetworkTables.
-
Field Details
-
METADATA_TABLE_NAME
The name of the NetworkTable under which the build constants are published.- See Also:
-
-
Constructor Details
-
BuildConstantsPublisher
Constructs a BuildConstantsPublisher.This constructor creates publishers for each build constant and publishes them to the provided network table instance.
- Parameters:
buildConstantsClass- Specially built class that contains the robot code built-time constants. See class description for instructions on how to generate the class.
-
-
Method Details
-
buildConstants
Gets the build constants extracted from the publisher. -
publish
Publishes the build constants to NetworkTables.This is typically called once during robot initialization.
- Parameters:
ntInstance- The top-level NetworkTable instance under whose "/Metadata" table the build constants are published.
-
log
public void log()Logs the build constants to the console.
-