Bang-Bang Control
Easydifficulty
Not every mechanism needs PID. A shooter flywheel is heavy and has one job: get back up to speed quickly after each shot. For that, the simplest controller is often good enough, and plenty of strong teams use it.
Getting a flywheel back up to speed
A heavy flywheel shrugs off small disturbances, but it's also slow to change speed, and the simple version here can't brake it at all. It only stops pushing and lets friction slow it down. (Driving the motor backwards or braking electrically would work, but that's not part of a two-output controller.) Each shot knocks the speed down, and you need it back before the next one. A gently tuned PID takes its time. What you want is full power the moment the speed drops and nothing once it recovers, which is bang-bang. The trouble is what it does once it gets there.
On or off
Compare the measured speed with the target and pick one of two outputs:
On a heavy flywheel this recovers speed about as fast as the motor physically can. The catch is that it never holds a speed. The motor is always either at full power or off, so the flywheel keeps drifting a little above and below the target, forever. That back-and-forth is called a limit cycle, and it's the red ripple in the demo. The speed can also overshoot, because the flywheel keeps its momentum and the loop reacts a little late.
On a light mechanism like an arm or a drivetrain, the same switching causes violent buzzing, big current spikes, and gear wear. Bang-bang works when the mechanism's inertia smooths out the switching, and a flywheel is the standard example. Adding a small hysteresis band, turning on below and off above , limits how often it switches.
In the demo, the red trace is bang-bang. It recovers fast after each shot but keeps rippling around the line. The green trace is take-back-half, which keeps the fast recovery but settles on a steady speed. Its derivation and code are in Advanced Topics → Take-Back-Half.
Living with the ripple
You can't tune the ripple away, because an on/off rule has no in-between output to settle on. If the ripple is small enough for your shots, bang-bang with a hysteresis band is all you need. If you need a steady, repeatable speed for consistent shot distance, use take-back-half, which keeps the fast recovery and then homes in on the steady power.
Bang-bang on the Control Hub
// For high-inertia mechanisms like a flywheel.
double bangBang(double measured, double target, double currentPower) {
if (measured < target - HYSTERESIS) return 1.0;
if (measured > target + HYSTERESIS) return 0.0;
return currentPower; // inside the band: hold whatever is commanded
}
Take out the hysteresis band. The measured speed sits right at the target and noise pushes it across
every other loop. At 50 loops a second, how often does the motor switch, and what does that do? Up to 25 times a second from full power to off. Every switch-on is a step in current, and a step in
current draw from the battery, so the voltage wobbles along with the chatter and other mechanisms feel
it. Near the target speed the flywheel's back-EMF keeps each current step modest, but the constant
switching is still hard on the motor and gearbox and adds noise to every other reading on the robot.Show solution
Too narrow and it still chatters. Too wide and the speed sags visibly between switches. What would you
log to pick it? Log the flywheel speed at full rate while it's holding speed. The spread of that signal is the
minimum: the band has to be wider than the noise, or noise alone will trip it. The maximum is however
much the speed can dip before shots start missing, which you can read off the same log.Show solution
Use bang-bang when recovery speed is what matters most and the mechanism is heavy, like a shooter you spin back up between shots. Use take-back-half when you also need a steady speed for consistent shot distance. Use PID plus feedforward when you need tight holding and controlled acceleration, or the mechanism isn't a flywheel.
- CTRL ALT FTC - FTC control framing for simple feedback strategies and when a controller's plant assumptions matter.
- Tyler Veness, Controls Engineering in FRC - competition-robotics control background for feedback, saturation, and actuator limits.
- Take-Back-Half - the Advanced Topics lesson that turns bang-bang's fast recovery into a steady flywheel hold.