Class StructArrayTelemetry<T,F>

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

public class StructArrayTelemetry<T,F> extends Object
Struct array Telemetry for arbitrary Struct serializable array types.

A lightweight wrapper that publishes a struct-encoded array value (e.g. SwerveModuleState[], SwerveModulePosition[]) to NetworkTables and/or a WPILib DataLog. It mirrors StructTelemetry, but publishes an array of struct-serializable values instead of a single value.

Example

// Create and publish a struct array entry for the current module states.
StructArrayTelemetry<SwerveModuleState, MyField> states = new StructArrayTelemetry<>(
    "states/current",       // NetworkTables key
    new SwerveModuleState[0], // default value
    MyField.CurrentStates,  // field representing
    SwerveModuleState.struct, // struct serializer
    false);                 // not tunable

NetworkTable driveTable = NetworkTableInstance.getDefault().getTable("Drivetrain");
states.enable();
states.setupNetworkTable(driveTable);

// In periodic:
states.set(drivetrain.getModuleStates());
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Enabled?
  • Constructor Summary

    Constructors
    Constructor
    Description
    StructArrayTelemetry(String keyString, T[] defaultVal, F field, org.wpilib.util.struct.Struct<T> struct, boolean tunable)
    Setup struct array 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.
    T[]
    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

    • StructArrayTelemetry

      public StructArrayTelemetry(String keyString, T[] defaultVal, F field, org.wpilib.util.struct.Struct<T> struct, boolean tunable)
      Setup struct array 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.