44 double tolerance = std::numeric_limits<double>::infinity())
45 : m_tolerance(tolerance) {
46 if (!std::is_constant_evaluated()) {
58 constexpr void SetSetpoint(
double setpoint) { m_setpoint = setpoint; }
73 return gcem::abs(m_setpoint - m_measurement) < m_tolerance;
81 constexpr void SetTolerance(
double tolerance) { m_tolerance = tolerance; }
102 constexpr double GetError()
const {
return m_setpoint - m_measurement; }
114 constexpr double Calculate(
double measurement,
double setpoint) {
115 m_measurement = measurement;
116 m_setpoint = setpoint;
118 return measurement < setpoint ? 1 : 0;
128 return Calculate(measurement, m_setpoint);
136 double m_setpoint = 0;
137 double m_measurement = 0;
140 inline static int instances = 0;
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Implements a bang-bang controller, which outputs either 0 or 1 depending on whether the measurement i...
Definition BangBangController.h:33
constexpr BangBangController(double tolerance=std::numeric_limits< double >::infinity())
Creates a new bang-bang controller.
Definition BangBangController.h:43
constexpr bool AtSetpoint() const
Returns true if the error is within the tolerance of the setpoint.
Definition BangBangController.h:72
constexpr double GetTolerance() const
Returns the current tolerance of the controller.
Definition BangBangController.h:88
constexpr double Calculate(double measurement, double setpoint)
Returns the calculated control output.
Definition BangBangController.h:114
constexpr double GetMeasurement() const
Returns the current measurement of the process variable.
Definition BangBangController.h:95
constexpr double Calculate(double measurement)
Returns the calculated control output.
Definition BangBangController.h:127
constexpr void SetTolerance(double tolerance)
Sets the error within which AtSetpoint will return true.
Definition BangBangController.h:81
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
constexpr void SetSetpoint(double setpoint)
Sets the setpoint for the bang-bang controller.
Definition BangBangController.h:58
constexpr double GetSetpoint() const
Returns the current setpoint of the bang-bang controller.
Definition BangBangController.h:65
constexpr double GetError() const
Returns the current error.
Definition BangBangController.h:102
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.h:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.h:21
Interface for Sendable objects.
Definition Sendable.h:16
static void ReportUsage(MathUsageId id, int count)
Definition MathShared.h:75
constexpr T abs(const T x) noexcept
Compile-time absolute value function.
Definition abs.hpp:40
@ kController_BangBangController