Skip to content

Commit 0a3ccf9

Browse files
authored
[wpimath] Add BangBangController Usage Reporting (#7411)
1 parent d92f17b commit 0a3ccf9

File tree

10 files changed

+27
-2
lines changed

10 files changed

+27
-2
lines changed

hal/src/generate/ResourceType.txt

+1
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ kResourceType_Redux_future4 = 112
114114
kResourceType_Redux_future5 = 113
115115
kResourceType_RevSparkFlexCAN = 114
116116
kResourceType_RevSparkFlexPWM = 115
117+
kResourceType_BangBangController = 116

hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hal/src/generated/main/native/include/hal/FRCUsageReporting.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hal/src/generated/main/native/include/hal/UsageReporting.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class WPILibMathShared : public wpi::math::MathShared {
139139
HAL_Report(HALUsageReporting::kResourceType_ProfiledPIDController,
140140
count);
141141
break;
142+
case wpi::math::MathUsageId::kController_BangBangController:
143+
HAL_Report(HALUsageReporting::kResourceType_BangBangController, count);
144+
break;
142145
}
143146
}
144147

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

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public void reportUsage(MathUsageId id, int count) {
115115
tResourceType.kResourceType_PIDController2, count);
116116
case kController_ProfiledPIDController -> HAL.report(
117117
tResourceType.kResourceType_ProfiledPIDController, count);
118+
case kController_BangBangController -> HAL.report(
119+
tResourceType.kResourceType_BangBangController, count);
118120
default -> {
119121
// NOP
120122
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ public enum MathUsageId {
3535

3636
/** ProfiledPIDController. */
3737
kController_ProfiledPIDController,
38+
39+
/** BangBangController. */
40+
kController_BangBangController,
3841
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public BangBangController(double tolerance) {
4545

4646
SendableRegistry.addLW(this, "BangBangController", instances);
4747

48-
MathSharedStore.reportUsage(MathUsageId.kController_PIDController2, instances);
48+
MathSharedStore.reportUsage(MathUsageId.kController_BangBangController, instances);
4949
}
5050

5151
/**

wpimath/src/main/native/include/frc/controller/BangBangController.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <wpi/sendable/Sendable.h>
1212
#include <wpi/sendable/SendableHelper.h>
1313

14+
#include "wpimath/MathShared.h"
15+
1416
namespace frc {
1517

1618
/**
@@ -40,7 +42,13 @@ class WPILIB_DLLEXPORT BangBangController
4042
*/
4143
constexpr explicit BangBangController(
4244
double tolerance = std::numeric_limits<double>::infinity())
43-
: m_tolerance(tolerance) {}
45+
: m_tolerance(tolerance) {
46+
if (!std::is_constant_evaluated()) {
47+
++instances;
48+
wpi::math::MathSharedStore::ReportUsage(
49+
wpi::math::MathUsageId::kController_BangBangController, instances);
50+
}
51+
}
4452

4553
/**
4654
* Sets the setpoint for the bang-bang controller.
@@ -127,6 +135,9 @@ class WPILIB_DLLEXPORT BangBangController
127135

128136
double m_setpoint = 0;
129137
double m_measurement = 0;
138+
139+
// Usage reporting instances
140+
inline static int instances = 0;
130141
};
131142

132143
} // namespace frc

wpimath/src/main/native/include/wpimath/MathShared.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum class MathUsageId {
2424
kOdometry_MecanumDrive,
2525
kController_PIDController2,
2626
kController_ProfiledPIDController,
27+
kController_BangBangController,
2728
};
2829

2930
class WPILIB_DLLEXPORT MathShared {

0 commit comments

Comments
 (0)