Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

MATLAB

Modern Control System Lab. Changwon National University

- Cart
C t type
t
Pendulum
P d l

Modern Control System Lab. Changwon National University

ml
x cx F
M m

ml

mgl

ml

x M m
ml cx F

ml
mgl f
2
ml
I

x

1

( M m)(mll 2 I ) m 2l 2

ml 2 I

mll

ml cx F

M m mgll f

Modern Control System Lab. Changwon National University

x
ml 2 I

1
( M m)(ml 2 I ) m 2l 2

ml
x

1
( M m)(mll 2 I ) m 2l 2

x

1

( M m)(ml 2 I ) m 2l 2

ml cx F

M m mgl f

(ml 2 I )(cx F ) ml (mgl f )

ml
l
(

cx

F
)

(
M

m
)(

mgl
l

c(ml 2 I ) x m 2l 2 g mlf (ml 2 I ) F

mlF

cmlx
mgl
(
M
m
)

(
M
m
)
f

Modern Control System Lab. Changwon National University

x

1


2
2 2
( M m)(ml I ) m l

c(ml 2 I ) x m 2l 2 g mlf (ml 2 I ) F

mlF

cmlx
mgl
(
M
m
)
(
M
m
)
f

M 5, m 1, l 1, g 9.8, c 0.01, f 0.01, I 0.02

x

1 0.0102 x 9.8 0.01 1.02 F

6.012

F
0.01
58.8
0.06

Modern Control System Lab. Changwon National University

- Cart
C t type
t
Pendulum
P d l

x

1 0.0102 x 9.8 0.01 1.02 F

6.012

0.01
x
58.8
0.06
F

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

Modern Control System Lab. Changwon National University

f(u)
( )

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

Modern Control System Lab. Changwon National University

f(u)
( )

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

Modern Control System Lab. Changwon National University

f(u)
( )

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

Modern Control System Lab. Changwon National University

f(u)
( )

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

Modern Control System Lab. Changwon National University

f(u)
( )

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

MATLAB

Modern Control System Lab. Changwon National University

( r , 0)
(r , 0)
l = 5;
r = 0.1;
x_plane
l
= [[-10
10 -10
10 10 10];
10]
y_plane = [-0.6 -0.5 -0.5 -0.6];
x_cart = [-1 -1 1 1];
y_cart = [-0.5 0.5 0.5 -0.5];
x_pole
l = [[-r -r r r];
]
y_pole = [-l 0 0 -l];

(r , l )
( r , l )

plane = fill(x_plane, y_plane, 'k');


grid
id on
hold on
cart = fill(x_cart, y_cart, 'g','EraseMode','normal');
pole = fill(x_pole, y_pole, 'b','EraseMode','normal');
h ld off
hold
ff
axis([-10 10 -8 4]);

Modern Control System Lab. Changwon National University

l cos , l sin
l cos , l sin

( r , 0)
(r , 0)

tan 1

r
l

3
3
1 r
1 r
l cos 2 tan l , l sin 2 tan l

(r , l )
( r , l )

3
3
1 r
1 r
l
cos

tan
,
l
sin

tan

l
l
2
2

Modern Control System Lab. Changwon National University

l = 5;
r = 0.1;

x_plane = [-10 -10 10 10];


y_plane = [-0.6 -0.5 -0.5 -0.6];
x_cart = [-1 -1 1 1];
y_cart = [-0.5 0.5 0.5 -0.5];
x pole = [-r -r r r];
x_pole
y_pole = [-l 0 0 -l];

plane = fill(x_plane, y_plane, 'k');


grid on
h ld on
hold
cart = fill(x_cart, y_cart, 'g','EraseMode','normal');
pole = fill(x_pole, y_pole, 'b','EraseMode','normal');
hold off
axis([-10
([
10 -8 4]);
])
t = 0:0.01:20*pi/180;

-2

-4

-6

-8
-10

-8

-6

-4

-2

for t = 0:0.01:20*pi/180
updatedX cart = x_cart
updatedX_cart
x cart + t;
temp_x = [l*cos(3/2*pi+t-atan(r/l)) r*cos(pi+t) r*cos(t) l*cos(3/2*pi+t+atan(r/l))];
temp_y = [l*sin(3/2*pi+t-atan(r/l)) r*sin(pi+t) r*sin(t) l*sin(3/2*pi+t+atan(r/l))];
updatedX_pole = t + temp_x;
updatedY_pole = temp_y;
set(cart,
t( t 'Xdata',
'Xd t ' updatedX_cart);
d t dX
t)
set(pole, 'Xdata', updatedX_pole,'Ydata', updatedY_pole);
drawnow;
for i=1:5000000
temp = i;
end
end

Modern Control System Lab. Changwon National University

10

MATLAB

Modern Control System Lab. Changwon National University

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KGain

Scope1

cart

Click Here

pole
p

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f( )
f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KK
Gain

Scope1

cart

Click Here

pole

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

l = 5;
r = 0.1;
x plane = [[-10
x_plane
10 -10
10 10 10];
y_plane = [-0.6 -0.5 -0.5 -0.6];
x_cart = [-1 -1 1 1];
y cartt = [[-0.5
y_ca
0.5 0.5 0.5 -0.5];
0.5];
x_pole = [-r -r r r];
y_pole = [-l 0 0 -l];
plane = fill(x_plane,
p
( p
yy_plane,
p
'k');
)
grid on
hold on
cart = fill(x_cart, y_cart, 'g','EraseMode','normal');
pole = fill(x_pole, y_pole, 'b','EraseMode','normal');
hold off
axis([-10 10 -8 4]);

Modern Control System Lab. Changwon National University

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f( )
f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KK
Gain

Scope1

cart

Click Here

pole

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f( )
f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

0
Constant

Scope

-KK
Gain

Scope1

cart

Click Here

pole

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

function y = test1(pos_cart,
test1(pos cart theta,
theta cart,
cart pole)
l = 5;
r = 0.1;
x_cart = [-1 -1 1 1];
updatedX
p
_cart = x_cart + p
pos_cart;;
temp_x = [l*cos(3/2*pi+theta-atan(r/l)) r*cos(pi+theta) r*cos(theta)
l*cos(3/2*pi+theta+atan(r/l))];
temp_y
p y = [l*sin(3/2*pi+theta-atan(r/l))
p
r*sin(pi+theta)
p
r*sin(theta)
l*sin(3/2*pi+theta+atan(r/l))];
updatedX_pole = pos_cart + temp_x;
updatedY_pole = temp_y;
set(cart, 'Xdata', updatedX_cart);
set(pole, 'Xdata', updatedX_pole,'Ydata', updatedY_pole);
drawnow;
y = 1;

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

MATLAB
LQR

Modern Control System Lab. Changwon National University

- LQR

x
0 0102 x 99.8
8 00.01
01 11.02
02 F

1 0.0102

6.012

x
F
0.01
58.8
0.06

1
0
0 x 0
x 0

0 0.0017 1.6301 0.0017 x 0.1697
x


F
0
0
0
1 0

0.0017

9.7804

0.01

0.1663

Modern Control System Lab. Changwon National University

1
0
0
0
0
0 0.0017 1.6301 0.0017
0.1697
, B

A
0
0
0
0
1

0
0.0017
9.7804
0.01
0.1663

1
0
Q
0

0 0 0
0 0 0
, R 0.01
0 5 0

0 0 0

K = lqr(A,B,Q,R)

Modern Control System Lab. Changwon National University

>>
>>
>>
>>
>>

A = [[0 1 0 0;; 0 -0.0017 -1.6301 -0.0017;; 0 0 0 1;; 0 -0.0017 -9.7804 -0.01];


];
B = [0 0.1697 0 0.1663]';
Q = [1 0 0 0; 0 0 0 0; 0 0 5 0; 0 0 0 0];
R = 0.01;
K=lqr(A,B,Q,R)

K=
10.0000

13.0808

12.7367

3.2320

Modern Control System Lab. Changwon National University

Click Here

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

Gain1

Scope
p

-K-

cart

K*u
pole

Gain

Scope1

MATLAB
Function
MATLAB Fcn

T
Terminator
i

Modern Control System Lab. Changwon National University

Click Here

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

Gain1

Scope
p

-K-

cart

K*u
pole

Gain

Scope1

MATLAB
Function
MATLAB Fcn

T
Terminator
i

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

Modern Control System Lab. Changwon National University

Click Here

f( )
f(u)

1
s

1
s

Fcn

Integrator

Integrator1

Scope

Scope2

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

Gain1

-K-

cart

K*u
pole

Gain

Scope1

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

Click Here

f( )
f(u)

1
s

1
s

Fcn

Integrator

Integrator1

Scope

Scope2

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

Gain1

-K-

cart

K*u
pole

Gain

Scope1

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

Click Here

f( )
f(u)

1
s

1
s

Fcn

Integrator

Integrator1

Scope

Scope2

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

Gain1

-K-

cart

K*u
pole

Gain

Scope1

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

Signal 1

Signal Builder

Click Here

f(u)

1
s

1
s

Fcn

Integrator

Integrator1

Scope

Scope2

f(u)

1
s

1
s

Fcn1

Integrator2

Integrator3

Gain1

-K-

cart

K*u
pole
l

Gain

Scope1

MATLAB
Function
MATLAB Fcn

Terminator

Modern Control System Lab. Changwon National University

test/Signal Builder : Group 1


2.5
Signal 1
2
1.5
1
0.5
0
-0.5
-1
1
-1.5
-2
-2.5
25

10
12
Time (sec)

14

16

18

20

Modern Control System Lab. Changwon National University

22

Modern Control System Lab. Changwon National University

You might also like