Class BangBangController
- All Implemented Interfaces:
Sendable
public class BangBangController extends Object implements Sendable
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 over-speeding 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
Constructors Constructor Description BangBangController()
Creates a new bang-bang controller.BangBangController(double tolerance)
Creates a new bang-bang controller. -
Method Summary
Modifier and Type Method Description boolean
atSetpoint()
Returns true if the error is within the tolerance of the setpoint.double
calculate(double measurement)
Returns the calculated control output.double
calculate(double measurement, double setpoint)
Returns the calculated control output.double
getError()
Returns the current error.double
getMeasurement()
Returns the current measurement of the process variable.double
getSetpoint()
Returns the current setpoint of the bang-bang controller.double
getTolerance()
Returns the current tolerance of the controller.void
initSendable(SendableBuilder builder)
Initializes thisSendable
object.void
setSetpoint(double setpoint)
Sets the setpoint for the bang-bang controller.void
setTolerance(double tolerance)
Sets the error within which atSetpoint will return true.
-
Constructor Details
-
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.
- 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
Sets the setpoint for the bang-bang controller.- Parameters:
setpoint
- The desired setpoint.
-
getSetpoint
Returns the current setpoint of the bang-bang controller.- Returns:
- The current setpoint.
-
atSetpoint
Returns true if the error is within the tolerance of the setpoint.- Returns:
- Whether the error is within the acceptable bounds.
-
setTolerance
Sets the error within which atSetpoint will return true.- Parameters:
tolerance
- Position error which is tolerable.
-
getTolerance
Returns the current tolerance of the controller.- Returns:
- The current tolerance.
-
getMeasurement
Returns the current measurement of the process variable.- Returns:
- The current measurement of the process variable.
-
getError
Returns the current error.- Returns:
- The current error.
-
calculate
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
Returns the calculated control output.- Parameters:
measurement
- The most recent measurement of the process variable.- Returns:
- The calculated motor output (0 or 1).
-
initSendable
Description copied from interface:Sendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceSendable
- Parameters:
builder
- sendable builder
-