ENع
→Controllability
الدرس 46 · State space and digital control

Controllability and observability

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

16 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

Before you design a controller from a state-space model, ask two questions: can the input steer every state, and can the output reveal every state? Follow the cart from "State-space models" through both rank tests, steer it to a target with two computed pushes, then watch two identical tanks fail both tests: one pump cannot hold them apart, and one total-level sensor cannot tell them apart.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 46 · تفاعلي
01 / 11

Two questions about a model

A state-space model ẋ = Ax + Bu, y = Cx raises two questions. Can the input u steer every state wherever we like? That is controllability. Can the output y reveal every state? That is observability. Start with the cart.

the cart from "State-space models"
  2 kg, spring 50 N/m, damper 4 N·s/m

x = [x₁, x₂] = [position, velocity]
u = force (N)      y = position (m)

A = [[  0,  1],    B = [0, 0.5]ᵀ
     [-25, -2]]    C = [1, 0]

controllable  u can drive x anywhere
observable    y lets us work out x
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Two questions about a model

    A state-space model ẋ = Ax + Bu, y = Cx raises two questions. Can the input u steer every state wherever we like? That is controllability. Can the output y reveal every state? That is observability. Start with the cart.

    the cart from "State-space models"
      2 kg, spring 50 N/m, damper 4 N·s/m
    
    x = [x₁, x₂] = [position, velocity]
    u = force (N)      y = position (m)
    
    A = [[  0,  1],    B = [0, 0.5]ᵀ
         [-25, -2]]    C = [1, 0]
    
    controllable  u can drive x anywhere
    observable    y lets us work out x
  2. The push reaches velocity

    B = [0, 0.5] says the force acts only on the velocity x₂, at 0.5 m/s² per newton. There is no wire from u to the position x₁: that entry of B is zero. Is the position out of reach?

    ẋ₁ = 0·x₁ + 1·x₂ + 0·u      ← u not here
    ẋ₂ = −25·x₁ − 2·x₂ + 0.5·u  ← u enters here
    
    B = [0, 0.5]ᵀ
    
    A zero entry is a missing wire: the force
    cannot change the position directly.
  3. Velocity carries it on

    No. Row one of A says ẋ₁ = x₂: velocity flows into position, so the push reaches x₁ one integration later. Multiplying shows it: AB = [0.5, −1]. Its first entry is no longer zero.

    B  = [0, 0.5]       u changes x₂ now
    AB = A·B
       = [ 0·0 + 1·0.5,
          −25·0 − 2·0.5]
       = [0.5, −1]       ...and x₁ next
    
    Each extra power of A follows the wires
    one more step: B, AB, A²B, ...
  4. The controllability matrix

    Put the two directions side by side: [B AB] = [[0, 0.5], [0.5, −1]]. Its determinant is −0.25, not zero, so the columns point different ways and span the plane. Rank 2 equals the number of states: controllable.

    A = [[0, 1], [-25, -2]]
    B = [0, 0.5]
    AB = [A[0][0]*B[0] + A[0][1]*B[1], A[1][0]*B[0] + A[1][1]*B[1]]
    det = B[0]*AB[1] - AB[0]*B[1]   # columns B and AB
    print(AB, det)                  # [0.5, -1.0] -0.25
    
    # n states: controllable iff rank [B AB ... A^(n-1)B] = n
  5. Steer it anywhere

    Controllable means we can solve for an input. Goal: from rest to 0.1 m, stopped, in 1 s. Two unknowns, two equations: push 2.17 N for half a second, then 4.20 N. It lands exactly, and 5 N holds it.

    A = [[0, 1], [-25, -2]]; B = [0, 0.5]
    def run(x, u, T, dt=1e-4):
        for _ in range(round(T / dt)):
            d = [A[i][0]*x[0] + A[i][1]*x[1] + B[i]*u for i in range(2)]
            x = [x[i] + d[i]*dt for i in range(2)]
        return x
    g1 = run(run([0, 0], 1, 0.5), 0, 0.5)  # 1 N early
    g2 = run([0, 0], 1, 0.5)               # 1 N late
    det = g1[0]*g2[1] - g1[1]*g2[0]        # not 0: solvable
    u1, u2 = 0.1*g2[1] / det, -g1[1]*0.1 / det
    x = run(run([0, 0], u1, 0.5), u2, 0.5)
    print(round(u1, 2), round(u2, 2), round(x[0], 3), abs(round(x[1], 3)))  # 2.17 4.2 0.1 0.0
  6. Two identical tanks

    Now a system that fails. Two identical tanks each head for the pump setting u with a 1-minute time constant: ẋ₁ = −x₁ + u, ẋ₂ = −x₂ + u. One pump feeds both, so B = [1, 1]. Every state has a wire.

    ẋ₁ = −x₁ + u       tank 1 (level, m)
    ẋ₂ = −x₂ + u       tank 2 (level, m)
    t in minutes
    
    A = [[-1,  0],     B = [1, 1]ᵀ
         [ 0, -1]]
    
    No wire between the tanks: A₁₂ = A₂₁ = 0.
    The pump reaches both directly.
  7. The gap ignores the pump

    Start tank 1 at 1 m and tank 2 empty, then run the pump. Subtract the equations: the gap x₁ − x₂ obeys d(gap)/dt = −gap. It fades as e^(−t) whatever u does. No input can hold the levels apart.

    def gap_after_2min(u_of_t, dt=1e-3):
        x1, x2 = 1.0, 0.0
        for n in range(2000):
            u = u_of_t(n * dt)
            x1 += (-x1 + u) * dt
            x2 += (-x2 + u) * dt
        return round(x1 - x2, 3)
    print(gap_after_2min(lambda t: 0), gap_after_2min(lambda t: 1), gap_after_2min(lambda t: 5 * t))  # 0.135 0.135 0.135
  8. The test catches it

    AB = [−1, −1] lies along the same line as B = [1, 1]. So [B AB] = [[1, −1], [1, −1]] has determinant 0 and rank 1. The pump moves only the average level. A wire to every state is not enough.

    A = [[-1, 0], [0, -1]]
    B = [1, 1]
    AB = [A[0][0]*B[0] + A[0][1]*B[1], A[1][0]*B[0] + A[1][1]*B[1]]
    det = B[0]*AB[1] - AB[0]*B[1]
    print(AB, det)    # [-1, -1] 0
    
    # reachable: only multiples of [1, 1] (the average)
    # out of reach: the gap direction [1, -1]
  9. Observability: what y reveals

    Now the mirror question. The cart's sensor reads position only: C = [1, 0]. Velocity is how fast that reading changes: CA = [0, 1]. Stacked, [C; CA] is the identity: determinant 1, rank 2. The cart is observable.

    A = [[0, 1], [-25, -2]]
    C = [1, 0]
    CA = [C[0]*A[0][0] + C[1]*A[1][0], C[0]*A[0][1] + C[1]*A[1][1]]
    det = C[0]*CA[1] - C[1]*CA[0]   # rows C and CA
    print(CA, det)                  # [0, 1] 1
    
    # y = x₁, dy/dt = CA·x = x₂: two readings, two states
  10. Two starts, one output

    Read the tanks with one sensor for the total level, C = [1, 1], pump off. Start A at [1, 0] and start B at [0, 1] give the same output, e^(−t), for ever. [C; CA] = [[1, 1], [−1, −1]]: rank 1, unobservable.

    def y_after(x1, x2, T=1.0, dt=1e-3):   # pump off
        for n in range(round(T / dt)):
            x1 += -x1 * dt
            x2 += -x2 * dt
        return round(x1 + x2, 4)          # y = Cx
    print(y_after(1, 0), y_after(0, 1), y_after(0.3, 0.7))  # 0.3677 0.3677 0.3677
  11. Test before you design

    State feedback can move every pole only if the system is controllable; an observer can place its error poles only if it is observable. The tanks hide a mode: their transfer function is just 2/(s + 1). Check the ranks first.

    C(sI − A)⁻¹B for the tanks
      = [1, 1]·diag(1/(s+1), 1/(s+1))·[1, 1]ᵀ
      = 2/(s + 1)        first order, 2 states
    the gap mode cannot be reached or seen
    
    # python-control (optional)
    import control as ct, numpy as np
    A = [[0, 1], [-25, -2]]; B = [[0], [0.5]]; C = [[1, 0]]
    np.linalg.matrix_rank(ct.ctrb(A, B))   # 2
    np.linalg.matrix_rank(ct.obsv(A, C))   # 2

اختبار يتاح بعد الخطوة الأخيرة.