Simulink_Debug的使用

1. 搭建模型

在这里插入图片描述

2. 启动 Debug 调试器

在这里插入图片描述

2.1 点击运行

左栏Simulation Loop: simulate(TestDebugSimulink) 高亮显示
ID = 0
右栏Outputs:输出:

%----------------------------------------------------------------%
[TM = 0                      ] simulate(TestDebugSimulink)
(sldebug @0): 

在这里插入图片描述

2.2 step into 一步步进行分析

在这里插入图片描述

2.3 第一次点击 stepinto

左栏Simulation Loop: initializationPhase 高亮显示
ID = 1
右栏Outputs:输出:

%----------------------------------------------------------------%
[TM = 0                      ] initializationPhase
(sldebug @1): 

由此可以看出:

  1. Outputs中输出的(sldebug @X):为左栏中的 ID号
  2. initializationPhase应为左栏中的Method

因此,不断地点击StepInto,在Outputs中得到内容如下
在这里插入图片描述

2.4 不断点击 stepinto,得到Outputs中的全部内容如下

警告: The behavior of the Simulink Debugger has been modified in R2012b. See release notes for details.
警告: 'Signal storage reuse' is enabled for this model. Block I/O values displayed in the debugger may not be correct.
 In order to preserve block output signal values, consider disabling the 'Signal storage reuse' option in the 'All Parameters' tab of the Configuration Parameters dialog

警告: 'Block reduction optimization' is enabled for this model. Some non-virtual blocks may not execute due to optimization.
 To be able to execute all non-virtual blocks consider disabling the 'Block reduction optimization' option in the 'All Parameters' tab of the Configuration Parameters dialog

%----------------------------------------------------------------%
[TM = 0                      ] simulate(TestDebugSimulink)
(sldebug @0): 
%----------------------------------------------------------------%
[TM = 0                      ] initializationPhase
(sldebug @1): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.SetupRunTimeResources
(sldebug @2): 
%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.SetupRunTimeResources 'TestDebugSimulink/x'
(sldebug @3): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.SetupRunTimeResources 'TestDebugSimulink/y'
(sldebug @4): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] 0:2 Sum.SetupRunTimeResources 'TestDebugSimulink/S1'
(sldebug @5): 
Data of 0:2 Sum block 'TestDebugSimulink/S1':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.SetupRunTimeResources 'TestDebugSimulink/Display'
(sldebug @6): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.InitializeConditions
(sldebug @7): 
%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.Start 'TestDebugSimulink/x'
(sldebug @8): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.Start 'TestDebugSimulink/y'
(sldebug @9): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.Start 'TestDebugSimulink/Display'
(sldebug @10): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
No data to display
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Enable
(sldebug @11): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.InvariantConstants
(sldebug @12): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.ParameterChangeEvent
(sldebug @13): 
%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.Outputs.Major 'TestDebugSimulink/x'
(sldebug @14): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
Y1     = [1]
%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.Outputs.Major 'TestDebugSimulink/y'
(sldebug @15): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
Y1     = [1]
%----------------------------------------------------------------%
[TM = 0                      ] 0:2 Sum.Outputs.Major 'TestDebugSimulink/S1'
(sldebug @16): 
Data of 0:2 Sum block 'TestDebugSimulink/S1':
U1     = [1]
U2     = [1]
Y1     = [2]
%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.Outputs.Major 'TestDebugSimulink/Display'
(sldebug @17): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
U1     = [2]
%----------------------------------------------------------------%
[TM = 0                      ] simulationPhase
(sldebug @18): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.ParameterChangeEvent
(sldebug @19): 
%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.Outputs.Major 'TestDebugSimulink/x'
(sldebug @20): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
Y1     = [1]
%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.Outputs.Major 'TestDebugSimulink/y'
(sldebug @21): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
Y1     = [1]
%----------------------------------------------------------------%
[TM = 0                      ] 0:2 Sum.Outputs.Major 'TestDebugSimulink/S1'
(sldebug @22): 
Data of 0:2 Sum block 'TestDebugSimulink/S1':
U1     = [1]
U2     = [1]
Y1     = [2]
%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.Outputs.Major 'TestDebugSimulink/Display'
(sldebug @23): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
U1     = [2]
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 1                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 1                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 2                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 2                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 3                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 3                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 4                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 4                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 5                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 5                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 6                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 6                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 7                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 7                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 8                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 8                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 9                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 9                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 10                     ] terminationPhase
(sldebug @26): 
%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.CleanupRunTimeResources
(sldebug @27): 
%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.Terminate
(sldebug @28): 
%----------------------------------------------------------------%
[TM = 10                     ] 0:0 Constant.CleanupRunTimeResources 'TestDebugSimulink/x'
(sldebug @29): 
%----------------------------------------------------------------%
[TM = 10                     ] 0:1 Constant.CleanupRunTimeResources 'TestDebugSimulink/y'
(sldebug @30): 
%----------------------------------------------------------------%
[TM = 10                     ] 0:2 Sum.CleanupRunTimeResources 'TestDebugSimulink/S1'
(sldebug @31): 
%----------------------------------------------------------------%
[TM = 10                     ] 0:3 Display.CleanupRunTimeResources 'TestDebugSimulink/Display'
(sldebug @32): 
%----------------------------------------------------------------%
[TM = 10                     ] simulate(TestDebugSimulink)
(sldebug @0): 

2.5 对Outpus中的内容进行分析

2.5.1 警告不用管

警告: The behavior of the Simulink Debugger has been modified in R2012b. See release notes for details.
警告: 'Signal storage reuse' is enabled for this model. Block I/O values displayed in the debugger may not be correct.
 In order to preserve block output signal values, consider disabling the 'Signal storage reuse' option in the 'All Parameters' tab of the Configuration Parameters dialog

警告: 'Block reduction optimization' is enabled for this model. Some non-virtual blocks may not execute due to optimization.
 To be able to execute all non-virtual blocks consider disabling the 'Block reduction optimization' option in the 'All Parameters' tab of the Configuration Parameters dialog

2.5.2 0-1秒

%----------------------------------------------------------------%
[TM = 0                      ] simulate(TestDebugSimulink)
(sldebug @0): 
// 开始仿真

%----------------------------------------------------------------%
[TM = 0                      ] initializationPhase
(sldebug @1): 
// Phase 的初始化

%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.SetupRunTimeResources
(sldebug @2): 
// 进行"TestDebugSimulink"文件模型仿真的资源加载

%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.SetupRunTimeResources 'TestDebugSimulink/x'
(sldebug @3): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
No data to display
// 模型中名为(第一个data)`x`的 Constant block 的资源加载,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.SetupRunTimeResources 'TestDebugSimulink/y'
(sldebug @4): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
No data to display
// 模型中名为(第二个data)`y`的 Constant block 的资源加载,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] 0:2 Sum.SetupRunTimeResources 'TestDebugSimulink/S1'
(sldebug @5): 
Data of 0:2 Sum block 'TestDebugSimulink/S1':
No data to display
// 模型中名为(第三个data)`S1`的 Sum block 的资源加载,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.SetupRunTimeResources 'TestDebugSimulink/Display'
(sldebug @6): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
No data to display
// 模型中名为(第四个data)`Display`的 Display block 的资源加载,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.InitializeConditions
(sldebug @7): 
// 初始化模型条件

%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.Start 'TestDebugSimulink/x'
(sldebug @8): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
No data to display
// 开始模型中名为(第一个data)`x`的 Constant block,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.Start 'TestDebugSimulink/y'
(sldebug @9): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
No data to display
// 开始模型中名为(第二个data)`y`的 Constant block,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.Start 'TestDebugSimulink/Display'
(sldebug @10): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
No data to display
// 开始模型中名为(第四个data)`y`的 Display block,且不需要显示

%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Enable
(sldebug @11): 
// 模型使能

%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.InvariantConstants
(sldebug @12): 
// 输出模型中的 InvariantConstants

%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.ParameterChangeEvent
(sldebug @13): 
// 输出模型中的 ParameterChangeEvent

%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.Outputs.Major 'TestDebugSimulink/x'
(sldebug @14): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
Y1     = [1]
// 命名为 x 的 Constant block 输出 1 

%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.Outputs.Major 'TestDebugSimulink/y'
(sldebug @15): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
Y1     = [1]
// 命名为 y 的 Constant block 输出 1

%----------------------------------------------------------------%
[TM = 0                      ] 0:2 Sum.Outputs.Major 'TestDebugSimulink/S1'
(sldebug @16): 
Data of 0:2 Sum block 'TestDebugSimulink/S1':
U1     = [1]
U2     = [1]
Y1     = [2]
// 命名为 S1 的 Sum block 两个输入相加,输出 2

%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.Outputs.Major 'TestDebugSimulink/Display'
(sldebug @17): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
U1     = [2]
// 命名为 Display 的 Display block 输入为 2

// 开始重复一次上述步骤
%----------------------------------------------------------------%
[TM = 0                      ] simulationPhase
(sldebug @18): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.ParameterChangeEvent
(sldebug @19): 
%----------------------------------------------------------------%
[TM = 0                      ] 0:0 Constant.Outputs.Major 'TestDebugSimulink/x'
(sldebug @20): 
Data of 0:0 Constant block 'TestDebugSimulink/x':
Y1     = [1]
%----------------------------------------------------------------%
[TM = 0                      ] 0:1 Constant.Outputs.Major 'TestDebugSimulink/y'
(sldebug @21): 
Data of 0:1 Constant block 'TestDebugSimulink/y':
Y1     = [1]
%----------------------------------------------------------------%
[TM = 0                      ] 0:2 Sum.Outputs.Major 'TestDebugSimulink/S1'
(sldebug @22): 
Data of 0:2 Sum block 'TestDebugSimulink/S1':
U1     = [1]
U2     = [1]
Y1     = [2]
%----------------------------------------------------------------%
[TM = 0                      ] 0:3 Display.Outputs.Major 'TestDebugSimulink/Display'
(sldebug @23): 
Data of 0:3 Display block 'TestDebugSimulink/Display':
U1     = [2]
// 结束重复一次上述步骤

不断地输出,更新。
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 0                      ] TestDebugSimulink.Update
(sldebug @25): 

2.5.3 1-9秒

不断地输出,更新。

%----------------------------------------------------------------%
[TM = 1                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 1                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 2                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 2                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 3                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 3                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 4                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 4                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 5                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 5                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 6                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 6                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 7                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 7                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 8                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 8                      ] TestDebugSimulink.Update
(sldebug @25): 
%----------------------------------------------------------------%
[TM = 9                      ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 9                      ] TestDebugSimulink.Update
(sldebug @25): 

2.5.4 9-10秒

%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.Outputs.Major
(sldebug @24): 
%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.Update
(sldebug @25): 

%----------------------------------------------------------------%
[TM = 10                     ] terminationPhase
(sldebug @26): 
// 结束 Phase

%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.CleanupRunTimeResources
(sldebug @27): 
// 清除资源

%----------------------------------------------------------------%
[TM = 10                     ] TestDebugSimulink.Terminate
(sldebug @28): 
// 结束

%----------------------------------------------------------------%
[TM = 10                     ] 0:0 Constant.CleanupRunTimeResources 'TestDebugSimulink/x'
(sldebug @29): 
// 清除 x

%----------------------------------------------------------------%
[TM = 10                     ] 0:1 Constant.CleanupRunTimeResources 'TestDebugSimulink/y'
(sldebug @30): 
// 清除 y

%----------------------------------------------------------------%
[TM = 10                     ] 0:2 Sum.CleanupRunTimeResources 'TestDebugSimulink/S1'
(sldebug @31): 
// 清除 S1

%----------------------------------------------------------------%
[TM = 10                     ] 0:3 Display.CleanupRunTimeResources 'TestDebugSimulink/Display'
(sldebug @32): 
// 清除 Display
%----------------------------------------------------------------%
[TM = 10                     ] simulate(TestDebugSimulink)
(sldebug @0): 
// 等待下一次仿真开始

3. 总结分析

Simulink 仿真主要步骤:

  1. 准备开始工作
  2. 仿真过程
  3. 重复仿真过程
  4. 不断地更新、输出
  5. 准备结束工作
  6. 结束仿真
  • 3
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值