Class StructArrayTelemetry<T,F>
java.lang.Object
yams.core.telemetry.StructArrayTelemetry<T,F>
- Type Parameters:
T- Type of the array elements being published, must beStructserializable.F- Enum type identifying which field this telemetry entry represents.
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 -
Constructor Summary
ConstructorsConstructorDescriptionStructArrayTelemetry(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 TypeMethodDescriptionvoidclose()Close the telemetry field.voiddisable()Disable the telemetry.voiddisplay(boolean state) Display the telemetry.voidenable()Enable the telemetry.T[]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
-
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-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
-