Matlab Simulink练习 2020-03-26

Simulink模块参数调节

1. 交互界面调节

参考

>> 使用模块参数值进行调优和实验
>> Log and Plot Simulation Data
在MODELING->Model Data Editor(1)中可以调节模块参数,还可以用字符变量代表其中的参数,如2处。点击3可以新建该变量参数值,并保存在Model Workspace(4或5)中。

Model Data Editor

在MODELING->Model Data Editor->Signals下拉框选择Instrumentation,右侧可以勾选Log Data,也可以在信号线上右键记录所选信号,则会出现一个Wifi信号一样的图标。这样被记录的信号波形可以通过SIMULATION->Data Inspector或Simscape Results查看;
或在SIMULATION -> PREPARE -> Configure Logging -> Simscape -> Data Logging中选择Log simulation data:All,并勾选(tick)open viewer after simulation

  • 如果在Workspace中变量名为simlog,则输入simlog.print可以查看各个信号名,方便后续调用simlog.xx.xxx.series
  • 绘制波形直接调用plot(simlog.xx.xxx,'units','rpm'),横坐标为时间,纵坐标为信号及其单位。For more information on plotting logged simulation data, see the simscape.logging.plot and simscape.logging.plotxy reference pages.

2. 使用编程的方式修改模块参数:

参考

>>设置模块参数值
>>优化、估计和扫描模块参数值

  1. 在仿真运行期间使用使用 get_paramset_param 函数;
  2. 多次仿真,使用不同参数使用 Simulink.SimulationInput ,对象运行多次仿真的详细信息,请参阅 sim

PI参数调节/控制器设计

1. Bode Diagram Design 手动调节PI参数实例

G = tf(1.5,[1 14 40.02]);
controlSystemDesigner('bode',G);
  1. 使用Control System Designer模块;
  2. 通过拉拽伯德图幅度特性曲线调节P(C的分子),满足阶跃响应上升时间Tr和过冲;
  3. 伯德图右键Add Pole or Zero->Integrator加入极点,因为多了积分I(C的分母s的系数),可以满足稳态要求。但是必须进一步调大增益,以满足上升时间:Right-click the Bode Editor plot area, and select Edit Compensator;
  4. 伯德图右键Add Pole or Zero->Iead增加超前网络(一个零点和一个极点)调节幅值裕量和相位裕量。

2. 自动识别并调整PID参数

这几个例子步骤都比较多,跟着练习,经常复习~~

  • 例1:识别电路伯德图并进行PID参数优化 >> Design Controller for Power Electronics Model Using Frequency Response Data
  • 例2:使用PID Tuner识别系统动态响应 >> Design PID Controller Using Simulated I/O Data
  • 例3:给定各种限制条件(Tr, overshoot, GM, PM, controller amplitude,et al.),自动选取PID参数PID参数初值的设定很重要!不好的初值可能无法收敛。
    >> Design Optimization-Based PID Controller for Linearized Simulink Model (GUI)
    >> Design Optimization to Meet Step Response Requirements (GUI) 使用Check Step Response Characteristics block+Response Optimization

模型线性化

1. 例:线性化电子回路,得到伯德图

  1. 使用linmod函数,使用比较复杂,不推荐;
    If your model has continuous states, use linmod. (Continuous states are the Simscape default.) If your model has mixed continuous and discrete states, or purely discrete states, use dlinmod.
%% Linearize a Circuit to View Frequency Response
% This example script shows how you can view the small-signal frequency
% response of a Simscape(TM) model by using linearization. It uses example
% model ssc_bipolar_nonlinear.
%
% An alternative and recommended way to linearize Simulink(R) and Simscape
% models is to use Simulink Control Design(TM). Simulink Control Design has
% tools that help you find operating points and returns a state-space model
% object that defines state names. If you have Simulink Control Design,
% open the model ssc_bipolar_nonlinear. On the Apps tab, under Control
% Systems, click Model Linearizer. In the Linear Analysis Tool, on the
% Linear Analysis tab, in the Linearize section, click Bode.

% Copyright 2012-2019 The MathWorks, Inc.

%% Open the model and set circuit parameters
open_system('ssc_bipolar_nonlinear')

%% Trim the model
% The Start simulation from steady state option is already selected from
% the model's Solver Configuration block. This ensures the circuit is
% initialized at the state defined by the transistor bias resistors.

%% Linearize
[a,b,c,d]=linmod('ssc_bipolar_nonlinear');
clear simlog_ssc_bipolar_nonlinear

%% Bode plot
npts = 100; f = logspace(-2,10,npts); G = zeros(1,npts); # 伯德图频率从10^(-2) Hz到10^10 Hz
for i=1:npts                                                       
    G(i) = c*(2*pi*1i*f(i)*eye(size(a))-a)^-1*b +d;    # eye单位矩阵         
end

% Reuse figure if it exists, else create new figure
try
    figure(h2_ssc_bipolar_nonlinear)
catch
    h2_ssc_bipolar_nonlinear=figure('Name', 'ssc_bipolar_nonlinear');
end

ah(1) = subplot(2,1,1);
magline_h=semilogx(f,20*log10(abs(G)));
grid                                                               
ylabel('Magnitude (dB)')                                           
title('Frequency Response (Nonlinear Bipolar Transistor)');
ah(2) = subplot(2,1,2);
phsline_h=semilogx(f,180/pi*unwrap(angle(G)));
set([magline_h,phsline_h],'LineWidth',1);
ylabel('Phase (degrees)')                                          
xlabel('Frequency (Hz)') 
grid                                                                                           

linkaxes(ah,'x') # 同步多个坐标区的范围

% Remove temporary variables
clear magline_h phsline_h a b c d G f npts i ah
  1. 使用Control Systems -> Model Linearizer.
  • Simscape里必须有Solver Configuration模块,接入电路,右键选中Start simulation from steady state;
  • Simulink -> Modeling -> Model Settings -> Data Import/Export, select the States check box to record the time series of x values in your workspace. If you also have input signals u in the model, you can capture those inputs by connecting To Workspace blocks to the input Simulink signal lines. Whichever method that you choose to find an operating point, if you want to use it for linearization, you must save the operating point information in the form of an operating point object, a simulation time t0, or a state vector x0 and input vector u0.
    这步好像不用勾选x,u也可以??
  • In the Simulink Toolstrip of the Nonlinear Bipolar Transistor model window, on the Apps tab, under Control Systems, click Model Linearizer;
  • In the Model Linearizer window, on the Linear Analysis tab, click the Bode plot button.
  1. 系统线性化基础知识
    >>Linearizing at an Operating Point
  • linear time-invariant (LTI) state space model:
    dx/dt = A·x + B·u
    y = C·x + D·u.

  • 选择合适的线性化点
    Simulink -> Apps -> Model Linearizer -> Linear Analysis -> Operating Point处设置。

    Although steady-state and other operating points (state x0 and inputs u0) might exist for your model. Operating points with a strongly nonlinear or discontinuous character are not suitable for linearization. You should analyze such models in full simulation, away from any discontinuities, and perturb the system by varying its inputs, parameters, and initial conditions. A common example is actuation systems, which should be linearized away from any hard constraints or end stops.

    Tip:
    Check for such an unsuitable operating point by linearizing at several nearby operating points. If the results differ greatly, the operating point is strongly nonlinear or discontinuous.


模块参数识别

  • 例1:给输入输出数据估计模型参数 >> Estimate Model Parameter Values (GUI)
  • 例2:利用响应优化来调节PID参数,使输出信号跟随给定 >> Design Optimization to Track Reference Signal (GUI)

你可能感兴趣的:(Matlab Simulink练习 2020-03-26)