Simulink ABS Example
Simulink ABS Example
This memo is a tutorial that demonstrates how you can combine a Simulink model with a VS Math
Model from BikeSim, CarSim, or TruckSim, and run the full system from within Simulink.
A simple antilock brake system (ABS) example is used in various forms in BikeSim, CarSim, and
TruckSim. This memo is not intended for specialists in ABS or brake system modeling, and does
not go into detail about the brake system aspects of the Simulink model. Rather, the point is to
show how to set up a VS vehicle model to work in the Simulink environment.
In order to follow the tutorial, you must have both Simulink (from The MathWorks) and your
VehicleSim product installed. The document assumes you are familiar with Simulink, and that you
have a basic understanding of how to use your VehicleSim product as achieved by going through
the Quick Start Guide.
2 / 23
Figure 3. Existing simulation results (CarSim).
3 / 23
2
1
3 4
Figure 4. Duplicate of Run Control dataset for brake test without ABS.
Figure 5.Use the “About” window to locate the current working directory.
2. Click on the pathname . This will bring up a view of the database folder in Windows
(Figure 6).
Figure 6. Windows view of VS database folder contents, including the folder named Extensions.
4 / 23
3. Notice that one of the folders is named Extensions . Double-click on that folder name
to view the contents (Figure 7).
Figure 7. Windows view Extensions folder contents, including the folder named Simulink.
4. One of the folders in Extensions is named Simulink. Double click to open the
Simulink folder (Figure 8). The Simulink folder contains many Simulink files, along
with some folders with supporting MATLAB files.
Figure 8. Duplicate the ABS model file and give the copy a new name.
5. Locate the ABS model file and duplicate it. For CarSim, the file is named abs_CS9.mdl
; for TruckSim the file is named ABS_TS9.mdl; for BikeSim the file is named
abs_v90.mdl. Change the name of the duplicate to abs_tutorial.mdl .
6. Go back to CarSim/TruckSim/BikeSim. Use Alt-Tab or click on a part of the window if
visible. The About window (Figure 5) is probably still visible. If so, close it.
5 / 23
1
Note Occasionally, the potential link does not appear on the first attempt. If this
happens, please repeat the selection of Models: Simulink from the drop-
down control.
2. Use the drop-down control for the new link and select the option [Link to New Dataset]
. You will be prompted to provide a name of the new dataset (Figure 11). Type a name
such as ABS for Tutorial and then click the Create button .
6 / 23
3. Notice that the screen has new controls after the link is made to the new dataset (Figure
12). The title in the center part of the screen now reads Run Control with Simulink , and
there are two new buttons: Run Now and Send to Simulink . Click on the link for the
newly linked dataset to view it (Figure 13).
1
2
3
4
Figure 12. Appearance of Run Control screen with link to Simulink dataset.
1 2
Figure 13. Select the Simulink model using the Windows file browser.
4. The first step in linking to a Simulink model is to specify a pathname to the file in the
pathname field on the screen . Do this by clicking the adjacent browser button to bring
up the Windows file browser . Browse to the Extensions\Simulink folder and select
7 / 23
the abs_tutorial.mdl file you created earlier , such that the relative pathname is
automatically inserted in the yellow field .
5. Use the Back button or the Home button to return to the Run Control screen (Figure 12).
6. Click the Send to Simulink button from the Run Control screen (Figure 12). The VS
Browser (CarSim/TruckSim/BikeSim) will launch Simulink using the file
abs_tutorial.mdl. Figure 14 shows the CarSim example model, with an S-Function
identified with the CarSim icon . The TruckSim and BikeSim examples are similar, but
use the icons associated with those products.
Note This Simulink has brake hydraulics (with dynamics) and a simple ABS
Controller . However, there is no longer a vehicle dynamics plant to
control.
8 / 23
2 3
2 3 4
1
6
Figure 16. Drag and drop a VS S-Function block from the Simulink Library Browser.
CarSim, TruckSim, and BikeSim each include three library S-Functions: a general-purpose
vehicle S-Function , an S-Function with support for a camera sensor , and an S-Function
that supports live video . Other than the names and icons, the S-Functions for CarSim are
9 / 23
the same as those for TruckSim and BikeSim. (All use the same internal code to connect a VS
Solver to Simulink.)
9. When making the Simulink model, you add the S-Function by dragging it as shown in the
figure to the intended location . You next connect input and output signals , as
you would do with any block (Figure 17).
6
7 8
10 / 23
1
2 3
2 3
11 / 23
7
8
9
7
10
11
8
7
10
12
7
10
8
13
14
12 / 23
7
10
8
13
Figure 24. Links to new Import and Export datasets from the Models: Simulink screen.
Import Variables
Click the Import Channels blue link to transfer to the I/O Channels: Import dataset for this
example. Initially, this is an empty dataset that does not name any Import variables (Figure 25).
2
1
3
Figure 26. Select a Run Control data with the vehicle of interest.
2. Use the drop-down control for the potential link to choose a Run Control dataset that
involves the vehicle of interest. For this example, select the braking run that was created earlier
13 / 23
. When you select the Run Control dataset, the VS Browser will jump to the Run Control
screen and then jump back to the Import screen. The Import screen now has information about
all of the Import variables that exist in the model and can potentially be activated for use with
Simulink (Figure 27).
2
1 4 5
6
7
Figure 27. Import screen appearance after a Run Control dataset was selected.
3. When the Run Control dataset was specified , two documentation files were automatically
generated that list all variables in the math model that might potentially be imported from
Simulink. One of the files is a tabbed-text file. The pathname for this tabbed-text file is shown
in the yellow field , and the number of variables is written underneath (there are 328 import
variables available for this example). The other is a spreadsheet file.
4. If you have Excel or another spreadsheet program installed, click the View Spreadsheet button
. The spreadsheet includes all available variables, their units, descriptions, and the type of
component. For example, Figure 28 shows a spreadsheet with the rows sorted based on the
Component type (column C), scrolled to view some variables related to Brakes.
Notes Depending on the spreadsheet tool and version, you might be given a
warning about the file format and extension not matching. The file has the
extension .xls and the format is tabbed text. It’s OK to open the file.
You might notice that Column E has either a 0 or the name VARIABLE.
This provides the GUI with the information need to support the drop-down
control (Figure 29) described below.
Close the spreadsheet when you are through viewing the contents.
14 / 23
Figure 28. Spreadsheet with all potential import variables for an example vehicle.
5. Use the Categories drop-down control on the Imports screen (Figure 27) to choose the
option Select by type of component. Notice that a list of component types is shown under the
control (Figure 29).
2
1 4 5
6
8 10 11
Figure 29. Import screen showing variables for the Braking category.
6. Select the component type Brakes . The list of available variables is adjusted to show
only variables related to Brakes.
7. Right-click on any of the available variables to see a longer name in a pop-up field .
15 / 23
8. For CarSim and TruckSim, find the Import variable in the Available Variables list with the
name IMP_PBK_L1 and double-click on it. The variable will appear in the list Variables
Activated for Import . A drop-down control is shown next to the variable name with
options Replace, Add, and Multiply . The default option is Replace, which is appropriate
for this example.
9. Add three more variables by double-clicking on their names in the Available Variables list:
IMP_PBK_L2, IMP_PBK_R1, and IMP_PBK_R2. The list Variables Activated for Import
should match Figure 30.
10
Figure 30. Four variables activated for Import in CarSim and TruckSim examples.
For BikeSim, activate the Import variables IMP_PBK_1 and IMP_PBK_2 (Figure 31).
10
7
Export Variables
A similar screen is used to define the set of variables that are exported from the VS solver to
Simulink. Navigate to the I/O Channels: Export screen by first clicking the Back button to return
to the Models: Simulink screen (Figure 24, page 13) and then clicking on the blue link for the
Export Channels .
You should now be viewing the I/O Channels: Export screen (Figure 32, shown for CarSim
during step 6 below). Initially, there will be no variables shown (similar to the Import screen as
shown in Figure 25, page 13). You will go through similar steps to obtain information about all
available output variables, and select those that should be activated for export to Simulink.
1. Use the drop-down control to Choose run to get export information . When this option is
selected, a potential link is shown for a Run Control dataset .
16 / 23
2
1 4 5
6 10
7
Figure 32. Activating variables for export out of the vehicle S-Function block.
2. Use the drop-down control for the potential link to choose the same Run Control dataset
that you selected as a reference for the Import variable screen (the new braking run). As before,
two documentation files are automatically generated. In this case, they list all variables in the
math model that might potentially be exported to Simulink. One of the files is the tabbed-text
file shown in the yellow field . The number of variables is written underneath (there are 641
output variables for this example). The other is a spreadsheet file, accessible with the View
Spreadsheet button .
3. As before, use the Categories drop-down control to choose the option Select by type of
component. Notice that a list of component types is shown under the control .
4. Select the component type Wheels . The list of available variables is adjusted to show
only variables related to Wheels.
5. Right-click on any of the available variables to see a longer name in a pop-up field .
Note Some of the right-click descriptions have extra information. For example,
the information shown for variable Vx_L1 includes a description of how
it is defined mathematically. When there are groups of similar variables
applied for repeated parts, such as the four wheels of this vehicle, only the
first variable in the group has the extra information. If you right-click on
the next variable (Vx_L2), the description has only basic information.
6. For CarSim and TruckSim, find the output variable in the Available Variables list with the
name Vx_L1 and double-click on it. The variable will appear in the list Variables Activated
for Export .
17 / 23
Add three more wheel variables by double-clicking on their names in the Available Variables
list: Vx_L2, Vx_R1, and Vx_R2.
Two more variables are needed for the CarSim and TruckSim examples that are not in the
Wheel category. To access them, use the Categories drop-down control to choose the
option Show all variables, and then select the variables Vx_SM and Pbk_Con.
The list Variables Activated for Export should match Figure 33.
10
Figure 33. Six variables activated for Export in CarSim and TruckSim examples.
For BikeSim, activate the five output variables listed in Figure 34.
2 5
1 4
6
10
18 / 23
1
2 3
19 / 23
1
1 2
20 / 23
1 2
Note If you change the vehicle, its properties, or the sets of import or export
variables from the VS browser, you must click the Send to Simulink
button to update the model in Simulink.
21 / 23
1
Multiple Ports
The VS S-Function supports Simulink models with multiple Import and Export ports. The database
for your VehicleSim product includes a multiport version of the ABS example, such as the CarSim
example shown in Figure 40.
In comparing the multiport version to the single-port version shown earlier (Figure 37, page 20),
you see the same blocks for the Brake Actuator Model , the ABS Controller Model , and the
CarSim S-Function . However, in in the multiple-port case, there are four import ports for
CarSim and three export ports .
The setup for this model from the VS Browser is almost the same as shown earlier. Figure 41 shows
the lower-left part of the Models: Simulink dataset, with the sidebar visible in order to see the
linked datasets . In this case, the blue links for Import and Export channels are not used,
and a link is made to an I/O Channels: Ports dataset . The I/O Channels: Ports dataset is
shown in the background of Figure 40.
The I/O Channels: Ports screen shows drop-down controls that specify four import ports
(Figure 40) and three export ports . Each Import port is represented with an Import dataset
and each Export port is represented with an Export dataset . The number of ports can be set to
anything between 0 and 20. The Import and Export datasets are made from the same libraries shown
for single-port models, in the previous section.
22 / 23
2 3
1 4
6
5 7
Figure 40. Alternate version of the ABS Model using multiple ports.
Figure 41. Models: Simulink dataset for multiport version of ABS example.
23 / 23