Create new Simscape component
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.
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 end
Create 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 end
Create 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 end
Create 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 end
newComponentName
— Name of Simscape component to createName 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'
templateComponentName
— Name of template Simscape componentName 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'
eqns
— Symbolic equationsSymbolic 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]
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
symWriteSSC('myComp.ssc','template.ssc',eq,'H1Header','%
New title','HelpText',{'% Description of the','% new component'})
'H1Header'
— TitleTitle 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'
'HelpText'
— Descriptive textDescriptive 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'}
simscapeEquation
| symReadSSCParameters
| symReadSSCVariables