Engee 文档
Notebook

连接模型

在这个例子中,我们将学习如何在Engee中对LTI系统的连接进行建模。 从简单的串行和并行连接到复杂的流程图。

检讨

Engee提供了许多功能来帮助您创建LTI模型联合。 这些包括功能:

*串行和并行连接(series, parallel)
*与反馈的连接(feedback, feedback2dof)
*输入和输出串联([ , ], [ ; ], append, array2mimo)
*流程图的一般构造(connect)

为了说明这些示例,我们将连接必要的库并创建两个具有以下传递函数的系统:

In [ ]:
Pkg.add(["RobustAndOptimalControl", "ControlSystems"])
In [ ]:
using ControlSystems
In [ ]:
H1 = tf(2,[1, 3, 0])
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}
   2
--------
s^2 + 3s

Continuous-time transfer function model
In [ ]:
H2 = zpk([],[-5],5)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Int64}}
   1
5-----
 s + 5

Continuous-time transfer function model

串行连接

使用运算符 * 或函数 series 对于lti模型的串行连接,例如:

GSConnectingModels_01.png
In [ ]:
H = H2 * H1
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Complex{Int64}}}
          1
10-----------------
  (s + 5)(s + 3)(s)

Continuous-time transfer function model
In [ ]:
H = series(H1,H2)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Complex{Int64}}}
          1
10-----------------
  (s + 5)(s + 3)(s)

Continuous-time transfer function model

并联连接

使用运算符 + 或函数 parallel 对于lti模型的并行连接,例如:

GSConnectingModels_02.png
In [ ]:
H = H1 + H2
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Float64, ComplexF64}}
   (1.0s + 2.6433981132056608)(1.0s + 0.7566018867943395)
5.0------------------------------------------------------
               (1.0s + 3.0)(1.0s)(1.0s + 5.0)

Continuous-time transfer function model
In [ ]:
H = parallel(H1,H2)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Float64, ComplexF64}}
   (1.0s + 2.6433981132056608)(1.0s + 0.7566018867943395)
5.0------------------------------------------------------
               (1.0s + 3.0)(1.0s)(1.0s + 5.0)

Continuous-time transfer function model

与反馈的联系

负反馈回路系统结构方案的标准视图:

GSConnectingModels_03.png

要识别一个封闭的系统,请使用函数 feedback.

In [ ]:
H = feedback(H1,H2)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Float64, ComplexF64}}
                                    1.0s + 5.0
2.0-----------------------------------------------------------------------------
   (1.0s + 5.663076827457541)(1.0s^2 + 2.3369231725424586s + 1.7658245340262375)

Continuous-time transfer function model

请注意,默认情况下反馈是负面的。 要给出积极的反馈,请使用以下语法:

In [ ]:
H = feedback(H1, H2, pos_feedback = true)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Float64, ComplexF64}}
                                   1.0s + 5.0
2.0---------------------------------------------------------------------------
   (1.0s^2 + 8.515690830166166s + 19.3914636736468)(1.0s - 0.5156908301661673)

Continuous-time transfer function model

组合输入和输出

您可以通过输入组合两个模型h1和H2的输入数据:

In [ ]:
H = [H1 H2]
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Complex{Int64}}}
Input 1 to output 1
     1
2----------
 (s + 3)(s)

Input 2 to output 1
   1
5-----
 s + 5

Continuous-time transfer function model

生成的模型有两个输入和一个输出,对应于以下方案:

GSConnectingModels_05.png

同样,您可以通过输入来组合H1和H2的输出:

In [ ]:
H = [ H1 ; H2 ]
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Complex{Int64}}}
Input 1 to output 1
     1
2----------
 (s + 3)(s)

Input 1 to output 2
   1
5-----
 s + 5

Continuous-time transfer function model

生成的模型H具有两个输出和一个输入,对应于以下流程图:

GSConnectingModels_06.png

最后,您可以使用以下方法组合两个模型的输入和输出:

In [ ]:
H = append(H1,H2)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Complex{Int64}}}
Input 1 to output 1
     1
2----------
 (s + 3)(s)

Input 1 to output 2
 1
0-
 1

Input 2 to output 1
 1
0-
 1

Input 2 to output 2
   1
5-----
 s + 5

Continuous-time transfer function model

生成的模型H具有两个输入和两个输出,并遵循框图:
GSConnectingModels_07.png

您可以使用串联从基本SISO模型构建MIMO模型,例如:

In [ ]:
[H1 -tf(10,[1, 10]); 0 H2]
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Complex{Int64}}}
Input 1 to output 1
     1
2----------
 (s + 3)(s)

Input 1 to output 2
 1
0-
 1

Input 2 to output 1
     1
-10------
   s + 10

Input 2 to output 2
   1
5-----
 s + 5

Continuous-time transfer function model

您也可以使用该功能 array2mimo. 例如,

In [ ]:
P = ss(-1,1,1,0);
sys_array = fill(P, 2, 2) # Создает массив систем
mimo_sys = array2mimo(sys_array)
Out[0]:
StateSpace{Continuous, Int64}
A = 
 -1   0   0   0
  0  -1   0   0
  0   0  -1   0
  0   0   0  -1
B = 
 1  0
 0  1
 1  0
 0  1
C = 
 1  1  0  0
 0  0  1  1
D = 
 0  0
 0  0

Continuous-time state-space model

基于流程图构建模型

您可以使用函数和操作的组合来构建简单流程图的模型。 例如,请考虑以下流程图:

GSConnectingModels_09.png 与以下数据块F,C,G,S:
In [ ]:
s = tf('s');
F = 1/(s + 1);
G = 100/(s^2 + 5*s + 100);
C = 20*(s^2 + s + 60)/s/(s^2 + 40*s + 400);
S = 10/(s + 10);

您可以定义封闭系统从r到y的传递函数,如下所示:

In [ ]:
T = F * feedback(G*C,S)
plot(step(T,10))
Out[0]:

但是对于更复杂的流程图,使用函数 connect 图书馆 RobustAndOptimalControl.jl. 要使用 connect,请按照以下步骤操作:

*识别图中的所有块,包括求和块;
*命名块的所有输入和输出通道;
*将系统块的输出与块的相应输入相匹配。

让我们看一下使用下面的框图的例子的函数的例子。
GSConnectingModels_11.png

导入和连接库 RobustAndOptimalControl.jl.

In [ ]:
import Pkg
Pkg.add("RobustAndOptimalControl")
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using RobustAndOptimalControl

使用功能 named_ss,以便为每个块设置输入和输出信号的名称。

In [ ]:
F1 = named_ss(F, x=:xF, u=:r, y=:u_f)
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 -1.0
B = 
 1.0
C = 
 1.0
D = 
 0.0

Continuous-time state-space model
With state  names: xF
     input  names: r
     output names: u_f
In [ ]:
G1 = named_ss(G, x=:xG, u=:u, y=:y_m)
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
  0.0   16.0
 -6.25  -5.0
B = 
 0.0
 2.0
C = 
 3.125  0.0
D = 
 0.0

Continuous-time state-space model
With state  names: xG1 xG2
     input  names: u
     output names: y_m
In [ ]:
C1 = named_ss(C, x=:xC, u=:e, y=:u_c)
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 0.0    4.0    0.0
 0.0    0.0   16.0
 0.0  -25.0  -40.0
B = 
 0.0
 0.0
 8.0
C = 
 2.34375  0.15625  2.5
D = 
 0.0

Continuous-time state-space model
With state  names: xC1 xC2 xC3
     input  names: e
     output names: u_c
In [ ]:
S1 = named_ss(S, x=:xS, u=:y_m, y=:y)
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 -10.0
B = 
 4.0
C = 
 2.5
D = 
 0.0

Continuous-time state-space model
With state  names: xS
     input  names: y_m
     output names: y

使用函数表示加法器 sumblock.

In [ ]:
Sum1 = sumblock("e = r - y")
Out[0]:
sumblock: NamedStateSpace{Continuous, Float64}
D = 
 1.0  -1.0

Continuous-time state-space model
With state  names: 
     input  names: r y
     output names: e
In [ ]:
Sum2 = sumblock("u = u_f + u_c")
Out[0]:
sumblock: NamedStateSpace{Continuous, Float64}
D = 
 1.0  1.0

Continuous-time state-space model
With state  names: 
     input  names: u_f u_c
     output names: u

仔细标记连接非常重要。 连接是根据一个块的输出连接到另一个块的输入的原则形成的。 例如,信号 е 是输出 Sum1,但它也是块的输入 C.

In [ ]:
connections = [
    :e => :e # output e Sum1 to input C
    :y => :y # output y S to input Sum1
    :u => :u # output u Sum2 to input G
    :u_f => :u_f # output u_f F to input Sum2
    :u_c => :u_c # output u_c C to input Sum2
    :y_m => :y_m # output G to input S
]
Out[0]:
6-element Vector{Pair{Symbol, Symbol}}:
   :e => :e
   :y => :y
   :u => :u
 :u_f => :u_f
 :u_c => :u_c
 :y_m => :y_m

识别输入信号也很重要 w1 休息一天 z1.

In [ ]:
w1 = [:r]
z1 = [:y_m]
Out[0]:
1-element Vector{Symbol}:
 :y_m

所有计算的数据提交到输入 connect. 您可以在Julia文档中了解有关所有函数参数的更多信息统一систем.

In [ ]:
P = connect([F1, C1, G1, S1, Sum1, Sum2], connections; w1,z1,unique = false)
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 -1.0  0.0       0.0       0.0   0.0    0.0    0.0
  0.0  0.0       4.0       0.0   0.0    0.0    0.0
  0.0  0.0       0.0      16.0   0.0    0.0    0.0
  0.0  0.0     -25.0     -40.0   0.0    0.0  -20.0
  0.0  0.0       0.0       0.0   0.0   16.0    0.0
  2.0  4.6875    0.3125    5.0  -6.25  -5.0    0.0
  0.0  0.0       0.0       0.0  12.5    0.0  -10.0
B = 
 1.0
 0.0
 0.0
 8.0
 0.0
 0.0
 0.0
C = 
 0.0  0.0  0.0  0.0  3.125  0.0  0.0
D = 
 0.0

Continuous-time state-space model
With state  names: xF##feedback#587 xC1##feedback#587 xC2##feedback#587 xC3##feedback#587 xG1##feedback#587 xG2##feedback#587 xS##feedback#587
     input  names: r
     output names: y_m

让我们构建由此产生的封闭系统的过渡过程。

In [ ]:
plot(stepinfo(step(P,5)))
Out[0]:

结论

在本文中,我们考虑了连接模型的方法。 您可以在[建筑系统]部分了解更多有关转换结构图的功能(https://engee.com/helpcenter/stable/julia/ControlSystems/lib/constructors.html )。