Skip to content

Make our units' versions of WPI classes loggable #6

@00magikarp

Description

@00magikarp

Some WPILib classes can be passed in as a parameter to Logger.recordOutput(...) since they implement the StructSerializable interface.

  /**
   * Records a single output field for easy access when viewing the log. On the simulator, use this
   * method to record extra data based on the original inputs.
   *
   * <p>This method serializes an array of objects as a struct automatically. Top-level protobuf
   * arrays are not supported.
   *
   * <p>This method is <b>not thread-safe</b> and should only be called from the main thread. Check
   * the <a href=
   * "https://docs.advantagekit.org/getting-started/common-issues/multithreading">documentation</a>
   * for details.
   *
   * @param <T> The object type.
   * @param key The name of the field to record. It will be stored under "/RealOutputs" or
   *     "/ReplayOutputs"
   * @param value The value of the field.
   */
  @SuppressWarnings("unchecked")
  public static <T extends StructSerializable> void recordOutput(String key, T... value) {
    if (running) {
      outputTable.put(key, value);
    }
  }

Proof

Implement these interfaces on our own classes that are meant to mirror the WPILib classes, like our Pose2d and Transform3d, so that they can be logged without fetching the wpilib object, if possible. Yes I don't know if this is possible.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions