Class StructTelemetry<T,F>
java.lang.Object
yams.core.telemetry.StructTelemetry<T,F>
- Type Parameters:
T- Type of the value being published, must beStructserializable.F- Enum type identifying which field this telemetry entry represents.
Struct Telemetry for arbitrary
Struct serializable types.
A lightweight wrapper that publishes a single struct-encoded value (e.g. Pose2d,
ChassisSpeeds, SwerveModuleState) to NetworkTables and/or a WPILib DataLog. It
mirrors DoubleTelemetry and BooleanTelemetry, but is generic over the value
type T and requires a Struct implementation to (de)serialize it.
Example
// Create and publish a struct entry for the robot pose under the Drivetrain table.
StructTelemetry<Pose2d> pose = new StructTelemetry<>(
"pose", // NetworkTables key
new Pose2d(), // default value
Pose2d.struct, // struct serializer
false); // not tunable
NetworkTable driveTable = NetworkTableInstance.getDefault().getTable("Drivetrain");
pose.enable();
pose.setupNetworkTable(driveTable);
// In periodic:
pose.set(drivetrain.getPose());
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStructTelemetry(String keyString, T defaultVal, F field, org.wpilib.util.struct.Struct<T> struct, boolean tunable) Setup struct telemetry for a field. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the telemetry field.voiddisable()Disable the telemetry.voiddisplay(boolean state) Display the telemetry.voidenable()Enable the telemetry.get()Get the value.getField()Get the field.booleanSet the value of the publisher, checking to see if the value is the same as the subscriber.voidsetDefaultValue(T defaultValue) Set default values.voidsetupDataLog(String prefix) Setup theDataLogwith this entry.voidsetupNetworkTable(org.wpilib.networktables.NetworkTable dataTable) Setup network tables.voidsetupNetworkTables(org.wpilib.networktables.NetworkTable dataTable, org.wpilib.networktables.NetworkTable tuningTable) Setup network tables.booleantunable()Check to see if the value has changed.
-
Field Details
-
enabled
protected boolean enabledEnabled?
-
-
Constructor Details
-
StructTelemetry
public StructTelemetry(String keyString, T defaultVal, F field, org.wpilib.util.struct.Struct<T> struct, boolean tunable) Setup struct telemetry for a field.- Parameters:
keyString- Key to use.defaultVal- Default value.field- Field representing.struct-Structserializer forT.tunable- Tunable.
-
-
Method Details
-
setDefaultValue
Set default values.- Parameters:
defaultValue- Default for the entry.
-
setupNetworkTables
public void setupNetworkTables(org.wpilib.networktables.NetworkTable dataTable, org.wpilib.networktables.NetworkTable tuningTable) Setup network tables.- Parameters:
dataTable- Data tables.tuningTable- Tuning table.
-
setupDataLog
Setup theDataLogwith this entry.- Parameters:
prefix- The prefix to this entry inDataLog
-
setupNetworkTable
public void setupNetworkTable(org.wpilib.networktables.NetworkTable dataTable) Setup network tables.- Parameters:
dataTable- Data tables.
-
set
Set the value of the publisher, checking to see if the value is the same as the subscriber.- Parameters:
value- Value to set.- Returns:
- True if value was able to be set.
-
get
Get the value.- Returns:
- value of telemetry.
- Throws:
RuntimeException- if the telemetry is enabled and this field is not tunable, so no tuning subscriber exists.RuntimeException- if the telemetry is enabled andsetupNetworkTables(NetworkTable, NetworkTable)was not called with a non-null tuning table, so no tuning subscriber exists.
-
tunable
public boolean tunable()Check to see if the value has changed.- Returns:
- True if the value has changed.
-
enable
public void enable()Enable the telemetry. -
disable
public void disable()Disable the telemetry. -
display
public void display(boolean state) Display the telemetry.- Parameters:
state- Enable or disable.
-
close
public void close()Close the telemetry field. -
getField
-