0% found this document useful (0 votes)
59 views49 pages

Inverted Pendulum Dynamics and Control

The document discusses the control of an inverted pendulum system, focusing on output feedback versus state-space approaches for tracking. It includes free body diagrams, variable relations, and equations of motion, along with control strategies to stabilize the pendulum by manipulating force inputs. Additionally, simulation results are provided to illustrate the effectiveness of different control methods in achieving desired states.

Uploaded by

fbhke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views49 pages

Inverted Pendulum Dynamics and Control

The document discusses the control of an inverted pendulum system, focusing on output feedback versus state-space approaches for tracking. It includes free body diagrams, variable relations, and equations of motion, along with control strategies to stabilize the pendulum by manipulating force inputs. Additionally, simulation results are provided to illustrate the effectiveness of different control methods in achieving desired states.

Uploaded by

fbhke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Inverted Pendulum System

Fall 2014

Output Feedback vs. State


Space Approach for Tracking

2014 Fall Inverted Pendulum Tracking


Inverted Pendulum System

x
θ

L/2

L
cos θ
L / 2 mg 2

F M

Fig 1. Inverted Pendulum System


Free Body Diagram : Rod & Cart

θ
About bar having mass ' m '

∑ F= x R=
x m 
xm  (1)

(a)
mg
L
2
cos θ ∑F y = Ry − mg = mym  (2)
Rx L L
Ry ∑ M =R x
2
cos θ + Ry sin θ = Iθ
2
 (3)

Ry
Rx

F M About cart having mass ' M '


(b)

∑F x =F − Rx =M 
x  (4)

Fig 2.
(a) free-body diagram of rod
(b) free-body diagram of cart
Variable Relation

L
xm= x − sin θ
2
y L
θ ym = cos θ
2
L
sin θ
2

xm L
xm= x − θ cos θ
L
cos θ
2
2 L
y m = − θ sin θ
x 2

x
L L
Fig 3. Relation between two center of gravities
 x + θ 2 sin θ − θ cos θ

xm =
2 2
L L
 − θ 2 cos θ − θsin θ
ym =
2 2
Equations & Desired State

From above relations, equations (1) ~ (4) can be rewritten as follow

 L L 
(1) Rx = x + θ 2 sin θ − θ cos θ 
m  
 2 2 
Initial condition
 L L 
(2) Ry = mg + m  − θ 2 cos θ − θsin θ  θ ( 0 ) = θ0
 2 2 
2 x ( 0) = 0
L L L
(3) Iθ = m 
x cos θ − m   θ + mg sin θ  (5)
2 2 2

(4) ( M + m ) x + m
2
(
L 2
)
θ sin θ − θ cos θ =
F  (6)
Equations & Desired State

From equation (5)

 
1  L   
2
L 

=
x   I + m    θ − mg sin θ 
L
m cos θ    2   2 
2
put this into (6) and arrange

1  2 L 
θ −m ( L / 2 ) sin (θ ) cos (θ ) θ 2 + ( M + m)mg sin (θ ) + m ( L / 2 ) cos (θ ) F 
2

(
( M + m) I + m ( L / 2 )
2
) 
− m 2 ( L / 2 ) cos 2 (θ ) 
2
2 

and from this, 


x also can be


1  m 2 ( L / 2 )2 sin (θ ) cos (θ ) g − m ( I + m( L / 2) 2 ) ( L / 2) sin(θ )θ 2 + ( I + m( L / 2) 2 ) F 
( )
x
( M + m) I + m ( L / 2 ) − m 2 ( L / 2 ) cos 2 (θ )  
2 2
1. Nonlinear System Control

Nonlinear System + Angle(θ ) and Angle Rate(θ ) Controller

x = θ θ x
T
x 

0 
ydes =  
0  I. 2nd Oscillation Controller θ 
= =  
II. P Controller Nonlinear y Cx
 x
III. PD Controller u System x

θ θ Not Fullstate Feedback

Fig 4. Block diagram for nonlinear system control


θ Control : by Force control

Desired state is that θ goes to zero at t → ∞


lim θ ( t ) = 0
(We do not care about x ( t ) ) t →∞

1  2  2 + ( M + m)mg L sin (θ ) + m ( L / 2 ) cos (θ ) F 


θ − ( ) (θ ) (θ ) θ
2

( )  m L / 2 sin cos 
( M + m) I + m ( L / 2 ) − m 2 ( L / 2 ) cos 2 (θ ) 
2 2
2

From above equation, we want to make θ → 0 by controlling appropriate F (t )

F is a control input u ( t ) , F (t ) = u ( t )

Three ways of control using force are introduced

I Make above equation about θlike θ =


−2ζωnθ − ωn2θ

II u ( t ) = F = − Kθ ( t )

III u (t ) =− Kθ ( t ) − Cθ
F=
θ Control : by Force control

1  2  2 + ( M + m)mg L sin (θ ) + m ( L / 2 ) cos (θ ) F 


θ − ( ) (θ ) (θ ) θ
2

( )  m L / 2 sin cos 
( M + m) I + m ( L / 2 ) − m 2 ( L / 2 ) cos 2 (θ ) 
2 2
2

( M + m)  L 
2 ( M + m) L
=
L
 I + m    − m cos θ and B = sin θ
Let A
L  2  
L
cos θ
2
m cos θ 
2 m
2 2

Then above equation can be expressed as follows


1 L B 1
θ =− m θ 2 sin θ + ⋅ mg + F
A 2 A A
If θ satisfies the following equation,

θ =
−2ζωnθ − ωn2θ

L
∴ u ( t ) =F =− 2 A ⋅ ζωn ⋅ θ − A ⋅ ωn2 ⋅ θ − B ⋅ mg + m sin θ ⋅ θ 2
2
With appropriate values of ζ and ωn , θ can be zero at t → ∞
θ Control : by Force control

1 L B 1
From the equation θ =− m θ 2 sin θ + ⋅ mg + F
A 2 A A
We want to control by

II u (t ) =− Kθ ( t ) ( K > 0 )
F=

1 L B K
θ =− m θ 2 sin θ + ⋅ mg − θ
A 2 A A

In this case, θ goes to zero when t → ∞ ?

III u ( t ) =− Kθ ( t ) − Cθ ( K > 0, C > 0 )


F=

θ =
1 L
− m θ 2 sin θ +
A 2
B
A
⋅ mg − (
1
A
Kθ + Cθ )
In this case, θ goes to zero when t → ∞ ?
Simulation : Force Control

Simulation
θ ( 0 ) = 0.1rad x ( 0) = 0 m ζ = 0.5 K = 30
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 ωn = 0.7 rad / s C = 15

I Simulation Results Plots ㅡ : ζ , ωn control --- : P control --- : PD control

0 1

-20 0

dx/dt [m]
x [m]

-40 -1

-60 -2

-80
0 10 20 30 40 50 -3
0 10 20 30 40 50
time [sec]
time [sec]
0.1 0.4

0.05 dθ/dt [rad] 0.2


θ [rad]

0 0

-0.05
-0.2
-0.1
0 10 20 30 40 50 -0.4
0 10 20 30 40 50
time [sec]
time [sec]
Fig 5. Simulation results of nonlinear system for three kinds of control
Simulation : Animation

Simulation
θ ( 0 ) = 0.1rad x ( 0) = 0 m ζ = 0.5 K = 30
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 ωn = 0.7 rad / s C = 15

II Force Plot and Simulation Results Animation


4
2nd Oscilation
2 P control
Force [N]

PD control
0 ㅡ : ζ , ωn control
-2
--- : P control
--- : PD control
-4
0 10 20 30 40 50
time [sec]

(a) 2nd Oscillation Control (b) P Control (c) PD Control


Fig 6. Simulation results Animation
After run simulation model

Open 'RUN _ file.m ' and execute


⇒ Four graphs (θ vs t , θ vs t , x vs t , x vs t )
&
Animation

Fig 7. Screenshot after run simulation


Nonlinear System

Y Equation of motions
x 2
L L L
θ Iθ = m 
x cos θ − m   θ + mg sin θ
2 2 2

( )
L/2 L
( M + m ) x + m θ2 sin θ − θ cos θ =F
L
cos θ
2
L / 2 mg 2

F M Control input : u ( t ) = F
X
θ ( 0 ) θ 0=
Initial Condition := , θ ( 0 ) 0,=
x ( 0 ) 0,=
x ( 0 ) 0

From combining above two equations


 x2  0
B 1 L 1    
θ = mg − m θ 2 sin θ + F  x1 
 B 1 L 2
mg − m θ sin θ  1
A A 2 A  x 
 A A 2   A
=x = 2
  +  0  F (t )
 x3  x4
 1 L B 1       

x= C  − m sin θθ 2 + mg + F  − g tan θ x
 4  C − m sin θθ 2 + mg − g tan θ   C 
  1 L B 
 A 2 A A    A 2    A 
 A 

( M + m)
 L 
2
L
, B=
( M + m)
L
sin θ
I + m ( L / 2)
2

Where =
A  I + m    − m cos θ C=
L  2   L m ( L / 2 ) cos θ
m cos θ  2 m cos θ 2
2 2
Angle and Angle Rate Controller

Control Strategy
− How to control u (t ) =
F (t ) ?
− Desired state when t → ∞ is θ → 0

i ) Applying a assumption that θ satisfies 2nd oscillation, bellow equation comes


B 1 L 2 1
θ =mg − −2ζωnθ − ωn2θ
m θ sin θ + F =
A A 2 A

In this case, control input becomes

u (t ) =F (t ) = ( ) L
A −2ζωnθ − ωn2θ − Bmg + m sin θ ⋅ θ 2
2

ii ) P control
u ( t ) = F ( t ) = − Kθ

iii ) PD control
u (t ) =
F (t ) =
− Kθ − Cθ
2. Linear System Control

Full State Feedback Controller


Linear System +
I. 0  Reference Tracking Controller
ydes =  
0 
II.  0 
ydes =  
 xdes  I. Full State Feedback Controller
u = -Kx θ 
= =  
Linear y Cx
 x
II. Reference Tracking Controller u System x
u = -Kx+r

x = θ θ x
T
x 

Fig 8. Block diagram for linear system control


Linear Model

By small angle assumption, sin (θ ) ≈ θ , cos (θ ) ≈ 1, θ 2 ≈ 0


 x2  0
 x1   B 1 L   
 x   mg − m θ 2 sin θ  1
 A A 2   A
then, =x = 2
  +  0  F (t ) becomes as follows
 x3  x4
     
 x4    1 L  B   C 
C  − A m 2 sin θθ + A mg  − g tan θ   A 
2

 

 0 1 0 0  0 
   
 mg ( L / 2 )  m ( L / 2) / ( M + m)

 x1  0 0 0  
 x   I + m ( L / 2 ) − m ( L / 2 ) / ( M + m)
2 2 2
  I + m ( L / 2 ) − m ( L / 2 ) / ( M + m) 
2 2 2
 
=x = 2 
  x+  F (t )
 x3  0 0 0 1  0 
 
  

 4 
x 

I + (m ( L / 2 )
2
)  
− 1 g 0 0 0 

 I + m ( L / 2 )
2
(
/ ( M )
+ m ) 

 
 I + m ( L / 2 ) − m ( L / 2 ) / ( M + m) 

( ) ( )
2 2
2
 
 I + m L / 2
2
− m 2
L / 2
2
/ ( M + m ) 
  

x1 x2 x3 x4 ]T θ θ x x 
T
=
where x [ =

( M + m )  I + m  L 2  − m L B=
( M + m) L θ I + m ( L / 2)
2
Where A=     , C=
m
L
  2   2 m
L 2 m ( L / 2)
2 2
Linear Model : Feedback Control

When a system is defined as x= Ax + Bu , we want to control x to make x(∞)= 0

Let u = − Kx
Then, x = Ax − Bu = ( A − BK ) x ⇒ x = e( A− BK )t

( x : n ×1 matrix, A : n × n matrix , B : n ×1 matrix, K :1× n matrix )

Appropriate gain K makes the system stable

θ θ x x  , K = [ k1 k2 k3 k4 ]
=where x [ =x1 x2 x3 x4 ]T
   
T

If eigenvalues ( poles ) of matrix A − BK have negative − real part ,


then x goes to zero at t → ∞

The control methods , which were introduced at the 'Nonlinear system' part,

! were failed to control state 'x' to be zero at t → ∞


On the otherhand, linear feedback control make the system to be stable about all state

Command 'acker ' can be used to get desired gain K


Simulation : Linear Feedback Control

θ ( 0 ) = 0.1rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Simulation Results Plots

0.15 0.05

0.1 0

dθ/dt [rad/s]
θ [rad]

-0.05
0.05
-0.1
0
-0.15
-0.05 -0.2
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
1 0.4
0.5 0.2

0
dx/dt [m/s] 0
x [m]

-0.5 -0.2
-1 -0.4
-1.5 -0.6
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 9. Simulation results of linear system for tracking control
Simulation : Linear Feedback Control - Animation

θ ( 0 ) = 0.1rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Force Plot and Simulation Results Animation

6
Force [N]

-2
0 20 40 60 80 100
time [sec]

Fig 10. Feedback Control Input and Simulation results Animation


Linear Model : Tracking Problem

We discussed linear feedback control.


This make it possible that all the states go to zero at t → ∞.
But what if we want to make the states converge to specific values ?

Q ) How to make the states converge to nonzero values

Reference Input Tracking

Introduce reference input u=


− Kx + r

Let xss and uss as state x and input u repectively at steady state
Then, u =uss − K ( x − xss )

x Ax + Bu
=
x1 x2 x3 x4 ]T θ θ x x  ,
T
if the system is like =where x [ =
=y Cx + Du
=0 Ax ss + Buss
At the steady state, this system becomes  (*) ( At steady state, x = 0 )
=
yss Cx ss + Duss
Linear Model : Tracking Problem

We want to make yss = rss for any value of rss


x ss = N x rss
To do this, asssume that and put these equations to (*)
uss = N u rss

= 0 AN x rss + BN u rss
Then
= rss CN x rss + DN u rss
 A B   Nx  0
It can be also written as a matrix form like C D   N  =  1 
  u  

A B
Assume that the inverse of   is exists, then this equation can be solved for N x and N u
C D 
−1
 Nx   A B  0
 N  = C D   1 
 u    
From above relation
Nu r − K ( x − N x r ) =
u= − Kx + ( N u + K N x ) r
where =
N Nu + K N x
=
− Kx + Nr
Simulation : Reference Tracking Control

Simulation
θ ( 0 ) = 0.1rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Simulation Results Plots

0.15 0.1

0.1 0

dθ/dt [rad/s]
θ [rad]

0.05 -0.1

0 -0.2

-0.05 -0.3
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]

8 1.5

6 1
dx/dt [m/s]
4 0.5
x [m]

2 0

0 -0.5

-2 -1
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]

Fig 11. Simulation results of linear system for tracking control


Simulation : Reference Tracking Control - Animation

Simulation
θ ( 0 ) = 0.1rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Force Plot and Simulation Results Animation

5
Force [N]

-5

-10
0 20 40 60 80 100
time [sec]
Fig 12. Reference Tracking Input and Simulation results Animation
3. Nonlinear System with Linear Controller

Full State Feedback Controller


Nonlinear System +
I. 0  Reference Tracking Controller
ydes =  
0 
II.  0 
ydes =  
 xdes  I. Full State Feedback Controller
u = -Kx θ 
= =  
Nonlinear y Cx
 x
II. Reference Tracking Controller u System x
u = -Kx+r

x = θ θ x
T
x 

Fig 8. Block diagram for nonlinear system with linear controller


Nonlinear System

Y Equation of motions
x 2
L L L
θ Iθ = m 
x cos θ − m   θ + mg sin θ
2 2 2

( )
L/2 L
( M + m ) x + m θ2 sin θ − θ cos θ =F
L
cos θ
2
L / 2 mg 2

F M Control input : u ( t ) = F
X
θ ( 0 ) θ 0=
Initial Condition := , θ ( 0 ) 0,=
x ( 0 ) 0,=
x ( 0 ) 0

From combining above two equations


 x2  0
B 1 L 1    
θ = mg − m θ 2 sin θ + F  x1 
 B 1 L 2
mg − m θ sin θ  1
A A 2 A  x 
 A A 2   A
=x = 2
  +  0  F (t )
 x3  x4
 1 L B 1       

x= C  − m sin θθ 2 + mg + F  − g tan θ x
 4  C − m sin θθ 2 + mg − g tan θ   C 
  1 L B 
 A 2 A A    A 2    A 
 A 

( M + m)
 L 
2
L
, B=
( M + m)
L
sin θ
I + m ( L / 2)
2

Where =
A  I + m    − m cos θ C=
L  2   L m ( L / 2 ) cos θ
m cos θ  2 m cos θ 2
2 2
Linear Feedback Control

When a system is defined as x= Ax + Bu , we want to control x to make x(∞)= 0

Let u = − Kx
Then, x = Ax − Bu = ( A − BK ) x ⇒ x = e( A− BK )t

( x : n ×1 matrix, A : n × n matrix , B : n ×1 matrix, K :1× n matrix )

Appropriate gain K makes the system stable

θ θ x x  , K = [ k1 k2 k3 k4 ]
=where x [ =x1 x2 x3 x4 ]T
   
T

If eigenvalues ( poles ) of matrix A − BK have negative − real part ,


then x goes to zero at t → ∞

The control methods , which were introduced at the 'Nonlinear system' part,

! were failed to control state 'x' to be zero at t → ∞


On the otherhand, linear feedback control make the system to be stable about all state

Command 'acker ' can be used to get desired gain K


Nonlinear System vs Linear System with Linear Feedback Control

θ ( 0 ) = 0.1rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Simulation Results Plots

0.15 0.05
Linear System
0
0.1

dθ/dt [rad/s]
Nonlinear System
θ [rad]

-0.05
0.05
-0.1
0
-0.15

-0.05 -0.2
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
1 0.05

0.5 0

0 dθ/dt [rad/s] -0.05


x [m]

-0.5 -0.1

-1 -0.15

-1.5 -0.2
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 9. Simulation results for linear Feedback control
Nonlinear System vs Linear System with Linear Feedback Control

θ ( 0 ) = 0.1rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Force Plot and Simulation Results Animation

8
Linear System
6
Nonlinear System
Force [N]

-2
0 20 40 60 80 100
time [sec]
8
Fig 10. Feedback Control Input (Nonlinear system)
Linear System and Simulation results Animation
6
Nonlinear System
Force [N]

-2
0 0.5 1 1.5 2 2.5 3
time [sec]
Nonlinear System vs Linear System with Linear Feedback Control

θ ( 0 ) = 1.57 rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Simulation Results Plots

10 40
Linear System
5 20

dθ/dt [rad/s]
Nonlinear System
θ [rad]

0 0

-5 -20

-10 -40
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
100 100

50
0 dx/dt [m/s] 0
x [m]

-50
-100
-100

-200 -150
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 11. Simulation results for linear feedback control
Nonlinear System vs Linear System with Linear Feedback Control

θ ( 0 ) = 1.57 rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Force Plot and Simulation Results Animation

2000
Linear System
1000 Nonlinear System
Force [N]

-1000

-2000
0 20 40 60 80 100
time [sec]
2000
Linear System Fig 12. Feedback Control Input (Nonlinear system)
1000 Nonlinear System and Simulation results Animation
Force [N]

-1000

-2000
0 0.5 1 1.5 2 2.5 3
time [sec]
Nonlinear System with Linear Feedback Control

θ ( 0 ) = 2.44 rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Simulation Results Plots

15 40

10 20

dθ/dt [rad/s]
θ [rad]

5 0

0 -20

-5 Linear System -40


Nonlinear System
-10 -60
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
2000 300

1500 200

1000 dx/dt [m/s] 100


x [m]

500 0

0 -100

-500 -200
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 13. Simulation results for linear feedback control
Nonlinear System with Linear Feedback Control - Animation

θ ( 0 ) = 2.44 rad x ( 0) = 0 m
Simulation
=K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2

Force Plot and Simulation Results Animation

2000
Linear System
1000 Nonlinear System
Force [N]

-1000

-2000
0 20 40 60 80 100
time [sec]

Fig 14. Feedback Control Input (Nonlinear system) and Simulation results Animation
Tracking Problem

We discussed linear feedback control.


This make it possible that all the states go to zero at t → ∞.
But what if we want to make the states converge to specific values ?

Q ) How to make the states converge to nonzero values

Reference Input Tracking

Introduce reference input u=


− Kx + r

Let xss and uss as state x and input u repectively at steady state
Then, u =uss − K ( x − xss )

x Ax + Bu
=
x1 x2 x3 x4 ]T θ θ x x  ,
T
if the system is like =where x [ =
=y Cx + Du
=0 Ax ss + Buss
At the steady state, this system becomes  (*) ( At steady state, x = 0 )
=
yss Cx ss + Duss
Tracking Problem

We want to make yss = rss for any value of rss


x ss = N x rss
To do this, asssume that and put these equations to (*)
uss = N u rss

= 0 AN x rss + BN u rss
Then
= rss CN x rss + DN u rss
 A B   Nx  0
It can be also written as a matrix form like C D   N  =  1 
  u  

A B
Assume that the inverse of   is exists, then this equation can be solved for N x and N u
C D 
−1
 Nx   A B  0
 N  = C D   1 
 u    
From above relation
Nu r − K ( x − N x r ) =
u= − Kx + ( N u + K N x ) r
where =
N Nu + K N x
=
− Kx + Nr
Nonlinear System vs Linear System with Reference Tracking Control

Simulation
θ ( 0 ) = 0.1rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Simulation Results Plots

0.15 0.1
Linear System
0.1 0

dθ/dt [rad/s]
Nonlinear System
θ [rad]

0.05 -0.1

0 -0.2

-0.05 -0.3
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
8 1.5

6 1

4 dx/dt [m/s] 0.5


x [m]

2 0

0 -0.5

-2 -1
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 15. Simulation results for tracking control
Nonlinear System vs Linear System with Reference Tracking Control

Simulation
θ ( 0 ) = 0.1rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]
Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Force Plot and Simulation Results Animation

5
Linear System
Nonlinear System
Force [N]

-5

-10
0 20 40 60 80 100
time [sec]
5

Fig 16. Reference Tracking Input (Nonlinear system)


Force [N]

0 and Simulation results Animation

-5
Linear System
Nonlinear System
-10
0 0.5 1 1.5 2 2.5 3
time [sec]
Nonlinear System vs Linear System with Reference Tracking Control

Simulation θ ( 0 ) = 1.57 rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]


Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Simulation Results Plots

10 40
Linear System
5 20

dθ/dt [rad/s]
Nonlinear System
θ [rad]

0 0

-5 -20

-10 -40
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
100 100

50
0 dx/dt [m/s] 0
x [m]

-50
-100
-100

-200 -150
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 17. Simulation results for tracking control
Nonlinear System vs Linear System with Reference Tracking Control

Simulation θ ( 0 ) = 1.57 rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]


Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Force Plot and Simulation Results Animation

2000
Linear System
1000 Nonlinear System
Force [N]

-1000

-2000
0 20 40 60 80 100
time [sec]
2000
Linear System
Fig 18. Reference Tracking Input (Nonlinear system)
Nonlinear System
1000 and Simulation results Animation
Force [N]

-1000

-2000
0 0.5 1 1.5 2 2.5 3
time [sec]
Nonlinear System vs Linear System with Reference Tracking Control

Simulation θ ( 0 ) = 3.05 rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]


Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Simulation Results Plots

10 40

5 20

dθ/dt [rad/s]
θ [rad]

0 0

-5 Linear System -20


Nonlinear System
-10 -40
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
200 200

100
0 dx/dt [m/s]
x [m]

0
-200
-100

-400 -200
0 20 40 60 80 100 0 20 40 60 80 100
time [sec] time [sec]
Fig 19. Simulation results for tracking control
Nonlinear System vs Linear System with Reference Tracking Control

Simulation θ ( 0 ) = 3.05 rad x ( 0) = 0 m =K [70.5, 22.7, − 0.3, − 0.6483]


Condition θ ( 0 ) = 0 rad / s x ( 0 ) = 0 m / s 2 xss= rss= 5

Force Plot and Simulation Results Animation

2000
Linear System
1000 Nonlinear System
Force [N]

-1000

-2000
0 20 40 60 80 100
time [sec]

Fig 20. Reference Tracking Input (Nonlinear system)


and Simulation results Animation
Appendix. A
How to use

Open ‘RUN_file.m’

1. Simulation(시간, 초기조건 등) 환경 설정
2. Parameter(질량, 길이 등) 값 설정
3. Gain 값 설정
4. 실행
5. ‘Simulaton_file.m’이 실행된다.

‘Simulation_file.m’

5. Nonlinear Equation을 실시간으로 계산(By function ‘ODE4 ’)


6. State의 실시간 값들이 얻어짐(x,theta…)
7. State의 시간에 대한 그래프 출력
How to use – RUN_file.m

Open ‘RUN_file.m’ Simulation Setting

Global 변수 선언

시뮬레이션에 필요한 함수인 ode45에 쓰일 변수를 선언.


부록B에 ode45에 대해서 설명해두었다.

Simulation time 설정
t0 : 초기 시간(=0)
tf : simulation 종료 시간
del_t : sampling time 설정

Initial Condition 설정
x0 : Cart의 초기 위치
d_x0 : Cart의 초기 속도
theta_0 : Rod의 초기 각도
d_theta_0 : Rod의 초기 각속도
Desired X 좌표 설정
rss : 목표 도달 X 좌표

Dynamic Parameter 설정
m : Rod의 질량
M : Cart의 질량
L : Rod의 길이
I : Rod의 moment of inertia (자동으로 계산)
g : 중력가속도 (고정값)

Control Gain 설정
K : P gain 값 설정 (양수)
C : D gain 값 설정 (양수, 0일 시에는 P Control)
Zeta : 댐핑 값 설정
wn : 공진주파수 설정
How to use – Simulation_file.m

▶ ‘RUN_file’ 을 실행시키면 자동으로 ‘Simulation_file.m ’이 실행된다.

ode45
Ode45라는 함수를 통해 nonlinear equation을 실시
간으로 풀어낼 수 있다.(부록B에 ode45에 대해 설명)

State의 실시간 값들이 얻어짐


앞서 설정한 simulation time동안의 매 순간의 data
값(카트 위치, 바의 각도 등)들이 ode45 함수의 결과
로 얻어진다.

결과의 시간에 대한 그래프 출력


이렇게 구해진 실시간 데이터 결과들을 시간에 대한
그래프로 출력한다.
Appendix. B
부록 : ode45

▶ ODE45 ?

MATALB에 내장돼있는 함수 & 미분방정식을 실시간으로 풀어주는 함수


이 때 exact solution을 구하는 것이 아닌, 수치해석 방법으로 실시간 해를 구한다.
Runge-Kutta method를 사용하는 numerical solver
내가 풀고자 하는 미분방정식을 풀어주는 함수를 만든다.

▶ Why ode45?

선형 뿐 아니라 비선형 미분방정식도 풀 수 있으며

사용방법 및 수식작성이 직관적이다.

▶ How to use?

함수 이름 작성, 변수 선언
(이 때 함수 이름은 저장 시에도 동일한 이름으로 저장해야 한다.)

x = f ( x ) 꼴 그대로 수식으로 옮긴다.


부록 : ode45

x
m
Example
mx + cx += ( 0 ) x0 , x=
kx 0, x= ( 0 ) x0 k c

1. 함수의 이름을 정하고 변수를 차례로 적어준다.(이때는 시간과 state x)


미분 term을 나타내는 변수, state를 한번 미분한 것을 의미한다. 즉, 𝒙𝒙̇ 를 의미

함수이름(저장 시 동일한 이름으로 저장해야한다.)

2. 미분방정식에 쓰이는 global 변수(state 제외)를 선언한다.

이 함수에서 이 변수들이 쓰이기 때문에 이 함수가 돌아가기 전,


이 변수들이 workspace 상에 선언되어 있어야 한다.

3. x = f ( x ) 꼴로 식을 만들어주고 code에 그대로 옮겨 적는다.

x = x dx가 (2x1)행렬임을
 x   x1 
1 2
먼저 선언해야 한다.
=
x =  x  , c k
   2  x2 =

x − x2 − x1
m m
부록 : ode45

▶ 문제의 미분방정식을 푸는 ode45를 MATLAB에 작성하면 다음과 같다.

Example
mx + cx += ( 0 ) x0 , x=
kx 0, x= ( 0 ) x0

▶ 그럼 이 때 다음과 같이, 앞에서 만든 ode45를 이용한 m-file을 작성하여 실행하면 다음과 같다.

10
Displacement
Velocity
5

X
-5

-10
0 2 4 6 8 10
t

사용할 함수 이름 t의 초기, 말기 값 State의 초기 값(x1, x2 차례로)

You might also like