› Sliding Mode Control Simulator Back
Control Engineering Simulator

Sliding Mode Control — VSC and Robustness

A real-time simulator that applies SMC to a disturbed second-order system and drives it to the origin with the switching law u=-k·sign(s). Vary c, k, φ and d to visualise robust convergence and chattering suppression.

Parameters
Sliding surface coefficient c
—
Switching gain k
—
Boundary layer width φ
—
Disturbance amplitude d
—

Plant: ẍ = -a·ẋ - b·x + u + d(t), a=1, b=2, x(0)=2, ẋ(0)=0, disturbance d(t)=d·sin(5t), dt=0.01, T=5 s.

Live Readouts
0.000
Switching variable s
2.000
State x₁
0.00
Control input u
0.00
Chattering index
Phase-Plane Animation and Control Input

In the phase plane the state reaches the sliding surface s=0 from the initial point (orange) and slides along it to the origin (green). The lower panel shows the switching of the control input u(t) (chattering).

Theory & Key Formulas

For the second-order system $\ddot x = -a\dot x - b x + u + d(t)$ the sliding surface is designed with the states $x_1=x,\ x_2=\dot x$.

Sliding surface $s$; $c$ is the positive coefficient that sets the slope of the surface:

$$s = c\,x_1 + x_2$$

Control law combining feedback linearisation with a switching term; $k$ is the switching gain:

$$u = -k\,\mathrm{sign}(s) - c\,x_2 + a\,x_2 + b\,x_1$$

Chattering suppression (smoothing) by the boundary layer $\varphi$:

$$\mathrm{sign}(s)\;\longrightarrow\;\tanh(s/\varphi)$$

Sliding condition and on-surface dynamics:

$$s\,\dot s \lt 0,\qquad s=0\ \Rightarrow\ \dot x_1 = -c\,x_1$$

If $k$ is chosen larger than the disturbance amplitude the reaching condition holds, and once on the surface the convergence is exponential with the rate set by $c$.

What Is the Sliding Mode Control Simulator?

🙋
I keep hearing the name sliding mode control, but what is actually "sliding"?
🎓
Roughly speaking, it is a control that draws a "slide" in state space in advance, and that slide is called the sliding surface. Look at the phase plane in the upper half of the simulator. The green dashed line is $s=c\,x_1+x_2=0$, the equation of the slide. The blue trajectory starts at (2, 0), first "reaches" this green line almost in a straight line, and then "slides" along it to the origin, doesn't it?
🙋
It does! But a disturbance is acting, and it still stops right at the origin. Is that what robustness means?
🎓
Yes, exactly that. If the switching gain $k$ in $u=-k\,\mathrm{sign}(s)\,\cdots$ is taken larger than the disturbance, the surface is reached in finite time. Once on the surface the dynamics become $\dot x_1=-c\,x_1$ and the state converges exponentially to the origin whatever the frequency or amplitude of the disturbance. In practice this property is prized in motor control and power converters. Try raising the "Disturbance amplitude d" slider to 5 and watch the state still converge near the origin (with k=5 left as it is, k no longer exceeds d, so |s| wobbles by about 0.1; raising k shrinks the wobble).
🙋
Impressive! But the red line in the lower graph (the control input u) is jagged. Is that chattering?
🎓
Yes. Because $\mathrm{sign}(s)$ is discontinuous at the origin, the control snaps back and forth the instant $s$ crosses zero. Set the "Boundary layer width φ" to 0: the chattering-index card should jump. Then raise φ to about 0.1: $\mathrm{sign}$ is replaced by $\tanh(s/\varphi)$ and the input becomes smooth. The price is a tiny residual error at the origin, but on real machines this compromise is essential to prevent wear.
🙋
How do you choose the slope c of the surface? Making it larger feels like it should converge faster.
🎓
Good question. $c$ sets the on-surface time constant $1/c$, so once on the surface convergence is indeed faster. But a larger $c$ also makes the initial $s(0)=c\,x_1(0)$ larger, and the time to reach the surface grows to roughly $s(0)/k$. Try $c$ = 10 in the simulator. With $k=5$ it takes about 4 s to reach the surface, slower than $c=2$ (about 0.85 s). Raising $k$ to 20 brings the reaching time down to about 1 s, but the input peak grows in proportion to $k$ to about 16, and on the surface the velocity $x_2=-c\,x_1$ is large too, so on real hardware this invites actuator saturation. The standard practice is to set $c$ a little below the mechanical bandwidth and $k$ from the disturbance estimate plus a margin.

Frequently Asked Questions

PID linearly superposes the proportional, integral and derivative of the error; it is intuitive to design and easy to tune. SMC, by contrast, has a nonlinear switching term, the "sign function", and can guarantee robustness theoretically if the upper bound of the disturbance is known. However, the switching term causes chattering that can damage machinery and power devices, so in practice it is smoothed with a boundary layer or higher-order SMC. Remember: PID for mild disturbances, SMC for parameter variation and strong disturbances.
To satisfy the reaching condition $V'=s\,\dot s\lt 0$, $k$ is designed to exceed the upper bound of the disturbance and model error. The basic rule is $k\gt |d|_\max+\eta$, where $\eta\gt 0$ is a margin corresponding to the reaching rate. Making $k$ too large increases the input amplitude of the switching and hence chattering, so keep the margin minimal. When the disturbance is hard to estimate, "adaptive sliding mode", which adjusts the gain automatically according to the state, is an option.
Inside $|s|\lt \varphi$, $\mathrm{sign}(s)\approx s/\varphi$ and the controller becomes high-gain proportional control towards the surface. Proportional control cannot remove steady-state error completely, so with an integrated or DC component of disturbance, $s$ settles at a small offset from zero. The error bound is proportional to $\varphi$, so φ is chosen backwards from the allowable error. Chattering and residual error are the classic trade-off. To remove it entirely, use integral sliding mode (ISM) or super-twisting.
For second-order systems the linear surface $s=c\,x_1+x_2$ is the most basic, but it is not mandatory. For higher-order systems it may be built as $s=(\frac{d}{dt}+c)^{n-1}x$, and nonlinear surfaces such as $s=x_2+\beta|x_1|^{\alpha}\mathrm{sign}(x_1)$ (terminal SMC) are used to aim at finite-time convergence. Because the surface design determines the behaviour after reaching, it is chosen with response time, overshoot and input constraints in mind.

Real-World Applications

Robot arm trajectory tracking: Multi-joint robots have strong inertial coupling between joints and large load variation, so model error is always present. Because SMC can drive the tracking error to zero as long as the error bound is known, it is widely used for trajectory control and force-control modes of industrial robots. A boundary layer is usually added to limit shocks to the reduction gears.

Power converters (DC-DC converters and inverters): The switching devices themselves embody "switching", so SMC and power electronics go well together. The output-voltage response is fast and robust to sudden load changes, and it is widely adopted in solar power conditioners and EV motor-drive inverters. Implementation with a boundary layer to limit the switching frequency is standard.

Aircraft and missile attitude control: Aerodynamic coefficients of flight vehicles change greatly with speed and altitude, and gain-scheduled PID cannot always keep up. Because SMC is insensitive to parameter variation, it is researched and implemented in terminal guidance laws for missiles and attitude control of re-entry vehicles.

Automotive ABS, ESC and electric power steering: Vehicle control, with its large uncertainty in road friction, is a natural application of SMC. Wheel-slip tracking in ABS, yaw-rate SMC in ESC and assist-torque SMC in EPS have been researched and put into production, and their robustness translates directly into safety.

Common Misconceptions and Points to Note

The most common misconception is to think that "the larger the gain k, the better the performance". In theory the reaching condition holds as long as $k$ exceeds the disturbance, but an oversized $k$ increases the input amplitude and intensifies chattering, wearing out or destroying the actuator. Set $k$ to 20 and $\varphi$ to 0 in the simulator: the chattering index should jump from about 3 at the defaults to around 25, and the input peak should rise to about 26. In practice keep k to about "disturbance bound + safety factor 1.5–2" and cover the remaining robustness with a boundary layer or an adaptive law.

The next most common is to assume that once a boundary layer φ is added you have "almost ideal SMC". The moment φ is introduced, strict invariance is lost and a finite residual error and low-frequency oscillation remain. Raise φ to 0.5 in the simulator and a small oscillation appears near the origin. Whether the error is acceptable depends on the application; for precision positioning the realistic answer is to add integral sliding mode (ISM) or super-twisting. Think of the boundary layer not as "the solution to chattering" but as "the knob for the trade-off".

Finally, note that this tool shows ideal SMC with a "perfectly known model". In an implementation the cancellation term $a\,x_2 + b\,x_1$ in the control law contains model error, which adds to the effective disturbance. On real hardware the gain $k$ is designed with model error included, or an error bound relative to a nominal model identified by system ID is derived, as standard procedure. Furthermore, in discrete-time implementation the switching frequency is limited by the sampling frequency, which is itself a cause of chattering. Even if the continuous simulation looks good, the behaviour can change when run at 1 kHz sampling.

How to Use

  1. Set the sliding-surface coefficient c (0.1–10), which fixes the on-surface time constant 1/c. A larger c gives faster convergence on the surface, but the initial s(0)=c·x₁(0) is larger, so the time to reach the surface (about s(0)/k) grows
  2. Enter the switching gain k (0.1–20). Choose it above the upper bound of the disturbance amplitude d to guarantee the sliding condition s·ṡ < 0
  3. Adjust the boundary-layer width φ (0–1.0). A larger φ replaces sign(s) with tanh(s/φ) and reduces chattering, at the cost of a larger residual error near the origin. φ=0 gives the ideal discontinuous switching
  4. Set the disturbance amplitude d (0–5, dimensionless) to test robustness. Keeping k fixed and varying d, watch the fluctuation of the switching-variable card s and the trajectory in the phase plane
  5. Whenever a parameter changes, the 5-second response of the second-order system is recomputed and the four cards (switching variable s, state x₁, control input u, chattering index) update in sync with the phase-plane and input animations

Worked Example

For the dimensionless plant ẍ=-ẋ-2x+u+d(t) with c=2.0, k=15, boundary layer φ=0.1 and disturbance amplitude d=2, the trajectory reaches the sliding surface s=2x₁+x₂ at t_reach≈0.29 s and the settling time (±2% band) is about 2.1 s. Lowering the surface coefficient to c=1.0 makes reaching faster (t_reach≈0.14 s) but the on-surface time constant 1/c of ẋ₁=-c·x₁ grows, so settling stretches to about 4.0 s. Reducing φ raises the chattering index and the high-frequency content of the input (the reaching and settling times are not displayed by the tool; they come from a numerical solution of the same model).

Practical Notes