Bang-Bang Control Simulator — Time-Optimal Control
A tool that visualizes bang-bang control, which drives the double integrator ẍ = u to the origin in minimum time under the input bound |u| ≤ u_max. Change the initial position, initial velocity and maximum input to see the switching curve, the phase-plane trajectory, the minimum reaching time and the switching instant update in real time.
Parameters
Initial position x₀
First offset from the origin (dimensionless)
Initial velocity v₀
Velocity at the starting instant (dimensionless)
Maximum input u_max
Input bound (maximum acceleration)
This is a double integrator. The control input u acts as an acceleration and takes only +u_max (full acceleration) or −u_max (full braking), switching at most once so as to reach the origin (0,0) in minimum time.
Results
—
Min reaching time t_final (s)
—
Switching instant t_switch (s)
—
First control input
—
Second control input
—
Velocity at switch v_sw
—
Input magnitude u_max
—
Phase plane — switching curve and bang-bang trajectory
The horizontal axis is position x, the vertical axis is velocity v. From the start point a parabolic arc meets the S-shaped switching curve; the control then flips and the state slides into the origin. A marker travels the trajectory in a loop.
Position and velocity time response
Control input u(t) — square wave
Theory & Key Formulas
$$\ddot x = u,\qquad |u|\le u_{max}$$
State equation of the double integrator. Position x, velocity v=ẋ, and the control input u acts as an acceleration bounded by ±u_max.
$$x = -\frac{v\,|v|}{2\,u_{max}}$$
The switching curve. States on this curve reach the origin with no switch. Above the curve apply u=−u_max, below it apply u=+u_max.
$$u^{*}(t)=\pm u_{max}\quad(\text{at most one switch})$$
By Pontryagin's minimum principle, the time-optimal input of the double integrator has a bang-bang structure with at most one switch.
What is Bang-Bang Control?
🙋
"Bang-bang control" — that name sounds rather violent. What kind of control is it?
🎓
The name comes from the image of slamming a switch "bang! bang!". Roughly speaking, it is a control that never uses an intermediate input value but always swings all the way to either the upper limit +u_max or the lower limit −u_max. In car terms, you never press the pedal halfway — it is always "full accelerator" or "full brake". An on/off choice, hence bang-bang.
🙋
A choice between full and full sounds like a crude kind of control. Is there any benefit to it?
🎓
Here is the thing — if your goal is to reach the target in the shortest possible time, bang-bang control is the optimal solution. Think of a system with bounds on the input. If you simply want to move fast, there is no reason to hold back. So "accelerate at full effort on the way out, brake at full effort on the way in" is the answer. For the double integrator ẍ = u that this tool handles, this can even be proved mathematically. Half-hearted pedal work actually makes you slower.
🙋
I see. But when exactly do you switch from full accelerator to full brake? The timing seems tricky.
🎓
That is where the "switching curve" comes in. Look at the phase plane above — horizontal axis position, vertical axis velocity. See that S-shaped curve? That is the switching curve, given by x = −v·|v|/(2·u_max). It marks "the states from which braking alone will stop you exactly at the origin". So the control law is simple: above the curve apply u=−u_max, below it apply u=+u_max. The instant the state's parabola hits the switching curve is the moment to switch.
🙋
Why does it become a parabola? In the chart too, the path curves from the start point and hits the curve.
🎓
When the input u is constant, the acceleration is constant, so the motion has constant acceleration. Take the relation between position x and velocity v and you get exactly v² = constant × x, a parabola. So in the phase plane the path is two parabolic arcs of opposite orientation joined together — one for +u_max and one for −u_max. The first arc reaches the switching curve, and the second (the switching curve itself) leads to the origin. "At most one switch" comes precisely from this "two parabolas" structure.
🙋
I am getting the theory. Do real elevators and robots use bang-bang control exactly like this?
🎓
The idea is used, but pure "full versus full" has drawbacks. Because the input jumps instantly from +u_max to −u_max, the machine takes a hard shock, and for an elevator carrying people the ride would feel terrible. Also, if the switch timing is slightly off, the state overshoots the origin and chatters (rapid repeated oscillation). So in practice engineers round the input near the switch, or hand over to feedback control near the target. Knowing the "theoretical fastest" and then compromising sensibly with reality — that is where design skill shows.
Frequently Asked Questions
Bang-bang control is a strategy in which the control input u is held at either the upper limit +u_max or the lower limit −u_max, never anything in between. It flips like an on/off switch. For a system whose input is bounded, such as the double integrator ẍ = u with |u| ≤ u_max, the solution that drives the state to a target in minimum time — the time-optimal control — is exactly this bang-bang control. This tool computes how many switches are needed to reach the origin from a given initial state in the shortest time.
By Pontryagin's minimum (maximum) principle, when the Hamiltonian is linear in the input u, the optimal u takes the extreme value ±u_max that minimizes the Hamiltonian at every instant. An intermediate value is optimal only on a singular arc, where the costate is exactly zero. The double integrator has no singular arc, so the optimal input is always +u_max or −u_max, with at most one switch. Intuitively, to move as fast as possible the answer is to accelerate at full effort and then brake at full effort.
The switching curve is the locus, in the phase plane (horizontal axis x, vertical axis v), of all states from which the origin can be reached with a single non-switching control. For the double integrator it is the S-shaped curve x = −v·|v|/(2·u_max). If the current state lies above this curve, apply u = −u_max; if it lies below, apply u = +u_max. The state follows a parabola until it meets the switching curve, then the control flips and it slides along the curve into the origin. The switching curve acts as the map of the optimal control.
It is the fastest in theory, but using it directly has drawbacks. First, because the input jumps instantly from +u_max to −u_max, it imposes a large shock and vibration on the actuator and structure. Second, a tiny error in the switching instant or in the model easily overshoots the origin and causes chattering (rapid repeated oscillation). In practice, elevators and hard-disk head positioning use a near-bang-bang profile, but combine it with measures such as rounding the input near the switch and handing over to feedback control close to the target.
Real-World Applications
HDD and optical-disc head positioning: Seek control, which moves a hard disk's magnetic head to a target track in minimum time, is the classic example of bang-bang control. In storage devices where every millisecond of access time matters, the voice-coil motor is driven at its current limit to accelerate, then switched to full deceleration partway. In reality a near-time-optimal profile with a rounded switch is used, and after settling the controller hands over to feedback control.
Motion profiles for elevators and material handling: Elevators, cranes and the transfer stages of semiconductor equipment must move "as fast as possible, yet without shock". The ideal is bang-bang with full acceleration and deceleration, but the abrupt change in acceleration (jerk) hurts ride comfort and causes loads to shift. Hence trapezoidal or S-curve velocity profiles are adopted as a "shock-limited time-optimal" form that deliberately rounds the corners of bang-bang.
Spacecraft attitude control and thruster firing: Thrusters (gas jets) are actuators that fundamentally operate only on/off, which is bang-bang control itself. Attitude maneuvers and orbit corrections of a satellite set the firing on-times and switch timing using time-optimal control theory. The switching-curve idea of the double integrator directly informs designs that reach the target attitude in minimum time while saving propellant.
High-speed positioning of robots and machine tools: In point-to-point motion that moves an industrial-robot arm or a machine-tool feed axis from point to point in minimum time, a bang-bang-like profile that uses up the motor torque limit is the baseline. Because cutting cycle time directly raises productivity, time-optimal trajectory generation under torque and velocity constraints is widely studied and implemented.
Common Misconceptions and Pitfalls
The most common misconception is "bang-bang control is the fastest, so it is always the best control". Bang-bang is optimal only when the chosen cost function is "minimize the reaching time". Change the criterion to "minimum energy consumption" or "minimum jerk (rate of change of acceleration)" and the optimal solution is no longer bang-bang. On real machines, abrupt input changes produce vibration, wear and noise, so it is normal to sacrifice a little time-optimality and choose a smoother input. Deciding "what exactly you want to optimize" first is the starting point of control design.
Next, the assumption that "once you compute the switching instant, you just flip the input on schedule". The reason this tool can compute the switching instant exactly is that the model (ẍ=u with an exact u_max) perfectly matches reality. A real machine always has friction, disturbances and model errors, so switching at the calculated instant will not stop it exactly at the origin. Overshoot a little and the state crosses back and forth over the switching curve, falling into "chattering" where the input rapidly alternates between +u_max and −u_max. Implementations prevent this with a thin dead band around the switching curve, or by handing over to linear feedback near the origin.
Finally, the misconception of generalizing that "there is always exactly one switch". At most one switch is a property specific to this double integrator (a second-order system). For higher-order systems, or systems with multiple poles, the number of switches in time-optimal control grows with the order of the system (a rough guide is at most n−1 switches for an n-th-order system). Memorizing "bang-bang = one switch" leads to errors when applying it to more complex systems. Note that this tool deals only with the most basic case, the double integrator.
How to Use
Set initial position x0 (range -10 to 10 m) and initial velocity v0 (range -5 to 5 m/s) using the sliders.
Specify maximum control input magnitude u_max (range 1 to 50 m/s²) representing thruster or actuator saturation limits.
Click Simulate to compute the time-optimal bang-bang trajectory: the controller applies +u_max or -u_max to minimize reaching time to equilibrium (x=0, v=0).
Review the switching instant t_switch where control reverses, final time t_final in seconds, and velocity v_sw at the switch point.
Worked Example
Consider a spacecraft docking scenario with x0=8 m (position error), v0=2 m/s (closing velocity), u_max=3 m/s². The simulator computes t_switch≈1.89 s at which control flips from u=-3 m/s² to u=+3 m/s², achieving v_sw≈-3.67 m/s. Total time t_final≈3.78 s brings the craft to origin with zero velocity. For a robotic manipulator with x0=-5 m, v0=-1 m/s, u_max=10 m/s², switching occurs at t_switch≈0.63 s, reaching equilibrium in t_final≈1.26 s.
Practical Notes
Bang-bang control is optimal for double-integrator systems (∫∫ dynamics); missile guidance and satellite attitude control exploit this principle to minimize fuel burn time.
Higher u_max reduces t_final nonlinearly; doubling actuator authority does not halve time due to the quadratic nature of the double integrator.
The switching curve (phase-plane boundary) depends only on u_max magnitude, not sign; symmetric initial conditions produce symmetric trajectories about the origin.
Real systems add rate limiters and deadbands; this simulator assumes ideal instantaneous switching without actuator lag or friction.