Page 855 - Mechatronics with Experiments
P. 855
®
®
MATLAB , SIMULINK , STATEFLOW, AND AUTO-CODE GENERATION 841
further sub-systems in a logical tree structure. The sub-system definitions should be a
representation of physical reality, as opposed to programming short cuts, in order to have
good re-usability and maintainability for the model.
Masking: A related topic to grouping is the “masking” of a block. Masking allows the
user to define a custom user interface to access the block parameters. It is like a custom
“wrapper” around the block (Figure A.14). Using “masking,” we can provide
1. the user more descriptive parameter information about the block parameters, and
2. hide the block details.
If a sub-system block is masked, double-clicking on the block brings up the user interface
that shows the parameters of the block that the user can change. It does not show the logical
details of the block. If a sub-system block is not masked but grouped, then double-clicking
on the block brings up a new window showing the logical details of that block. In order to
mask a block or sub-system block, select it first. Then, select the sub-system,
Edit → Mask Subsystem to “mask” a subsystem
Edit → Unmask Subsystem to “unmask” an already “masked” subsystem
Under this selection, we need to define the following tabs for masking
Icon
Parameters
Initialization
Documentation
Block masks can be activated and deactivated. Once a mask is defined, deactivating it does
not lose the mask information. The mask information is still saved and can be activated
by the user at any time. The masked block parameters can be assigned values as constants
in this interface or as variables where the variables would later be assigned values in the
®
MATLAB workspace. “Icon” allows us to define a bit mapped image file to be displayed
on the masked block (file formats supported: bmp, jpg, tif),
image ( imread (’filename.jpg’))
The “Icon” feature can be very useful to visually describe the model by attaching an image
to the block to display, and it is highly recommended.
®
Another useful tool in Simulink models it to have a button that you can double click
®
®
to execute a MATLAB command, such as running an M-file. The Simulink block used
for that function is in
“Model-Wide Utilities: Model Info Block”
Copy this block to the model window. Right-click the mouse to bring up the block properties
menu. You can enter any desired text to describe (document) information about the model.
Let us connect the PD controller (Figure A.13) and the mass-spring-damper model
(Figure A.14) and simulate the system response. The equations described by the Simulink ®
graphics are
m̈ x(t) = u(t); mass − force dynamics (A.2)
u(t) = k (x (t) − x(t)) − k ̇ x(t); PD control (A.3)
v
p
d