BangBangController

class wpimath.controller.BangBangController(tolerance: float = inf)

Bases: Sendable

Implements a bang-bang controller, which outputs either 0 or 1 depending on whether the measurement is less than the setpoint. This maximally-aggressive control approach works very well for velocity control of high-inertia mechanisms, and poorly on most other things.

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.

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 for atSetpoint.

atSetpoint() bool

Returns true if the error is within the tolerance of the setpoint.

Returns:

Whether the error is within the acceptable bounds.

calculate(*args, **kwargs)

Overloaded function.

  1. calculate(self: wpimath._controls._controls.controller.BangBangController, measurement: float, setpoint: float) -> float

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).

  1. calculate(self: wpimath._controls._controls.controller.BangBangController, measurement: float) -> float

Returns the calculated control output.

Parameters:

measurement – The most recent measurement of the process variable.

Returns:

The calculated motor output (0 or 1).

getError() float

Returns the current error.

Returns:

The current error.

getMeasurement() float

Returns the current measurement of the process variable.

Returns:

The current measurement of the process variable.

getSetpoint() float

Returns the current setpoint of the bang-bang controller.

Returns:

The current setpoint.

getTolerance() float

Returns the current tolerance of the controller.

Returns:

The current tolerance.

initSendable(builder: wpiutil._wpiutil.SendableBuilder) None
setSetpoint(setpoint: float) None

Sets the setpoint for the bang-bang controller.

Parameters:

setpoint – The desired setpoint.

setTolerance(tolerance: float) None

Sets the error within which AtSetpoint will return true.

Parameters:

tolerance – Position error which is tolerable.