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
1. Description of symbols
Some of the styles and symbols used in this article can be found in the following table descriptions.


2. MBD 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

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

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

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

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.

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.

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

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.

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

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

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.

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.

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.

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.

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:

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.

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.

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:

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.

3. MBD Basic Function Introduction
3.1 Basic functions
3.1.1 Shortcut operation

3.1.2 Block operations

4. Block Description
4.1 Component Functions

5. MBD model
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:

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

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

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

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:

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)

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

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

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.
6. MBD Engineering and Analysis
(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:

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.

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.

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.

6.2.2 Algorithmic processing of CAN signals

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)

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

- 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

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:
- 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) 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.

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

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

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

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


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.

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.

7. MBD Engineering Results
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)

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)

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)

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.

8. Component Related
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 Name | Interface Phenomena |
app.check_terminate | Interface return value 225: This operation requires mini program running |
app.end_log | Interface return value 225: This operation requires mini program running |
app.enter_critical_section | Interface return value 225: This operation requires mini program running |
app.leave_critical_section | Interface return value 225: This operation requires mini program running |
app.log_system_var_value | Interface return value 225: This operation requires mini program running |
app.set_check_failed_terminate | Interface return value 225: This operation requires mini program running |
app.set_thread_priority | Interface return value 225: This operation requires mini program running |
app.start_log | Interface return value 225: This operation requires mini program running |
app.start_log_w_filename | Interface return value 225: This operation requires mini program running |
app.start_system_message_log | Interface return value 225: This operation requires mini program running |
app.terminate_application | Interface return value 225: This operation requires mini program running |
app.try_enter_critical_section | Interface 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)