Subsystems Matlab Help

One potential disadvantage of a graphical interface such as Simulink is that, to simulate a complex system, the diagram can become rather large and therefore somewhat cumbersome. Simulink, however, provides for the creation of sub system blocks, which playa role analogous to that of subprograms in a programming language. A subsystem block is actually a Simulink program represented by.a single block. A subsystem block, once created, can be used in other Simulink programs. We also introduce some other blocks in this section. To illustrate subsystem blocks we will use a simple hydraulic system whose model IS based on the conservation of mass principle familiar to engineers. Because

the governing equations are similar to other engineering applications, such as electric circuits and devices, the lessons learned from this example will enable you to use Simulink for other applications. .

A Hydraulic System

The working fluid in a hydraulic system is an incompressible fluid such as water or a silicon-based oil. (Pneumatic systems operate with compressible fluids, such as air.) Consider a hydraulic system composed of a tank of liquid of mass density p (Figure 9.7-1). The tank shown in cross section in the figure is cylindrical with a bottom area A. A flow source dumps liquid into the tank at the mass flow rate

A hydraulics~stem with a flowsource

A hydraulics~stem with a flowsource

qmi(t). The total mass in the tank is m =p Ah, and from conservation of mass we , have ddmt dh = pA dt =qmi – qmo (9.7-1) since p and A are constants. If the outlet is a pipe that discharges to atmospheric pressure pa and provides a resistance to flow that is proportional to the pressure difference across its ends, then the outlet flow rate is – 1 pgh qmo = R[(pgh + Pa) – Pal =R where R is called the fluid resistance. Substituting this expression into equation (9.7-1) gives the model: dh pg pATt =qmi(t) – lih (9.7-2 The transfer function is

H(s) 1 Qmi(S) = pAs + pgj R

On the other hand, the outlet may be a valve or other restriction that provide nonlinear resistance to the flow. In such cases, a common model is the signed square- root relation

1 qmo = RSSR(~P)

where qmo is the outlet mass flow rate, R is the resistance, ~P is the pres difference across the resistance, and (li:p if P  0 SSR(p) =JiM if P < 0
Note that we may express the SSR(u) function in MATLAB

sgn(u) *sqrt (abs (u) ). Consider the slightly different system shown in Figure 9.7-2, which flow source q and two pumps that supply liquid at the pressures PI and Pr- Su

A hydraulic system with a flow source and pump.

A hydraulic system with a flow source and pump.

the resistances are nonlinear and obey the signed-square-root relation. Then the model of the system is the following:
dh I 1
pA- =q + -SSR(PI – p) – -SSR(p – p,)
dt . RI R,
where A is the bottom area and p = pgh. The pressures PI and p, are the gage
pressures at the left- and right-hand sides. Gage pressure is the difference between the absolute pressure and atmospheric pressure. Note that the atmospheric pressure Po cancels out of the model because of the use of page pressure. We will use this application to introduce the following Simulink elements:
• Subsystem blocks, and
• Input and Output Ports.
You can create a subsystem block in one of two ways: by dragging the Subsystem
block from the library to the model window or by first creating a Simulink model and then “encapsulating” it within a bounding box. We will illustrate the latter method.

We will create a subsystem block for the liquid-level system shown in
Figure 9.7-2. First construct the Simulink model shown in Figure 9.7-3. The oval blocks are Input and Output Ports (In 1 and Out 1), which are available in the Ports and Subsystems library. Note that you can use MATLAB variables aria expressions when entering the gains in each of the four Gain blocks.

Before running the program we will assign values to these variables in the MATLAB Command window. Enter the gains for the four Gain blocks using the expressions shown in the block. You may also use a variable as the Initial condition of the Integrator block. Name this variable hO. The SSR blocks are examples of the Fcn block, which is in the User-Defined Functions library. Double-click on the block and enter the MATLAB expression

SimUliokmodclofthe~.wn in Figure9.7-2.

SimUliokmodclofthe~.wn in Figure9.7-2.

The Subsystem block.

The Subsystem block.

sgn (u) * sqrt (abs (u ) ). Note that the Fcn block requires you to use the variable u. The output of the Fen block must be a scalar, as is the case here, and you cannot perform matrix operations in the Fcn block, but these are not needed here. (An alternative to the Fcn block is the MATLAB Fen block to be discussed in Section 9.9.) Save the model and give it a name, such as Tank. . Now create a “bounding box” surrounding the diagram. Do this by placing the mouse cursor in the upper left, holding the mouse button down, and dragging the expanding box to the lower right to enclose the entire diagram. Then choose Create Subsystem from the Edit menu. Simulink will then replace the diagram with a single block having as many input and output ports as required and will assign default names. You can resize the block to make the labels readable. You may view or edit the subsystem-by double-clicking on it. The result is shown in Figure 9.7-4.

Connecting Subsystem procks.

Wenow create a simulation ofthe system shown in Figure 9 7-5, where the mass inflow rate q is a step function. To do this, create the Simulink model shown in Figure 9.7~. The square blocks are Constant blocks from the Sources library. These give constant inputs (which are not the same as step function inputs). The larger rectangular blocks are two subsystem blocks of the type just created. To insert them into the model, first open the Tank subsystem model, select Copy from the Edit menu, then paste it twice into the new model window. Connect

A hydraulic system with two tanks

A hydraulic system with two tanks

Simulink model of the system shown in Figure 9.7-5.

Simulink model of the system shown in Figure 9.7-5.

the input and output ports and edit the labels as shown. Then double-click on the Tank 1 subsystem block, set the left-side gain 1/ R_l equal to 0, the right-side gain l/R.:…r equal to l/R_l, and the gain l/rho* A equal to 1 /rho* A_I. Set the Initial condition of the integrator to hlO. Note that setting the gain l/R_l equal to 0 is equivalent to R_l = 00, which indicates no inlet on the left-hand side. Then double-click oil the Tank 2 subsystem block, set the left-side gain l/R_l equal to l/R_l, the right-side gain l/R_r equal to l/R_2, and the gain l/rho* A equal to l/rho* .Set the Initial condition of the integrator to h2 o. For the Step block, set the Step time to 0, the Initial value to 0, the Final value to the variable <Ll, and the Sample time to O.Save the model using a name other than Tank. Before running the model, in the Command window assign numerical values to the variables. As an example, you may type the following values for water, in U. S. Customary units, in the Command window. Left Pressure BottomPressure
RightPressure Atmosphere .

»A_l = 2;A_2 = S;rho = 1.94;g = 32.2;
»R_1 = 20;R_2 = SO;CLl = O.3;hlO = 1;h20 = 10;
After selecting a simulation Stop time, you may run the simulation. The Scope will display the plots of theheights hi and h2 versus time. Figures 9.7-7, 9.7-8, and 9.7-9 illustrate some electrical and mechanical systems that are likely candidates for application of subsystem blocks. In Figure 9.7-7, the basic element for the subsystem block is an RC circuit. In Figure 9.7-8, the basic element for the subsystem block is a mass connected to two elastic elements.

A vibrating system.

A vibrating system.

An armature-controlled de motor.

An armature-controlled de motor.

Figure”9.7-9 is the block diagram of an armature-controlled de motor, which may be converted into a subsystem block. The inputs for the block would be the voltage from a controller and a load torque, and the output would be the motor speed. Such a block would be useful in simulating systems containing several motors, such as a robot arm.

Posted on July 25, 2015 in simulink

Share the Story

Back to Top
Share This