Skip to content

Commit

Permalink
[wpimath] Add BangBangController Usage Reporting (#7411)
Browse files Browse the repository at this point in the history
  • Loading branch information
sciencewhiz authored Nov 21, 2024
1 parent d92f17b commit 0a3ccf9
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions hal/src/generate/ResourceType.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ kResourceType_Redux_future4 = 112
kResourceType_Redux_future5 = 113
kResourceType_RevSparkFlexCAN = 114
kResourceType_RevSparkFlexPWM = 115
kResourceType_BangBangController = 116
2 changes: 2 additions & 0 deletions hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hal/src/generated/main/native/include/hal/UsageReporting.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions wpilibc/src/main/native/cppcs/RobotBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class WPILibMathShared : public wpi::math::MathShared {
HAL_Report(HALUsageReporting::kResourceType_ProfiledPIDController,
count);
break;
case wpi::math::MathUsageId::kController_BangBangController:
HAL_Report(HALUsageReporting::kResourceType_BangBangController, count);
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public void reportUsage(MathUsageId id, int count) {
tResourceType.kResourceType_PIDController2, count);
case kController_ProfiledPIDController -> HAL.report(
tResourceType.kResourceType_ProfiledPIDController, count);
case kController_BangBangController -> HAL.report(
tResourceType.kResourceType_BangBangController, count);
default -> {
// NOP
}
Expand Down
3 changes: 3 additions & 0 deletions wpimath/src/main/java/edu/wpi/first/math/MathUsageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ public enum MathUsageId {

/** ProfiledPIDController. */
kController_ProfiledPIDController,

/** BangBangController. */
kController_BangBangController,
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public BangBangController(double tolerance) {

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

MathSharedStore.reportUsage(MathUsageId.kController_PIDController2, instances);
MathSharedStore.reportUsage(MathUsageId.kController_BangBangController, instances);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>

#include "wpimath/MathShared.h"

namespace frc {

/**
Expand Down Expand Up @@ -40,7 +42,13 @@ class WPILIB_DLLEXPORT BangBangController
*/
constexpr explicit BangBangController(
double tolerance = std::numeric_limits<double>::infinity())
: m_tolerance(tolerance) {}
: m_tolerance(tolerance) {
if (!std::is_constant_evaluated()) {
++instances;
wpi::math::MathSharedStore::ReportUsage(
wpi::math::MathUsageId::kController_BangBangController, instances);
}
}

/**
* Sets the setpoint for the bang-bang controller.
Expand Down Expand Up @@ -127,6 +135,9 @@ class WPILIB_DLLEXPORT BangBangController

double m_setpoint = 0;
double m_measurement = 0;

// Usage reporting instances
inline static int instances = 0;
};

} // namespace frc
1 change: 1 addition & 0 deletions wpimath/src/main/native/include/wpimath/MathShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum class MathUsageId {
kOdometry_MecanumDrive,
kController_PIDController2,
kController_ProfiledPIDController,
kController_BangBangController,
};

class WPILIB_DLLEXPORT MathShared {
Expand Down

0 comments on commit 0a3ccf9

Please sign in to comment.