mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
[hal,wpilib,wpimath] Add Usage Reporting for Choreo and PathWeaver (#7464)
This commit is contained in:
@@ -38,4 +38,7 @@ public enum MathUsageId {
|
||||
|
||||
/** BangBangController. */
|
||||
kController_BangBangController,
|
||||
|
||||
/** PathWeaver Trajectory. */
|
||||
kTrajectory_PathWeaver,
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
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;
|
||||
@@ -68,6 +70,8 @@ public final class TrajectoryUtil {
|
||||
return elements;
|
||||
}
|
||||
|
||||
private static int pathWeaverTrajectoryInstances;
|
||||
|
||||
/**
|
||||
* Imports a Trajectory from a JSON file exported from PathWeaver.
|
||||
*
|
||||
@@ -76,6 +80,8 @@ public final class TrajectoryUtil {
|
||||
* @throws IOException if reading from the file fails.
|
||||
*/
|
||||
public static Trajectory fromPathweaverJson(Path path) throws IOException {
|
||||
MathSharedStore.reportUsage(
|
||||
MathUsageId.kTrajectory_PathWeaver, ++pathWeaverTrajectoryInstances);
|
||||
return createTrajectoryFromElements(TrajectoryUtilJNI.fromPathweaverJson(path.toString()));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ Trajectory TrajectoryUtil::FromPathweaverJson(std::string_view path) {
|
||||
|
||||
wpi::json json = wpi::json::parse(fileBuffer.value()->GetCharBuffer());
|
||||
|
||||
wpi::math::MathSharedStore::ReportUsage(
|
||||
wpi::math::MathUsageId::kTrajectory_PathWeaver,
|
||||
++pathWeaverTrajectoryInstances);
|
||||
|
||||
return Trajectory{json.get<std::vector<Trajectory::State>>()};
|
||||
}
|
||||
|
||||
|
||||
@@ -53,5 +53,9 @@ class WPILIB_DLLEXPORT TrajectoryUtil {
|
||||
* @return the trajectory represented by the JSON
|
||||
*/
|
||||
static Trajectory DeserializeTrajectory(std::string_view jsonStr);
|
||||
|
||||
private:
|
||||
// Usage reporting for PathWeaver Trajectory instances
|
||||
inline static int pathWeaverTrajectoryInstances = 0;
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
@@ -25,6 +25,7 @@ enum class MathUsageId {
|
||||
kController_PIDController2,
|
||||
kController_ProfiledPIDController,
|
||||
kController_BangBangController,
|
||||
kTrajectory_PathWeaver,
|
||||
};
|
||||
|
||||
class WPILIB_DLLEXPORT MathShared {
|
||||
|
||||
Reference in New Issue
Block a user