[hal] Change usage reporting to string-based (#7763)

This commit is contained in:
Peter Johnson
2025-02-07 12:37:23 -08:00
committed by GitHub
parent bfff891b5c
commit 764ada9b66
188 changed files with 637 additions and 2298 deletions

View File

@@ -17,10 +17,10 @@ public interface MathShared {
/**
* Report usage.
*
* @param id the usage id
* @param count the usage count
* @param resource the resource name
* @param data arbitrary string data
*/
void reportUsage(MathUsageId id, int count);
void reportUsage(String resource, String data);
/**
* Get the current time.

View File

@@ -25,7 +25,7 @@ public final class MathSharedStore {
public void reportError(String error, StackTraceElement[] stackTrace) {}
@Override
public void reportUsage(MathUsageId id, int count) {}
public void reportUsage(String resource, String data) {}
@Override
public double getTimestamp() {
@@ -58,11 +58,11 @@ public final class MathSharedStore {
/**
* Report usage.
*
* @param id the usage id
* @param count the usage count
* @param resource the resource name
* @param data arbitrary string data
*/
public static void reportUsage(MathUsageId id, int count) {
getMathShared().reportUsage(id, count);
public static void reportUsage(String resource, String data) {
getMathShared().reportUsage(resource, data);
}
/**

View File

@@ -1,44 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.math;
/** WPIMath usage reporting IDs. */
public enum MathUsageId {
/** DifferentialDriveKinematics. */
kKinematics_DifferentialDrive,
/** MecanumDriveKinematics. */
kKinematics_MecanumDrive,
/** SwerveDriveKinematics. */
kKinematics_SwerveDrive,
/** TrapezoidProfile. */
kTrajectory_TrapezoidProfile,
/** LinearFilter. */
kFilter_Linear,
/** DifferentialDriveOdometry. */
kOdometry_DifferentialDrive,
/** SwerveDriveOdometry. */
kOdometry_SwerveDrive,
/** MecanumDriveOdometry. */
kOdometry_MecanumDrive,
/** PIDController. */
kController_PIDController2,
/** ProfiledPIDController. */
kController_ProfiledPIDController,
/** BangBangController. */
kController_BangBangController,
/** PathWeaver Trajectory. */
kTrajectory_PathWeaver,
}

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.controller;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
@@ -45,7 +44,7 @@ public class BangBangController implements Sendable {
SendableRegistry.add(this, "BangBangController", instances);
MathSharedStore.reportUsage(MathUsageId.kController_BangBangController, instances);
MathSharedStore.reportUsage("BangBangController", String.valueOf(instances));
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.controller;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
@@ -111,7 +110,7 @@ public class PIDController implements Sendable, AutoCloseable {
instances++;
SendableRegistry.add(this, "PIDController", instances);
MathSharedStore.reportUsage(MathUsageId.kController_PIDController2, instances);
MathSharedStore.reportUsage("PIDController", String.valueOf(instances));
}
@Override

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.controller;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.util.sendable.Sendable;
@@ -66,7 +65,7 @@ public class ProfiledPIDController implements Sendable {
instances++;
SendableRegistry.add(this, "ProfiledPIDController", instances);
MathSharedStore.reportUsage(MathUsageId.kController_ProfiledPIDController, instances);
MathSharedStore.reportUsage("ProfiledPIDController", String.valueOf(instances));
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.filter;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.util.DoubleCircularBuffer;
import java.util.Arrays;
import org.ejml.simple.SimpleMatrix;
@@ -73,7 +72,7 @@ public class LinearFilter {
m_outputGains = Arrays.copyOf(fbGains, fbGains.length);
instances++;
MathSharedStore.reportUsage(MathUsageId.kFilter_Linear, instances);
MathSharedStore.reportUsage("LinearFilter", String.valueOf(instances));
}
/**

View File

@@ -7,7 +7,6 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.Meters;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Twist2d;
import edu.wpi.first.math.kinematics.proto.DifferentialDriveKinematicsProto;
import edu.wpi.first.math.kinematics.struct.DifferentialDriveKinematicsStruct;
@@ -47,7 +46,7 @@ public class DifferentialDriveKinematics
*/
public DifferentialDriveKinematics(double trackWidthMeters) {
this.trackWidthMeters = trackWidthMeters;
MathSharedStore.reportUsage(MathUsageId.kKinematics_DifferentialDrive, 1);
MathSharedStore.reportUsage("DifferentialDriveKinematics", "");
}
/**

View File

@@ -7,7 +7,6 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.Meters;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.units.measure.Distance;
@@ -41,7 +40,7 @@ public class DifferentialDriveOdometry extends Odometry<DifferentialDriveWheelPo
gyroAngle,
new DifferentialDriveWheelPositions(leftDistanceMeters, rightDistanceMeters),
initialPoseMeters);
MathSharedStore.reportUsage(MathUsageId.kOdometry_DifferentialDrive, 1);
MathSharedStore.reportUsage("DifferentialDriveOdometry", "");
}
/**

View File

@@ -7,7 +7,6 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.Meters;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
@@ -50,7 +49,7 @@ public class DifferentialDriveOdometry3d extends Odometry3d<DifferentialDriveWhe
gyroAngle,
new DifferentialDriveWheelPositions(leftDistanceMeters, rightDistanceMeters),
initialPoseMeters);
MathSharedStore.reportUsage(MathUsageId.kOdometry_DifferentialDrive, 1);
MathSharedStore.reportUsage("DifferentialDriveOdometry3d", "");
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.kinematics;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Twist2d;
import edu.wpi.first.math.kinematics.proto.MecanumDriveKinematicsProto;
@@ -82,7 +81,7 @@ public class MecanumDriveKinematics
frontLeftWheelMeters, frontRightWheelMeters, rearLeftWheelMeters, rearRightWheelMeters);
m_forwardKinematics = m_inverseKinematics.pseudoInverse();
MathSharedStore.reportUsage(MathUsageId.kKinematics_MecanumDrive, 1);
MathSharedStore.reportUsage("MecanumDriveKinematics", "");
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.kinematics;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
@@ -31,7 +30,7 @@ public class MecanumDriveOdometry extends Odometry<MecanumDriveWheelPositions> {
MecanumDriveWheelPositions wheelPositions,
Pose2d initialPoseMeters) {
super(kinematics, gyroAngle, wheelPositions, initialPoseMeters);
MathSharedStore.reportUsage(MathUsageId.kOdometry_MecanumDrive, 1);
MathSharedStore.reportUsage("MecanumDriveOdometry", "");
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.kinematics;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
@@ -40,7 +39,7 @@ public class MecanumDriveOdometry3d extends Odometry3d<MecanumDriveWheelPosition
MecanumDriveWheelPositions wheelPositions,
Pose3d initialPoseMeters) {
super(kinematics, gyroAngle, wheelPositions, initialPoseMeters);
MathSharedStore.reportUsage(MathUsageId.kOdometry_MecanumDrive, 1);
MathSharedStore.reportUsage("MecanumDriveOdometry3d", "");
}
/**

View File

@@ -8,7 +8,6 @@ import static edu.wpi.first.units.Units.MetersPerSecond;
import static edu.wpi.first.units.Units.RadiansPerSecond;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Twist2d;
@@ -81,7 +80,7 @@ public class SwerveDriveKinematics
}
m_forwardKinematics = m_inverseKinematics.pseudoInverse();
MathSharedStore.reportUsage(MathUsageId.kKinematics_SwerveDrive, 1);
MathSharedStore.reportUsage("SwerveDriveKinematics", "");
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.kinematics;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
@@ -37,7 +36,7 @@ public class SwerveDriveOdometry extends Odometry<SwerveModulePosition[]> {
m_numModules = modulePositions.length;
MathSharedStore.reportUsage(MathUsageId.kOdometry_SwerveDrive, 1);
MathSharedStore.reportUsage("SwerveDriveOdometry", "");
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.kinematics;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
@@ -46,7 +45,7 @@ public class SwerveDriveOdometry3d extends Odometry3d<SwerveModulePosition[]> {
m_numModules = modulePositions.length;
MathSharedStore.reportUsage(MathUsageId.kOdometry_SwerveDrive, 1);
MathSharedStore.reportUsage("SwerveDriveOdometry3d", "");
}
/**

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.trajectory;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.jni.TrajectoryUtilJNI;
@@ -81,7 +80,7 @@ public final class TrajectoryUtil {
*/
public static Trajectory fromPathweaverJson(Path path) throws IOException {
MathSharedStore.reportUsage(
MathUsageId.kTrajectory_PathWeaver, ++pathWeaverTrajectoryInstances);
"Trajectory.PathWeaver", String.valueOf(++pathWeaverTrajectoryInstances));
return createTrajectoryFromElements(TrajectoryUtilJNI.fromPathweaverJson(path.toString()));
}

View File

@@ -5,7 +5,6 @@
package edu.wpi.first.math.trajectory;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import java.util.Objects;
/**
@@ -66,7 +65,7 @@ public class TrapezoidProfile {
public Constraints(double maxVelocity, double maxAcceleration) {
this.maxVelocity = maxVelocity;
this.maxAcceleration = maxAcceleration;
MathSharedStore.reportUsage(MathUsageId.kTrajectory_TrapezoidProfile, 1);
MathSharedStore.reportUsage("TrapezoidProfile", "");
}
}