Composite Component Using import
Statements
This example shows how you can use import
statements to implement a
composite component equivalent to the one described in Composite Component — DC Motor. The two components are identical, but,
because of the use of the import
statements, the amount of typing in the
nodes
and components
sections is significantly
reduced.
import foundation.electrical.electrical; % electrical domain class definition import foundation.electrical.elements.*; % electrical elements import foundation.mechanical.rotational.*; % mechanical rotational domain and elements component DC_Motor1 % DC Motor1 % This block models a DC motor with an equivalent circuit comprising a % series connection of a resistor, inductor, and electromechanical converter. % Default values are the same as for the Permanent Magnet DC Motor example model. nodes p = electrical; % +:left n = electrical; % -:left R = rotational; % R:right C = rotational; % C:right end parameters rotor_resistance = { 3.9, 'Ohm' }; % Rotor Resistance rotor_inductance = { 12e-6, 'H' }; % Rotor Inductance motor_inertia = { 0.01, 'g*cm^2' }; % Inertia breakaway_torque = { 0.02e-3, 'N*m' }; % Breakaway friction torque coulomb_torque = { 0.02e-3, 'N*m' }; % Coulomb friction torque breakaway_velocity = { 0.1, 'rad/s' }; % Breakaway friction velocity back_emf_constant = { 0.072e-3, 'V/rpm' }; % Back EMF constant end components(ExternalAccess=observe) rotorResistor = resistor(R = rotor_resistance); rotorInductor = inductor(l = rotor_inductance); rotationalElectroMechConverter = rotational_converter(K = back_emf_constant); friction = friction(brkwy_trq = breakaway_torque, Col_trq = coulomb_torque, ... brkwy_vel = breakaway_velocity); motorInertia = inertia(inertia = motor_inertia); end connections connect(p, rotorResistor.p); connect(rotorResistor.n, rotorInductor.p); connect(rotorInductor.n, rotationalElectroMechConverter.p); connect(rotationalElectroMechConverter.n, n); connect(rotationalElectroMechConverter.R, friction.R, motorInertia.I, R); connect(rotationalElectroMechConverter.C, friction.C, C); end end
Consider the three import
statements at the
beginning of the file. The first one:
import foundation.electrical.electrical;
is a qualified import of the Foundation electrical domain class.
Therefore, in the nodes
section, you can define
the p
and n
nodes simply as electrical
.
The second statement:
import foundation.electrical.elements.*;
is an unqualified import, which imports all subnamespaces and classes under the
foundation.electrical.elements
subnamespace and therefore gives you
direct access to all the Foundation electrical components in the Elements sublibrary, such as
inductor
, resistor
, and
rotational_converter
.
The third statement:
import foundation.mechanical.rotational.*;
is an unqualified import, which imports all subnamespaces and classes under the
foundation.mechanical.rotational
subnamespace and therefore gives you
direct access to the Foundation mechanical rotational domain definition
(rotational
) and components (such as friction
and
inertia
).
The nodes
block declares two electrical nodes, p
and n
,
and two mechanical rotational nodes, R
and C
.
The components
block declares all the member
(constituent) components, using the following components from the Simscape™ Foundation
library:
Resistor
Inductor
Rotational Electromechanical Converter
Rotational Friction
Inertia
Because of the import
statements at the top of the file, these classes
already exist in the scope of the file, and you do not have to specify their complete names
starting from the top-level namespace folder.