Sistem Modeling: Physical Setup System Parameters Design Criteria System Equations

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 52

SISTEM

MODELING

Contents
 Physical setup
 System parameters
 Design criteria
 System equations

Physical setup
A ball is placed on a beam, see figure below, where it is allowed to roll with 1 degree of freedom along the
length of the beam. A lever arm is attached to the beam at one end and a servo gear at the other. As the
servo gear turns by an angle , the lever changes the angle of the beam by . When the angle is
changed from the horizontal position, gravity causes the ball to roll along the beam. A controller will be
designed for this system so that the ball's position can be manipulated.

System parameters
For this problem, we will assume that the ball rolls without slipping and friction between the beam and ball
is negligible. The constants and variables for this example are defined as follows:

(m) mass of the ball 0.11 kg

(R) radius of the ball 0.015 m

(d) lever arm offset 0.03 m

(g) gravitational acceleration 9.8 m/s^2

(L) length of the beam 1.0 m

(J) ball's moment of inertia 9.99e-6 kg.m^2


(r) ball position coordinate

(alpha) beam angle coordinate

(theta) servo gear angle

Design criteria
 Settling time < 3 seconds
 Overshoot < 5%

System equations
The second derivative of the input angle actually affects the second derivative of . However, we will
ignore this contribution. The Lagrangian equation of motion for the ball is then given by the following:

(1)

Linearization of this equation about the beam angle, , gives us the following linear approximation
of the system:

(2)

The equation which relates the beam angle to the angle of the gear can be approximated as linear by the
equation below:

(3)

Substituting this into the previous equation, we get:

(4)

1. Transfer Function

Taking the Laplace transform of the equation above, the following equation is found:

(5)

Rearranging we find the transfer function from the gear angle ( ) to the ball position ( ).

(6)

It should be noted that the above plant transfer function is a double integrator. As such it is marginally
stable and will provide a challenging control problem.

The transfer function can be implemented in MATLAB as follows:

m = 0.111;

R = 0.015;
g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2

P_ball =

0.21

----

s^2

Continuous-time transfer function.

2. State-Space

The linearized system equations can also be represented in state-space form. This can be done by
selecting the ball's position ( ) and velocity ( ) as the state variable and the gear angle ( ) as the input.
The state-space representation is shown below:

(7)

However, for our state-space example we will be using a slightly different model. The same equation for
the ball still applies but instead of controlling the position through the gear angle, , we will control the
torque applied to the beam directly. Below is the representation of this system:

(8)
(9)

Note: For this system the gear and lever arm would not be used, instead a motor at the center of the
beam will apply torque to the beam, to control the ball's position.

The state-space equations can be represented in MATLAB with the following commands (these
equations are for the torque control model).

H = -m*g/(J/(R^2)+m);

A = [0 1 0 0

0 0 H 0

0 0 0 1

0 0 0 0];

B = [0 0 0 1]';

C = [1 0 0 0];

D = [0];

ball_ss = ss(A,B,C,D)

ball_ss =

A =

x1 x2 x3 x4

x1 0 1 0 0

x2 0 0 7 0

x3 0 0 0 1

x4 0 0 0 0

B =

u1
x1 0

x2 0

x3 0

x4 1

C =

x1 x2 x3 x4

y1 1 0 0 0

D =

u1

y1 0

Continuous-time state-space model.

ANALISIS

Contents
 System model
 Pole/zero map
 Open-loop step response

System model

The transfer function from the gear angle ( ) to the ball position ( ), as derived in the Ball &
Beam: System Modeling page.

(1)

Open a new m-file and add the following code to create a transfer function model in MATLAB.

m = 0.111;

R = 0.015;
g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2

P_ball =

0.21

----

s^2

Continuous-time transfer function.

Pole/zero map
The Ball and Beam system is a type II system which has two poles at the origin, as seen in the pole/zero
map below. Since the poles are not strictly in the left half plane, the open loop system will be unstable as
seen in the step response below.

pzmap(P_ball)
Open-loop step response
Now, we would like to observe the ball's response to a step input on the motor servo gear
angle (1-radian step). To do this you will need to add the following line to your m-file.

step(P_ball)
From this plot it is clear that the system is unstable in open-loop causing the ball to roll right off the end of
the beam. Therefore, some method of controlling the ball's position in this system is required. Several
examples of controller design are provided in these tutorials to address this problem.

CONTROL

PID

Contents
 Closed-loop representation
 Proportional control
 Proportional-derivative control
The open-loop transfer function of the plant for the ball and beam experiment is given below:

(1)

The design criteria for this problem are:

 Settling time less than 3 seconds


 Overshoot less than 5%
To see the derivation of the equations for this problem refer to the Ball & Beam: System Modeling page.

Closed-loop representation
The block diagram for this example with a controller and unity feedback of the ball's position is shown
below:
First, we will study the response of the system shown above when a proportional controller is used. Then,
derivative and/or integral control will be added if necessary.

Recall, that the transfer function for a PID controller is:

(2)

Proportional control

The closed-loop transfer function for proportional control with a proportional gain ( ) equal to 100, can
be modeled by copying the following lines of MATLAB code into a new m-file.

m = 0.111;

R = 0.015;

g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2;

Kp = 1;

C = pid(Kp);

sys_cl=feedback(C*P_ball,1);
Now, we can model the system's response to a step input of 0.25 m. Add the following line of code to
your m-file and run it. You should get the following output:

step(0.25*sys_cl)

axis([0 70 0 0.5])

As you can see, the system remains marginally stable with the addition of a proportional gain. Try
changing the value of and note that the system remains unstable.

Proportional-derivative control
Now, we will add a derivative term to the controller. Copy the following lines of code to an m-file and run it
to view the system's response to this control method. Your plot should be similar to the following:

m = 0.111;

R = 0.015;

g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;
s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2;

Kp = 10;

Kd = 10;

C = pid(Kp,0,Kd);

sys_cl=feedback(C*P_ball,1);

t=0:0.01:5;

step(0.25*sys_cl)

Now the system is stable but the overshoot is much too high and the settling time needs to go down a bit.
From the PID tutorial page in the section on characteristics of P, I, and D controllers, we see that by
increasing we can lower the overshoot and decrease the settling time slightly. Therefore, make =
20 in your m-file and run it again. Your output should be:

Kp = 10;

Kd = 20;

C = pid(Kp,0,Kd);

sys_cl=feedback(C*P_ball,1);

step(0.25*sys_cl)

The overshoot criterion is met but the settling time needs to come down a bit. To decrease the settling
time we may try increasing the slightly to increase the rise time. The derivative gain ( ) can also be
increased to take off some of the overshoot that increasing will cause. After playing with the gains a
bit, the following step response plot can be achieved with = 15 and = 40:

Kp = 15;

Kd = 40;

C = pid(Kp,0,Kd);

sys_cl=feedback(C*P_ball,1);
step(0.25*sys_cl)

As you can see from the above plot all the control objectives have been met without the use of an integral
controller (settling time for this example is considered achieved when the response is less than 2% of its
final value). Remember, that for a control problem there is usually more than one solution for the
problem.

ROOT LOCUS

Contents
 Open-loop root locus
 Lead controller
 Selecting the gain
 Plotting the closed-loop response
The open-loop transfer function of the plant for the ball and beam experiment is given below:

(1)

The design criteria for this problem are:

 Settling time less than 3 seconds


 Overshoot less than 5%
To see the derivation of the equations for this problem refer to the Ball & Beam: System Modeling page.
Open-loop root locus
The main idea of the root locus design is to estimate the closed-loop response from the open-loop root
locus plot. By adding zeroes and/or poles to the original system (adding a compensator), the root locus
and thus the closed-loop response will be modified. Let us first view the root locus for the plant in open
loop. Create a new m-file with the following MATLAB code in order to model the plant and plot the root
locus. Now, run the m-file and you should see the following root locus plot:

m = 0.111;

R = 0.015;

g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2;

rlocus(P_ball)
As you can see the system has two poles at the origin which go off to infinity along the imaginary axes.

The design criteria can also be plotted onto the root locus using the sgrid command. This command
generates a grid of constant damping ratio and natural frequency. The damping ratio ( ) and natural
frequency ( ) were found using the following equations which relate them to our maximum percent
overshoot ( ) and settling time ( ) requirements:

(2)

(3)

Note, that the equation with is found by assuming the system has settled when the response remains
within 2% of its final value. From these equations, the damping ratio and natural frequency were found to
be 0.7 and 1.9 respectively.

sgrid(0.70, 1.9)

axis([-5 5 -2 2])
The area between the two dotted diagonal lines represents locations where the percent overshoot is less
than 5%. The area outside the curved line represents locations where the settling time is less than 3
seconds. Note that no region of the plot falls within the design criteria shown by these lines. To remedy
this and bring the root locus into the left-hand plane for stability we will try adding a lead-compensator to
the system.

Lead controller
A first order lead compensator tends to shift the root locus into the left-hand plane. For a more detailed
description of lead compensators refer to the Lead & Lag Compensator Design page. A lead
compensator has the form given below:

(4)

where, the magnitude of is less than the magnitude of .

Now, let us add the controller to the plant and view the root locus. We will position the zero near the origin
to cancel out one of the poles. The pole of our compensator will be placed to the left of the origin to pull
the root locus further into the left-hand plane. Add the following lines of MATLAB code to your m-file. Run
your m-file in the MATLAB command window and you should see the following:

zo = 0.01;

po = 5;

C=tf([1 zo],[1 po]);


rlocus(C*P_ball)

sgrid(0.70, 1.9)

Now, the branches of the root locus are within our design criteria.

Selecting the gain


Now that we have moved the root locus into the left-hand plane, we may select a gain that will satisfy our
design requirements. We can use the rlocfind command to help us do this. Add the
code [k,poles]=rlocfind(C*P_ball) onto the end of your m-file.

Then go to the plot and select a point near those indicated by the cross marks on the plot below.
After doing this, you should see the following output in the MATLAB command window.

Select a point in the graphics window

selected_point =

-2.4917 + 1.0109i

k =
34.7474

poles =

-2.4950 + 1.0109i

-2.4950 - 1.0109i

-0.0101

Note that the values returned in your MATLAB command window may not be exactly the same, but
should at least have the same order of magnitude. Now, we can plot the response with this gain.

Plotting the closed-loop response


This value of k can be put into the system and the closed-loop response to a step input of 0.25 m can be
obtained. Add the following lines to your m-file to perform this analysis. Run your m-file and select a point
on the root locus similar to the selected point above. The step response should look like the following.

sys_cl=feedback(k*C*P_ball,1);

t=0:0.01:5;

figure

step(0.25*sys_cl,t)
From this plot we see that when a 0.25-m step input is given to the system both the settling time and
percent overshoot design criteria are met.

Note: A design problem does not necessarily have a unique answer. Using this method (or any other)
may result in many different compensators. Try running your m-file several more times selecting a
different point each time and study the effect this has on the step response. For practice you may also
want to go back to the original open-loop root locus and try to find other ways to add zeros and poles to
get a better response.

FREQUENCY

Contents
 Open-loop bode plot
 Phase-lead controller
 Adding more phase
The open-loop transfer function of the plant for the ball and beam experiment is given below:

(1)

The design criteria for this problem are:

 Settling time less than 3 seconds


 Overshoot less than 5%
To see the derivation of the equations for this problem refer to the Ball & Beam: System Modeling page.
Open-loop bode plot
The main idea of frequency based design is to use the Bode plot of the open-loop transfer function to
estimate the closed-loop response. Adding a controller to the system changes the open-loop Bode plot,
therefore changing the closed-loop response. Let's first draw the bode plot for the original open-loop
transfer function. Create a new m-filewith the following code and then run it in the MATLAB command
window. You should get the following Bode plot:

m = 0.111;

R = 0.015;

g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2;

bode(P_ball)
From this plot we see that the phase margin is zero. Since the phase margin is defined as the change in
open-loop phase shift necessary to make a closed-loop system unstable this means that our zero phase
margin indicates our system is unstable. We want to increase the phase margin and we can use a lead
compensator controller to do this. For more information on Phase and Gain margins please refer to
the Introduction: Frequency Domain Methods for Controller Design page.

Phase-lead controller
A first order phase-lead compensator has the form given below:

(2)

The phase-lead compensator will add positive phase to our system over the frequency
range and , which are called the corner frequencies. The maximum added phase for one lead
compensator is 90 degrees. For our controller design we need a percent overshoot of less than 5%,
which corresponds to a of 0.7. Generally will give you the minimum phase margin needed to
obtain your desired overshoot. Therefore, we require a phase margin greater than 70 degrees.

To obtain and , the following steps can be applied.

1. Determine the positive phase needed: We need at least 70 degrees from our controller.

2. Determine the frequency where the phase should be added (center frequency): In our case this
is difficult to determine because the phase vs. frequency graph in the bode plot is a flat line. However, we
have a relation between bandwidth frequency ( ) and settling time which tells us that is
approximately 1.92 rad/s. Therefore, we want a center frequency just before this. For now we will choose
1 rad/sec.

3. Determine the constant from the equation below: this determines the required space between
the zero and the pole for the maximum phase added.
(3)

where phi refers to the desired phase margin. For 70 degrees, = 0.0311.

4. Determine and from the following equations:

(4)

(5)

For 70 degrees and center frequency = 1, = 0.176 and = 5.67.

Now, we can add our lead controller to the system and view the bode plot. Remove the bode command
from your m-file and add the following. You should get the following bode plot:

phi=70*pi/180;

a=(1-sin(phi))/(1+sin(phi));

w=1;

T=1/(w*sqrt(a));

K = 1;

C = K*(1+T*s)/(1+a*T*s);

bode(C*P_ball)
You can see that our phase margin is now 70 degrees. Let's check the closed-loop response to a step
input of 0.25 m. Add the following to your m-file. You should get the following plot:

sys_cl = feedback(C*P_ball,1);

t = 0:0.01:5;

step(0.25*sys_cl,t)
Although the system is now stable and the overshoot is only slightly over 5%, the settling time is not
satisfactory. Increasing the gain will increase the crossover frequency and make the response faster.
With = 5, your response should look like:

K = 5;

C = K*(1+T*s)/(1+a*T*s);

sys_cl = feedback(C*P_ball,1);

bode(C*P_ball)

step(0.25*sys_cl,t)
The response is faster, however, the overshoot is much too high. Increasing the gain further will just
make the overshoot worse.

Adding more phase


We can increase our phase-lead compensator to decrease the overshoot. Create an m-file and copy the
following code from your web-browser into it:

pm = 80;

w = 1;

K = 1;

%view compensated system bode plot

pmr = pm*pi/180;

a = (1 - sin(pmr))/(1+sin(pmr));

T = sqrt(a)/w;

aT = 1/(w*sqrt(a));

C = K*(1+aT*s)/(1+T*s);
figure

bode(C*P_ball)

%view step response

sys_cl = feedback(C*P_ball,1);

t = 0:0.01:5;

figure

step(0.25*sys_cl,t)
The overshoot is fine but the settling time is just a bit long. Try different numbers and see what happens.
Using the following values the design criteria was met.

pm = 85;
w = 1.9;

K = 2;

%view compensated system bode plot

pmr = pm*pi/180;

a = (1 - sin(pmr))/(1+sin(pmr));

T = sqrt(a)/w;

aT = 1/(w*sqrt(a));

C = K*(1+aT*s)/(1+T*s);

figure

bode(C*P_ball)

%view step response

sys_cl = feedback(C*P_ball,1);

t = 0:0.01:5;

figure

step(0.25*sys_cl,t)
Note: A design problem does not necessarily have a unique answer. Using this method (or any other)
may result in many different compensators. For practice you may want to go back and change the added
phase, gain, or center frequency.

STATE-SPASE
Contents
 Full state-feedback controller
 Reference input
The state-space representation of the ball and beam example is given below:

(1)

(2)

Unlike the previous examples where we controlled the gear's angle to control the beam and ball, here we
are controlling . By doing this we are essentially controlling a torque applied at the center of the beam
by a motor. Therefore, we do not need a gear and lever system.

The design criteria for this problem are:

 Settling time less than 3 seconds


 Overshoot less than 5%
To see the derivation of the equations for this problem refer to the Ball & Beam: System Modeling page.

Full state-feedback controller


We will design a controller for this physical system that utilizes full state-feedback control. A schematic of
this type of system is shown below:

Recall, that the characteristic polynomial for this closed-loop system is the determinant
of , where is the Laplace variable. For our system the and matrices are both
4x4. Hence, there should be four poles for our system. In designing our full-state feedback controller we
can move these poles anywhere we want.

For our design we desire an overshoot of less than 5% which corresponds to a of 0.7 (please refer to
your textbook for the relationship between overshoot and damping ratio). On a root locus this criterion is
represented as a 45 degree line emanating from the origin and extending out into the left-half plane. We
want to place our desired poles on or beneath this line. Our next criterion is a settling time less than 3
seconds, which corresponds to a = 4.6 / = 4.6 / 3 = 1.53, represented by a vertical line at -1.53 on
the root locus. Anything beyond this line in the left-half plane is a suitable place for our poles. Therefore
we will place our poles at -2+2i and -2-2i. We will place the other poles far to the left for now, so that they
will not affect the response too much. To start with place them at -20 and -80. Now that we have our
poles we can use MATLAB to find the controller ( matrix) by using the place command. Copy the
following code to an m-file to model the system and find the matrix:

m = 0.111;

R = 0.015;

g = -9.8;

J = 9.99e-6;

H = -m*g/(J/(R^2)+m);

A = [0 1 0 0

0 0 H 0

0 0 0 1

0 0 0 0];

B = [0;0;0;1];

C = [1 0 0 0];

D = [0];

ball_ss = ss(A,B,C,D);

p1 = -2+2i;

p2 = -2-2i;

p3 = -20;

p4 = -80;
K = place(A,B,[p1,p2,p3,p4])

K =

1.0e+03 *

1.8286 1.0286 2.0080 0.1040

After adding the matrix, the state space equations now become:

(3)

(4)

We can now simulate the closed-loop response to a 0.25-m step input by using the lsim command. Add
the following to your m-file. Run your m-file and you should get the following plot:

t = 0:0.01:5;

u = 0.25*ones(size(t));

sys_cl = ss(A-B*K,B,C,D);

[y,t,x] = lsim(sys_cl,u,t);

plot(t,y)
From this plot we see that there is a large steady state error, to compensate for this, we will need to add a
reference input compensation (explained in next section). However, the overshoot and settling time
criteria are met. If we wanted to reduce the overshoot further, we could make the imaginary part of the
pole smaller than the real part. Also, if we wanted a faster settling time we would move the poles further
in the left-half plane. Feel free to experiment with the pole positions to see these trends.

Reference input
Now we want to get rid of the steady-state error. In contrast to the other design methods, where we
feedback the output and compare it to the reference input to compute an error, with a full-state feedback
controller we are feeding back both states. We need to compute what the steady-state value of the states
should be, multiply that by the chosen gain , and use a new value as our reference for computing the
input. This can be done by adding a constant gain after the reference. The schematic below shows
this relationship:

can be found using the user-defined function rscale.m. Download it here, rscale.m, and place it in the
directory that your m-file is in. Copy the following to your m-file and run it to view the step response
with added.

Nbar=rscale(ball_ss,K)

t = 0:0.01:5;

u = 0.25*ones(size(t));

[y,t,x]=lsim(Nbar*sys_cl,u,t);

plot(t,y)

Nbar =

1.8286e+03
Now the steady-state error has been eliminated and all the design criteria are satisfied.

Note: A design problem does not necessarily have a unique answer. Using this method (or any other)
may result in many different compensators. For practice you may want to go back and try to change the
pole positions to see how the system responds.

DIGITAL

Contents
 Digital PID controller
 Discrete Transfer Function
 Open-loop response
 Proportional control
 Proportional-derivative control
The open-loop transfer function of the plant for the ball and beam experiment is given below:

(1)

The design criteria for this problem are:

 Settling time less than 3 seconds


 Overshoot less than 5%
To see the derivation of the equations for this problem refer to the Ball & Beam: System Modeling page.

Digital PID controller


If you refer to any of the PID control problem for continuous systems, the PID transfer function was
expressed as

(2)

As you noticed the above transfer function was written in terms of . For the digital PID control, we use
the following transfer function in terms of .

(3)

Discrete Transfer Function


The first thing to do here is to convert the above continuous system transfer function to an equivalent
discrete transfer function. To do this, we will use the MATLAB function c2d. To use c2d, we need to
specify three arguments: system, sampling time (Ts), and the 'method'. You should already be familiar
with how to create a system from numerator and denominator matrices. The sampling time should be
smaller than sec, where is the closed-loop bandwidth frequency. The method we will
use is the zero-order hold ('zoh'). Assuming that the closed-loop bandwidth frequency is around 1 rad/sec,
let the sampling time be 1/50 sec/sample. Now we are ready to use c2d. Enter the following commands
to an m-file. Running this m-file in the MATLAB command window gives you the following matrices.

m = 0.111;

R = 0.015;

g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

s = tf('s');

P_ball = -m*g*d/L/(J/R^2+m)/s^2;

Ts = 1/50;

ball_d = c2d(P_ball,Ts,'zoh')

ball_d =

4.2e-05 z + 4.2e-05
-------------------

z^2 - 2 z + 1

Sample time: 0.02 seconds

Discrete-time transfer function.

Open-loop response
Now we will observe the ball's response to a step input of 0.25 m. To do this, enter the following
commands into a new m-file and run it in the command window. You should see the following response.

numDz = 0.0001*[0.42 0.42];

denDz = [1 -2 1];

Ts = 1/50;

ball_d = tf(numDz,denDz,Ts);

[x,t] = step(0.25*ball_d,5);

stairs(t,x)
From this plot, it is clear that the open-loop system is unstable causing the ball to roll off the end of the
beam.

Proportional control

Now we will add proportional control ( ) to the system and obtain the closed-loop system response. For
now let equal 100 and see what happens to the response. Enter the following commands into a new
m-file and run it in the command window.

Ts = 1/50;

z = tf('z',Ts);

dP_ball = 0.0001*(0.42*z + 0.42)/(z^2 - 2*z + 1);

Kp=100;

sys_cl = feedback(Kp*dP_ball,1);

[x,t] = step(0.25*sys_cl,5);
stairs(t,x)

As you can see, the addition of proportional control does not make the system stable. You may try to
increase the proportional gain ( ) and confirm that the system remains unstable.

Proportional-derivative control

Now we will add a derivative term to the controller. Keep the proportional gain ( ) equal to 100, and let
the derivative gain ( ) equal to 10. Copy the following code to an new m-file and run it to view the
system response.

Ts = 1/50;

z = tf('z',Ts);

dP_ball = 0.0001*(0.42*z + 0.42)/(z^2 - 2*z + 1);

Kp=100;

Kd=10;
C = ((Kp+Kd)*z^2 - (Kp+2*Kd)*z + Kd)/(z^2 + z);

sys_cl = feedback(C*dP_ball,1);

[x,t] = step(0.25*sys_cl,5);

stairs(t,x)

Now the system is stable, but the rise time is too long. From the PID Tutorial page, we see that the
increasing the proportional gain ( ) will decrease the rise time. Let's increase the proportional gain ( )
to 1000 and see what happens. Change in the above m-file from 100 to 1000 and rerun it in the
command window. You should see the following step response.

Kp=1000;

Kd=10;

C = ((Kp+Kd)*z^2 - (Kp+2*Kd)*z + Kd)/(z^2 + z);


sys_cl = feedback(C*dP_ball,1);

[x,t] = step(0.25*sys_cl,5);

stairs(t,x)

As you can see, all of the design requirements are satisfied. For this particular problem, no
implementation of an integral control was needed. But remember there is more than one solution for a
control problem. For practice, you may try different P, I and D combinations to obtain a satisfactory
response.

SIMULINK

MODELING

Contents
 Problem setup
 Building the model in Simulink
 Open-loop response

Problem setup
A ball is placed on a beam, see figure below, where it is allowed to roll with 1 degree of freedom along the
length of the beam. A lever arm is attached to the beam at one end and a servo gear at the other. As the
servo gear turns by an angle theta, the lever changes the angle of the beam by alpha. When the angle is
changed from the horizontal position, gravity causes the ball to roll along the beam. A controller will be
designed for this system so that the ball's position can be manipulated.

For this problem, we will assume that the ball rolls without slipping and friction between the beam and ball
is negligible. The constants and variables for this example are defined as follows:

(m) mass of the ball 0.11 kg

(R) radius of the ball 0.015 m

(d) lever arm offset 0.03 m

(g) gravitational acceleration 9.8 m/s^2

(L) length of the beam 1.0 m

(J) ball's moment of inertia 9.99e-6 kg.m^2

(r) ball position coordinate

(alpha) beam angle coordinate

(theta) servo gear angle

The design criteria for this problem are:

 Settling time less than 3 seconds


 Overshoot less than 5%
The second derivative of the input angle alpha actually affects the second derivative of . However, we
will ignore this contribution. The Lagrangian equation of motion for the ball is then given by the following:

(1)
The beam angle ( ) can be expressed in terms of the angle of the gear ( ).

(2)

Building the model in Simulink


In this example, rather than expressing all the forces and geometric constraints (which is difficult to model
in Simulink for dynamic systems with constraints) we will model the nonlinear Lagrangian equation of
motion directly. This equation gives as a function of the state and input variables, , , , and . We
will make use of the Fcn block to express this function. First, we must express the derivatives of the
output, .

 Open a new model window in Simulink.


 Insert an Integrator block from the Continuous library.
 Insert a second Integrator to the right of the first, and connect the two with a line.
 Label the line connecting the two "d/dt(r)". To label a line, double-click near the line where you
want the label (in this case, just below the line)
 Draw a line from the second Integrator and label it "r".
 Insert an Out1 block from the Sinks library and connect it to the "r" signal line. This will form the
output of the system.
 Change the label of the Out1 block to "r" by single-clicking on the existing "Out1" label.

Now, we will insert the function which takes the vector and returns .

Insert a Fnc block from the User-Defined Functions library and connect its output to the input of the first
Integrator. Edit the Fcn block by double clicking it, and change it's function to the following:

(3)

This function block takes an input vector, u, where each component is referred to as , , etc. In
our case, , , , and .
 Close the dialog box and change the label of the Fcn block to "Ball-Beam Lagrangian Model"
(you can add newlines in the label by hitting return).

Now, we will begin to construct the function input vector u by feeding back the state signals from the
integrators and forming a vector from them with a Mux block.

 Insert a Mux block from the Signal Routing library and connect its output to the input of the
Ball-Beam block.
 Edit the Mux block (by double-clicking on it) and change its number of inputs to 4. The Mux
block should now have four inputs.
 Tap a line off the d/dt(r) signal (hold Ctrl while drawing) and connect it to the second input of the
Mux block.
 Tap a line of the r signal and connect it to the first input of the Mux block.

Now we will construct the signals and from the input .

 Insert an In block on the left side of your model window. Change its label to "theta".
 Insert a Gain block and connect it to the theta block. Change its gain value (double-click on it) to
"d/L".
 Connect the output of the gain block to the third input of the Mux block. Label this line "alpha".
 Insert a Derivative block from the Continuous library and place it underneath the alpha signal
line.
 Tap a line off the output of the Gain block and connect it to the input of the Derivative block.
 Connect the output of the Derivative block to the fourth input off the Mux block.
Save your model as "ball.slx". You can download ours by right-clicking here and then selecting Save link
as ....

Open-loop response
To generate the open-loop response, it is helpful to first contain this model in a subsystem block.

 Create a new model window (select New from the File menu in Simulink or hit Ctrl-N).
 Insert a Subsystem block from the Ports & Subsystems library.
 Open the Subsystem block by double clicking on it. You will see a new model window labeled
"Subsystem".
 Open your previous model window named ball.slx. Select all of the model components by
selecting Select All from the Edit menu (or hit Ctrl-A).
 Copy the model into the paste buffer by selecting Copy from the Edit menu (or hit Ctrl-C).
 Paste the model into the Subsystem window by selecting Paste from the Edit menu (or
hit Ctrl-V) in the Subsystem window
 Close the Subsystem window. You will see the Subsystem block in the untitled window with one
input terminal labeled theta and one output terminal labeled r.
 Resize the Subsystem block to make the labels visible by selecting it and dragging one of the
corners.
 Label the Subsystem block "Ball and Beam Model".
 Insert a Step block (from the Sources library) and connect it to the input of the Ball and Beam
Model.
 Edit the Step block (by double clicking on it to bring up the dialog box) and change the Step
Time value to 0. Close the Step block dialog box.
 Insert a Scope block (from the Sinks library) and connect it to the output of the Ball and Beam
Model.

We will actually run this open-loop simulation model in the Ball & Beam: Simulink Controller Design page.
In this page we will then design and simulate a controller for the system.

CONTOL
Contents
 Simulink model
 Open-loop response
 Extracting the linear model into MATLAB
 Building a lead compensator
 Closed-loop response

Simulink model
The Simulink model for the ball and beam system was developed in the Ball & Beam: Simulink
Modeling section, and can be downloaded by right-clicking here and then selecting Save link as ....

Open-loop response
Before obtaining a step response, we must set the physical parameters. Enter the following commands at
the MATLAB prompt.

m = 0.111;

R = 0.015;

g = -9.8;

L = 1.0;

d = 0.03;

J = 9.99e-6;

We are now ready to run the simulation. Start the simulation by selecting Run from the Simulation menu
(or hit Ctrl-T). When the simulation is finished, open the Scope by double clicking on it. You will see the
following response.
From this plot it is clear that the system is unstable in open-loop causing the ball to roll right off the end of
the beam. Therefore, some method of controlling the ball's position in this system is required. Later in this
tutorial, we will implement a lead compensator.

Extracting the linear model into MATLAB


The Simulink model can be extracted into an equivalent state-space or transfer function model in
MATLAB. This is done through the use of In1 and Out1 blocks and the MATLAB function linmod.

At the MATLAB prompt, enter the following commands. You will see the following output providing the
open-loop model of the system.

[A,B,C,D] = linmod('ball')

[num,den] = ss2tf(A,B,C,D)

A =

0 1

0 0

B =

0.2100

C =
1 0

D =

num =

0 0 0.2100

den =

1 0 0

We can verify this model by obtaining an open-loop step response. Enter the following command at the
MATLAB prompt. You will see the following open-loop response:

step(num,den);

Building a lead compensator


In the Ball & Beam: Root Locus Controller Design page a lead compensator was designed with a zero at
-0.01, a pole at -5, and a gain of 37.1. We will now construct this controller in Simulink.

 Bring up your open-loop Ball and Beam model window (or download ours by
right-clicking here and then selecting Save link as ....)
 Delete the line which connects the Step block to the Ball and Beam model block.
 Insert a Transfer Function block from the Continuous library to the left of the Ball and Beam
block, and connect its output to the input of the Ball and Beam block.
 Edit the Transfer Function block and change its numerator to "[1 0.01]" and its denominator to
"[1 5]".
 Change the label of the Transfer Function block to "Lead Compensator".
 Insert a Gain block to the left of the Lead Compensator and connect its output to the Lead
compensator's input.
 Change the Gain value to "37.1".
 Insert a Sum block to the left of the Gain block and change it's value to "+-". Connect the output
of the Sum to the input of the Gain block.
 Tap a line off the output of the Ball and Beam model and connect it to the negative input of the
Sum.
 Connect the Step block to the positive input of the Sum block.

You can download our version of the closed-loop model by right-clicking here and then selecting Save
link as ....

Closed-loop response
Start the simulation in Simulink. Once the run is complete, double-click on the Scope block and you
should see the following response.

You might also like