symWriteSSC
Create new Simscape component
Syntax
Description
symWriteSSC(
creates a new Simscape™ component newComponentName,templateComponentName,eqns)newComponentName using an existing
component templateComponentName as a template and adding
eqns. Thus, the new component has both the existing
equations taken from the template component and the added equations.
symWriteSSC(
uses additional options specified by one or more newComponentName,templateComponentName,eqns,Name,Value)Name,Value
pair arguments.
Examples
Create a new Simscape component by using an existing component as a template and adding an equation.
Suppose you have the Simscape component spring.ssc in your current
folder.
type('spring.ssc');component spring < foundation.mechanical.rotational.branch
parameters
spr_rate = { 10, 'N*m/rad' };
end
variables
phi = { value = { 0, 'rad'}, priority = priority.high };
end
function setup
if spr_rate <= 0
pm_error('simscape:GreaterThanZero','Spring rate' )
end
end
equations
w == phi.der;
t == spr_rate*phi;
end
endCreate symbolic variables with names of the parameters and variables of
the component you are going to use when creating new equations. Also create
a symbolic variable, u, to denote the energy of the
rotational spring.
syms spr_rate phi u
Create the equation defining the energy u.
eq = u == spr_rate*phi^2/2;
Create the new component, myRotationalSpring.ssc, that
is a copy of the component spring.ssc with an additional
equation defining the energy of the rotational spring.
symWriteSSC('myRotationalSpring.ssc','spring.ssc',eq)
Warning: Equations contain undeclared variables 'u'. > In symWriteSSC (line 94)
symWriteSSC creates the component
myRotationalSpring.ssc.
type('myRotationalSpring.ssc');component myRotationalSpring
parameters
spr_rate = { 10, 'N*m/rad' };
end
variables
phi = { value = { 0, 'rad'}, priority = priority.high };
end
function setup
if spr_rate <= 0
pm_error('simscape:GreaterThanZero','Spring rate' )
end
end
equations
w == phi.der;
t == spr_rate*phi;
u == phi^2*spr_rate*(1.0/2.0);
end
endCreate a Simscape component with the title and descriptive text different from those of the template component.
Suppose you have the Simscape component spring.ssc in your current folder.
This component does not have any title or descriptive text.
type('spring.ssc');component spring < foundation.mechanical.rotational.branch
parameters
spr_rate = { 10, 'N*m/rad' };
end
variables
phi = { value = { 0, 'rad'}, priority = priority.high };
end
function setup
if spr_rate <= 0
pm_error('simscape:GreaterThanZero','Spring rate' )
end
end
equations
w == phi.der;
t == spr_rate*phi;
end
endCreate symbolic variables with names of the parameters and variables of
the component you are going to use when creating new equations. Also create
a symbolic variable, u, to denote the energy of the
rotational spring.
syms spr_rate phi u
Create the equation defining the energy u.
eq = u == spr_rate*phi^2/2;
Create the new component, myRotationalSpring.ssc, based
on the spring.ssc component. Add the equation
eq, the title “Rotational Spring”, and
a few lines of descriptive text to the new component.
symWriteSSC('myRotationalSpring.ssc','spring.ssc',eq,... 'H1Header','% Rotational Spring',... 'HelpText',{'% The block represents an ideal mechanical rotational linear spring.',... '% Connections R and C are mechanical rotational conserving ports.'... '% The block positive direction is from port R to port C. This means'... '% that the torque is positive if it acts in the direction from R to C.'})
Warning: Equations contain undeclared variables 'u'. > In symWriteSSC (line 94)
symWriteSSC creates the component
myRotationalSpring.ssc.
type('myRotationalSpring.ssc');component myRotationalSpring
% Rotational Spring
% The block represents an ideal mechanical rotational linear spring.
% Connections R and C are mechanical rotational conserving ports.
% The block positive direction is from port R to port C. This means
% that the torque is positive if it acts in the direction from R to C.
parameters
spr_rate = { 10, 'N*m/rad' };
end
variables
phi = { value = { 0, 'rad'}, priority = priority.high };
end
function setup
if spr_rate <= 0
pm_error('simscape:GreaterThanZero','Spring rate' )
end
end
equations
w == phi.der;
t == spr_rate*phi;
u == phi^2*spr_rate*(1.0/2.0);
end
endInput Arguments
Name of Simscape component to create, specified as a file name enclosed in
single quotes. File must have the extension .ssc. If you
do not provide file extension, symWriteSSC assumes it
to be .ssc. If you do not specify the absolute path,
symWriteSSC creates the new component in the
current folder.
Example: 'MyNewComponent.ssc'
Name of template Simscape component, specified as a file name enclosed in single quotes.
File must have the extension .ssc. If you do not provide
the file extension, symWriteSSC assumes it to be
.ssc. The component must be on the MATLAB® path or in the current folder.
Example: 'TemplateComponent.ssc'
Symbolic equations, specified as a row vector.
Example:
[ y(t) == diff(x(t), t), m*diff(y(t), t, t) + b*y(t) + k*x(t) ==
F]
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
Example: symWriteSSC('myComp.ssc','template.ssc',eq,'H1Header','% New
title','HelpText',{'% Description of the','% new
component'})
Title specified as a row vector of characters (type
char) starting with %. If the first character is
not %, then symWriteSSC adds %.
If the template component has a title and you use
H1Header, the new component will have the title
specified by H1Header. If the template component has
a title and you call symWriteSSC without
H1Header, the new component will have the same
title as the template component.
Example: 'H1Header','% New title'
Descriptive text, specified as a cell array of row vectors of
characters. Each row vector must start with %. If the first character is
not %, then symWriteSSC adds %.
If the template component has descriptive text and you use
HelpText, the new component will have only the
text specified by HelpText. In this case,
symWriteSSC does not copy the descriptive text
of the template component to the new component. If the template
component has a title and you call symWriteSSC
without HelpText, the new component will have the
same descriptive text as the template component.
Example: 'HelpText',{'% Description of the','% new
component'}
Version History
Introduced in R2016a
See Also
symReadSSCParameters | symReadSSCVariables | simscapeEquation
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)