Modeling and Digital Simulation Case Studies: 3.1 Pre-Lab Assignment
Modeling and Digital Simulation Case Studies: 3.1 Pre-Lab Assignment
|
0
r(o) = )(t)
3.2. LABORATORY PROCEDURE 13
Figure 3.2: Electric circuit analogy for the mechanical system in Fig. 3.1a
which is of course mathematically equivalent to (3.1). Equation (3.1) can also be written in state
space form by selecting the two state variables as displacement and velocity: r
1
(t) = r(t) and
r
2
(t) = r(t). The rst-order dierential equations then become
dr
1
(t)
dt
= r
2
(t)
dr
2
(t)
dt
=
1
`
)(t)
/
`
r
1
(t)
1
`
r
2
(t)
(3.3)
For convenience, we will dene multiple outputs: j
1
= r
1
(t) and j
2
= r
2
(t). Thus the state space
expression of this system is
[
r
1
(t)
r
2
(t)
]
=
[
0 1
|
1
1
1
] [
r
1
(t)
r
2
(t)
]
+
[
0
1
1
]
)(t)
[
j
1
(t)
j
2
(t)
]
=
[
1 0
0 1
] [
r
1
(t)
r
2
(t)
] (3.4)
The simulation diagram for Equations (3.3) is shown in Figure 3.3
Figure 3.3: Simulation diagram for the mechanical system in Case Study 1
With the system initially at rest, a constant force of )(t) = 32 Newtons is applied at time t = 0.
The system in question has a mass of 2 kg and a spring constant of 32 kg,s
2
. We are told that the
damping coecient, 1, may be adjusted to obtain a desirable response.
The systems characteristic equationfrom Eq. (3.2)is given by
:
2
+
1
`
: +
/
`
= 0 (3.5)
which may be compared to the standard second-order transfer function
:
2
+ 2.
n
+.
2
n
= 0 (3.6)
14 CHAPTER 3. MODELING AND DIGITAL SIMULATION CASE STUDIES
Pre-lab Exercise
Perform the following analysis:
1. The dashpot damping is adjusted to 1 = 2 Ns/m. Determine the natural frequency of
oscillation (.
n
), damping ratio (), percent overshoot (1O = 100c
1
2
), peak time (t
=
t
.
1
2
), and settling time (t
s
4t).
2. The dashpot damping is adjusted to 1 = 56 N-s/m. Determine, damping ratio , response
time constants t
1
and t
2
, and settling time t
s
4 max(t
1
, t
2
).
3. Determine the frictional coecient 1 for the response to be critically damped. What is the
response time constant and approximate settling time?
Lab Exercise (Digital Simulation using SIMULINK)
To create a SIMULINK block diagram presentation of the system shown in Figure 3.3 double
click on the SIMULINK icon on the MATLAB toolbar, or type simulink at the MATLAB prompt.
Click on the create a new model icon on the SIMULINK toolbar. An untitled window for designing
and simulating a new model will open. Double click on the Simulink library icon, this will open
nine subsystems libraries. Open the Source Library and drag the Step Input block to the open new
model window. Double click on the Step Input to open its dialog box, set the parameters Step time
to 0, and Final value to 32. Get two integrators from the Continuous library, three Gain blocks
on one Sum block from the Math Library, one Scope and one XY Graph from the Sink library,
one Mux block from Signals and Systems library. Open the Sum block dialog box and enter the
required summing point signs + . Once you have dragged all the required blocks and placed
them on the new model window, join the in-ports and out-ports to create the simulation model.
The purpose of Mux block (Multiplex) is to combine the velocity and displacement signals into a
composite signal so as to display both signals on one Scope. XYGraph is used to display the state
trajectory, i.e., velocity versus displacement plot. Connect r
1
to the rst input and r
2
to the second
input of the XY Graph. Open the XY Graph dialog box, set the x-axis limits to 0, 2, the y-axis
limits to 4 and Sample time to 0.01. An mle named MSFanimation.m has been developed for
animating the motion of the massspring- friction system during simulation. To add this animation,
get an S-Function block form the functions & Tables library, place it on your model window and
connect its input terminal to the signal coming from the output of the Mux block. Make sure that
you have obtained MSFanimation.m and InAmin.m les from your instructor and placed it on a
folder in the current directory. Open the S-Function block for its name enter MSFanimation, and
for the S-Function parameter enter 0.01. Set the gain blocks to the given values and the damping
coecient specied in part (a) above.
Solver page
Before, starting simulation, you must set the simulation parameters. Pull down the Simulation
dialog box and select Simulation Parameters. Set the start time to 0 and the stop time to a suitable
value. For solver option select Variable-step and any of the Continuous integration routine such as
ode45 or ode23. For more accurate response you may change the Relative tolerance from 10
3
to
10
5
. If you select Fixed-step, again make sure you select a Continuous integration routine such as
ode4 (Runge-Kutta). You can also change the step size from auto to small value such as 0.0001.
Follow the same procedure in the remaining case studies in this lab and make sure the Solver option
is not set for discrete.
Simulate and obtain a print of the Scope. The scope yellow trace will not print well. Also, the
Simulink XY Graph cannot be printed. A Script m-le named plotscope has been developed which
3.2. LABORATORY PROCEDURE 15
captures the scope plot and produces a Figure plot. At the MATLAB prompt type
plotscope
then click on the Scope Figure (outside the plot area) and hit return you will have a Figure
print. You can add label and legend commands or edit the graph. You can use this procedure for
the XY Graph or the animation plot. An alternative way to obtain a Figure plot is to place two To
Workspace blocks from the Sink library and connect their inputs to r
1
, and r
2
signals, and dening
r1 and r2 for the variables. The time array can be obtained by feeding a Clock block into another
To Workspace block and dening a variable t for time. After performing the simulation you can
use plot function to obtain the desired Figure plot. Repeat the simulation for the value of B given
part (b) and the value determined in part (c) above. Document the plots obtained for the above
three cases, determine and summarize the time-domain specications for each case. Comment on
the nature of each response and discuss the eect of damping coecient on the resulting response.
MSFanimation
Scope
Mux
B/M
S-Function
Step
K/M
( ) 32 ( ) f t u t
1
s
Sum
1
s
XY Graph
1/M
Integrator2 Integrator1
x1 x2
Displacement
Velocity
Figure 4.4 SIMULINK diagram for the mechanical system. Case study 1
T
T
T
B
T
Figure 3.4: SIMULINK diagram for the mechanical system in Case Study 1
3.2.2 Case Study 2: Simple Pendulum
Consider the simple pendulum illustrated in Figure 3.5 where a mass of : kg is hung from a hinge
by a rigid rod of length | meters. The rod is light enough that its mass can be neglected. The rod
is displaced by angle 0 radians from the equilibrium position. Assume a viscous friction for the
motion with a damping coecient of 1 Kg-s/m. The tangential velocity of the mass is |
0. The
tangential forces acting to restore the pendulum to equilibrium are
1
T
= :p sin(0) 1|
0
where p is the gravitational acceleration. Also from Newtons law, we have
1
T
= :|
0
Combining the above equations, we get
0 +
1
:
0 +
p
|
sin(0) = 0 (3.7)
Equation 3.7 is nonlinear because of the sin(0) term. We can now write the above equation in state
variable form. Let r
1
= 0, and r
2
=
0 (angular velocity). Then,
r
1
= r
2
r
2
=
1
:
r
2
p
|
sin(r
1
) (3.8)
16 CHAPTER 3. MODELING AND DIGITAL SIMULATION CASE STUDIES
be neglected. The rod is displaced by angle radians from the equilibrium
mg
l
T
sin mg T
Figure 4.5 Simple Pendulum
T
Figure 3.5: Simple Pendulum
The simulation diagram for equations in 3.8 is shown in Figure 3.6. The mass is displaced from the
lation diagram for equations in (4.8) is shown in Figure 4.6
1
s
1
( ) x t
1
s
B m
1
sin ( )
g
x t
l
2 1
( ) ( ) x t x t
2
( ) x t
Figure 4.6 Simulation diagram for the pendulum. Case study 2
T x
Figure 3.6: Simulation diagram for the pendulum in Case Study 2
equilibrium by 0.5 radians (28.65
o
) at time t = 0. Mass : = 0.5 Kg, the rod length is | = 0.613 m
and the gravitational acceleration is 9.81 m/s
2
. Two cases of frictional coecient will be considered:
(a) 1 = 0.05 Kg-s/m
(b) 1 = 4.0 Kg-s/m
Lab Exercise (Digital Simulation using SIMULINK)
Create a SIMULINK block diagram presentation of the system shown in Figure 3.5. Drag all
the required blocks and place them on a new model window. For the nonlinear term, get the Fcn
block from the Function & Tables library. Use u for the input variable name, e.g. 16 :in(n).
Specify the gain 1,: and connect all blocks to create the simulation model shown in Figure 3.7.
Open the last integrator dialog box and set the initial condition to 0.5 for the angular displacement.
The initial velocity is zero. Therefore, set the Initial condition parameter for the rst integrator
to 0. Place one scope to display the angle 0 (signal r
1
) and another scope to display the velocity
signal r
2
. Use a XYGraph to display the state trajectory, i.e., velocity versus displacement plot.
Connect r
1
to the rst input and r
2
to the second input. Open the XY Graph dialog box, and set
the x-axis limits to 5, 0.5, the y-axis limits to 2, 2 and Sample time to 0.01. An m-le named
3.2. LABORATORY PROCEDURE 17
B/m
1
s
Inte
x
B
PenAnimation
Theta
Mux
S-Function
Fcn
Sum
1
s
x2 x1
XY Graph
9.81/0.613*sin(u)
Integrator2 grator1
omega
Figure 3.7: SIMULINK diagram for the pendulum in Case Study 2
PenAnimation.m has been developed for animating the pendulum swing during simulation. To add
this animation, get a Mux block with two inputs. Connect r
1
to the top inport and r
2
to the lower
inport. Next get an S-Function block from the Functions & Tables library, place it on the your
model window and connect its in-port terminal to the signal coming from the Mux block. Make
sure that you have obtained this m le from your instructor and placed it on a folder in the path
of MATLAB. Open the SFunction block, for its name enter PenAnimation and for the S-Function
parameter enter 0.01.
(a) The frictional coecient 1 = 0.05 Kg-s/m.
Simulate and print the zero-input response (natural response) for the angular displacement
and state trajectory. You may want to reduce the simulation nal time to a suitable value.
Comment on the nature of response. When a system returns to its equilibrium point after
a disturbance, the system is said to be stable. Is the system stable about its equilibrium
point 0 = 0 ? How would you describe the system stability if the damping coecient 1 were
neglected? Use plotsope to capture the Scope trace and the XY Graph.
(b) Repeat for the frictional coecient 1 = 4 Kg-s/m.
Linearization
Many control systems are designed to return to their equilibrium position when subjected to
a small disturbance. Nonlinear systems are often linearized assuming small deviation from the
equilibrium point. The nonlinear dierential equation describing the motion of the pendulum
can be linearized if the initial angle of deection is small.
Let 0 = 0
0
+0, substitute in (3.7) and expand the sin term. For small 0 assuming sin(0)
0, cos(0) 1, and cos(0
0
) 1, show that (3.7) results in the linearized dierential equation
given by
d
2
0
dt
2
+
1
:
d0
dt
+
p
|
d0
dt
(3.9)
This approximation is reasonably accurate for ,4 0 ,4.
(c) The state variable equation in terms of the small changes 0 and
J0
J|
is the same as (3.8),
except sin r
1
is replaced by r
1
. Copy the SIMULINK nonlinear model and paste it on the
same model window, replace the Fnc block with a gain block and set the parameter to the
18 CHAPTER 3. MODELING AND DIGITAL SIMULATION CASE STUDIES
value given by p,|. Eliminate the s-function in the duplicate model. In order to validate the
linearized model use a Mux block with two inputs and connect its inports to the r
1
signal
of each model and a Scope to its out-port terminal. Simulate for 1 = 0.05 in both models
and obtain the response. State if the linearized model response is in close agreement with the
nonlinear model. The characteristic equation of the linearized model is
:
2
+
1
:
: +
p
|
= 0 (3.10)
(d) For the given values of | , and : , nd the value of 1 for critically damped response. Set the
1 to this value in both models and repeat the simulation. Comment on the response.
3.2.3 Case Study 3: Nonlinear Dierential Equation with Saturation
One of the useful features of SIMULINK is the availability of nonlinear blocks, such as switch, relay,
deadzone, backlash, rate-limiter, saturation, Coulomb friction, and many other nonlinear functions.
These are very useful for studying the eects of nonlinearities on the behavior of the system. This
study deals with the simulation of a nonlinear dierential equation. The angular displacement of a
dynamic system is given by
d
2
c
dt
2
+ 4
dc
dt
+o
0
sin(c) = 30n(t) (3.11)
where n(t) is a unit step input and
o
0
= 35.6 for 0 t t
t
o
0
= 15 for 0 t
t
< (3.12)
and c is constrained as follows
2 c 2 (3.13)
where t
t
is a threshold switching time. Where large value of t
t
may result in an unbounded response.
Transforming to state variable form, let r
1
= c, and r
2
=
c, then
r
1
= r
2
r
2
= o
0
sin r
1
4r
2
+ 30n(t) (3.14)
The SIMULINK diagram for the above system is shown in Figure 3.8. Equation (3.12) is repre-
sented by the Switch block and equation (3.13) is represented by the Saturation block.
Lab Exercise (Digital Simulation using SIMULINK)
Construct the above Simulink diagram, and in Step block set the Step time to 0, Final time to
1. Open the Simulation Parameters dialog box, set the Stop time to 5 seconds and select ode45.
Obtain the response for t
t
= 0.4 , and t
t
= 3 seconds. Comment on the behavior of the response
for each case.
3.2. LABORATORY PROCEDURE 19
block.
Delta
Step
x1
1 ( ) u t
1
s
Sum
1
s
Gain integr 2
integ 1
30
35.6*sin(u)
15*sin(u)
Saturation
x'1=x2
x'2
0
c
t t d d
c
t t d d f
4
T
Figure 3.8: SIMULINK diagram for the Case Study 3
3.2.4 Case Study 4: Inverted Pendulum
This fourth study deals with the classic problem of balancing an inverted pendulum. This study
demonstrates the control of an inherently unstable system of balancing systems that occurs in the
areas of missile stabilization and robotics. This study also demonstrates the Linearization of a
nonlinear system.
Figure 3.9 shows an inverted pendulum of length | and mass : supported by a frictionless pivot
on a cart of mass `. It is to be balanced by means of a force n applied to the cart. That is, the cart
must be moved in such a way that the pendulum is in upright position. In a physical system there
would be sensors to measure the position and velocity of the cart and the angle 0 measured from
the vertical position. This is also a model of the attitude control of a space booster on takeo. This
mg
l
T
u
x
T T T
T T
Figure 3.9: Inverted pendulum on a cart.
is similar to the balancing of a broomstick on the palm of your hand. The equilibrium condition
is when 0(t), and
0(t) returns to zero. The visual location of your hand and the position of the
broomstick and the proper movement of your hand is the required feedback without which it is
not possible to balance the broomstick. The dierential equations describing the motion of the
system is obtained by summing the forces on the pendulum, which result in the following nonlinear
20 CHAPTER 3. MODELING AND DIGITAL SIMULATION CASE STUDIES
equations.
(` +:) r + (:1cos(0))
0 = (:1sin(0))(
0)
2
+n
(:1cos(0)) r +:1
2
0 = :p1sin(0) (3.15)
Pre-Lab Exercise
(a) Linearize the above equations in the neighborhood of the zero initial states. Hint: Substitute
0 for sin(0), 1 for cos(0), and 0 for (
0)
2
. With the state variables dened as r
1
= 0, r
2
=
0,
r
3
= r, and r
4
= r, show that the linearized state equation is
r
1
r
2
r
3
r
4
0 1 0 0
1+n
1J
p 0 0 0
0 0 0 1
n
1
p 0 0 0
r
1
r
2
r
3
r
4
1
1J
0
1
1
n (3.16)
If we want to have all the state variables available as the output, we dene the C matrix as an
identity matrix and 1 is a 4 1 zero matrix
C =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
, 1 =
0
0
0
0
(3.17)
Lab Exercise (Digital Simulation using SIMULINK)
(b) The parameters of the inverted pendulum are ` = 4 kg, : = 0.2 kg, 1 = 0.5 m, and p = 9.81
m/s. In a MATLAB script le dene the system parameters and the , 1, C, 1 matrices.
M = 4; m = 0.2; g =9.81; L =.5;
A = [ 0 1 0 0;
(M+m)/(M*L)*g 0 0 0;
0 0 0 1;
-m/M*g 0 0 0];
B = [0; -1/(L*M); 0; 1/M]; %Column vector
C = eye(4); %Identity matrix
D = zeros(4, 1); %Column vector
x 0 = [0.1 0 0.1 0];
Save the le as Lab4CS4aData.m
Launch Simulink, open a new model, get the State-Space block from the Continuous library and
construct the above state model. Double click on the State-Space block to open its dialog box
and for parameters type , 1, C, and 1. Note that MATLAB is case sensitive. For the initial
condition type, [0.1 0 0.1 0] or r
0
. In the Simulation Parameters dialog box set Start Time
to 0, Stop Time to 3 second. For Solver option use a variable step size and ode45 algorithm.
3.2. LABORATORY PROCEDURE 21
Connect a Demux block to separate the signals, and use two scopes to display 0 and r. Get
an Inport block from the Source library and use it as an input terminal. Also get an Outport
block from the Sink library and connect it to the signal for 0 as shown in Figure 3.10. These
terminals will enable us to nd the system transfer function from the Simulink diagram.
x Ax Bu
y Cx Du
Theta
x
Demux
State-Space
In 1
Out 1
1
2
Terminator 2
Terminator 1
Demux
Figure 4.10 Simulink block diagram for the Inverted Pendulum.
Figure 3.10: SIMULINK Diagram for the Inverted Pendulum in Case Study 4.
Save the Simulink model as Lab4CS4a.mdl.
Run the script m-le Lab4CS4aData at the MATLAB prompt to calculate the , 1, C, and 1
matrices. These values are now dened and are available in Simulink. Start the Simulation in
SIMULINK and obtain a plot of 0 and r . Comment on the stability of the system. MATLAB
provides the function linmod to extract a linear model in state variables or as a transfer function
model using the Simulink le name as argument. At the MATLAB prompt type the following
commands to obtain the linearized transfer function model, and roots of the characteristic
equation.
[num, den]=linmod(Lab4CS4a);
r = roots(den);
You may have found that the angle 0 increases without limit, i.e. the response is unbounded.
Also you may nd that a root of the characteristic equation is positive. This again conrms
an unbounded response and we say that the system is unstable, that is, the inverted pendulum
will fall over unless a suitable control force via state feedback is used.
(c) The purpose is to design a control system such that for a small initial disturbance the pendulum
can be brought back to the vertical position (0 = 0), and the cart can be brought back to the
reference position (r = 0).
One approach in modern control systems, accomplished by the use of state feedback, is known as
pole-placement design. The pole-placement design allows all roots of the system characteristic
equation to be placed in desired locations. This results in a regulator with 1 constant gain
vector. In pole-placement design the control is achieved by feeding back the state variables
through a regulator with constant gains. Consider the control system presented in the state-
variable form
r(t) = r(t) +1n(t)
j(t) = Cr(t) (3.18)
Consider the block diagram of the system shown in Figure 3.11 with the following state feedback
control.
n(t) = 1r(t) (3.19)
22 CHAPTER 3. MODELING AND DIGITAL SIMULATION CASE STUDIES
Plant
n
K
( ) u t
2
K
1
K
Plant
( )
n
x t
1
( ) x t
2
( ) x t
"
( ) y t
Figure 3.11: Control system design via pole placement.
where 1 is a / 1 matrix of constant feedback gain. The control system input is assumed
to be zero. The purpose of this system is to return all state variables to values of zero when
the states have been perturbed. Substituting (3.19) into (3.18), the closed-loop system state-
variable representation is
r(t) = [11]r(t) =
}
r(t) (3.20)
The design objective is to nd the gain matrix such that the characteristic equation for the
controlled system is identical to the desired characteristic equation. A custom-made function
named [K, Af] = placepole(A, B, C, P) is developed for the pole placement design. , 1, C are
system matrices and 1 is a row vector containing the desired closed-loop poles. This function
returns the gain vector 1 and the closed-loop system matrix
}
. Also, the MATLAB Control
System Toolbox contains two functions for pole-placement design. Function K = acker(A, B,
P) is for single input systems, and function K = place(A, B, p), which uses a more reliable
algorithm, is for multi-input systems.
An aspect of state variable design is state feedback design. In this study use the custom made
function [K, Af] = placepol(A, B, C, P) and design a state feedback controller to place the
closed-loop poles at
1 = [1 ,0.5, 4, 5]
Add the above two statements to the script le Lab4CS4aData4.m as shown below.
M = 4; m = 0.2; g =9.81; L =.5;
A = [ 0 1 0 0;
(M+m)/(M*L)*g 0 0 0;
0 0 0 1;
-m/M*g 0 0 0];
B = [0; -1/(L*M); 0; 1/M]; %Column vector
C = eye(4); %Identity matrix
D = zeros(4, 1); %Column vector
x 0 = [0.1 0 0.1 0];
P = [-2+j*.5, -2-j*.5, -5, -4];
[K, Af] = placepol(A, B, C, P);
Save as Lab4CS4bData.m. In Simulink, open the Lab4CS4a.mdl. Add the state feedbacks and
set the gains to 1(1), 1(2), 1(3), and 1(4) as shown in Figure 3.12. Run the script le
Lab4CS4bData to evaluate the gain matrix 1 for use in the Simulink. Rename the model as
Lab4CS4b.mdl. Start the Simulation in SIMULINK and obtain a plot of 0 and r, comment
3.3. TAKE-HOME ASSIGNMENT 23
x Ax Bu
y Cx Du
theta
Demux
State-Space
In 1
Out 1
1
2
Demux
(4) K
(1) K
(2) K
(3) K
( ) ( ) u t Kx t
State feedback
using pole-placement design
1 K
2 K
3 K
4 K
Sum
x
Figure 4.12 Control of Inverted Pendulum via pole placement.
T x
Figure 3.12: Control of Inverted Pendulum via pole placement.
on the stability of the system. To see an inverted pendulum animation make sure you have
obtained the m-le named InvPenAnimation.m. After simulation type InvPenAnimation at the
MATLAB prompt.
At the MATLAB prompt type the following commands to obtain the linearized transfer function
model, and roots of the compensated characteristic equation.
[num, den]=linmod(Lab4CS4b);
r = roots(den);
Check for the roots of the compensated system. Are they the same as the specied values? Is
the system stable that is, will the pendulum return to the vertical equilibrium position?
3.3 Take-Home Assignment
Experiment 4.1 and Experiment 4.2 in Cyber Exploration Laboratory at the end of Chapter 4 of
Control Systems Engineering by Nise, 5th Edition.
Bibliography
[1] Hadi Saadat. Computational Aids in Control Systems Using MATLAB. McGraw-Hill. 1993.
[2] Hadi Saadat website. http://people.msoe.edu/ saadat/matlab.htm