Class MechanismTelemetry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMotorController(String subTableName, SmartMotorController motorController) Wire an additionalSmartMotorController's telemetry into a named child table of this mechanism, without disturbing the mechanism's own data/tuning table references or loop-time publisher.org.wpilib.networktables.NetworkTableGet the telemetry NetworkTable.org.wpilib.networktables.NetworkTableGet the tuning NetworkTable.publishDouble(String key, String unit) Publish a mechanism-leveldoublefield under this mechanism's data table, and if this mechanism was set up with a DataLog name viasetupTelemetry(String, String)to the DataLog as well.<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 viasetupTelemetry(String, String)to the DataLog as well.<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 viasetupTelemetry(String, String)to the DataLog as well.voidSetup loop time publisher.voidsetupTelemetry(String mechanismTelemetryName) Setup telemetry for the Mechanism and motor controller.voidsetupTelemetry(String mechanismTelemetryName, String dataLogName) Setup telemetry for the Mechanism, additionally logging every field published throughpublishDouble(String, String),publishStruct(String, Struct), andpublishStructArray(String, Struct)to a WPILib DataLog under the given name.voidsetupTelemetry(String mechanismTelemetryName, SmartMotorController motorController) Setup telemetry for the Mechanism and motor controller.voidUpdate the loop time.
-
Constructor Details
-
MechanismTelemetry
public MechanismTelemetry()Create mechanism telemetry, publish it withsetupTelemetry(String).
-
-
Method Details
-
setupLoopTime
public void setupLoopTime()Setup loop time publisher. -
setupTelemetry
Setup telemetry for the Mechanism and motor controller.- Parameters:
mechanismTelemetryName- Mechanism Telemetry Name.motorController-SmartMotorControllerto setup telemetry for.
-
setupTelemetry
Setup telemetry for the Mechanism and motor controller.- Parameters:
mechanismTelemetryName- Mechanism Telemetry Name.
-
setupTelemetry
Setup telemetry for the Mechanism, additionally logging every field published throughpublishDouble(String, String),publishStruct(String, Struct), andpublishStructArray(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
Wire an additionalSmartMotorController'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 singlesetupTelemetry(String)call and loop timer for the mechanism, instead of each motor re-runningsetupTelemetry(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-SmartMotorControllerto set up telemetry for.
-
publishDouble
Publish a mechanism-leveldoublefield under this mechanism's data table, and if this mechanism was set up with a DataLog name viasetupTelemetry(String, String)to the DataLog as well. For fields tied to aSmartMotorControllerusesetupTelemetry(String, SmartMotorController)oraddMotorController(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), ornullfor none.- Returns:
DoubleConsumerto push values to.
-
publishStruct
Publish a mechanism-level struct field under this mechanism's data table, and if this mechanism was set up with a DataLog name viasetupTelemetry(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-Structschema for the published type.- Returns:
Consumerto push values to.
-
publishStructArray
Publish a mechanism-level struct array field under this mechanism's data table, and if this mechanism was set up with a DataLog name viasetupTelemetry(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-Structschema for the published element type.- Returns:
Consumerto 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.
-