@@ -414,16 +414,29 @@ function LimPID(; name, k = 1, Ti = false, Td = false, wp = 1, wd = 1,
414414end
415415
416416"""
417- StateSpace(A, B, C, D=0; x_start=zeros(size(A,1)), name)
417+ StateSpace(A, B, C, D=0; x_start=zeros(size(A,1)), u0=zeros(size(B,2)), y0=zeros(size(C,1)), name)
418418
419419A linear, time-invariant state-space system on the form.
420- ```
420+ ```math
421421ẋ = Ax + Bu
422422y = Cx + Du
423423```
424424Transfer functions can also be simulated by converting them to a StateSpace form.
425+
426+ `y0` and `u0` can be used to set an operating point, providing them changes the dynamics from an LTI system to the affine system
427+ ```math
428+ ẋ = Ax + B(u - u0)
429+ y = Cx + D(u - u0) + y0
430+ ```
431+ For a nonlinear system
432+ ```math
433+ ẋ = f(x, u)
434+ y = h(x, u)
435+ ```
436+ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u₀), u₀`.
425437"""
426- function StateSpace (; A, B, C, D = nothing , x_start = zeros (size (A, 1 )), name)
438+ function StateSpace (; A, B, C, D = nothing , x_start = zeros (size (A, 1 )), name,
439+ u0 = zeros (size (B, 2 )), y0 = zeros (size (C, 1 )))
427440 nx, nu, ny = size (A, 1 ), size (B, 2 ), size (C, 1 )
428441 size (A, 2 ) == nx || error (" `A` has to be a square matrix." )
429442 size (B, 1 ) == nx || error (" `B` has to be of dimension ($nx x $nu )." )
@@ -442,9 +455,11 @@ function StateSpace(; A, B, C, D = nothing, x_start = zeros(size(A, 1)), name)
442455 # pars = @parameters A=A B=B C=C D=D # This is buggy
443456 eqs = [ # FIXME : if array equations work
444457 [Differential (t)(x[i]) ~ sum (A[i, k] * x[k] for k in 1 : nx) +
445- sum (B[i, j] * input. u[j] for j in 1 : nu) for i in 1 : nx]. .. , # cannot use D here
458+ sum (B[i, j] * (input. u[j] - u0[j]) for j in 1 : nu)
459+ for i in 1 : nx]. .. , # cannot use D here
446460 [output. u[j] ~ sum (C[j, i] * x[i] for i in 1 : nx) +
447- sum (D[j, k] * input. u[k] for k in 1 : nu) for j in 1 : ny]. .. ,
461+ sum (D[j, k] * (input. u[k] - u0[k]) for k in 1 : nu) + y0[j]
462+ for j in 1 : ny]. .. ,
448463 ]
449464 compose (ODESystem (eqs, t, vcat (x... ), [], name = name), [input, output])
450465end
0 commit comments