连续离散混合系统控制与仿真

简单二阶系统

先研究最简单的二阶积分器串联型系统
x ˙ 1 = x 2 x ˙ 2 = u \begin{aligned} & \dot x_1 = x_2 \\ & \dot x_2 = u \\ \end{aligned} x˙1=x2x˙2=u
使用零阶保持法离散化(见附录),
A = [ 0 1 0 0 ] , B = [ 0 1 ] A=\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix},\quad B=\begin{bmatrix} 0 \\ 1 \end{bmatrix} A=[0010],B=[01]
设控制器周期(即离散化周期)为 T T T 已知,则矩阵指数
( s I − A ) − 1 = [ s − 1 0 s ] − 1 = 1 s 2 [ s 1 0 s ] e A t = L − 1 ( s I − A ) − 1 = L − 1 [ 1 s 1 s 2 0 1 s ] = [ 1 t 0 1 ] F = e A T = [ 1 T 0 1 ] G = ∫ 0 T e A t d t B = [ T T 2 2 0 T ] [ 0 1 ] = [ T 2 2 T ] \begin{aligned} & (sI-A)^{-1}=\begin{bmatrix} s & -1 \\ 0 & s \end{bmatrix}^{-1} =\frac 1{s^2}\begin{bmatrix} s & 1 \\ 0 & s \end{bmatrix} \\ & \text{e}^{At}=\mathcal L^{-1}(sI-A)^{-1}=\mathcal L^{-1} \begin{bmatrix} \frac 1s & \frac 1{s^2} \\ 0 & \frac 1s \end{bmatrix} =\begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix} \\ & F=\text{e}^{AT}=\begin{bmatrix} 1 & T \\ 0 & 1 \end{bmatrix} \\ & G=\int_0^T\text{e}^{At}\text{d}tB =\begin{bmatrix} T & \frac{T^2}2 \\ 0 & T \end{bmatrix} \begin{bmatrix} 0 \\ 1 \end{bmatrix} =\begin{bmatrix} \frac{T^2}2 \\ T \end{bmatrix} \end{aligned} (sIA)1=[s01s]1=s21[s01s]eAt=L1(sIA)1=L1[s10s21s1]=[10t1]F=eAT=[10T1]G=0TeAtdtB=[T02T2T][01]=[2T2T]
于是
x ⃗ ( n + 1 ) = F x ⃗ ( n ) + G u ( n ) = [ 1 T 0 1 ] x ⃗ ( n ) + [ T 2 2 T ] u ( n ) \begin{aligned} \vec x(n+1) =& F\vec x(n) + Gu(n) \\ =& \begin{bmatrix} 1 & T \\ 0 & 1 \end{bmatrix}\vec x(n) +\begin{bmatrix} \frac{T^2}2 \\ T \end{bmatrix}u(n) \\ \end{aligned} x (n+1)==Fx (n)+Gu(n)[10T1]x (n)+[2T2T]u(n)

u ( n ) = − K x ⃗ ( n ) = − [ k 1 k 2 ] [ x 1 x 2 ] u(n) = -K\vec x(n) = -\begin{bmatrix} k_1 & k_2 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} u(n)=Kx (n)=[k1k2][x1x2]
代入得
x ⃗ ( n + 1 ) = ( F − G K ) x ⃗ ( n ) = ( [ 1 T 0 1 ] + [ T 2 2 k 1 T 2 2 k 2 T k 1 T k 2 ] ) x ⃗ ( n ) \begin{aligned} \vec x(n+1) =& (F-GK)\vec x(n) \\ =& \left(\begin{bmatrix} 1 & T \\ 0 & 1 \end{bmatrix} +\begin{bmatrix} \frac{T^2}2k_1 & \frac{T^2}2k_2 \\ Tk_1 & Tk_2 \end{bmatrix} \right)\vec x(n) \\ \end{aligned} x (n+1)==(FGK)x (n)([10T1]+[2T2k1Tk12T2k2Tk2])x (n)
给定两个极点就可以使用比较系数法计算出 k 1 , k 2 k_1,k_2 k1,k2。除此以外还有一种便于使用计算机求解的方法
K = [ 0 ⋯ 0 1 ] [ G F G F n − 1 G ] α ( F ) K= \begin{bmatrix} 0 & \cdots & 0 & 1 \end{bmatrix} \begin{bmatrix} G & FG & F^{n-1}G \end{bmatrix}\alpha(F) K=[001][GFGFn1G]α(F)
其中 α ( x ) \alpha(x) α(x) 为给定极点的特征多项式,例如给定两个极点为 λ 1 , λ 2 \lambda_1,\lambda_2 λ1,λ2,则 α ( x ) = ( x − λ 1 ) ( x − λ 2 ) \alpha(x)=(x-\lambda_1)(x-\lambda_2) α(x)=(xλ1)(xλ2)。设给定重极点 λ 1 = λ 2 = − 5 \lambda_1=\lambda_2=-5 λ1=λ2=5,变换到离散域 z = e s T = e − 0.5 z=\text e^{sT}=\text e^{-0.5} z=esT=e0.5。仿真结果如图所示,图中 u u u 为控制量, y = x 1 y=x_1 y=x1 为状态量。
连续离散混合系统控制与仿真_第1张图片

参考

教材[1]里有更完整的推导过程,链接[2]里有另一个混合系统控制的例子。

  1. 孙增圻. 计算机控制理论与应用. 清华大学出版社.
  2. simucpp系列教程(3)例程解析(第二部分)

附录:零阶保持器离散化

对使用状态空间描述的线性系统
x ⃗ ′ = A x ⃗ + B u y = C x ⃗ + D u \begin{array}{l} \vec x'=A\vec x+Bu \\ y=C\vec x+Du \end{array} x =Ax +Buy=Cx +Du
使用零阶保持法可以离散化成
x ⃗ ( k + 1 ) = F x ⃗ ( k ) + G u ( k ) y ( k ) = C x ⃗ ( k ) + D u ( k ) \begin{array}{l} \vec x(k+1)=F\vec x(k)+Gu(k) \\ y(k)=C\vec x(k)+Du(k) \end{array} x (k+1)=Fx (k)+Gu(k)y(k)=Cx (k)+Du(k)
其中
F = e A T , G = ∫ 0 T e A t d t B F=\text{e}^{AT},G=\int_0^T\text{e}^{At}\text{d}tB F=eAT,G=0TeAtdtB
e A T \text{e}^{AT} eAT 是矩阵指数。
推导
x ′ ( t ) = A x ( t ) + B u ( t ) x ( t ) = e A ( t − t 0 ) x ( t 0 ) + ∫ t 0 t e A ( t − τ ) B u ( τ ) d τ \begin{aligned} & x'(t)=Ax(t)+Bu(t) \\ & x(t)=\text{e}^{A(t-t_0)}x(t_0)+\int_{t_0}^t\text{e}^{A(t-\tau)}Bu(\tau)\text{d}\tau \\ \end{aligned} x(t)=Ax(t)+Bu(t)x(t)=eA(tt0)x(t0)+t0teA(tτ)Bu(τ)dτ
t 0 = k T t_0=kT t0=kT t = ( k + 1 ) T t=(k+1)T t=(k+1)T,则
x ( ( k + 1 ) T ) = e A T x ( k T ) + ∫ k T ( k + 1 ) T e A ( k T + T − τ ) B u ( τ ) d τ ∫ k T ( k + 1 ) T e A ( k T + T − τ ) B u ( τ ) d τ = t = k T + T − τ ∫ 0 T e A t B u ( k T + T − t ) d t x ( k + 1 ) = e A T x ( k ) + ∫ 0 T e A t B d t u ( k ) \begin{aligned} & x((k+1)T)=\text{e}^{AT}x(kT)+\int_{kT}^{(k+1)T}\text{e}^{A(kT+T-\tau)}Bu(\tau)\text{d}\tau \\ & \int_{kT}^{(k+1)T}\text{e}^{A(kT+T-\tau)}Bu(\tau)\text{d}\tau \xlongequal{t=kT+T-\tau}\int_0^T\text{e}^{At}Bu(kT+T-t)\text{d}t \\ & x(k+1)=\text{e}^{AT}x(k)+\int_0^T\text{e}^{At}B\text{d}tu(k) \\ \end{aligned} x((k+1)T)=eATx(kT)+kT(k+1)TeA(kT+Tτ)Bu(τ)dτkT(k+1)TeA(kT+Tτ)Bu(τ)dτt=kT+Tτ 0TeAtBu(kT+Tt)dtx(k+1)=eATx(k)+0TeAtBdtu(k)

附录:代码

计算反馈控制系数 K K K 的代码

#include 
#include "zhnmat.hpp"
using namespace zhnmat;
using namespace std;
typedef std::vector<double>  vecdble;
Mat polynomial(Mat x, vecdble lambda) {
    double order = x.row();
    if (order != x.col()) return Mat();
    Mat ans = eye(order);
    for (uint32_t i = 0; i < order; i++)
        ans *= x - lambda[i]*eye(order);
    return x;
}
int main(void) {
    double T = 0.1;
    Mat F(2, 2, vecdble{1, T, 0, 1});
    Mat G(2, 1, vecdble{T*T*0.5, T});
    Mat K(1, 2);
    K.set(0, 0, G.at(1,0));
    K.set(0, 1, (F*G).at(1,0));
    K *= polynomial(F, vecdble{-3, -3});
    cout << K << endl;
}

二阶积分器串联型系统仿真代码

#include "simucpp.hpp"
using namespace simucpp;
int main() {
    Simulator sim1;
    FUIntegrator(uint1, &sim1);
    FUIntegrator(uint2, &sim1);
    FUConstant(cnst1, &sim1);
    FUOutput(uout1, &sim1);
    sim1.connectU(cnst1, uint1);
    sim1.connectU(uint1, uint2);
    sim1.connectU(uint2, uout1);
    sim1.Initialize();
    double ctrl;
    for (uint32_t n1 = 0; n1 < 20; n1++) {
        ctrl = (3-uint2->Get_OutValue()) * 15.24;
        ctrl -= uint1->Get_OutValue() * 7.04;
        for (uint32_t i = 0; i < 100; i++) {
            cnst1->Set_OutValue(ctrl);
            sim1.Simulate_OneStep();
        }
    }
    sim1.Plot();
    return 0;
}

你可能感兴趣的:(控制,控制,线性代数,矩阵)