Sharing | TSMaster MBD Module Explained: From Model Building to Automation Testing in Practice

In automotive MBD development, TSMaster MBD module is deeply integrated with TSMaster's advanced bus analysis, simulation and test platform, aiming to provide engineers with a set of end-to-end seamless solutions from automatic model compilation, code integration to automated test. In this article, we will teach you how to build a project from scratch and build an efficient test process, providing a practical guide to optimize the development workflow.

Keywords:TSMaster, MBD


Some of the styles and symbols used in this article can be found in the following table descriptions.

Style Sheet Description
Symbol Table Description

2.1 Application scenarios

Model Block Diagrams (also known as MBDs) are used to model, simulate and analyze dynamic systems.It uses a graphical programming environment based on block diagrams, which is particularly suitable for the simulation and design of complex systems (e.g., control systems, signal processing, communication systems, etc.).

The model block diagrams in TSMaster use a block diagram representation to build a system model by dragging and dropping modules and connecting signal lines, and support discrete-time as well as hybrid system simulations, where parameters can be adjusted during simulation and results can be seen immediately.

The model block diagram advantages are as follows:

  • 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
technical articles 20250828 1 MBD module
Fig. 1: Block diagram of the model

2.2 model block diagram

The Model Block Diagram module toolbar mainly contains common engineering operations such as undo, redo, open from outside, save current file, create new model, export svg, clear run results, generate applet library, run model, step and stop.

2.2.1 Toolbar

technical articles 20250828 2 MBD modules
Figure 2: Model Block Diagram Toolbar

The functional buttons in the Model Block Diagram toolbar are described as follows: (Table 1: Model Block Diagram Toolbar Description)

technical articles 20250828 3 MBD modules

New SubItem details: (Table 2: New SubItem description)

technical articles 20250828 4 MBD modules

2.2.2 Model Block Diagram Configuration

2.2.2.1 Model Block Diagram Setup

The model block diagram settings allow you to set the simulation start time, simulation end time, fixed step size, and simulation mode settings.The solver in TSMaster is a fixed-step solver, which maintains a fixed time step to advance the simulation, and will not be adjusted due to the dynamic changes of the system, and is suitable for real-time simulation.

technical articles 20250828 5 MBD modules
Figure 3: Model Block Diagram - Setup - Solver

The data types in the model block diagram settings are categorized into double (double-precision floating-point) and single (single-precision floating-point); most of the modules in the model block diagram use the double type by default, which is suitable for high-precision scientific calculations, and very large or very small quantities of arithmetic operations; the single type is not the default type, and needs to be explicitly specified, and it is mostly used for real-time simulation to accelerate the speed of calculations (see Figure 4). After binding the added data warehouse in the settings of the model block diagram, you can use the variables and data types in the data warehouse.

technical articles 20250828 6 MBD module
Figure 4: Model Block Diagram - Settings - Data Types

The debugging part of the model block diagram setup, the model debugging process, sets the simulation to pause at a specific point in time, and after the pause the simulation is carried out by stepping. (See Figure 5.)

technical articles 20250828 7 MBD modules
Figure 5 : Model Block Diagram - Setup - Debugging

2.3 Model Manager

The Model Manager interface includes three modules: Model List, Data Warehouse and Global Settings.. There are two main functions in the toolbar: open all and close all.

technical articles 20250828 8 MBD modules
Figure 6: Model Manager interface display

The model list displays information about all model block diagrams loaded in the current TSMaster project, the package block name, type, version, last modification, status and file path (see 2.2 for a detailed description of model block diagrams).

technical articles 20250828 9 MBD modules
Figure 7 : Model Manager - Model List

The data warehouse displays information about all the data warehouses added in the current TSMaster project, the package block name, type, version, last modification, status and file path (see 2.4 for a detailed description of the data warehouse).

technical articles 20250828 10 MBD modules
Figure 8: Model Manager - Data Warehouse

Add a path (or add a cascade path) to the "Model Search Path" in the global settings. After adding the environment variable Path path, the reference a model depends on b, c, and d. After adding the paths of b c d, you can open a model with a b c d in its entirety.

technical articles 20250828 11 MBD modules
Figure 9: Model Manager - Global Settings

2.4 data warehouse

A data warehouse is a persistent repository for storing model-related data. It can store design data that defines parameters and signals, and can also include data that defines model behavior.The Data Warehouse does not store simulation data, i.e., inputs or outputs to and from the Inport and Outport modules during model simulation. The entries in the data warehouse are persistent.

The data warehouse consists of three modules: variables, data types, and attributes.

The configuration is saved in the data warehouse as a JSON file, which defines the name of the data warehouse, the last modifier, the added data types and information about the variables, and you can also add variables, data types and other information by importing the originally saved JSON file.

Data Warehouse Interface
Figure 10 : Data Warehouse Interface

2.4.1 Variables

Signals and parameters can be added to the Variable module in the Data Warehouse. You can export the Variable module to C code, and then import the C code into a C applet, and all the variables added to the Variable module can be used in the C applet.

technical articles 20250828 13 MBD modules
Figure 11 : Data Warehouse Variables and C Applets

The Variables module of the Data Warehouse can import Simulink data dictionaries. The type of the added variable data can be modified to other types, such as: double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, and boolean, or it can be the type added in the data type (see 2.4.2 for more details on data types), such as: Enum :EnumType, Bus:BusType, Value:ValueType, Numeric:NumericType, etc.; the initial value, type, array size, maximum value, minimum value, unit and description in the variable can be modified.

technical articles 20250828 14 MBD modules
Figure 12: Data Warehouse - Variables

Association of variables in the data warehouse with the model block diagram: Add a component to the model block diagram (DataStoreRead, for example) and bind the data type to the added data warehouse (e.g. DataRepo) in the settings. At this point, the datastore in the DataStoreRead can select the variables added to the data warehouse, and the Constant component can read the parameters (e.g. Para) added to the variables in the data warehouse. This is shown in the following figure:

technical articles 20250828 15 MBD modules
Fig. 13 : Linkage of data warehouse with model block diagrams

2.4.2 Data types

The data type module in the data warehouse can add variable types, bus types, enumeration types, alias types, and numeric types; the data added in the data types can be exported as C header files, and all types in the data types can be used in C applets by importing the header files in the C applet; load the .h file under the libs\common path, and the global definition of the reference to the header file, you can use the data types in the calling header file.

technical articles 20250828 16 MBD modules
Figure 14 : Data Warehouse Data Types and C Applets

The enumeration type of the data types in the data warehouse allows you to add enumeration data, modify default values and storage types, while the other data types support modifying names and descriptions.

technical articles 20250828 17 MBD modules
Figure 15 : Data Warehouse - Data Types

The data types in the data warehouse are linked to the model block diagram: add components to the model block diagram (take Constant as an example), bind the data warehouse in the data types in the settings to the data warehouse that has been added (take DataRepo as an example), and the output data types in Constant can be selected from the data types that have been added to the data warehouse, as in the following figure:

technical articles 20250828 18 MBD modules
Fig. 16 : Linkage of data warehouse with model block diagrams

2.4.3 Properties

The Properties module in the Data Warehouse allows you to add created data warehouses, remove data warehouses, and open data warehouses. When a data warehouse (in the case of DataRepo, hereafter referred to as DataRepo) references another data warehouse (in the case of DataRepo1, hereafter referred to as DataRepo1), DataRepo's variable and data type tables are free to associate DataRepo1's data types with it, but the variable table does not explicitly DataRepo1 variables in DataRepo1.

technical articles 20250828 19 MBD module
Figure 17 : Data Warehouse Dependencies

3.1 Basic functions

3.1.1 Shortcut operation

MBD Basic Function Introduction

3.1.2 Block operations

Block (component) operations

4.1 Component Functions

Block Description

5.1 Simulink model

Download the RollAxisAutopilot.slx (URL 1) and RollAxisAutopilotHarness.slx (URL 2) files from the MATLAB website

URL 1:

https://ww2.mathworks.cn/help/ecoder/gs/getting-started-with-embedded-coder.html

URL 2:

https://ww2.mathworks.cn/help/ecoder/gs/compare-model-simulation-and-generated-code-results.html

5.1.1 Introduction to the RollAxisAutopilot model

5.1.1.1 About the model

The model shows the implementation of a cross-roller autopilot control system designed for code generation.

This model represents a basic roll axis autopilot with two modes of operation: roll attitude hold and heading hold. The mode logic for these modes is outside of this model. The model architecture represents the heading hold mode and the basic roll attitude function as atomic subsystems.

The traverse attitude control function is a PID controller that uses traverse attitude and traverse rate feedback to generate aileron commands.

The input to the controller is the basic roll angle reference or roll command to track the desired heading. The model is shown below:

Schematic of RollAxisAutopilot
Figure 18: Schematic of RollAxisAutopilot

5.1.1.2 RollAxisAutopilot/RollAngleReference

The basic lateral camber reference calculation is implemented as a subsystem RollAngleReference.

technical articles 20250828 24 MBD modules
Figure 19: Schematic of RollAxisAutopilot/RollAngleReference

5.1.1.3 RollAxisAutopilot/HeadingMode

The subsystem HeadingMode calculates the traverse command to track the desired heading.

technical articles 20250828 25 MBD modules
Figure 20: Schematic of RollAxisAutopilot/HeadingMode

5.1.1.4 RollAxisAutopilot/BasicRollMode

The subsystem BasicRollMode calculates the rollover attitude control function (PID).

technical articles 20250828 26 MBD modules
Figure 21: Schematic of RollAxisAutopilot/BasicRollMode

5.1.2 Model import

Drag and drop the RollAxisAutopilotHarness.slx file into TSMaster and the model will be loaded directly into the model block diagram as shown below:

technical articles 20250828 27 MBD modules
Figure 22: Schematic of RollAxisAutopilotHarness

The roll_harness_TestInputs.mat file in the FileName of the Signal Editor component in the model block diagram is placed in the RollAxisAutopilotHarness.slx sibling directory, and the roll_harness_TestInputs_Maneuver_1 .csv file to the same directory as RollAxisAutopilotHarness.slx, and roll_harness_TestInputs_Maneuver_1.csv holds the input data for the model.

The Signal Conversion component in the model block diagram converts the input double type data from the Signal Editor to the corresponding single, boolean and then to the sub-module Roll Axis Autopilot (this sub-module is the content of RollAxisAutopilot.slx. See 5.1.1 for details)

technical articles 20250828 28 MBD modules
Figure 23: RollAxisAutopilotHarness running

5.2 Model results

The results of the RollAxisAutopilotHarness.slx model run in MATLAB are as follows:

technical articles 20250828 29 MBD modules
Figure 24: RollAxisAutopilotHarness-MATLAB run results

The results of the run with the RollAxisAutopilotHarness.slx model loaded in the model block diagram in TSMaster are as follows:

technical articles 20250828 30 MBD modules
Figure 25: RollAxisAutopilotHarnessTSMaster run results

Write the output result of Ail_Cmd to the system variable, and observe the change of the system variable in the graph of TSMaster.The model block diagram in TSMaster can add Display or Scope to any Output null to display the output data in real time.


(See 7.1 for project results.) The database used in this paper is CAN_FD_Powertrain.dbc, which comes with the TSMaster software and is located in the folder \Data\Demo\Databases under the installation path of TSMaster. As shown in the figure below:

technical articles 20250828 31 MBD modules
Figure 26: Database Path

CAN Database The Demo database in Figure 25 is databased into TSMaster and the CAN bus simulation is activated for use in subsequent signal mapping.

technical articles 20250828 32 MBD modules
Figure 27: Database Loading

6.1 Variable preparation

Add CAN database and system variables, and set the direction of signal and system variable mapping in CAN data to bidirectional transmission, so as to facilitate the subsequent modification of the value of the system variables to control the change of CAN signals.

technical articles 20250828 33 MBD modules
Figure 28: Signal Mapping

6.2 Engineering

6.2.1 Signal Input

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.

DataStoreWrite Binding
Figure 29: DataStoreWrite Binding

6.2.2 Algorithmic processing of CAN signals

technical articles 20250828 35 MBD modules
Fig. 30: Example of signal algorithm processing

Simple CAN signal algorithm processing, example steps are as follows:

(1) Create a new TSMaster project and load the database in Figure 11 (CAN_FD_Powertrain.dbc for example)

technical articles 20250828 36 MBD modules
Figure 31: Loading the database

(2) Create system variable Var0

technical articles 20250828 37 MBD modules
Figure 32: Adding System Variables

(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".

technical articles 20250828 38 MBD modules
Fig. 33: Mapping of system variables to CAN signals

(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.

technical articles 20250828 39 MBD modules
Figure 34: System variable value Sine change

(5) Algorithmic processing of CAN signals: add subsystem operation, use FromWorkspace to read the value of the system variable Var0 as input to the subsystem, and Constant as another input to the subsystem.

The algorithm modules that can be added to the subsystem are:

  • Calculus Operations: Integrator and Derivative
  • Discrete systems: Unit Delay, Delay, etc.
  • Logic and Comparison Components: Logical Operator (logical gates such as AND/OR/NOT); Relational Operator (comparison operators such as >, <, ==); Switch (conditional selection based signals), Multiport Switch (multiport selection)
  • 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.    

technical articles 20250828 40 MBD modules
Fig. 35: Detailed presentation of the signaling algorithm subsystems

  • 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.

6.2.3 CAN signal edge detection

technical articles 20250828 41 MBD module
Figure 36: Example of a signal edge

CAN signal processing operation in accordance with 5.2.1, the model block diagram in the addition of the component DataStoreRead, DataStoreRead binding system variables to obtain the value of the system variables, in the SubSystem to add the relevant edge components to observe the signal edge changes:

  1. Edge Detector
  2. Detect Increase : Detect Increase, module outputs 1 (True), otherwise outputs 0 (False)
  3. Detect Decrease : Detect Decrease, module outputs 1 (True), otherwise outputs 0 (False)
  4. Detect Change : Detect any change, the module outputs 1 (True), otherwise outputs 0 (False)

The components in the sub-module are schematically shown below:

technical articles 20250828 42 MBD modules
Figure 37: Signal Edge Subsystem Detailed View

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) Connect Edge Detector to the first input signal of Switch by converting the signal type through DataTypeConversion; the control signal of Switch is connected to Constant module (value of Constant is 1); Detect Decrease is converted to the third input signal of Switch, and the module chooses to output the first input signal or the third input signal according to the value of the control signal. Detect Decrease converts the signal type and connects it to the third input signal of the Switch, and the module chooses to output the first input signal or the third input signal according to the value of the control signal.

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 connected to Manual Switch Input 1 and Constant connected to Manual Switch Input 2 implements a "manually controlled signal change monitor."

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.

6.2.4 Use of other components

There are other components utility components in the model block diagram, such as:

(1) Ground: Ground the input signal to prevent warnings about unconnected input ports.

technical articles 20250828 43 MBD modules
Figure 38: Ground Example

(2) Sign: Signal symbol judgment, in the need to understand the symbol of the signal is the Sign component can be connected to the connection line.

technical articles 20250828 44 MBD modules
Figure 39: Sign Example

(3) Clock: real-time access to the current module simulation time

(4) Stop Simulation: Simulation can be stopped immediately when the input signal is not zero.

technical articles 20250828 45 MBD modules
Figure 40: Clock Example

(5) Step: The signal can be controlled to generate a jump from the initial value to the final value at a specified time.

technical articles 20250828 46 MBD modules
Figure 41: Step Example

(6) Control subsystem execution ports: Enable Port and 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.

technical articles 20250828 47 MBD modules
Figure 42: Enable Port and Trigger Port
technical articles 20250828 48 MBD modules
Figure 43: Enable Port and Trigger Port Subsystem External Display

6.2.5 Applet library usage

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.

technical articles 20250828 49 MBD modules
Figure 44: Generating a C Applet Library

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.

technical articles 20250828 50 MBD modules
Figure 45: Graphics program calls applet library

7.1 Sample Project Operation and Results

After the example project is built, the model block diagram is run sequentially in the graphics program.

The value of Sine Ware is assigned to the system variable Var0 in the signal input, and then the value of the system variable is assigned to the CAN signal through the configuration in the signal mapping, which is seen in real time in the graph and the message changes are seen in the Trace window. (5.2.2 Example effect) (see Figure 46)

technical articles 20250828 51 MBD modules
Figure 46: Signal Input Results

CAN signal algorithm processing process will be Sine signal and constant module, Sine first absolute value processing, and then add the two and then gain processing and finally multiply, and then through the Output port output, connected to the Scope and Display show, you can add the Output port at any location will be real-time data output observation. (See Figure 47)

technical articles 20250828 52 MBD modules
Figure 47: Algorithmic Processing Results

In the CAN signal edge detection detection, connect Output1 to the irregular signal output in the Switch (determined by the control signal); connect the other Output2 to the ManualSwitch, where Input is a constant 1 and all outputs are constant 1. (5.2.3 Example effect) (see Figure 48)

technical articles 20250828 53 MBD modules
Figure 48: Edge detection results

Other components in use Input2 (SubSystem input connected to a Sine sine wave) is connected to Sign and outputs according to the acquired signal sign: if the input is greater than 0, the output is 1; if the input is equal to 0, the output is 0; and if the input is less than 0, the output is -1. (5.2.4 Example effect) (see Figure 49)

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.

technical articles 20250828 54 MBD modules
Figure 49: Other Component Results

8.1 Component Related

The components in the model block diagram may have problems during use:

(1) Signal Editor component with no IO null only supports importing RollAxisAutopilotHarness.slx as a demo (only supports importing CSV);

(2) Model reference currently only supports loading Simulink, mbd in slx and TSMaster, and user associations are currently supported;

(3) Constant does not support vectors, complex numbers, but matrices and structures;

(4) The callback button is currently just purely compatible with Simulink importing slx without reporting errors, it doesn't do anything practical;

(5) Variables in state jump conditions in the Chart component are not actively created at this time;

8.2 API Related

Some of the APIs bound in the component FunctionCaller are only for applets and are shown in the function list for demonstration purposes only.

Interface NameInterface Phenomena
app.check_terminateInterface return value 225: This operation requires mini program running
app.end_logInterface return value 225: This operation requires mini program running
app.enter_critical_sectionInterface return value 225: This operation requires mini program running
app.leave_critical_sectionInterface return value 225: This operation requires mini program running
app.log_system_var_valueInterface return value 225: This operation requires mini program running
app.set_check_failed_terminateInterface return value 225: This operation requires mini program running
app.set_thread_priorityInterface return value 225: This operation requires mini program running
app.start_logInterface return value 225: This operation requires mini program running
app.start_log_w_filenameInterface return value 225: This operation requires mini program running
app.start_system_message_logInterface return value 225: This operation requires mini program running
app.terminate_applicationInterface return value 225: This operation requires mini program running
app.try_enter_critical_sectionInterface return value 225: This operation requires mini program running

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)

发表回复

en_USEnglish
×
×

产品入口: 产品添加到购物车

XML 地图