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

State-space models

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

18 دقيقة10 خطوات5 أسئلةAdvanced
عن هذا الدرس

Describe a system by its state: the few numbers it remembers. Take the cart on a spring and damper, choose position and velocity as the state, and write its motion as ẋ = Ax + Bu, y = Cx + Du. Work the matrices by hand at one moment, step them on a computer in plain Python, watch the state spiral home in the state space, and see that the eigenvalues of A are the poles of the transfer function.

ستتعلّم

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

شكل 44 · تفاعلي
01 / 10

What the cart remembers

Take the 2 kg cart on a 50 N/m spring and a 4 N·s/m damper. To predict its future you need two numbers now: position x₁ and velocity x₂. That pair is the state, the cart's memory.

state = the smallest set of numbers that, with the
input from now on, fixes everything that happens next

x₁ = position   (m)
x₂ = velocity   (m/s)

frozen moment used in the next steps:
x = [0.1, 0.5]   u = 10 N
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. What the cart remembers

    Take the 2 kg cart on a 50 N/m spring and a 4 N·s/m damper. To predict its future you need two numbers now: position x₁ and velocity x₂. That pair is the state, the cart's memory.

    state = the smallest set of numbers that, with the
    input from now on, fixes everything that happens next
    
    x₁ = position   (m)
    x₂ = velocity   (m/s)
    
    frozen moment used in the next steps:
    x = [0.1, 0.5]   u = 10 N
  2. Two first-order equations

    Swap the one second-order equation 2ẍ + 4ẋ + 50x = u for two first-order ones. Position changes at the velocity: ẋ₁ = x₂. Newton gives ẋ₂ = −25x₁ − 2x₂ + 0.5u. An integrator turns each rate into its state.

    2ẍ + 4ẋ + 50x = u        (Newton, one 2nd-order eq.)
    
    ẋ₁ = x₂
    ẋ₂ = (u − 4·x₂ − 50·x₁) / 2
       = −25·x₁ − 2·x₂ + 0.5·u
    
    ẋ means "rate of change of x". Integrating a
    rate over time gives the state back: that is
    the ∫ block.
  3. A: how the state moves

    Put the numbers that multiply the states in a grid: A = [[0, 1], [−25, −2]]. Row one gives ẋ₁, row two gives ẋ₂. At x = [0.1, 0.5], A·x = [0.5, −3.5]. A holds the spring and the damper.

    A = [[  0,  1],        row 1: ẋ₁ = 0·x₁ + 1·x₂
         [-25, -2]]        row 2: ẋ₂ = −25·x₁ − 2·x₂
    
    A·x at x = [0.1, 0.5]:
      row 1:   0·0.1 + 1·0.5    =  0.5
      row 2: −25·0.1 − 2·0.5    = −3.5
    A·x = [0.5, −3.5]
    
    −25 = −k/m (spring)   −2 = −b/m (damper)
  4. B: where the input enters

    The force only reaches the velocity, at 1/m = 0.5 per newton, so B is the column [0, 0.5]. With u = 10 N, B·u = [0, 5]. Add the two parts and you have the state equation: ẋ = Ax + Bu.

    B = [0, 0.5]ᵀ          (a column: one input)
    B·u = [0·10, 0.5·10] = [0, 5]
    
    state equation:
      ẋ = A·x + B·u
        = [0.5, −3.5] + [0, 5]
        = [0.5, 1.5]
    
    One line, however many states there are.
  5. Integrate: the state moves on

    The sum ẋ = [0.5, 1.5] is how fast the state changes. The integrator adds ẋ·dt to the state over and over. After 1 ms the state is [0.1005, 0.5015]. The integrator is the only memory here.

    ẋ  = [0.5, 1.5]
    dt = 0.001 s
    
    x_new = x + ẋ·dt
          = [0.1 + 0.5·0.001, 0.5 + 1.5·0.001]
          = [0.1005, 0.5015]
    
    A real integrator does this continuously;
    a computer does it in small steps.
  6. C: what we measure

    We measure position only, so C = [1, 0] picks x₁ out of the state: y = 0.1 m. D = 0 because the force does not reach the output directly. y = Cx + Du is the output equation.

    C = [1, 0]     D = 0
    
    y = C·x + D·u
      = 1·0.1 + 0·0.5 + 0·10
      = 0.1 m
    
    The four matrices A, B, C, D are the whole
    state-space model.
  7. Step it on a computer

    Start at rest and push with 10 N. Every millisecond: ẋ = Ax + Bu, then x = x + ẋ·dt, then y = Cx. The cart peaks at 0.305 m after 0.64 s and settles at 0.2 m.

    # x' = Ax + Bu, y = Cx, forward Euler
    A = [[0, 1], [-25, -2]]
    B = [0, 0.5]
    x, u, dt, peak = [0.0, 0.0], 10.0, 0.001, 0.0
    for n in range(6000):          # 6 s
        dx = [A[i][0]*x[0] + A[i][1]*x[1] + B[i]*u for i in range(2)]
        x = [x[i] + dx[i]*dt for i in range(2)]
        peak = max(peak, x[0])     # y = Cx = x[0]
    print(round(peak, 3), round(x[0], 3))  # 0.306 0.2
    # exact peak 0.305 m: Euler with 1 ms is 0.306
  8. The path through state space

    Plot velocity against position and the state draws a spiral into (0.2 m, 0 m/s), where the spring holds the 10 N push. The plane of all possible states is called the state space.

    x₂ (velocity) against x₁ (position), same run:
    
    start        (0, 0)
    fastest      0.76 m/s
    furthest     0.305 m, velocity 0
    end          (0.2, 0): spring force 50·0.2 = 10 N
    
    Each point is one state; the input moves it
    along a path that never crosses itself.
  9. Eigenvalues of A are poles

    Solve det(sI − A) = s² + 2s + 25 = 0: s = −1 ± j4.90. These eigenvalues of A are the poles of 1/(2s² + 4s + 50). The −1 sets how fast the swing dies; 4.90 rad/s how fast it swings.

    sI − A = [[s,   -1  ],
              [25,  s+2 ]]
    det = s(s+2) + 25 = s² + 2s + 25
    s = −1 ± j√24 = −1 ± j4.90
    
    C(sI − A)⁻¹B = 0.5/(s² + 2s + 25)
                 = 1/(2s² + 4s + 50)   same cart
    
    # python-control (optional)
    # import control as ct
    # sys = ct.ss(A, B, [[1, 0]], 0); sys.poles()
  10. Why use matrices

    Many inputs, many outputs and many states all fit the same four matrices. A computer steps them with one loop, and the state holds things a transfer function hides. The lessons that follow use A and B to place poles.

    size of the matrices, n states, m inputs, p outputs:
      A  n×n     B  n×m
      C  p×n     D  p×m
    cart: n = 2, m = 1, p = 1
    
    same form for a drone, a motor, a power grid.
    The transfer function only sees input → output;
    the state model also sees inside.

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