在汽车电子开发领域,基于模型的设计以其高效率、高集成度和便于验证的优势,正日益成为主流的开发范式。作为连接模型与物理世界的桥梁,TSMaster的MBD功能模块扮演着至关重要的角色。它将MATLAB/Simulink模型无缝集成到总线网络环境中,使得工程师能够在真实的硬件在环测试台上,对控制模型进行实时验证,或将模型作为虚拟ECU参与到整个网络仿真中。本文将深入解析TSMaster中MBD工程的搭建流程与核心功能。
Keywords:TSMaster, MBD
TSMaster MBD 概念解析
- MBD 的基本概念
 基于模型的设计(Model-Based Design,MBD)是一种软件工程方法,它在设计、开发和验证复杂系统时使用模型为中心的方法。MBD通过使用数学模型来描述系统的行为和特性,为复杂系统的开发提供了一种数学化与可视化的创新方法。
- TSMaster MBD 模块
 TSMaster模型框图模块是太阳集团6138开发的类Simulink的建模模块,用于支持基于模型开发模式(MBD),通过拖放模块和连接信号线来构建系统模型,支持连续时间、离散时间以及混合系统的仿真。当前已发布的模块功能包含如下内容:
- Rich Module Library: Contains predefined modules in the fields of mathematical operations, signal processing, control systems, communication systems, and so on;
- Hierarchical modeling: supports the creation of hierarchical models through subsystems; can combine multiple modules into subsystems; supports multi-level subsystem nesting; can create conditional execution subsystems (enable, trigger, etc.);
- Simulation function: support the parallel operation of subsystems with different sampling rates; automatically handle the signal transfer between modules with different rates;
- Deep integration: data can be read directly from TSMaster system variables; simulation results can be exported to mbd files for analysis; relevant functions in the model block diagram can be called to operate on TSMaster;
- MIL, SIL, HIL are supported;
- Support directly load Simulink sldd, slx and other files simulation

MBD 工程搭建实战
以下是一个详细的步骤指南,演示如何从零开始搭建一个完整的MBD工程。
本文中使用的数据库为TSMaster软件中附带的数据库CAN_FD_Powertrain.dbc所在地址为TSMaster安装路径下\Data\Demo\Databases文件夹中。如下图所示:

CAN数据库中的Demo数据库到TSMaster中,并激活CAN总线仿真,以便后续信号映射中使用。

1. 变量准备
添加CAN数据库和系统变量,将CAN数据中的信号与系统变量映射方向设置为双向传递,方便后续修改系统变量的值来控制CAN信号的变化

2. 工程搭建
2.1 信号输入
Add the database in TSMaster beforehand. (Note: You cannot select a signal with a maximum and minimum value of 0.) In the signal mapping connect the CAN signals (/EngineData/EngSpeed as an example) with the system variables (Var0 as an example), and set the mapping direction to: from system variables to signals only.
The model block diagram of the added components Sine Wave and DataStoreWrite, DataStoreWrite binding system variables (Var0 as an example), the Sine Wave and DataStoreWrite connected together, the realization of the system variable value is Sine curve changes.

2.2 CAN信号的算法处理

Simple CAN signal algorithm processing, example steps are as follows:
(1)新建TSMaster工程,加载数据库(以CAN_FD_Powertrain.dbc为例)

(2) Create system variable Var0

(3) Connect the system variable Var0 to the CAN signal (/EngineData/EngSpeed signal, for example) in the signal mapping, and select the mapping direction "from system variable to signal only".

(4) Add the model block diagram, add Sine Wave and ToWorkspace components in the model block diagram, ToWorkspace binds the system variable Var0, Sine Wave connects to ToWorkspace to realize the Sine change of the system variable value, and at the same time, realize the Sine change of the CAN signal value.

(5)CAN信号的算法处理:添加子系统operation,使用FromWorkspace读取系统变量Var0的值作为输入子系统,Constant作为另一个输入给子系统。
The algorithm modules that can be added to the subsystem are:
- Calculus Operations: Integrator and Derivative
- Discrete systems: Unit Delay, Delay, etc.
- 逻辑与比较组件:Logical Operator(AND/OR/NOT等逻辑门);Relational Operator(比较运算符,如>、<、==);Switch(基于条件选择信号)、Multiport Switch(多路选择)
- Mathematical algorithms: Sum (summation), Product (product), Gain (gain multiplication), Abs (absolute value), etc.; Trigonometry (trigonometric functions, e.g., sin, cos); Min Max (extreme value operations); Exp (exponentiation), Log (logarithm), Sqrt (square root)
Adding the EnablePort group to a subsystem will, outside the subsystem, add Constant to connect to the EnablePort port can control whether to execute the current subsystem by modifying the value of Constant.

- Output: The Output port in the subsystem can be connected to any place for output
Through the above steps the CAN signal values can be processed in the model block diagram and then displayed in the form of graphical changes using Scope in the output module, or in the form of numerical changes through Display, or by using ToWorkspace and then writing to the system variables and then adding the system variables to the graphical window for observation. All the added algorithm-related components of the link can be added by adding the output module to observe the data changes at each stage in real time.
2.3 CAN信号边沿检测

模型框图中的添加组件DataStoreRead,DataStoreRead绑定系统变量来获取系统变量值,在SubSystem中添加相关边沿组件观察信号边沿变化:
- Edge Detector
- Detect Increase : Detect Increase, module outputs 1 (True), otherwise outputs 0 (False)
- Detect Decrease : Detect Decrease, module outputs 1 (True), otherwise outputs 0 (False)
- Detect Change : Detect any change, the module outputs 1 (True), otherwise outputs 0 (False)
The components in the sub-module are schematically shown below:

The output port of the edge detection component can be connected to Scope in the output module to display in the form of graphical changes or in the form of numerical changes through Display.
Edge detection is used in conjunction with Switch:
1)将Edge Detector通过DataTypeConversion转换信号类型,连接到Switch的第一个输入信号;Switch的的控制信号连接Constant模块(Constant值为1);Detect Decrease转换信号类型后,连接到Switch的第三个输入信号, 模块根据 控制信号 的取值选择输出第一个输入信号或第三个输入信号。
Selectively outputs the falling edge detection result:
Since the control signal is fixed to 1, the Switch will always select the 3rd input (i.e., the output of Detect Decrease), and the final system is equivalent to a falling edge detector with data type conversion.
Redundancy Design Intent:
Although the general-purpose edge detection result of Edge Detector is connected (input 1), it is masked by fixing the control signal, leaving only the dedicated falling edge detection function of Detect Decrease.
2)Detect Change 连接到Manual Switch 输入1,Constant 连接到Manual Switch 输入2实现了一个 “手动控制的信号变化监视器”。
Monitor mode:Output signal change detection results (change = 1, no change = 0);
Fixed output mode:Ignores the input signal and always outputs the preset Constant value.
2.4 其他组件使用
There are other components utility components in the model block diagram, such as:
(1)Ground:输入信号接地,防止出现关于未连接的输入端口的警告。

(2)Sign:信号符号判断,在需要了解信号的符号是可以将Sign组件连接到连线中。

(3)Clock:实时获取当前模块仿真时间。
(4)Stop Simulation:在输入信号不为0时可以立即停止仿真。

(5)Step:可以控制信号在指定时间产生从初始值到终值的跳变。

(6)控制子系统执行端口:Enable Port和Trigger Port。
By adding an Enable Port (or Trigger Port) to a subsystem, an additional input port is created outside of the subsystem, and the execution of the current subsystem is controlled externally by modifying the value of the signal connected to the port.


2.5 小程序库使用
Model generation mp is called arbitrarily after generating mp, realizing the graphic program (or C applet) to run the model block diagram, and controlling the operation of the model block diagram more conveniently.

Adding a new graphical program, adding an execution unit binding API function call, selecting the applet library function, and using the run function can be implemented to run the model block diagram in the graphical program.

MBD Engineering Results
Sample Project Operation and Results
After the example project is built, the model block diagram is run sequentially in the graphics program.
信号输入中将Sine Ware的值赋值给系统变量Var0,再通过信号映射中的配置将系统变量的值赋值给CAN信号,在图形中实时看到,Trace窗口中也能看到报文变化。

CAN信号算法处理过程中将Sine信号和常数模块,Sine先进行绝对值处理,再将两者相加而后进行增益处理最后相乘,再通过Output端口输出,连接到Scope和Display展示,可以在任意位置添加Output端口将实时数据输出观察。

CAN信号边沿检测检测中,将Output1连接到Switch中输出的不规则的信号(由控制信号决定);将另一个Output2连接到ManualSwitch中,Input是一个常数1,所有输出为常数1。

其他组件使用中Input2(SubSystem输入连接的是Sine正弦波)连接到Sign,根据获取到的信号符号输出:如果输入大于0,输出为1;如果输入等于0,输出为0;如果输入小于0,输出为-1。
The Clock output is the real-time simulation time, connected to Output1, and the final result displayed at the end of the run is the simulation end time in the setup.
Step is set to step from 2 to 9, connecting to Output2, so the result of the final step is shown.

掌握TSMaster MBD模块,意味着您能将基于模型设计的效率优势从仿真领域无缝延伸至实车测试与验证,极大地压缩开发周期,提升系统可靠性。关于TSMaster MBD 相关组件说明欢迎阅读《TSMaster MBD模块全解析:从模型搭建到自动化测试的完整实践》..
Which feature of TSMaster are you most interested in? Or what problems have you encountered in practical applications?
Welcome to share your experience or questions in the comment section, any ideas or suggestions can also be comment section message interaction, will have the opportunity to win the TOSUN mystery gift bag Oh ~!
Tip:
1. Software download:
Click on the software download link below to download and install directly, beta version is recommended:
2. Software upgrades:
You can check for upgrades to the latest version within the software, provided that your computer has an Internet connection.
Note: TOSUN Technical Support Email:support@tosunai.cnWe welcome inquiries! (Company and contact information must be indicated)
 
				







