Class MechanismTelemetry

java.lang.Object
yams.core.telemetry.MechanismTelemetry

public class MechanismTelemetry extends Object
Mechanism telemetry.

Publishes mechanism state setpoint position/velocity, current mechanism position, loop time, and motor controller data to NetworkTables under the Mechanisms/<name> and Tuning/<name> tables. Data is visible in SmartDashboard, Elastic, and Advantage Scope.

This class is managed internally by mechanism classes such as Arm, Elevator, and FlyWheel. You do not usually construct it directly; instead enable telemetry through the mechanism's configuration object before constructing the mechanism:

Enabling via ArmConfig

ArmConfig armConfig = new ArmConfig()
    .withMotor(new TalonFXConfig(1))
    .withLength(Meters.of(0.5))
    .withMass(Kilograms.of(2.0))
    .withHardLimits(Degrees.of(-10), Degrees.of(90))
    .withTelemetry("Arm", TelemetryVerbosity.HIGH);  // enables MechanismTelemetry

Arm arm = new Arm(armConfig);

Enabling via ElevatorConfig

ElevatorConfig elevatorConfig = new ElevatorConfig()
    .withMotor(new TalonFXConfig(2))
    .withDrumRadius(Inches.of(1.0))
    .withMass(Kilograms.of(4.0))
    .withTelemetry("Elevator", TelemetryVerbosity.HIGH);  // enables MechanismTelemetry

Elevator elevator = new Elevator(elevatorConfig);
  • Constructor Details

    • MechanismTelemetry

      public MechanismTelemetry()
      Create mechanism telemetry, publish it with setupTelemetry(String).
  • Method Details

    • setupLoopTime

      public void setupLoopTime()
      Setup loop time publisher.
    • setupTelemetry

      public void setupTelemetry(String mechanismTelemetryName, SmartMotorController motorController)
      Setup telemetry for the Mechanism and motor controller.
      Parameters:
      mechanismTelemetryName - Mechanism Telemetry Name.
      motorController - SmartMotorController to setup telemetry for.
    • setupTelemetry

      public void setupTelemetry(String mechanismTelemetryName)
      Setup telemetry for the Mechanism and motor controller.
      Parameters:
      mechanismTelemetryName - Mechanism Telemetry Name.
    • setupTelemetry

      public void setupTelemetry(String mechanismTelemetryName, String dataLogName)
      Setup telemetry for the Mechanism, additionally logging every field published through publishDouble(String, String), publishStruct(String, Struct), and publishStructArray(String, Struct) to a WPILib DataLog under the given name.
      Parameters:
      mechanismTelemetryName - Mechanism Telemetry Name.
      dataLogName - DataLog entry name prefix for this mechanism's fields.
    • addMotorController

      public void addMotorController(String subTableName, SmartMotorController motorController)
      Wire an additional SmartMotorController's telemetry into a named child table of this mechanism, without disturbing the mechanism's own data/tuning table references or loop-time publisher.

      Use this for mechanisms driven by more than one SmartMotorController (e.g. a swerve module's drive and azimuth motors, or a differential mechanism's left and right motors) so that every motor shares the single setupTelemetry(String) call and loop timer for the mechanism, instead of each motor re-running setupTelemetry(String, SmartMotorController) and clobbering the previous motor's table/loop-time state.

      Parameters:
      subTableName - Name of the child table to nest this motor's telemetry under, relative to the mechanism's data and tuning tables.
      motorController - SmartMotorController to set up telemetry for.
    • publishDouble

      public DoubleConsumer publishDouble(String key, String unit)
      Publish a mechanism-level double field under this mechanism's data table, and if this mechanism was set up with a DataLog name via setupTelemetry(String, String) to the DataLog as well. For fields tied to a SmartMotorController use setupTelemetry(String, SmartMotorController) or addMotorController(String, SmartMotorController) instead.
      Parameters:
      key - NetworkTables key, relative to this mechanism's data table.
      unit - Unit metadata for the field (consumed by Advantage Scope/Elastic), or null for none.
      Returns:
      DoubleConsumer to push values to.
    • publishStruct

      public <T> Consumer<T> publishStruct(String key, org.wpilib.util.struct.Struct<T> struct)
      Publish a mechanism-level struct field under this mechanism's data table, and if this mechanism was set up with a DataLog name via setupTelemetry(String, String) to the DataLog as well.
      Type Parameters:
      T - Type of the published value.
      Parameters:
      key - NetworkTables key, relative to this mechanism's data table.
      struct - Struct schema for the published type.
      Returns:
      Consumer to push values to.
    • publishStructArray

      public <T> Consumer<T[]> publishStructArray(String key, org.wpilib.util.struct.Struct<T> struct)
      Publish a mechanism-level struct array field under this mechanism's data table, and if this mechanism was set up with a DataLog name via setupTelemetry(String, String) to the DataLog as well.
      Type Parameters:
      T - Type of the published array elements.
      Parameters:
      key - NetworkTables key, relative to this mechanism's data table.
      struct - Struct schema for the published element type.
      Returns:
      Consumer to push values to.
    • getDataTable

      public org.wpilib.networktables.NetworkTable getDataTable()
      Get the telemetry NetworkTable.
      Returns:
      Telemetry NetworkTable.
    • getTuningTable

      public org.wpilib.networktables.NetworkTable getTuningTable()
      Get the tuning NetworkTable.
      Returns:
      Tuning NetworkTable.
    • updateLoopTime

      public void updateLoopTime()
      Update the loop time.