Engee 文档
Notebook

直流电机控制

本示例比较了三种直流电机控制方法:

  • 直接控制
  • 反馈控制
  • LQR 控制。

让我们比较一下这些方法对负载干扰的敏感性。

问题陈述

在锚控制 DCT 中,输入电压$V_a$ 控制电机轴的角速度。

xxdcdemofigures_01.png

本例展示了两种控制 DPT 的方法,以降低$\omega$ 对负载变化(电机负载产生的扭矩变化)的敏感性。

xxdcdemofigures_02.png

简化的直流电机模型如上图所示。转矩参数$T_d$ 模拟负载干扰。应尽量减少此类干扰引起的速度波动。

让我们来设置电机参数。在本例中,物理常数为

In [ ]:
Pkg.add(["LinearAlgebra", "RobustAndOptimalControl", "ControlSystems", "ControlSystemsBase"])
In [ ]:
import Pkg; 
Pkg.add("ControlSystemsBase")
Pkg.add("RobustAndOptimalControl")
Pkg.add("LinearAlgebra")
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
   Resolving package versions...
    Updating `~/.project/Project.toml`
  [37e2e46d] + LinearAlgebra
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using ControlSystems, ControlSystemsBase, RobustAndOptimalControl, LinearAlgebra

R = 2.0 ;   
L = 0.5;     
Km = 0.1;   
Kb = 0.1;    
Kf = 0.2;    
J = 0.02;    

让我们建立一个具有两个输入 ($V_a$,$T_d$) 和一个输出 ($w$) 的 DPT 模型。首先,让我们以传递函数的形式来定义上述结构图中各块的描述。

In [ ]:
h1 = tf([Km], [L, R])
h2 = tf([1], [J, Kf]) 
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
    1.0
-----------
0.02s + 0.2

Continuous-time transfer function model

建立模块之间的联系。分配输入和输出信号的名称,定义汇总模块,并使用函数connect() 建立模块之间的联系。

为输入和输出信号指定名称。

In [ ]:
H1 = named_ss(h1, x = :xH1, u = :uH1, y = :yH1)
H2 = named_ss(h2, x = :xH2, u = :uH2, y = :yH2)
Kb = named_ss(ss(Kb), x = :xKb, u = :uKb, y = :yKb)

指定汇总单元的输入和输出信号。

In [ ]:
Sum1 = sumblock("uH1 = Va - yKb")
Sum2 = sumblock("uH2 = yH1 + Td")

在模块的输出和输入之间建立对应关系。

In [ ]:
connections = [
    :uH1 => :uH1;
    :yH1 => :yH1;
    :uH2 => :uH2;
    :yH2 => :uKb;
    :yKb => :yKb;   
]

设置外部输入信号和输出信号。

In [ ]:
w1 = [:Va, :Td]
z1 = [:yH2]

将参数传递给函数connect() ,以获得系统模型。

In [ ]:
dcm = connect([H2, H1, Kb, Sum1, Sum2], connections; z1, w1, verbose = true)

现在我们来看看单步冲击的响应。

In [ ]:
V_a = dcm[1,1];
plot(stepinfo(step(V_a,2.5)))
Out[0]:

当输入($Td=0$ )受到单步冲击时,输出信号的稳态值为 0.244。

直流电机的直接控制

第一种控制方式是直接控制。系统将输入所需的角速度值 ($w_{ref}$) 并模拟外部转矩 ($Td$) 。

xxdcdemofigures_03.png

直接耦合增益$K_{ff}$ 必须设置为直流增益的倒数,从$Va$ 到$w$ 。

In [ ]:
Kff = 1/dcgain(V_a)[1]
Out[0]:
4.099999999999999

为评估直接耦合设计在负载扰动下的有效性,请模拟对阶跃指令$w_{ref}=1$ 的响应,在$t=5 и t=10$ 秒之间的扰动为$Td = -0,1 Нм$ :

In [ ]:
t = 0:0.01:15
Td = -0.1 * (5 .< t .< 10)          
u = hcat( ones( length(t) ), Td )       

cl_ff = dcm * Diagonal( [Kff, 1] )   

h_1 = lsim( cl_ff, u, t )
plot( h_1, label = "Прямое управление, h_1(t)" )
plot!( t, Td, label = "Внешний возмущающий момент, Td" )
Out[0]:

反馈系统

让我们考虑控制的第二种变体,并描述反馈控制结构。

xxdcdemofigures_04.png

为确保稳态误差为零,我们将控制器$C(s)$ 用作增益积分器。

要确定增益 K,我们可以使用应用于开环传输的均方根霍德图方法 ($1/s * (Va \to w)$) :

In [ ]:
rlocusplot( ss( tf( 1, [1, 0] ) ) * V_a )
Out[0]:

将鼠标悬停在曲线上,熟悉增益值和相应的极点。可以看到,两个根的轨迹与虚轴相交。在这些点上,$K\approx55$ 。为了使系统保持稳定,我们需要选择$K<55$ 。让我们选择$K = 5$ 。

In [ ]:
K = 5;

说出输入和输出信号的名称。

In [ ]:
C = named_ss( tf( K,[1, 0] ), x=:xC, u=:e, y=:Va )
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 0.0
B = 
 2.0
C = 
 2.5
D = 
 0.0

Continuous-time state-space model
With state  names: xC
     input  names: e
     output names: Va

指定汇总单元的输入和输出信号。

In [ ]:
sum = sumblock( "e = w_ref - yH2" )
Out[0]:
sumblock: NamedStateSpace{Continuous, Float64}
D = 
 1.0  -1.0

Continuous-time state-space model
With state  names: 
     input  names: w_ref yH2
     output names: e

在模块的输出和输入之间建立对应关系。

In [ ]:
connections1 = [
    :e => :e;
    :Va => :Va;
    :yH2 => :yH2
]
Out[0]:
3-element Vector{Pair{Symbol, Symbol}}:
   :e => :e
  :Va => :Va
 :yH2 => :yH2

设置外部输入信号和输出信号

In [ ]:
w1 = [ :w_ref, :Td ]
z1 = [ :yH2 ]
Out[0]:
1-element Vector{Symbol}:
 :yH2

将参数传递给函数connect() ,以获得系统模型。

In [ ]:
cl_rloc = connect( [sum, C, dcm], connections1; w1, z1 )
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 0.0   -12.5      0.0
 0.0   -10.0      3.2
 1.25   -0.3125  -4.0
B = 
 2.0  0.0
 0.0  8.0
 0.0  0.0
C = 
 0.0  6.25  0.0
D = 
 0.0  0.0

Continuous-time state-space model
With state  names: xC##feedback#237 xH2##feedback#227##feedback#237 xH1##feedback#227##feedback#237
     input  names: w_ref Td
     output names: yH2

让我们绘制直接控制和反馈控制的输出信号。

In [ ]:
h_2 = lsim( cl_rloc, u, t )       
plot( h_1, label = "Прямое управление, h_1(t)" )
plot!( h_2, label = "Управление с обратной связью, h_2(t)" )
plot!( t, Td, label = "Внешний возмущающий момент, Td" )
Out[0]:

反馈控制的结果比直接控制方法好得多。不过,在动作开始和结束时都会出现峰值$Td$ 。

用懒惰二次方控制器控制直流电机

为了进一步提高性能,我们尝试为下图所示的反馈结构设计一个线性二次调节器(LQR)。

xxdcdemofigures_05.png

除了积分之外,LQR 电路还利用状态矢量$x=(i,w)$ 来合成控制电压$Va$ 。所得电压为 $$ Va = K1w+K2\frac{w}{s}+K3i $$ 其中$i$ 为电枢电流

为了更好地抑制扰动,我们使用了 "惩罚 "大积分误差的成本函数。例如

$$ C = \int_0^\infty (20q(t)^2+\omega(t)^2+0.01V_a(t)^2)\,\mathrm{d}x $$

其中

$$ q(s)=\frac{\omega(s)}{s} $$

我们计算出该成本函数的最佳 LQR 增益。

将输出w/s 添加到模型dcm 中。

In [ ]:
dc_aug = [ 1 ; ss( tf( 1,[1, 0] ) ) ] * V_a 
Out[0]:
NamedStateSpace{Continuous, Float64}
A = 
 0.0    6.25     0.0
 0.0  -10.0      3.2
 0.0   -0.3125  -4.0
B = 
 0.0
 0.0
 0.5
C = 
 0.0  6.25  0.0
 1.0  0.0   0.0
D = 
 0.0
 0.0

Continuous-time state-space model
With state  names: ##x#239 xH2##feedback#227 xH1##feedback#227
     input  names: Va
     output names: ##y#2411 ##y#2412

设置权重矩阵 Q 和 R,并使用函数lqr 合成控制器。

In [ ]:
Q = [ 20 0 0; 0 1 0; 0 0 1 ]
R = 0.01
K_lqr = lqr( dc_aug, Q, R )
Out[0]:
1×3 Matrix{Float64}:
 44.7214  25.5262  14.1526

这样就得到了一个闭环系统。

让我们使用add_output() 添加输出x 。但为此我们需要变量 dcm 具有 StateSpace 数据类型,这是函数add_output() 所要求的。因此,我们使用ss() 进行转换。

In [ ]:
dcm_new = add_output(ss(dcm), I(2))
Out[0]:
StateSpace{Continuous, Float64}
A = 
 -10.0      3.2
  -0.3125  -4.0
B = 
 0.0  8.0
 0.5  0.0
C = 
 6.25  0.0
 1.0   0.0
 0.0   1.0
D = 
 0.0  0.0
 0.0  0.0
 0.0  0.0

Continuous-time state-space model

让我们添加一个积分器。

In [ ]:
C = K_lqr * append( tf(1, [1, 0]), tf(1), tf(1) ) 
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
Input 1 to output 1
44.72135954999597
-----------------
      1.0s

Input 2 to output 1
25.526213567574707
------------------
       1.0

Input 3 to output 1
14.152551403054153
------------------
       1.0

Continuous-time transfer function model

描述带有 LQR 的开环控制系统。

In [ ]:
OL = dcm_new * append( C, ss(1) ) 
Out[0]:
StateSpace{Continuous, Float64}
A = 
 -10.0      3.2  0.0
  -0.3125  -4.0  2.795084971874748
   0.0      0.0  0.0
B = 
 0.0   0.0                0.0                8.0
 0.0  12.763106783787354  7.076275701527076  0.0
 8.0   0.0                0.0                0.0
C = 
 6.25  0.0  0.0
 1.0   0.0  0.0
 0.0   1.0  0.0
D = 
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

Continuous-time state-space model

描述使用 LQR 的闭环控制系统。

In [ ]:
CL = feedback( OL, I(3), U1=1:3, Y1=1:3 )
Out[0]:
StateSpace{Continuous, Float64}
A = 
 -10.0                  3.2                0.0
 -13.075606783787354  -11.076275701527077  2.795084971874748
 -50.0                  0.0                0.0
B = 
 0.0   0.0                0.0                8.0
 0.0  12.763106783787354  7.076275701527076  0.0
 8.0   0.0                0.0                0.0
C = 
 6.25  0.0  0.0
 1.0   0.0  0.0
 0.0   1.0  0.0
D = 
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

Continuous-time state-space model

传递函数 (w_ref,Td)$\to$ w

In [ ]:
cl_lqr = CL[ 1, 1:3:4 ]
Out[0]:
StateSpace{Continuous, Float64}
A = 
 -10.0                  3.2                0.0
 -13.075606783787354  -11.076275701527077  2.795084971874748
 -50.0                  0.0                0.0
B = 
 0.0  8.0
 0.0  0.0
 8.0  0.0
C = 
 6.25  0.0  0.0
D = 
 0.0  0.0

Continuous-time state-space model

最后,让我们通过绘制输出图来比较三种 DCT 控制方案。

In [ ]:
h_3 = lsim( cl_lqr, u, t )
plot( [h_1, h_2, h_3], label=["Прямое управление, h_1(t)" "Управление с обратной связью, h_2(t)" "Регулирование LQR, h_3(t)"] )
plot!( t, Td, label = "Внешний возмущающий моомент, Td" )
Out[0]:

通过分析曲线图可以看出,与前一种控制方法相比,输出信号的峰值变小了。

结论

本示例考虑了控制对象(直流电机)模型的创建。对三种控制 DCT 的方法进行了比较。通过对所获得的系统响应进行分析,结果表明采用 LQR 的控制方法最为有效,能够最好地抵御外部干扰转矩的影响。