The Background: About Me
The Background: About Me
The Background: About Me
The background
The acceptance of model based design across the embedded community has led to more and more systems being
developed in Simulink. The complexities of simulink models are increasing with more and more features being
incorporated to controllers. To analyse the outputs of simulink models we generally rely on scope and display
blocks. But, when we work with large models it is no longer possible to understand what is happening in the
system with scope and display block alone. It would have been better if you have a customizable GUI which
consists of a panel of buttons, checkboxes etc which feeds all the necessary data required to the model and there
is a similar GUI which displays the output of the model use plots, fields etc. This assists you to test and analyse
the model more efficiently and in turn provides a facility to do extensive functional testing as you do in
ControlDesk in a HIL rig. As you are already aware simulink/matlab provide features to make this possible
namely GUIDE & S-function. What many people have difficulty is how to link both. This is what I want to
address here.
Through a simple exercise I would try to explain how a GUI could be made and how it can be linked to
SIMULINK model.
Tutorial is written assuming that you have basic idea of GUIDE, S-function etc.
AIM
To make 2 GUI's
1. Feeds information to simulink model
2. Collects information from simulink model and displays it
Components
The following are the components and their description
No Name Description
1. InpGUI.fig Fig file generated from GUIDE for Input GUI
3. Inpgui_sf.m M file S function which collects information from Input GUI and outputs to
mode
4. Ingui_test.mdl Test model with GUI, S function integrated
7. Opgui_sf.m M file S function which collects information from model and outputs to
Output GUI
8. Opgui_test.mdl Test model with GUI, S function integrated
Step by step process
1. Creating the GUI
This is simple and essentially drag and drop work using GUIDE.
Input GUI
Output GUI
-All components were given specific tags for easy identification
Some information
In each Figure there is a property called "Userdata" where you can store any information. The
information stored here is retained even if figure is closed.
In each simulink block ObjectParameters" there is a field call "Userdata" where you can store any
information. The information stored here is retained even when model is closed.
Figure has a handle hObject by means of which all properties of the figure can be accessed
Each block has a handle by means of which all block properties could be accessed
Model
4. M file s function
Input GUI S function (inpgui_sf.m)
The S-function read the GUI and generates outputs that goes to SIMULINK.
The important functions that you can find inside the s-function, what it does and what modification is to be done
inside them to integrate with GUI are described in sections below.
MdlUpdate function
No change needed
Mdloutputs function
Here the current GUI settings is read from figure and S-function block outputs are updated accordingly
The GUI settings data structure element value are written to S-function block output ports.
MdlInitialize function
- Specify the number of inputs the s- function has (number of inputs from Simulink to GUI)
- All other settings can be usually kept at default values
- Call the OpGUI figure (this cause the figure M-script to be executed, which will in turn cause GUI to
appear)
MdlUpdate function
The following operations are to be done here
- get the figure handle which is stored in blocks 'UserData'
- Search and find the handles of various objects in the figure
- Update the GUI objects based on S-function block inputs using the figure handle
Mdloutputs function
No change here as there are no outputs.
The input model (inpguitest.mdl) will read InpGUI and pass it to SIMULINK
The output model (opguitest.mdl) will read from SIMULINK and pass it to OpGUI.