Class StructTelemetry<T,F>

java.lang.Object
yams.core.telemetry.StructTelemetry<T,F>
Type Parameters:
T - Type of the value being published, must be Struct serializable.
F - Enum type identifying which field this telemetry entry represents.

public class StructTelemetry<T,F> extends Object
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
    Modifier and Type
    Field
    Description
    protected boolean
    Enabled?
  • Constructor Summary

    Constructors
    Constructor
    Description
    StructTelemetry(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 Type
    Method
    Description
    void
    Close the telemetry field.
    void
    Disable the telemetry.
    void
    display(boolean state)
    Display the telemetry.
    void
    Enable the telemetry.
    get()
    Get the value.
    Get the field.
    boolean
    set(T value)
    Set the value of the publisher, checking to see if the value is the same as the subscriber.
    void
    setDefaultValue(T defaultValue)
    Set default values.
    void
    Setup the DataLog with this entry.
    void
    setupNetworkTable(org.wpilib.networktables.NetworkTable dataTable)
    Setup network tables.
    void
    setupNetworkTables(org.wpilib.networktables.NetworkTable dataTable, org.wpilib.networktables.NetworkTable tuningTable)
    Setup network tables.
    boolean
    Check to see if the value has changed.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • enabled

      protected boolean enabled
      Enabled?
  • 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 - Struct serializer for T.
      tunable - Tunable.
  • Method Details

    • setDefaultValue

      public void setDefaultValue(T defaultValue)
      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

      public void setupDataLog(String prefix)
      Setup the DataLog with this entry.
      Parameters:
      prefix - The prefix to this entry in DataLog
    • setupNetworkTable

      public void setupNetworkTable(org.wpilib.networktables.NetworkTable dataTable)
      Setup network tables.
      Parameters:
      dataTable - Data tables.
    • set

      public boolean set(T value)
      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

      public T 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 and setupNetworkTables(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

      public F getField()
      Get the field.
      Returns:
      field.