Class BangBangController
- All Implemented Interfaces:
TelemetryLoggable, ComplexTunable
Note that this is an *asymmetric* bang-bang controller - it will not exert any control effort in the reverse direction (e.g. it won't try to slow down an overspeeding shooter wheel). This asymmetry is *extremely important*. Bang-bang control is extremely simple, but also potentially hazardous. Always ensure that your motor controllers are set to "coast" before attempting to control them with a bang-bang controller.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new bang-bang controller.BangBangController(double tolerance) Creates a new bang-bang controller. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the error is within the tolerance of the setpoint.doublecalculate(double measurement) Returns the calculated control output.doublecalculate(double measurement, double setpoint) Returns the calculated control output.doublegetError()Returns the current error.doubleReturns the current measurement of the process variable.doubleReturns the current setpoint of the bang-bang controller.Gets the telemetry table type.doubleReturns the current tolerance of the controller.Gets the tunable table type.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.voidpublishTunable(TunableTable table) Publishes the tunable to the given table.voidsetSetpoint(double setpoint) Sets the setpoint for the bang-bang controller.final voidsetTolerance(double tolerance) Sets the error within which atSetpoint will return true.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ComplexTunable
publishChildTunable, publishChildTunable, removeChildTunable, setChildTunableChanged, updateTunable
-
Constructor Details
-
BangBangController
public BangBangController(double tolerance) Creates a new bang-bang controller.Always ensure that your motor controllers are set to "coast" before attempting to control them with a bang-bang controller.
- Parameters:
tolerance- Tolerance foratSetpoint.
-
BangBangController
public BangBangController()Creates a new bang-bang controller.Always ensure that your motor controllers are set to "coast" before attempting to control them with a bang-bang controller.
-
-
Method Details
-
setSetpoint
public void setSetpoint(double setpoint) Sets the setpoint for the bang-bang controller.- Parameters:
setpoint- The desired setpoint.
-
getSetpoint
public double getSetpoint()Returns the current setpoint of the bang-bang controller.- Returns:
- The current setpoint.
-
atSetpoint
public boolean atSetpoint()Returns true if the error is within the tolerance of the setpoint.- Returns:
- Whether the error is within the acceptable bounds.
-
setTolerance
public final void setTolerance(double tolerance) Sets the error within which atSetpoint will return true.- Parameters:
tolerance- Position error which is tolerable.
-
getTolerance
public double getTolerance()Returns the current tolerance of the controller.- Returns:
- The current tolerance.
-
getMeasurement
public double getMeasurement()Returns the current measurement of the process variable.- Returns:
- The current measurement of the process variable.
-
getError
public double getError()Returns the current error.- Returns:
- The current error.
-
calculate
public double calculate(double measurement, double setpoint) Returns the calculated control output.Always ensure that your motor controllers are set to "coast" before attempting to control them with a bang-bang controller.
- Parameters:
measurement- The most recent measurement of the process variable.setpoint- The setpoint for the process variable.- Returns:
- The calculated motor output (0 or 1).
-
calculate
public double calculate(double measurement) Returns the calculated control output.- Parameters:
measurement- The most recent measurement of the process variable.- Returns:
- The calculated motor output (0 or 1).
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-
publishTunable
Description copied from interface:ComplexTunablePublishes the tunable to the given table.This function may be called when the tunable is initially published or republished during backend migration, and it must not throw. If an exception escapes, registry and backend state is not guaranteed to be restored.
- Specified by:
publishTunablein interfaceComplexTunable- Parameters:
table- table
-
getTunableType
Description copied from interface:ComplexTunableGets the tunable table type. Default is no specified table type (null).- Specified by:
getTunableTypein interfaceComplexTunable- Returns:
- Table type
-