Skip to content

Commit baa6379

Browse files
authored
[wpimath] Add usage reporting for state-space classes (#8453)
- LinearQuadraticRegulator - Kalman filters - Pose estimators - LinearSystemLoop Fixes #2925.
1 parent 0d1dd84 commit baa6379

File tree

20 files changed

+95
-0
lines changed

20 files changed

+95
-0
lines changed

wpilibc/src/main/native/cppcs/RobotBase.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ class WPILibMathShared : public wpi::math::MathShared {
146146
HAL_Report(HALUsageReporting::kResourceType_PathWeaverTrajectory,
147147
count);
148148
break;
149+
case wpi::math::MathUsageId::kController_LinearQuadraticRegulator:
150+
HAL_Report(HALUsageReporting::kResourceType_LinearQuadraticRegulator,
151+
count);
152+
break;
153+
case wpi::math::MathUsageId::kEstimator_KalmanFilter:
154+
HAL_Report(HALUsageReporting::kResourceType_KalmanFilter, count);
155+
break;
156+
case wpi::math::MathUsageId::kEstimator_PoseEstimator:
157+
HAL_Report(HALUsageReporting::kResourceType_PoseEstimator, count);
158+
break;
159+
case wpi::math::MathUsageId::kEstimator_PoseEstimator3d:
160+
HAL_Report(HALUsageReporting::kResourceType_PoseEstimator3d, count);
161+
break;
162+
case wpi::math::MathUsageId::kSystem_LinearSystemLoop:
163+
HAL_Report(HALUsageReporting::kResourceType_LinearSystemLoop, count);
164+
break;
149165
}
150166
}
151167

wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ public void reportUsage(MathUsageId id, int count) {
126126
HAL.report(tResourceType.kResourceType_BangBangController, count);
127127
case kTrajectory_PathWeaver ->
128128
HAL.report(tResourceType.kResourceType_PathWeaverTrajectory, count);
129+
case kController_LinearQuadraticRegulator ->
130+
HAL.report(tResourceType.kResourceType_LinearQuadraticRegulator, count);
131+
case kEstimator_KalmanFilter ->
132+
HAL.report(tResourceType.kResourceType_KalmanFilter, count);
133+
case kEstimator_PoseEstimator ->
134+
HAL.report(tResourceType.kResourceType_PoseEstimator, count);
135+
case kEstimator_PoseEstimator3d ->
136+
HAL.report(tResourceType.kResourceType_PoseEstimator3d, count);
137+
case kSystem_LinearSystemLoop ->
138+
HAL.report(tResourceType.kResourceType_LinearSystemLoop, count);
129139
default -> {
130140
// NOP
131141
}

wpimath/src/main/java/edu/wpi/first/math/MathUsageId.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,19 @@ public enum MathUsageId {
4141

4242
/** PathWeaver Trajectory. */
4343
kTrajectory_PathWeaver,
44+
45+
/** Linear Quadratic Regulator. */
46+
kController_LinearQuadraticRegulator,
47+
48+
/** Kalman Filter. */
49+
kEstimator_KalmanFilter,
50+
51+
/** Pose Estimator. */
52+
kEstimator_PoseEstimator,
53+
54+
/** 3D Pose Estimator. */
55+
kEstimator_PoseEstimator3d,
56+
57+
/** Linear System Loop. */
58+
kSystem_LinearSystemLoop,
4459
}

wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package edu.wpi.first.math.controller;
66

77
import edu.wpi.first.math.DARE;
8+
import edu.wpi.first.math.MathSharedStore;
9+
import edu.wpi.first.math.MathUsageId;
810
import edu.wpi.first.math.Matrix;
911
import edu.wpi.first.math.Num;
1012
import edu.wpi.first.math.StateSpaceUtil;
@@ -124,6 +126,8 @@ public LinearQuadraticRegulator(
124126
m_u = new Matrix<>(new SimpleMatrix(B.getNumCols(), 1));
125127

126128
reset();
129+
MathSharedStore.getMathShared()
130+
.reportUsage(MathUsageId.kController_LinearQuadraticRegulator, 1);
127131
}
128132

129133
/**
@@ -163,6 +167,8 @@ public LinearQuadraticRegulator(
163167
m_u = new Matrix<>(new SimpleMatrix(B.getNumCols(), 1));
164168

165169
reset();
170+
MathSharedStore.getMathShared()
171+
.reportUsage(MathUsageId.kController_LinearQuadraticRegulator, 1);
166172
}
167173

168174
/**

wpimath/src/main/java/edu/wpi/first/math/estimator/ExtendedKalmanFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package edu.wpi.first.math.estimator;
66

77
import edu.wpi.first.math.DARE;
8+
import edu.wpi.first.math.MathSharedStore;
9+
import edu.wpi.first.math.MathUsageId;
810
import edu.wpi.first.math.Matrix;
911
import edu.wpi.first.math.Nat;
1012
import edu.wpi.first.math.Num;
@@ -163,6 +165,8 @@ public ExtendedKalmanFilter(
163165
}
164166

165167
m_P = m_initP;
168+
169+
MathSharedStore.getMathShared().reportUsage(MathUsageId.kEstimator_KalmanFilter, 2);
166170
}
167171

168172
/**

wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package edu.wpi.first.math.estimator;
66

77
import edu.wpi.first.math.DARE;
8+
import edu.wpi.first.math.MathSharedStore;
9+
import edu.wpi.first.math.MathUsageId;
810
import edu.wpi.first.math.Matrix;
911
import edu.wpi.first.math.Nat;
1012
import edu.wpi.first.math.Num;
@@ -87,6 +89,8 @@ public KalmanFilter(
8789
m_initP = new Matrix<>(DARE.dare(discA.transpose(), C.transpose(), discQ, discR));
8890

8991
reset();
92+
93+
MathSharedStore.getMathShared().reportUsage(MathUsageId.kEstimator_KalmanFilter, 1);
9094
}
9195

9296
/**

wpimath/src/main/java/edu/wpi/first/math/estimator/PoseEstimator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package edu.wpi.first.math.estimator;
66

77
import edu.wpi.first.math.MathSharedStore;
8+
import edu.wpi.first.math.MathUsageId;
89
import edu.wpi.first.math.MathUtil;
910
import edu.wpi.first.math.Matrix;
1011
import edu.wpi.first.math.Nat;
@@ -79,6 +80,7 @@ public PoseEstimator(
7980
m_q.set(i, 0, stateStdDevs.get(i, 0) * stateStdDevs.get(i, 0));
8081
}
8182
setVisionMeasurementStdDevs(visionMeasurementStdDevs);
83+
MathSharedStore.getMathShared().reportUsage(MathUsageId.kEstimator_PoseEstimator, 1);
8284
}
8385

8486
/**

wpimath/src/main/java/edu/wpi/first/math/estimator/PoseEstimator3d.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package edu.wpi.first.math.estimator;
66

77
import edu.wpi.first.math.MathSharedStore;
8+
import edu.wpi.first.math.MathUsageId;
89
import edu.wpi.first.math.MathUtil;
910
import edu.wpi.first.math.Matrix;
1011
import edu.wpi.first.math.Nat;
@@ -87,6 +88,7 @@ public PoseEstimator3d(
8788
m_q.set(i, 0, stateStdDevs.get(i, 0) * stateStdDevs.get(i, 0));
8889
}
8990
setVisionMeasurementStdDevs(visionMeasurementStdDevs);
91+
MathSharedStore.getMathShared().reportUsage(MathUsageId.kEstimator_PoseEstimator3d, 1);
9092
}
9193

9294
/**

wpimath/src/main/java/edu/wpi/first/math/estimator/SteadyStateKalmanFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package edu.wpi.first.math.estimator;
66

77
import edu.wpi.first.math.DARE;
8+
import edu.wpi.first.math.MathSharedStore;
9+
import edu.wpi.first.math.MathUsageId;
810
import edu.wpi.first.math.Matrix;
911
import edu.wpi.first.math.Nat;
1012
import edu.wpi.first.math.Num;
@@ -107,6 +109,7 @@ public SteadyStateKalmanFilter(
107109
m_K = new Matrix<>(S.getStorage().solve(C.times(P).getStorage()).transpose());
108110

109111
reset();
112+
MathSharedStore.getMathShared().reportUsage(MathUsageId.kEstimator_KalmanFilter, 4);
110113
}
111114

112115
/** Resets the observer. */

wpimath/src/main/java/edu/wpi/first/math/estimator/UnscentedKalmanFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package edu.wpi.first.math.estimator;
66

7+
import edu.wpi.first.math.MathSharedStore;
8+
import edu.wpi.first.math.MathUsageId;
79
import edu.wpi.first.math.Matrix;
810
import edu.wpi.first.math.Nat;
911
import edu.wpi.first.math.Num;
@@ -163,6 +165,7 @@ public UnscentedKalmanFilter(
163165
m_pts = new MerweScaledSigmaPoints<>(states);
164166

165167
reset();
168+
MathSharedStore.getMathShared().reportUsage(MathUsageId.kEstimator_KalmanFilter, 3);
166169
}
167170

168171
static <S extends Num, C extends Num>

0 commit comments

Comments
 (0)