You are on page 1of 55

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

00H0

0001

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:
Tidak seperti contoh sebelumnya di mana kami mengontrol sudut roda gigi untuk mengontrol
balok dan bola, di sini kita mengendalikan $ \ ddot {\ alpha} $. Dengan melakukan ini kita
pada dasarnya mengendalikan torsi yang diterapkan di pusat balok oleh motor. Oleh karena
itu, kami tidak membutuhkan sistem persneling dan tuas.
Kriteria desain untuk masalah ini adalah:
Waktu penyelesaian kurang dari 3 detik
Overshoot kurang dari 5%
Untuk melihat derivasi persamaan untuk masalah ini, lihat halaman Ball & Beam: System
Modelling. Kontrol umpan balik status penuh Kami akan mendesain controller untuk sistem
fisik ini yang menggunakan kontrol umpan-balik penuh. Skema dari jenis sistem ini
ditunjukkan di bawah ini
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:
Ingat, bahwa polinomial karakteristik untuk sistem loop tertutup ini adalah penentu, di mana
variabel Laplace. Untuk sistem kami, dan matriks keduanya 4x4. Oleh karena itu, harus ada
empat tiang untuk sistem kami. Dalam mendesain pengontrol umpan balik keadaan penuh,
kita dapat memindahkan kutub ini ke mana pun yang kita inginkan.
Untuk desain kami, kami menginginkan overshoot kurang dari 5% yang sesuai dengan 0,7
(silakan merujuk ke buku Anda untuk hubungan antara overshoot dan rasio redaman). Pada
locus root, kriteria ini direpresentasikan sebagai garis 45 derajat yang memancar dari titik
asal dan memanjang ke bidang setengah kiri. Kami ingin menempatkan kutub yang kami
inginkan pada atau di bawah garis ini. Kriteria kami berikutnya adalah waktu penyelesaian
kurang dari 3 detik, yang sesuai dengan = 4,6 / = 4,6 / 3 = 1,53, diwakili oleh garis vertikal
di -1,53 pada lokus akar. Apa pun di luar garis ini di pesawat setengah kiri adalah tempat
yang cocok untuk tiang kami. Oleh karena itu kami akan menempatkan tiang kami pada -2 +
2i dan -2-2i. Kami akan menempatkan kutub lainnya jauh ke kiri untuk saat ini, sehingga
mereka tidak akan terlalu banyak mempengaruhi respons. Untuk memulai dengan
menempatkannya pada -20 dan -80. Sekarang kita memiliki kutub kita, kita dapat
menggunakan MATLAB untuk menemukan pengontrol (matriks) dengan menggunakan
perintah tempat. Salin kode berikut ke m-file untuk memodelkan sistem dan temukan
matriksnya:

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

00H0

0001

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

Setelah menambahkan matriks, persamaan ruang negara sekarang menjadi:

(3)
(4)
Kita sekarang dapat mensimulasikan respon loop tertutup ke input langkah 0,25-m dengan
menggunakan perintah lsim. Tambahkan yang berikut ini ke file-m Anda. Jalankan m-file
Anda dan Anda harus mendapatkan plot berikut:

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)

Dari plot ini kita melihat bahwa ada kesalahan steady state yang besar, untuk mengimbangi
ini, kita perlu menambahkan kompensasi input referensi (dijelaskan di bagian berikutnya).
Namun, kriteria waktu overshoot dan settling time terpenuhi. Jika kita ingin mengurangi
overshoot lebih jauh, kita bisa membuat bagian imajiner dari kutub lebih kecil dari bagian
sebenarnya. Juga, jika kita menginginkan waktu penyelesaian yang lebih cepat, kita akan
memindahkan kutub lebih jauh ke dalam setengah kiri pesawat. Jangan ragu untuk
bereksperimen dengan posisi kutub untuk melihat tren ini.
Masukan referensi
Sekarang kita ingin menyingkirkan kesalahan steady-state. Berbeda dengan metode desain
lainnya, di mana kami umpan balik output dan membandingkannya dengan input referensi
untuk menghitung kesalahan, dengan kontroler umpan balik negara penuh kami memberi
makan kembali kedua negara. Kita perlu menghitung apa yang harus dilakukan oleh negara
dengan status steady state, mengalikannya dengan keuntungan yang dipilih , dan
menggunakan nilai baru sebagai referensi kita untuk menghitung input. Ini dapat dilakukan
dengan menambahkan gain konstan setelah referensi. Skema di bawah ini menunjukkan
hubungan ini:

dapat ditemukan menggunakan rscale.m fungsi yang ditentukan pengguna. Unduh di sini,
rscale.m, dan letakkan di direktori tempat m-file Anda. Salin berikut ini ke m-file Anda dan
jalankan untuk melihat respons langkah dengan ditambahkan .

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
Sekarang kesalahan steady state telah dieliminasi dan semua kriteria desain dipenuhi.
Catatan: Masalah desain tidak harus memiliki jawaban unik. Menggunakan metode ini (atau
lainnya) dapat menghasilkan banyak kompensator yang berbeda. Untuk latihan Anda
mungkin ingin kembali dan mencoba mengubah posisi kutub untuk melihat bagaimana sistem
merespons.

DIGITAL

Contents

 Digital PID controller


 Discrete Transfer Function
 Open-loop response
 Proportional control
 Proportional-derivative control
Fungsi transfer loop terbuka dari tanaman untuk percobaan bola dan balok diberikan di
bawah ini:

(1)
Kriteria desain untuk masalah ini adalah:
Menempatkan waktu kurang dari 3 detik
Overshoot kurang dari 5%
Untuk melihat derivasi persamaan untuk masalah ini, lihat halaman Ball & Beam: System
Modelling.
Kontroler PID digital
Jika Anda merujuk ke salah satu masalah kontrol PID untuk sistem berkelanjutan, fungsi
transfer PID dinyatakan sebagai

(2)
Ketika Anda memperhatikan fungsi transfer di atas ditulis dalam bentuk. Untuk kontrol PID
digital, kami menggunakan fungsi transfer berikut dalam hal.

(3)

Fungsi Transfer Diskrit


Hal pertama yang harus dilakukan di sini adalah mengubah fungsi transfer sistem kontinu di
atas ke fungsi transfer diskret ekuivalen. Untuk melakukan ini, kita akan menggunakan fungsi
MATLAB c2d. Untuk menggunakan c2d, kita perlu menentukan tiga argumen: sistem, waktu
sampling (Ts), dan 'metode'. Anda seharusnya sudah terbiasa dengan cara membuat sistem
dari matriks pembilang dan penyebut. Waktu pengambilan sampel harus lebih kecil dari
detik, di mana frekuensi gelombang loop tertutup. Metode yang akan kita
gunakan adalah hold nol-order ('zoh'). Dengan asumsi bahwa frekuensi bandwidth loop
tertutup adalah sekitar 1 rad / detik, biarkan waktu sampling menjadi 1/50 detik / sampel.
Sekarang kami siap menggunakan c2d. Masukkan perintah berikut ke m-file. Menjalankan
m-file ini di jendela perintah MATLAB memberi Anda matriks berikut.

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.

Tanggapan loop terbuka


Sekarang kita akan mengamati respon bola ke input langkah 0,25 m. Untuk melakukan ini,
masukkan perintah berikut ke dalam m-file baru dan jalankan di jendela perintah. Anda
harus melihat tanggapan berikut.

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)

Dari plot ini, jelas bahwa sistem loop terbuka tidak stabil menyebabkan bola menggulung
ujung balok.
Kontrol proporsional

Sekarang kita akan menambahkan kontrol proporsional ( ) ke sistem dan mendapatkan


respons sistem loop tertutup. Untuk sekarang, beri nilai 100 dan lihat apa yang terjadi
pada respons. Masukkan perintah berikut ke dalam m-file baru dan jalankan di jendela
perintah.

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)

Seperti yang Anda lihat, penambahan kontrol proporsional tidak membuat sistem menjadi
stabil. Anda dapat mencoba meningkatkan keuntungan proporsional ( ) dan memastikan
bahwa sistem tetap tidak stabil.
Kontrol turunan proporsional
Sekarang kita akan menambahkan istilah turunan ke controller. Pertahankan gain
proporsional ( ) sama dengan 100, dan biarkan gain turunan ( ) sama dengan 10. Salin
kode berikut ke file m baru dan jalankan untuk melihat respons sistem.

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.
Sekarang sistemnya stabil, tetapi waktu naiknya terlalu lama. Dari halaman PID Tutorial,
kita melihat bahwa peningkatan perolehan proporsional ( ) akan menurunkan waktu naik.
Mari tingkatkan keuntungan proporsional ( ) menjadi 1000 dan lihat apa yang terjadi.
Ubah file-m di atas dari 100 ke 1000 dan jalankan kembali di jendela perintah. Anda
harus melihat respons langkah berikut.

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)
Seperti yang Anda lihat, semua persyaratan desain dipenuhi. Untuk masalah khusus ini, tidak
diperlukan implementasi kontrol integral. Tetapi ingat ada lebih dari satu solusi untuk
masalah kontrol. Untuk latihan, Anda dapat mencoba kombinasi P, I, dan D yang berbeda
untuk mendapatkan respons yang memuaskan.
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