Simscape Tutorial
Simscape Tutorial
R2014a
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
September 2007 Online only New for Version 2.0 (Release 2007b)
March 2008 Online only Revised for Version 2.1 (Release 2008a)
October 2008 Online only Revised for Version 3.0 (Release 2008b)
March 2009 Online only Revised for Version 3.1 (Release 2009a)
September 2009 Online only Revised for Version 3.2 (Release 2009b)
March 2010 Online only Revised for Version 3.3 (Release 2010a)
September 2010 Online only Revised for Version 3.4 (Release 2010b)
April 2011 Online only Revised for Version 3.5 (Release 2011a)
September 2011 Online only Revised for Version 3.6 (Release 2011b)
March 2012 Online only Revised for Version 3.7 (Release 2012a)
September 2012 Online only Revised for Version 3.8 (Release 2012b)
March 2013 Online only Revised for Version 3.9 (Release 2013a)
September 2013 Online only Revised for Version 3.10 (Release 2013b)
March 2014 Online only Revised for Version 3.11 (Release 2014a)
Contents
Product Fundamentals
1
Simscape Product Description . . . . . . . . . . . . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
vi Contents
1
Product Fundamentals
Simscape models can be used to develop control systems and test system-level
performance. You can extend the libraries using the MATLAB® based
Simscape language, which enables text-based authoring of physical modeling
components, domains, and libraries. You can parameterize your models using
MATLAB variables and expressions, and design control systems for your
physical system in Simulink®. To deploy your models to other simulation
environments, including hardware-in-the-loop (HIL) systems, Simscape
supports C-code generation.
Key Features
• Single environment for modeling and simulating mechanical, electrical,
hydraulic, thermal, and other multidomain physical systems
• Libraries of physical modeling blocks and mathematical elements for
developing custom components
• MATLAB based Simscape language, enabling text-based authoring of
physical modeling components, domains, and libraries
• Physical units for parameters and variables, with all unit conversions
handled automatically
• Ability to simulate models that include blocks from related physical
modeling products without purchasing those products
• Support for C-code generation
1-2
Creating a New Simscape™ Model
When you type ssc_new at the MATLAB Command prompt, the software
opens the main Simscape library and creates a new model prepopulated with
certain blocks, as shown in the following illustration.
1-3
1 Product Fundamentals
By default, the model name is not specified, the model contains a Solver
Configuration block with the default solver set to ode23t, a Simulink-PS
Converter block, and a PS-Simulink Converter block connected to a Scope
block.
You can use the ssc_new command arguments to specify the model name, add
a domain-specific reference block, and change the default solver. See the
ssc_new command reference page for details. For example, typing
ssc_new('rotor1','rotational','ode15s')
After using ssc_new, continue developing your model by copying the blocks,
as needed, and adding other blocks from the Simscape libraries.
For electrical models, you can also use the Creating A New Circuit example as
a template for a new model. This example also opens an Electrical Starter
1-4
Creating a New Simscape™ Model
Palette, which contains links to the most often used electrical components.
Open the example by typing ssc_new_elec in the MATLAB Command
Window and use File > Save As to save it under the desired model name.
Then delete the unwanted components and add new ones from the Electrical
Starter Palette and from Simscape libraries.
1-5
1 Product Fundamentals
1-6
Evaluating Performance of a DC Motor
The main model window contains a DC Motor subsystem with two electrical
and two mechanical rotational ports.
1-7
1 Product Fundamentals
1-8
Evaluating Performance of a DC Motor
DC Motor Subsystem
1-9
1 Product Fundamentals
1 Double-click the Motor Current and RPM scopes to open them. During
simulation, these windows display the motor current and shaft speed,
respectively, as functions of time.
2 In the toolbar of the model window, click to start the simulation. The
Simscape solver evaluates the model, calculates the initial conditions, and
runs the simulation. This process might take a few seconds. The message
in the bottom-left corner of the model window provides the status.
3 Examine the simulation results in the Motor Current and RPM scope
windows.
1-10
Evaluating Performance of a DC Motor
For the first 0.1 seconds, the motor has no external load, and the speed
builds up to the no-load value. Then at 0.1 seconds, the stall torque
is applied as a load to the motor shaft. Zooming in on the RPM and
Motor Current scopes shows that the model matches the manufacturer
parameters for no-load speed, no-load current, and stall torque.
Reduce the supply voltage to 1.25 volts (to simulate the battery running down)
and vary the load torque to find the maximum torque at this reduced voltage.
1-11
1 Product Fundamentals
2 Run the simulation. Note the effect of reduced voltage on the no-load speed.
1-12
Evaluating Performance of a DC Motor
3 Try varying the load torque to find the maximum torque at this reduced
voltage. Double-click the Step source block, enter different final values for
the input signal, and rerun the simulation.
The next illustration shows the simulation results for Final value set to
-0.2e-3, which corresponds to (1.25/1.5)*0.24mNm, as the magnitude of
the torque-speed curve is proportional to voltage for a DC motor.
1-13
1 Product Fundamentals
Replace the torque source with a simple mechanical load, for example, a fan,
for which the torque is defined by alpha*speed^2, where alpha is -1e-10
Nm/(rad/s)^2.
1 Delete the Step source and the Simulink-PS Converter block from the
model.
3 Drag the PS Product block and the PS Gain block to the model window.
1-14
Evaluating Performance of a DC Motor
5 Double-click the Gain block to open its dialog box. Enter Gain value of
-1e-10 and click OK.
6 Run the simulation and assess motor performance with the new load.
1-15
1 Product Fundamentals
1-16