Skip to the lesson
FixTheRobot Explore Robotics / Guidance, Navigation and Control / M5 Nonlinear, Scheduled and Adaptive Control / M5-T4

Guidance, Navigation and Control · Theory · M5

M5-T4 — Sliding-Mode Control

Force the error onto a surface where it must decay, and switch hard enough to stay there against any bounded disturbance. The hardness is both the strength and the cost.

  • Lesson 4 of 7
  • Intermediate
  • Module 5: Nonlinear, Scheduled and Adaptive Control
  • Theory
  • About 11 minutes to read

Dynamic inversion needs a model. Sliding-mode control needs only a bound on what the model gets wrong, and gives in return an error dynamics that does not depend on the disturbance at all. This lesson designs the surface and the switching law for Hopper's pitch, proves that the surface is reached, shows what the switching does to a gimbal with a servo lag and a rate limit, and replaces it with a boundary layer at a stated cost in accuracy.

Learning objectives

After this lesson, you should be able to:

  • Choose a sliding variable so that motion on it is a first-order decay with a chosen rate.
  • Derive the switching gain that guarantees the surface is reached against a bounded disturbance.
  • Explain chattering and relate it to the actuator servo and rate limit.
  • Choose a boundary-layer width and state the resulting error bound.

The intuition

UAV M5-T16: Disturbance rejection and wind compensation cancelled a disturbance by estimating it. Sliding-mode control takes the opposite stance: the disturbance is not estimated, only bounded, and the controller is made strong enough to beat any disturbance inside the bound.

A surface to live on

For Hopper's pitch, θ¨=λ2θ+bδ+d\ddot{\theta} = \lambda^2\theta + b\delta + d, define the sliding variable s=q+c θs = q + c\,\theta with c=3c = 3 rad/s. If ss is held at zero the pitch obeys θ˙=−cθ\dot{\theta} = -c\theta: a first-order decay with a pole at −3, whatever the plant or the disturbance does, because they never enter. The second-order problem has been reduced to two steps: bring ss to zero, then let the pitch decay on its own.

Switching to stay on it

The control that drives ss to zero in finite time is a hard switch: push as hard as the largest disturbance whenever ss is positive, and the opposite way whenever it is negative. If the push exceeds the disturbance bound, ss cannot stay on either side, and slides along zero. With a gimbal that has a 40 rad/s servo and a 3 rad/s rate limit, though, a hard switch is a command that flips sign thousands of times per second, and the gimbal tries to follow: chattering.

A boundary layer

The remedy is to replace the switch by a saturation: full push when ∣s∣|s| exceeds a thickness φ\varphi, proportional inside. The gimbal then moves smoothly. The surface is no longer held exactly: the loop stays within ∣s∣≤φ|s| \le \varphi, and the pitch within φ/c\varphi/c of zero. A thicker layer gives a gentler gimbal and a larger error, and the width is chosen from the rate limit and the accuracy needed.

Gimbal command with a sign switching law and with a boundary layerGimbal angle against time over 0.4 seconds, after sliding has begun. With the pure sign law the command ripples rapidly about a mean near minus 0.05 radians, so the gimbal rate is above its 3 radians per second limit for 30 percent of the time. With a boundary layer of 0.2 the command is smooth and follows the disturbance.00.10.20.30.4-0.15-0.1-0.0500.050.10.15time (s), after sliding has begungimbal angle (rad) sign switching law: chatter boundary layer 0.2: smooth
The gimbal command in the sliding phase. The sign law chatters; the boundary layer of 0.2 gives a smooth command at a cost of a small tracking error.

Sliding mode buys independence from a bounded disturbance with a hard switch. The switch is paid for in actuator activity, and a boundary layer pays it back in accuracy.

Definitions

Sliding variable ss
A combination of the states, s=q+c θs = q + c\,\theta, whose zero set is the sliding surface.
Reaching and sliding
The first phase brings ss to zero; the second keeps it there while the state moves along the surface.
Matched disturbance
A disturbance that enters through the same channel as the control, as dd does in θ¨\ddot{\theta}. Only matched disturbances are rejected completely.
Boundary layer φ\varphi
The thickness of the band around s=0s = 0 inside which the switch is replaced by a linear segment.
The sliding-mode law
δ=−1b^(λ^2θ+c q+η sat(s/φ))\delta = -\dfrac{1}{\hat{b}}\bigl(\hat{\lambda}^2\theta + c\,q + \eta\,\mathrm{sat}(s/\varphi)\bigr)
The first two terms are the equivalent control that would keep s at zero if there were no disturbance. The last is the switching term: η is the switching gain and sat is the saturation, which is the sign function for φ→0\varphi \to 0.
The reaching condition
η>D+(model error terms)\eta > D + \text{(model error terms)}
The switching gain must exceed the bound D on the disturbance, plus whatever the model errors contribute. Then the surface is reached in finite time and held.
Boundary-layer error
∣s∣≤φ⇒∣θ∣≤φ/c in the steady state|s| \le \varphi \quad\Rightarrow\quad |\theta| \le \varphi/c \text{ in the steady state}
Inside the layer the state is no longer on the surface. The pitch decays toward a band of width φ/c\varphi/c and stays within it. The bound is conservative when the disturbance is small.

Derivation: the reaching condition and the layer bound

Hopper's pitch with a matched disturbance ∣d∣≤D|d| \le D and the law with λ^=λ, b^=b\hat{\lambda} = \lambda,\ \hat{b} = b.

  1. s˙=θ¨+c q=λ2θ+bδ+d+c q\dot{s} = \ddot{\theta} + c\,q = \lambda^2\theta + b\delta + d + c\,q

    Differentiate the sliding variable and substitute the plant.

  2. s˙=d−η sgn(s)\dot{s} = d - \eta\,\mathrm{sgn}(s)

    Substitute the sign form of the law (φ→0\varphi \to 0): the model terms cancel and what remains is the disturbance and the switching term.

  3. s s˙=s d−η ∣s∣≤−(η−D) ∣s∣s\,\dot{s} = s\,d - \eta\,|s| \le -(\eta - D)\,|s|

    Multiply by ss and use ∣d∣≤D|d| \le D. This is 12ddts2\tfrac{1}{2}\tfrac{d}{dt}s^2.

  4. treach≤∣s(0)∣η−Dt_{\mathrm{reach}} \le \dfrac{|s(0)|}{\eta - D}

    With η>D\eta > D the function s2/2s^2/2 is a Lyapunov function (the method of M5-T1: Lyapunov Stability) that decreases at a rate no smaller than (η−D)∣s∣(\eta - D)|s|, so ∣s∣|s| reaches zero in finite time.

The boundary layer

  1. s˙=d−η s/φ(∣s∣≤φ)\dot{s} = d - \eta\,s/\varphi \quad (|s| \le \varphi)

    Inside the layer the saturation is linear, so the sliding variable obeys a first-order stable equation driven by the disturbance.

  2. ∣s∣ss≤φDη (for a constant d),∣s∣≤φ always|s|_{ss} \le \dfrac{\varphi D}{\eta}\ \text{(for a constant } d), \qquad |s| \le \varphi \text{ always}

    At a steady state s=φd/ηs = \varphi d/\eta, which is smaller than φ\varphi when η>D\eta > D.

  3. ∣θ∣ss≤∣s∣max⁡c|\theta|_{ss} \le \dfrac{|s|_{\max}}{c}

    On the band the pitch obeys θ˙=−cθ+s\dot{\theta} = -c\theta + s, a stable first-order system driven by a bounded input, so its steady value is bounded by ∣s∣/c|s|/c.

The switching term overpowers any matched disturbance within a known bound, so the error dynamics on the surface are those the designer chose. The price is a command that switches faster than the actuator can follow; the boundary layer trades exactness for a smooth command.

A worked example

Hopper's pitch from 0.3 rad with c=3c = 3, switching gain η=1.5\eta = 1.5 against a disturbance d=1.0sin⁡3td = 1.0\sin 3t rad/s² (so D=1D = 1), a 40 rad/s gimbal servo, a 0.15 rad limit and a 3 rad/s rate limit that is only monitored.

  1. Pure switching. The sliding variable is held to |s| ≤ 0.002 and the pitch to 3·10⁻⁴ rad after 5 s: near-perfect rejection. The gimbal rate has an rms of 2.71 rad/s and exceeds the 3 rad/s limit 30% of the time.
  2. Boundary layer 0.05. |s| ≤ 0.033 and |θ| ≤ 0.0079 rad; the gimbal rate has an rms of only 0.12 rad/s and never exceeds the limit.
  3. Wider layers. φ = 0.2, 0.5, 1.0 give |θ| ≤ 0.030, 0.058, 0.074 rad, and the same gimbal activity (rms 0.12 to 0.13 rad/s).
  4. Bound check. The bound φ/c\varphi/c is 0.017, 0.067, 0.17 and 0.33 rad for the layers 0.05 to 1.0: always above the measured values, and conservative because the disturbance is not at its worst the whole time.
  5. Reading. The pure switch is the most accurate and the only one that violates the actuator. The thinnest layer already removes the chatter and costs an error of 0.008 rad, small against a 0.3 rad start.
import math
import gnckit as g

lam2, b = 0.49, 19.62
c = 3.0                                    # sliding surface s = q + c theta : on it, theta decays with pole -c
D = 1.0                                    # bound on the unknown disturbance acceleration
eta = 1.5                                  # switching gain > D
wservo, dmax = 40.0, 0.15
dt = 0.0005

def run(phi, T=10.0):
    th, q, d = 0.3, 0.0, 0.0
    ths, qs, ss, ds, drate = [], [], [], [], []
    for k in range(int(T / dt)):
        t = k * dt
        s = q + c * th
        sat = 1.0 if phi == 0 else max(-1.0, min(1.0, s / phi))
        sgn = (1.0 if s > 0 else -1.0 if s < 0 else 0.0) if phi == 0 else sat
        u = -(lam2 * th + c * q + eta * sgn) / b
        u = max(-dmax, min(dmax, u))
        dist = D * math.sin(3.0 * t) 
        dd = wservo * (u - d)
        th, q, d = th + dt * q, q + dt * (lam2 * th + b * d + dist), d + dt * dd
        ths.append(th); qs.append(q); ss.append(q + c * th); ds.append(d); drate.append(dd)
    return ths, qs, ss, ds, drate

print('sliding mode, s = q + 3 theta, switching gain 1.5 against a disturbance of 1.0 sin(3 t) rad/s^2, 40 rad/s gimbal servo:')
n0 = int(5.0 / dt)
for phi in (0.0, 0.05, 0.2, 0.5, 1.0):
    th, q, s, d, dr = run(phi)
    tail = slice(n0, None)
    maxth = max(abs(x) for x in th[tail]); maxs = max(abs(x) for x in s[tail])
    rms = math.sqrt(sum(x * x for x in dr[tail]) / len(dr[tail]))
    # fraction of time the gimbal rate exceeds the 3 rad/s limit (the actuator would be rate limited)
    frac = sum(1 for x in dr[tail] if abs(x) > 3.0) / len(dr[tail])
    label = 'sign (phi = 0)' if phi == 0 else f'phi = {phi:4.2f}'
    print(f'  {label:14s}: |theta| <= {maxth:.4f} rad after 5 s, |s| <= {maxs:.3f}, gimbal rate rms {rms:5.2f} rad/s, rate above 3 rad/s {100 * frac:4.0f}% of the time')
sliding mode, s = q + 3 theta, switching gain 1.5 against a disturbance of 1.0 sin(3 t) rad/s^2, 40 rad/s gimbal servo:
  sign (phi = 0): |theta| <= 0.0003 rad after 5 s, |s| <= 0.002, gimbal rate rms  2.71 rad/s, rate above 3 rad/s   30% of the time
  phi = 0.05    : |theta| <= 0.0079 rad after 5 s, |s| <= 0.033, gimbal rate rms  0.12 rad/s, rate above 3 rad/s    0% of the time
  phi = 0.20    : |theta| <= 0.0298 rad after 5 s, |s| <= 0.127, gimbal rate rms  0.13 rad/s, rate above 3 rad/s    0% of the time
  phi = 0.50    : |theta| <= 0.0581 rad after 5 s, |s| <= 0.246, gimbal rate rms  0.13 rad/s, rate above 3 rad/s    0% of the time
  phi = 1.00    : |theta| <= 0.0743 rad after 5 s, |s| <= 0.315, gimbal rate rms  0.12 rad/s, rate above 3 rad/s    0% of the time
The plant, a 40 rad/s servo and the switching law are stepped at 0.5 ms; the tail after 5 s gives the error and the gimbal-rate statistics for each boundary-layer width.

In robotics

Sliding-mode control is used where the disturbances are large, bounded and poorly modelled, and where the actuator is fast.

  • Power electronics and motor drives. The switches are the actuator, so hard switching costs nothing: the original home of the method.
  • Vehicles. Attitude and trajectory loops with large aerodynamic or thrust uncertainty use a boundary layer (smoothed sliding mode) or a higher-order variant. Hopper's thrust-vector actuator, with a rate limit, is on the unfavourable side of this trade.
  • Choosing the layer. Pick the width from the rate limit first (the gimbal must follow the command), and read the error bound φ/c\varphi/c from it. If the error is too large, a faster actuator or a lower switching gain is what is needed, not a thinner layer.
  • Unmatched and dynamic effects. A disturbance that does not enter through the control channel, a servo lag or a delay is not rejected, and can excite the chatter. The 40 rad/s servo above is already enough to make the pure switch violate the rate limit.
  • Higher-order sliding modes. Variants that switch the derivative of the control keep finite-time convergence and give a continuous command. They are in the references.

Design the same loop with the tools of module 3 and compare delay margins: the boundary-layer law is a saturated high-gain PD loop, and its margins are those of the linear segment, as the lab M5-L1: Schedule the Gains Through the Burn shows when the schedule is added.

Common misconceptions

“Sliding mode is robust to everything.”

It rejects matched disturbances inside the assumed bound. Unmatched disturbances, actuator lag and delay are not covered, and they are the usual source of chatter.

“A thinner boundary layer is always better.”

It improves accuracy and returns the chatter. Below a width set by the servo bandwidth and the rate limit the gimbal is asked for what it cannot do. The layer is chosen from the actuator first.

“The switching gain should be as large as possible.”

It must exceed the disturbance bound, and any excess only increases the activity of the command and the noise sensitivity. The smallest value that clears the bound with some margin is the right one.

“Chattering is a numerical artefact.”

In a simulation with a fixed step the chatter is visible at the step frequency, but the cause is physical: a real servo with lag cannot follow the switching and produces a real oscillation, as the 30% rate violation above shows.

“On the sliding surface the system forgets the plant.”

The motion along the surface depends only on the surface, but only after the state reaches it. Reaching takes time, during which the plant and the disturbance matter, and the control saturates if the start is far.

Key takeaways

  1. A sliding variable such as s=q+cθs = q + c\theta reduces the second-order problem to a first-order decay with pole −c on the surface.
  2. A switching gain larger than the matched-disturbance bound brings s to zero in a time at most ∣s(0)∣/(η−D)|s(0)|/(\eta - D).
  3. The hard switch rejects the disturbance almost perfectly but chatters: with a 40 rad/s servo Hopper's gimbal exceeds its rate limit 30% of the time.
  4. A boundary layer φ removes the chatter and leaves ∣s∣≤φ|s| \le \varphi, so ∣θ∣≲φ/c|\theta| \lesssim \varphi/c.
  5. With φ = 0.05 the error is 0.008 rad and the gimbal rate rms is 0.12 rad/s.
  6. Unmatched disturbances, lag and delay are outside the guarantee; the layer is chosen from the actuator first.

References and further reading

Each source is marked free or paid. Free to read does not mean free to reuse: the course resources page lists every source with its licence.

Knowledge check

Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

The disturbance bound is D = 1 rad/s² and the switching gain is η = 1.5. Starting at |s| = 0.9, give an upper bound on the time to reach the surface.

Explanation

The sliding variable satisfies s·ṡ ≤ −(η − D)|s| = −0.5|s|, so |s| falls at least at 0.5 per second, and treach ≤ 0.9/0.5 = 1.8 s. The actual time is shorter because the disturbance is rarely at its worst: in the simulation the variable is within 0.05 in about 1 s. The bound shows that raising η toward D lengthens the reach, and η below D gives no guarantee.

Question 2

With a boundary layer φ = 0.2 and c = 3, what pitch error does the theory allow, and what does the simulation give?

Explanation

The bound is |θ| ≲ φ/c = 0.2/3 = 0.067 rad. The simulation gives 0.030 rad, smaller than the bound because the disturbance is a sine of amplitude D, not a worst-case constant, and the bound assumes the sliding variable sits at the edge of the layer. A conservative bound is the correct behaviour of a theorem; a designer who needs less error has to narrow the layer or lower c.

Question 3

Why can a pure switching law violate a rate limit that the same law with a boundary layer satisfies?

Explanation

The pure switch flips the command between two values whenever s changes sign, which in a loop with delay and servo lag happens many times per second, so the command has an effective rate far above the limit (the rms gimbal rate is 2.71 rad/s, above 3 rad/s 30% of the time). The boundary layer replaces the flips by a proportional command inside the band, which moves at the rate of the disturbance (rms 0.12 rad/s). The disturbance rejection is the same in kind and the actuator activity is 20 times smaller.

What’s next

Next lesson

M5-T5 — Adaptive Control and Its Risks

Derive a model-reference adaptive law from a Lyapunov function, and explain parameter drift, loss of margin and why adaptive loops are hard to certify.

Nothing below is required to finish this lesson.

Other courses on this site treat neighbouring topics from their own angle:

This course leaves the following to the pages that already teach them: