0% found this document useful (0 votes)
5 views26 pages

Final Project - Control System Design

The document outlines a final project for MECH4321 focusing on the control system design of an inverted pendulum on a cart, detailing the methodology for system modeling, controller design, and simulation settings. The objective is to develop a dynamic model that maintains the pendulum in an upright position through effective control strategies. It includes sections on kinetic and potential energy calculations, Lagrangian formation, and the application of the Euler-Lagrange equation for system dynamics.

Uploaded by

Jonathan Bryan
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)
5 views26 pages

Final Project - Control System Design

The document outlines a final project for MECH4321 focusing on the control system design of an inverted pendulum on a cart, detailing the methodology for system modeling, controller design, and simulation settings. The objective is to develop a dynamic model that maintains the pendulum in an upright position through effective control strategies. It includes sections on kinetic and potential energy calculations, Lagrangian formation, and the application of the Euler-Lagrange equation for system dynamics.

Uploaded by

Jonathan Bryan
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 Control – Final Project

MECH4321 - A (AME 455)

Control System Design - Group 1


Ellohnia Michelle Angella (2022360006)
Jonathan Bryan (2022360005)

Mechanical Engineering
Faculty of Engineering and Technology
Sampoerna University
2025
Table of Contents
Chapter 1: Introduction .............................................................................................................. 3
1.1 Background ................................................................................................................ 3
1.2 Objectives .................................................................................................................. 3
Chapter 2: Methodology ............................................................................................................ 4
2.1 System Modelling ...................................................................................................... 4
Coordinates and Kinematics .............................................................................................. 4
Computation of Kinetic Energy ......................................................................................... 5
Computation of Potential Energy....................................................................................... 6
Lagrangian Formation ........................................................................................................ 6
Linearization ...................................................................................................................... 8
Linearized State-Space..................................................................................................... 10
Laplace Transformation ................................................................................................... 11
Block Diagram Formation ............................................................................................... 11
2.2 Controller Design Method ....................................................................................... 13
Controllability analysis .................................................................................................... 13
Linear Quadratic Regulator (LQR) Derivation ................................................................ 14
Error Tracking .................................................................................................................. 15
2.3 Simulation Settings and Reference Tracking ................................................................. 17
Chapter 3: Results and Discussion ........................................................................................... 19
3.1 Closed-Loop Stability Verification ................................................................................ 19
3.2 Reference-Tracking Performance for Different 𝑥𝑑 ....................................................... 19
Chapter 4: Conclusion.............................................................................................................. 25
References ................................................................................................................................ 26

2
Chapter 1: Introduction
1.1 Background
A control system refers to a mechanism that regulates a measurable variable and keeps
it near a desired value, even when external factors act to disturb or alter that variable [1]. A
controller is an algorithm or mechanism that takes measurements of a system and computes an
action (or input) that forces the system to behave in a desired way [2]. The inverted pendulum
on a cart is a classical benchmark system used in control engineering to study the stabilization
of inherently unstable mechanical dynamics [3]. The system consists of a cart of mass 𝑚𝑐 that
translates horizontally along a track while carrying a slender rod of mass 𝑚𝑝 and length 𝑙,
which rotates freely about a pivot attached to the cart. The generalized coordinates that describe
the system are the cart position 𝑥 and the pendulum angle 𝜃 measured from the upright vertical
position. The control input 𝑢 is a horizontal force applied to the cart, typically generated by a
motor or actuator, which influences both the cart’s linear motion and the pendulum’s angular
motion due to inertial coupling.

This system is well known for its open-loop instability. When the pendulum is upright
at 𝜃 = 0, gravity produces a torque that drives the pendulum away from equilibrium, causing
the configuration to diverge unless continuously corrected. As a result, the upright position
cannot be maintained without active feedback control. The nonlinear coupling between cart
motion and pendulum rotation further complicates the dynamics, as a force applied to move
the cart affects the pendulum angle, and any deviation in 𝜃 produces reactive forces on the cart.
Because of these characteristics, the system requires a controller that can act rapidly and
accurately to counteract disturbances, regulate the coupled motion, and prevent the pendulum
from falling.

1.2 Objectives
The objective of this project is to obtain a tractable dynamic model of the cart–
pendulum plant that enables designing a controller to keep the pendulum upright (𝜃 = 0) for
all 𝑡 ≥ 0 with bounded cart motion and feasible control effort. The system is modeled as a
planar cart of mass M driven by a horizontal force u, carrying a slender rod of mass mmm,
centre-of-mass distance l, and inertia I.

3
Chapter 2: Methodology
2.1 System Modelling

Figure 1. Free-body Diagram of Pendulum and Cart

Coordinates and Kinematics


General coordinates
▪ Cart position 𝑥 along the track
▪ Pendulum angle 𝜃 from the vertical (upright at 𝜃 = 0).
▪ Pendulum’s Centre of Mass (COM) has coordinates and velocities below:
𝑙 𝑙
𝑥𝐺 = 𝑥 + 𝑠𝑖𝑛𝜃, 𝑦𝐺 = 𝑐𝑜𝑠𝜃
2 2

To express the cart–pendulum’s dynamics entirely in terms of generalized coordinates


and their rates, we first compute the kinetic energy and potential energy. The kinetic energy
captures the cart translation, the rod COM translation, and the rod’s rotation (including their
coupling), so mass distribution and geometry are built in. On the other hand, the potential
energy captures gravity’s dependence on configuration. With the right 𝑇(𝑞, 𝑞̇ ) and 𝑉(𝑞), the
system can be modelled without explicitly solving for internal hinge forces. The detailed
derivation is presented below.

4
Computation of Kinetic Energy
The cart's translation, 𝑇𝑃 , and the pendulum's translation and rotation (about its COM),
𝑇𝑐 , are expressed as:
1 1
𝑇𝑃 = 𝑚𝑃 𝑣𝐺2 + 𝐼𝐺 𝜃̇ 2
2 2
1
𝑇𝐶 = 𝑚𝐶 𝑥̇ 2
2
1 1
𝑇 = 𝑇𝑃 + 𝑇𝐶 = 𝑚𝐶 𝑥̇ 2 + 𝑚𝑃 𝑣𝐺2
2 2
To compute the pendulum’s translational kinetic energy, the COM velocity can be computed
by differentiating the position of COM:
𝑙 𝑙
𝑥̇ 𝐺 = 𝑥̇ + 𝑐𝑜𝑠𝜃, 𝑦̇ 𝐺 = − 𝑐𝑜𝑠𝜃
2 2
𝑙𝜃̇ 𝑙𝜃̇ 𝑙𝜃̇
𝑣𝐺 = 𝑥̇ 𝑖̂ + 𝐽̂ = (𝑥̇ + 𝑐𝑜𝑠𝜃) 𝑖̂ + (− sin 𝜃) 𝑗̂
2 2 2
Since the kinetic energy depends on the speed squared, 𝑣𝐺2 is computed and the result is then
expanded and simplified as below:
2 2
𝑙𝜃̇ 𝑙𝜃̇
𝑣𝐺2 = (𝑥̇ + 𝑐𝑜𝑠𝜃) + (− sin 𝜃)
2 2
2 2
𝑙𝑥̇ 𝜃̇ 𝑙𝜃̇ 𝑙𝜃̇
𝑣𝐺2 2
= 𝑥̇ + 2 𝑐𝑜𝑠𝜃 + ( ) cos 𝜃 + ( ) sin2 𝜃
2
2 2 2
𝑙 2 𝜃̇ 2
𝑣𝐺2 = 𝑥̇ 2 + 𝑥̇ 𝜃̇𝑙𝑐𝑜𝑠𝜃 +
4
Finally, 𝑣𝐺2 is then substituted back into T to get a usable expression for controller design and
1
linearization; For a uniform rod with the moment of inertia of 𝐼𝐺 = 12 𝑚𝑝 𝑙 2, the final kinetic

energy can be defined as:


1 1
𝑇 = 𝑚𝐶 𝑥̇ 2 + 𝑚𝑃 𝑣𝐺2
2 2
1 1 𝑙 2 𝜃̇ 2
𝑇 = 𝑚𝑐 𝑥̇ 2 + 𝑚𝑃 (𝑥̇ 2 + 𝑥̇ 𝜃̇𝑙𝑐𝑜𝑠𝜃 + )
2 2 4
1 1 𝑙 2 𝜃̇ 2
𝑇 = (𝑚𝑐 + 𝑚𝑝 )𝑥̇ 2 + 𝑚𝑃 (𝑥̇ 𝜃̇𝑙𝑐𝑜𝑠𝜃 + )
2 2 4
1 1 1
𝑇 = (𝑚𝑐 + 𝑚𝑝 )𝑥̇ 2 + 𝑚𝑃 𝑥̇ 𝜃̇𝑙𝑐𝑜𝑠𝜃 + 𝑚𝑝 𝑙 2 𝜃̇ 2
2 2 8

5
Computation of Potential Energy
𝑙
With the angle measured from the vertical and the COM at 2, the rod’s height can be
𝑙
written as, 𝑦𝐺 = 2 𝑐𝑜𝑠𝜃. Choosing the upright position (𝜃 = 0) as the zero-energy level, the
l
elevation change is Δy = 2 (1 − 𝑐𝑜𝑠𝜃) . Hence the gravitational potential energy can be

expressed as:
𝑙 𝑚𝑃 𝑔𝑙
𝑉 = 𝑚𝑃 𝑔 (1 − 𝑐𝑜𝑠𝜃) = 𝑐𝑜𝑠𝜃
2 2

Lagrangian Formation
Coordinates and Assumptions
To model the inverted pendulum, we use the generalized coordinates:
𝑞1 = 𝑥 (cart position); 𝑞2 = 𝜃 (angle from vertical, upright at 0)
The pendulum is modelled as a uniform rod of length 𝑙 and mass 𝑚𝑝 , with center of mass
located at 𝑙/2. The cart has mass 𝑚𝑐 . The control input is a horizontal force applied to the cart,
denoted by:
𝑢(𝑡) = 𝐹(𝑡)
A positive 𝑢(𝑡) accelerates the cart toward the right. This force is assumed to be generated by
a linear actuator (motor-driven wheels or a belt mechanism). Since the input force acts directly
on the cart coordinate, its contribution appears in the Euler–Lagrange equation as the
generalized force:
𝑄𝑥 = 𝑢(𝑡)
If viscous friction is included, it enters as a disturbance force
𝑄𝑥 = 𝑢(𝑡) − 𝑏𝑥̇ ,
However, friction is not the control input. At the hinge, no external torque is applied, therefore:
𝑄𝜃 = 0
Lagrangian Expression
Using the velocity expressions of the cart and the rod’s center of mass, the system Lagrangian
becomes:
ℒ(𝑞, 𝑞)̇ = 𝑇 − 𝑉
1 1 1 𝑚𝑃 𝑔𝑙
ℒ = (𝑚𝑐 + 𝑚𝑝 )𝑥̇ 2 + 𝑚𝑃 𝑥̇ 𝜃̇𝑙𝑐𝑜𝑠𝜃 + 𝑚𝑝 𝑙 2 𝜃̇ 2 − 𝑐𝑜𝑠𝜃
2 2 8 2
1 1 𝑙 2 𝜃̇ 2 𝑚𝑃 𝑔𝑙
ℒ = 𝑚𝑐 𝑥̇ 2 + 𝑚𝑝 (𝑥̇ 2 + 𝑥̇ 𝜃̇𝑙𝑐𝑜𝑠𝜃 + )− 𝑐𝑜𝑠𝜃
2 2 4 2

6
Applying Euler-Lagrange for each coordinate,
General form with inputs:
𝑑 𝜕ℒ 𝜕ℒ
( )− = 𝑄𝑖
𝑑𝑡 𝜕𝑡 𝜕𝑞𝑖
At 𝑞1 = 𝑥,
𝜕ℒ 𝑚𝑝 𝑙
= (𝑚𝑐 + 𝑚𝑝 )𝑥̇ + 𝜃̇𝑐𝑜𝑠𝜃
𝜕𝑥̇ 2
𝑑 𝜕ℒ 𝑚𝑝 𝑙
( ) = (𝑚𝑐 + 𝑚𝑝 )𝑥̇ + (𝜃̈𝑐𝑜𝑠𝜃 − 𝜃̇ 2 𝑠𝑖𝑛𝜃)
𝑑𝑡 𝜕𝑥̇ 2
𝜕ℒ
=0
𝜕𝑥
𝑚𝑝 𝑙
(𝑚𝑐 + 𝑚𝑝 )𝑥̇ + (𝜃̈𝑐𝑜𝑠𝜃 − 𝜃̇ 2 𝑠𝑖𝑛𝜃) = 𝑄𝑥
2

With input only, 𝑄𝑥 = 𝑢 = 𝐹 (If viscous cart friction, 𝑏𝑥̇ , is added then 𝑄𝑥 = 𝐹 − 𝑏𝑥̇ )
At 𝑞2 = 𝜃,
𝜕ℒ 𝑚𝑝 𝑙 𝑚𝑝 𝑙 2
= 𝑥̇ 𝑐𝑜𝑠𝜃 + 𝜃̇
𝜕𝜃̇ 2 4
𝑑 𝜕ℒ 𝑚𝑝 𝑙 𝑚𝑝 𝑙 2
( )= (𝑥̈ 𝑐𝑜𝑠𝜃 − 𝑥̇ 𝜃̇ 𝑠𝑖𝑛𝜃) + 𝜃̈
𝑑𝑡 𝜕𝜃̇ 2 4
𝜕ℒ 𝜕𝑇 𝜕𝑉 𝑚𝑝 𝑙 𝑚𝑝 𝑔𝑙
= − = (− 𝑥̇ 𝜃̇𝑠𝑖𝑛𝜃) − ( sin 𝜃)
𝜕𝜃 𝜕𝜃 𝜕𝜃 2 2
𝑚𝑝 𝑙 2 𝑚𝑝 𝑙
𝜃̈ + 𝑥̈ 𝑐𝑜𝑠𝜃 + 𝑚𝑝 𝑔𝑙 sin 𝜃 = 𝑄𝜃
4 2
𝑄𝜃 = 0
𝑚𝑝 𝑙 2 𝑚𝑝 𝑙
𝜃̈ + 𝑥̈ 𝑐𝑜𝑠𝜃 + 𝑚𝑝 𝑔𝑙 sin 𝜃 = 0
4 2

7
Linearization
The control objective is to stabilize the pendulum around the upright position,
corresponding to the equilibrium point 𝜃 ≈ 0 . To linearize the system, linearization by
Jacobian theorem was utilized, yielding the following linear model:
𝑙
Let 𝑟 = 2,

𝑥̈ 𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝜃̇ 2 𝑠𝑖𝑛𝜃
𝑀(𝜃) [ ̈ ] = [ ]
𝜃 𝑚𝑝 𝑔𝑟𝑠𝑖𝑛𝜃
Where the mass matrix is:
𝑚 𝐶 + 𝑚𝑃 𝑚𝑝 𝑟𝑐𝑜𝑠𝜃
𝑀(𝜃) = [ ]
𝑚𝑝 𝑟𝑐𝑜𝑠𝜃 𝑚𝑝 𝑟 2
Since Jacobian linearization requires the dynamics as explicit functions of states and input, the
equation can be expressed in terms of acceleration:
𝑥̈ 𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃
[ ̈ ] = 𝑀(𝜃)−1 [ ]
𝜃 𝑚𝑝 𝑔𝑟𝑠𝑖𝑛𝜃
𝑥̈ 𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃 1 𝑚𝑝 𝑟 2 −𝑚𝑝 𝑟𝑐𝑜𝑠𝜃
[ ̈] = [ ]∙ [ ]
𝜃 𝑚𝑝 𝑔𝑟𝑠𝑖𝑛𝜃 (𝑚𝑐 + 𝑚𝑝 )𝑚𝑝 𝑟 2 ∙ (𝑚𝑝 𝑟𝑐𝑜𝑠𝜃)(𝑚𝑝 𝑟𝑐𝑜𝑠𝜃) −𝑚𝑝 𝑟𝑐𝑜𝑠𝜃 𝑚𝐶 + 𝑚𝑃
Finding the determinant,
𝐷 = (𝑚𝑐 + 𝑚𝑝 )𝑚𝑝 𝑟 2 − (𝑚𝑝 𝑟𝑐𝑜𝑠𝜃)(𝑚𝑝 𝑟𝑐𝑜𝑠𝜃)
𝐷 = 𝑚𝑝 𝑟 2 (𝑚𝑐 + 𝑚𝑝 sin2 𝜃)
(𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃)𝑚𝑝 𝑟 2 + (𝑚𝑝 𝑔𝑟𝑠𝑖𝑛𝜃)(−𝑚𝑝 𝑐𝑜𝑠𝜃)
𝑥̈ 𝐷
[ ̈] =
𝜃 (𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃)(−𝑚𝑝 𝑟𝑐𝑜𝑠𝜃) + (𝑚𝑝 𝑔𝑟𝑠𝑖𝑛𝜃)(𝑚𝑐 + 𝑚𝑝 )
[ 𝐷 ]
Solving for 𝑥̈ and 𝜃̈,
𝑚𝑝 𝑟 2 [(𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃) − 𝑚𝑝 𝑔(𝑠𝑖𝑛𝜃𝑐𝑜𝑠𝜃)]
𝑥̈ =
𝑚𝑝 𝑟 2 (𝑚𝑐 + 𝑚𝑝 sin2 𝜃)
(𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃) − 𝑚𝑝 𝑔(𝑠𝑖𝑛𝜃𝑐𝑜𝑠𝜃)
𝑥̈ =
(𝑚𝑐 + 𝑚𝑝 sin2 𝜃)
𝑙
(𝐹 − 𝑏𝑥̇ + 𝑚𝑝 (2)𝜃̇ 2 𝑠𝑖𝑛𝜃) − 𝑚𝑝 𝑔(𝑠𝑖𝑛𝜃𝑐𝑜𝑠𝜃)
𝑥̈ =
(𝑚𝑐 + 𝑚𝑝 sin2 𝜃)
(𝐹 − 𝑏𝑥̇ + 𝑚𝑝 𝑟𝜃̇ 2 𝑠𝑖𝑛𝜃)(−𝑚𝑝 𝑐𝑜𝑠𝜃) + 𝑚𝑝 𝑔(𝑠𝑖𝑛𝜃)(𝑚𝑐 + 𝑚𝑝 )
𝜃̈ =
𝑚𝑝 𝑟 2 (𝑚𝑐 + 𝑚𝑝 sin2 𝜃)
𝑙
(𝐹 − 𝑏𝑥̇ + 𝑚𝑝 (2)𝜃̇ 2 𝑠𝑖𝑛𝜃) (−𝑚𝑝 𝑐𝑜𝑠𝜃) + 𝑚𝑝 𝑔(𝑠𝑖𝑛𝜃)(𝑚𝑐 + 𝑚𝑝 )
𝑙
𝑚𝑝 (2)2 (𝑚𝑐 + 𝑚𝑝 sin2 𝜃)

8
The first-order state variables are then defined as:
𝑥1 𝑥
𝑥2 𝑥̇
𝑥𝑠 = [𝑥 ] = [𝜃]
3
𝑥4 𝜃̇
𝑥1̇ = 𝑥2 , 𝑥2̇ = 𝑓1 (𝑥3 , 𝑥4 , 𝑢) = 𝑥̈ 𝑥3̇ = 𝑥4 , 𝑥4 = 𝑓2 (𝑥3 ,̇ 𝑥4 , 𝑢) = 𝜃̈

Computing the Jacobian Entries


The linearized system has the form 𝛿𝑥̇ = 𝐴𝛿𝑥 + 𝐵𝛿𝑢, therefore partial derivatives are
taken at the equilibrium:
𝜕𝑓 𝜕𝑓
𝐴 = 𝜕𝑥 |𝑥𝑠0 ,𝑢0 and 𝐵 = 𝜕𝑢 |𝑥𝑠0,𝑢0
𝑠

Since 𝑓1 and 𝑓2 are obtained from multiplying the right-hand side with 𝑀(𝜃)−1, evaluating at
the equilibrium (𝜃 = 0, 𝜃̇ = 0) leaves only the input 𝑢 and the gravity term proportional to
𝑠𝑖𝑛𝜃. The 𝜃̇ 2 and 𝑠𝑖𝑛𝜃 terms vanish at this point.
Partial Derivative Computation:
From the kinematics,
𝜕𝑥1̇ 𝜕𝑥3̇
= [0 1 0 0], = [0 0 0 1]
𝜕𝑥𝑠 𝜕𝑥𝑠
𝜕𝑓
For 𝑥2̇ = 𝑓1 , 𝑒𝑣𝑎𝑙𝑢𝑎𝑡𝑒 𝑑𝑥1 ,
3

𝜕𝑓1 𝜕 0 0
|0 = (𝑟𝑜𝑤 1 𝑜𝑓 𝑀(0)−1 ) [ ] = (𝑎11 , 𝑎12 ) [ ] = −𝑎12 𝑚𝑃 𝑔𝑙
𝜕𝜃 𝜕𝜃 −𝑚 𝑃 𝑔𝑙 𝜃=0
−𝑚 𝑃 𝑔𝑙

𝜕𝑓
For 𝑥4̇ = 𝑓2 , 𝑒𝑣𝑎𝑙𝑢𝑎𝑡𝑒 𝜕𝑥2 ,
3

𝜕𝑓2 0
|0 = (𝑎21 , 𝑎22 ) [ ] = −𝑎22 𝑚𝑃 𝑔𝑙
𝜕𝜃 −𝑚 𝑃 𝑔𝑙

For the input derivative,


𝜕 𝑥̈ 1 𝑎11
[ ̈ ] |0 = 𝑀(0)−1 [ ] = [𝑎 ]
𝜕𝑢 𝜃 0 21

Therefore, B has entries of 𝐵(2) = 𝑎11 and 𝐵(4) = 𝑎21 . Putting it together, nonzero
linearization entries can be written as:
𝐴(1,2) = 1, 𝐴(3,4) = 1
𝐴(2,3) = −𝑎12 𝑚𝑃 𝑔𝑙
𝐴(4,3) = −𝑎22 𝑚𝑃 𝑔𝑙
𝐵(2) = 𝑎11 , 𝐵(4) = 𝑎21

9
The known 𝑎𝑖𝑗 constants are then substituted to obtain closed-form values for
𝐴(1,2), 𝐴(4,3), 𝐵(2), 𝐵(4) in terms of 𝑚𝑐 , 𝑚𝑝 , 𝑙, 𝑔.
2𝑚𝑃 𝑔
𝐴(2.3) =
𝑚𝐶
4(𝑚𝐶 + 𝑚𝑃 )𝑔
𝐴(4,3) = −
𝑙𝑚𝐶
1
𝐵(2) =
𝑚𝑐
2
𝐵(4) = −
𝑙𝑚𝐶

Linearized State-Space
Controller synthesis uses first-order model; Therefore, the linearized dynamics are
written in the form of:
𝑇
𝑥𝑠̇ = 𝐴𝑥𝑠 + 𝐵𝑢 with the state vector being, 𝑥𝑠 = [𝑥, 𝑥̇ , 𝜃, 𝜃̇]
0 0 0
0 1 2𝑚𝑃 𝑔 1
0 0 0
𝑚𝐶 𝑚𝐶
𝐴= , 𝐵=
0 1 0
0 0 4(𝑚𝐶 + 𝑚𝑃 )𝑔 2
0 0 − 0 −
[ 𝑙𝑚𝐶 ] [ 𝑙𝑚𝐶 ]
From the second row of 𝑥𝑠̇ = 𝐴𝑥𝑠 + 𝐵𝑢 (state space (𝑥̈ )), the cart acceleration is expressed in
terms of 𝜃 and 𝑢:
2𝑚𝑃 𝑔 1
𝑥̈ = 𝜃+ 𝑢
𝑚𝐶 𝑚𝐶
From the fourth row of state space (𝜃̈), the pendulum angular acceleration is:
6(𝑚𝐶 + 𝑚𝑃 )𝑔 6
𝜃̈ = − 𝜃− 𝑢
𝑙(4𝑚𝐶 + 𝑚𝑃 ) 𝑙(4𝑚𝐶 + 𝑚𝑃 )
Rearranging the equation so that 𝑢 is the subject then gives:
𝑢 = 𝑚𝐶 𝑥̈ − 2𝑚𝑃 𝑔𝜃
Substituting the expression for 𝑢 into the 𝜃̈ equation as a function of 𝜃 and 𝑥̈ :
2 4(𝑚𝐶 + 𝑚𝑃 )𝑔
𝜃̈ = − (𝑚𝐶 𝑥̈ − 2𝑚𝑃 𝑔𝜃) − 𝜃
𝑙𝑚𝐶 𝑙𝑚𝐶
2 4𝑔
𝜃̈ = − 𝑥̈ − 𝜃
𝑙 𝑙

10
Laplace Transformation
Because transfer functions are defined in the Laplace domain, take the Laplace
transform (zero initial conditions) to obtain:
4𝑔 2
𝑠 2 Θ(𝑠) = − Θ(𝑠) − s2 Χ(𝑠)
𝑙 𝑙
Θ(𝑠)
Rearranging for produces the linearized relation from cart acceleration/position to
Χ(𝑠)

pendulum angle:
2 2
Θ(𝑠) 𝑠
𝐺(𝑠) = =− 𝑙
Χ(𝑠) 4𝑔
𝑠2 +
𝑙

Block Diagram Formation

Figure 2. Block Diagram of the System

The block diagram shown in Figure 2 represents the closed-loop implementation of the
linearized state-space model of the gantry crane pendulum system. The plant dynamics are
expressed in state-space form as:
𝑥𝑠̇ = 𝐴𝑥𝑠 + 𝐵𝑢, 𝑦 = 𝐶𝑥
where the state vector is defined as:
𝑥
𝑥̇
𝑥𝑠 = [𝜃]
𝜃̇
In this configuration, the control input 𝑢 corresponds to a horizontal force applied to
the cart, generated by the motor, and expressed in Newtons. This applied force produces cart
motion and indirectly affects the pendulum dynamics due to inertial coupling.

The block diagram is constructed by directly mapping the terms of the state-space
equation 𝑥̇ 𝑠 = 𝐴𝑥𝑠 + 𝐵𝑢. The controller generates the required control signal 𝑢, which is then
passed through the input matrix block (B), producing the term 𝐵𝑢. In parallel, the current state

11
vector is multiplied by the system matrix (A), generating the term 𝐴𝑥𝑠 . These two signals are
summed, resulting in the time derivative of the state vector, 𝑥̇ 𝑠 .

The resulting signal then passes through the integrator block, which implements:
𝑥𝑠 (𝑡) = ∫ 𝑥̇ 𝑠 (𝑡)𝑑𝑡

The reference vector can be expressed as:


𝑥𝑜
𝑥̇ 𝑜
𝑥𝑜 = [𝜃 ]
𝑜
𝜃̇𝑜
This state vector is fed back to the controller to complete the closed feedback loop.
A reference state vector is introduced to define the desired equilibrium condition:
𝑥𝑑
𝑥𝑑̇
𝑥𝑑 = [𝜃 ]
̅̅̅
𝑑
𝜃̇𝑑
For stabilization around the upright position, the desired values are typically 𝑥𝑑 = 0, 𝜃𝑑 = 0,
𝑥̇ 𝑑 = 0, and 𝜃̇𝑑 = 0. The first summing junction compares the desired reference vector and
the actual plant state, generating the error signal:

𝑒 = ̅̅̅
𝑥𝑑 − ̅̅̅.
𝑥𝑜

This error signal becomes the input to the controller, which computes the appropriate force
command 𝑢 to minimize the state error. The feedback arrangement ensures that the system
regulates the pendulum angle and cart motion toward the desired equilibrium.

12
2.2 Controller Design Method

Controllability analysis
Before designing any state-feedback controller, it is necessary to verify that the
linearized model of the inverted pendulum is fully controllable. Controllability ensures that all
system states can be influenced by the control input and therefore guarantees that a stabilizing
feedback gain 𝐾 exists. The linearized system is expressed in state-space form:

𝑇
𝑥̇ 𝑠 = 𝐴𝑥𝑠 + 𝐵𝑢, 𝑥𝑠 = [𝑥 𝑥̇ 𝜃 𝜃̇]

with the corresponding 𝐴 and 𝐵 matrices obtained previously during the modelling and
linearization stage. To check controllability, the controllability matrix 𝒞 = [ 𝐵 𝐴𝐵 𝐴2 𝐵 𝐴3 𝐵 ]
is constructed. The system is controllable if rank(𝒞) = 4.

The following MATLAB script evaluates the controllability matrix and its rank:

Code:
g = 9.81; % gravity [m/s^2]
mc = 5.0; % cart mass [kg]
mp = 1; % pendulum mass [kg]
l = 2; % pendulum length [m]

A=[0 1 0 0;
0 0 2*mp*g/mc 0;
0 0 0 1;
0 0 -4*(mc+mp)*g/(l*mc) 0 ];

B = [ 0;
1/mc;
0;
-2/(l*mc) ];
%% --- 3.1 CHECKING CONTROLLABILITY --------------------------------------
Co = ctrb(A,B); % controllability matrix
rankCo = rank(Co);

fprintf('Rank(Controllability Matrix) = %d\n', rankCo);

if rankCo == size(A,1)
fprintf('System is CONTROLLABLE -> stabilizing gain K exists.\n\n');
else
fprintf('System is NOT fully controllable.\n\n');
end
Output:
Rank(Controllability Matrix) = 4

13
System is CONTROLLABLE -> stabilizing gain K exists.
The result of the computation shows:
rank(𝒞) = 4,
indicating that the system is fully controllable, and therefore a stabilizing state-feedback
controller 𝑢 = −𝐾𝑥𝑠 can be designed.

Linear Quadratic Regulator (LQR) Derivation


After confirming controllability, a Linear Quadratic Regulator is used to compute the
optimal state-feedback gain. The LQR method guarantees that the closed-loop system is stable
and that the controller minimizes a quadratic performance index. The cost function is defined
as:

𝐽 = ∫ (𝑥𝑠𝑇 𝑄𝑥𝑠 + 𝑢𝑇 𝑅𝑢) 𝑑𝑡,
0

where 𝑄 penalizes state deviations and 𝑅penalizes excessive control effort. To strongly enforce
pendulum stabilization, higher penalties are assigned to 𝜃and 𝜃̇:

𝑄 = 𝑑𝑖𝑎𝑔(1, 0.1, 100, 10) 𝑅 = 0.1

MATLAB solves the continuous-time Algebraic Riccati Equation to obtain the optimal gain:

𝐾 = 𝑅 −1 𝐵 𝑇 𝑃.

The controller is implemented using the following MATLAB code:

Code:
g = 9.81; % gravity [m/s^2]
mc = 5.0; % cart mass [kg]
mp = 1; % pendulum mass [kg]
l = 2; % pendulum length [m]

A=[0 1 0 0;
0 0 2*mp*g/mc 0;
0 0 0 1;
0 0 -4*(mc+mp)*g/(l*mc) 0 ];

B = [ 0;
1/mc;
0;
-2/(l*mc) ];

%% --- 3.2 LINEAR QUADRATIC REGULATOR ------------------------------------


14
Q = diag([1 0.1 100 10]); % state penalty
R = 0.1; % input penalty

K = lqr(A,B,Q,R); % optimal LQR gain

fprintf('LQR gain K = [k1 k2 k3 k4] = \n');


disp(K);

Acl = A - B*K; % closed-loop system matrix


lam = eig(Acl);

fprintf('Closed-loop eigenvalues of A - B*K:\n');


disp(lam);

if all(real(lam) < 0)
fprintf('All eigenvalues have negative real parts -> CLOSED-LOOP IS STABLE.\n\n');
else
fprintf('Closed-loop is NOT stable.\n');
end
Output:
LQR gain K = [k1 k2 k3 k4] =
3.1623 6.6317 -15.6096 -10.3600

Closed-loop eigenvalues of A - B*K:


-1.1900 + 4.7905i
-1.1900 - 4.7905i
-0.5091 + 0.5001i
-0.5091 - 0.5001i

All eigenvalues have negative real parts -> CLOSED-LOOP IS STABLE.

All eigenvalues of the closed-loop matrix, 𝐴𝑐𝑙 = 𝐴 − 𝐵𝐾 have strictly negative real parts,
confirming mathematically that the LQR controller stabilizes the inverted pendulum around
the upright equilibrium.

Error Tracking
To evaluate the performance of the closed-loop system under the designed LQR
controller, the error dynamics are analyzed. The tracking error is defined as

𝑒(𝑡) = 𝑥(𝑡) − 𝑥𝑑 ,

where 𝑥𝑑 is the desired equilibrium state. Since the control law is given by 𝑢 = −𝐾(𝑥 − 𝑥𝑑 ),
the resulting closed-loop error dynamics become:

𝑒̇ (𝑡) = (𝐴 − 𝐵𝐾)𝑒(𝑡)

15
This linear differential equation admits the analytical solution 𝑒(𝑡) = 𝑒 (𝐴−𝐵𝐾)𝑡 𝑒(0), which is
used to compute the evolution of the error states over time. An initial perturbation of 5∘ is
applied to the pendulum angle to test the controller’s ability to restore the upright equilibrium.

The following MATLAB script computes the error trajectory over a 15-second interval using
the matrix exponential:

Code:
g = 9.81;
mc = 5.0;
mp = 1.0;
l = 2.0;

A = [0 1 0 0;
0 0 2*mp*g/mc 0;
0 0 0 1;
0 0 -4*(mc+mp)*g/(l*mc) 0];

B = [0;
1/mc;
0;
-2/(l*mc)];

K = [3.1623 6.6317 -15.6096 -10.3600];

A_cl = A - B*K;

x0 = [0; 0; 5*pi/180; 0];


x_d = [0; 0; 0; 0];
e0 = x0 - x_d;

t_end = 15;
dt = 0.01;
T = 0:dt:t_end;

E = zeros(4, length(T));

for i = 1:length(T)
t = T(i);
E(:,i) = expm(A_cl * t) * e0;
end

figure;
plot(T, E(1,:), T, E(2,:), T, E(3,:), T, E(4,:), 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Error States');
title('Error Dynamics of the Closed-Loop System');
legend('e_1','e_2','e_3','e_4');

16
grid on;

e15 = E(:, end)


Output:

Figure 3. Time response of error dynamics

The computed error at 𝑡 = 15 seconds is:


−0.1443
0.0375
𝑒(15) = 10−3 [ ]
−0.0017
0.0028
−1.443 × 10−4
−5
= [ 3.75 × 10−6 ]
−1.7 × 10
2.8 × 10−6

These numerical results show that all error components converge to values extremely close to
zero, with magnitudes between 10−4and 10−6. The cart position error and pendulum angle
error decay rapidly, and both velocity terms also diminish to negligible values. This
demonstrates that the LQR controller successfully stabilizes the inverted pendulum and drives
the entire state vector toward the desired equilibrium. The small final errors confirm that the
closed-loop system is asymptotically stable and exhibits excellent tracking performance under
the designed control law.

2.3 Simulation Settings and Reference Tracking

17
To evaluate the performance of the designed LQR controller beyond small-angle
stabilization, the closed-loop system is also tested under different reference values for the
desired cart position 𝑥𝑑 . Incorporating reference tracking allows the controller to regulate the
cart toward a specified location while keeping the pendulum balanced around the upright
equilibrium. This assessment is important because a stabilizing feedback gain alone does not
guarantee acceptable tracking behaviour; the controller must demonstrate that it can move the
system toward different equilibrium points without violating the stability of the pendulum.

The implemented control law is 𝑢(𝑡) = −𝐾(𝑥(𝑡) − 𝑥𝑑 ), where the reference vector is
𝑥𝑑
𝑥𝑑̇
𝑥𝑑 = [𝜃 ]
̅̅̅
𝑑
̇𝜃𝑑
By varying 𝑥𝑑 , the system is driven to different desired cart positions while the pendulum angle
remains regulated around 𝜃 = 0. For this study, several reference values are tested to observe
how the controller responds to setpoint changes which include large negative values, large
positive values, and a combination of both. The purpose of these tests is to examine whether
every chosen value of the desired state leads to the same final steady-state result as the baseline
condition where,
0
0
𝑥𝑑 = [ ]
0
0
Listed below are the chosen values,

−100 × 103 −1 × 103 1 × 103 100 × 103


3 3 3 3
𝑥𝑑1 = [−100 × 103 ] , 𝑥𝑑2 = [−1 × 103 ] , 𝑥𝑑3 = [1 × 103 ] , 𝑥𝑑4 = [100 × 103 ],
−100 × 10 −1 × 10 1 × 10 100 × 10
−100 × 103 −1 × 103 1 × 103 100 × 103

1 × 107
7
𝑥𝑑5 = [ −5 × 10 4 ].
−24.32 × 10
3 × 106

The simulation is performed over a fixed time interval of 15 seconds using a time step of 0.01
seconds. Each simulation begins with the pendulum perturbed by 5 degrees from the vertical
to assess whether the controller can simultaneously suppress the angular disturbance and guide
the cart toward the specified reference. This setup provides a direct measure of the controller’s
robustness and its ability to achieve both stabilization and tracking objectives.

18
Chapter 3: Results and Discussion
3.1 Closed-Loop Stability Verification
The linearized model of the inverted pendulum was verified to be fully controllable,
indicating that a stabilizing feedback gain exists for the system. Using the LQR design method,
an optimal feedback matrix 𝐾 was obtained, and the resulting closed-loop matrix 𝐴 − 𝐵𝐾
exhibited eigenvalues with strictly negative real parts. This confirms mathematically that the
controller stabilizes the intrinsically unstable inverted pendulum around the upright
equilibrium. The error dynamics were evaluated using the analytical solution

𝑒(𝑡) = 𝑒 (𝐴−𝐵𝐾)𝑡 𝑒(0),

with an initial angular perturbation of 5∘ . The simulation results demonstrate that all four error
states converge exponentially toward zero. At 𝑡 = 15seconds, the final error vector

−1.44 × 10−4
−5
𝑒(15) = [ 3.75 × 10 −6 ]
−1.7 × 10
2.8 × 10−6

indicates negligible steady-state deviations in cart position, cart velocity, pendulum angle, and
angular velocity. These values confirm that the LQR controller effectively restores the
pendulum to the upright configuration while regulating cart motion.

3.2 Reference-Tracking Performance for Different 𝑥𝑑

The first case examines the system response when the desired state is assigned large
negative values to observe how the states evolve under extreme negative inputs,

−100 × 103
3
𝑥𝑑 = [−100 × 103 ]
−100 × 10
−100 × 103

Using the MATLAB code and adjusting the 𝑥𝑑 values, the value of the error is computed to be,

26.71
−46.26
𝑒(15) = [ ]
−1.72
5.63 × 10−1

19
Figure 4. Time response of error dynamics (Case 1)

The plot in Figure 4 shows that the state trajectories for Case 1 gradually converge toward zero,
demonstrating that the system drives the states to the same final value as in the baseline
condition. This confirms that even under large negative desired-state inputs, the system
maintains consistent behaviour and reaches the expected equilibrium.

After confirming that the system converges correctly under large negative inputs, the second
case examines the response when the desired state is assigned smaller negative values to see
whether the system maintains the same convergence behaviour under milder conditions, with
desired state,

−1 × 103
3
𝑥𝑑 = [−1 × 103 ]
−1 × 10
−1 × 103

Using the MATLAB code and adjusting the 𝑥𝑑 values, the value of the error is computed to be,

2.67 × 10−1
−1
𝑒(15) = [−4.63 × 10−2 ]
−1.72 × 10
5.60 × 10−3

20
Figure 5. Time response of error dynamics (Case 2)

As illustrated in Figure 5, the state responses for this case also decrease steadily and converge
to zero over time. This behaviour matches the final value observed in the baseline condition,
showing that even when the desired state is set to smaller negative values, the system
consistently drives all states toward equilibrium. These results confirm that the system
maintains correct convergence characteristics under milder negative inputs, just as it did in the
first case.

Following the consistent convergence observed under both large and small negative inputs, the
third case evaluates the system response when the desired state is assigned small positive values
to determine whether the system preserves the same stable behaviour under opposite-signed
conditions, with desired state,

1 × 103
3
𝑥𝑑 = [1 × 103 ]
1 × 10
1 × 103

and the output of the error is shown below,

−2.67 × 10−1
−1
𝑒(15) = [ 4.63 × 10−2 ]
1.72 × 10
−5.60 × 10−3

21
Figure 6. Time response of error dynamics (Case 3)

As shown in Figure 6, the state trajectories for this case also move steadily toward zero,
demonstrating that the system continues to converge to the same final value as the baseline
condition even when the desired state is set to small positive inputs. This confirms that the
system maintains consistent and stable behaviour across opposite-signed desired states,
reinforcing the correctness of the system response observed in the previous cases.

Building on the stable convergence observed under small positive inputs, the fourth case
examines the system response when the desired state is assigned larger positive values to verify
whether the system continues to exhibit the same reliable behaviour under more extreme
positive conditions, with desired state,

100 × 103
3
𝑥𝑑 = [100 × 103 ]
100 × 10
100 × 103

and the output is shown below,

−26.71
46.26
𝑒(15) = [ ]
1.72
−5.63 × 10−1

22
Figure 7. Time response of error dynamics (Case 4)

Figure 7. shows that the state responses in this case gradually move toward zero, confirming
that the system reaches the same final value as the baseline condition even under large positive
desired-state inputs. This outcome demonstrates that the system preserves its stability and
correct convergence behaviour across a wide range of positive values, consistent with the trends
observed in cases three.

Following the consistent convergence across positive and negative inputs, the fifth case
investigates the system response when the desired state contains a combination of positive and
negative values to determine whether the system can maintain the same stable behaviour under
mixed-sign conditions, with desired state,

1 × 107
7
𝑥𝑑 = [ −5 × 10 4 ]
−24.32 × 10
3 × 106

and the output is computed to be,

4.20 × 104
4
𝑒(15) = [−1.08 × 104 ]
0.05 × 10
−0.08 × 104

23
Figure 8. Time response of error dynamics (Case 5)

Figure 8 demonstrates that the state trajectories for this mixed-sign input set also converge
toward zero, indicating that the system reaches the same final value as the baseline condition
despite the opposing directions of the desired-state components. This result shows that the
system remains stable and behaves consistently even when the inputs vary in sign, reinforcing
the overall conclusion that the system converges correctly for all tested desired-state
configurations.

Taken together, the baseline and reference tracking simulations show that the designed LQR
controller meets the primary design goal of stabilizing the inverted pendulum around the
upright equilibrium while regulating cart motion. For all tested reference vectors, including
very large positive and negative values as well as the mixed-sign case, the closed-loop
trajectories remain bounded and converge toward the same equilibrium state as in the nominal
condition, which indicates that the controller handles extreme and unrealistic references
correctly at the mathematical level of the linear model. Overall, the observed convergence
behaviour is consistent with the theoretical prediction based on the negative real parts of the
closed-loop eigenvalues and the analytical error solution 𝑒(𝑡) = e(𝐴−𝐵𝐾)𝑡 𝑒(0), confirming that
the implemented LQR law achieves the expected asymptotic stability and reference tracking
properties for the linearized inverted pendulum system.

24
Chapter 4: Conclusion
Through this project, the students gained a structured understanding of how to move
from a physical description of a mechanical system to a working feedback controller. Starting
from the free body diagram and Lagrangian formulation, the inverted pendulum was modelled
in terms of generalized coordinates, linearized around the upright equilibrium, and expressed
in state space form, which clarified how mass, geometry, and gravity shape the dynamics. The
controllability analysis showed how algebraic tools can determine whether a system is suitable
for state feedback, while the LQR design process illustrated how the weighting matrices 𝑄and
𝑅encode trade-offs between state accuracy and control effort. Implementing the controller in
MATLAB and analysing both eigenvalues and time responses provided practical insight into
the relationship between mathematical stability proofs, numerical simulations, and the choice
of reference signals. More broadly, this project reinforced the importance of carefully defining
control objectives, selecting appropriate models and assumptions, and interpreting simulation
results in light of real-world physical limitations.

25
References
[1] R. Kennaway, “When causation does not imply correlation,” in Elsevier eBooks, 2020,
pp. 49–72. doi: 10.1016/b978-0-12-818948-1.00004-6. Available:
[Link]

[2] M. T. Morgan and T. A. Haley, “Design of food process controls systems,” in Elsevier
eBooks, 2007, pp. 485–552. doi: 10.1016/b978-081551538-8.50019-4. Available:
[Link]

[3] S. Mukherjee and M. Buragohain, “Stabilization and Performance Analysis of an


Inverted Pendulum using Classical and Intelligent Control Techniques,” International
Journal of Innovative Technology and Exploring Engineering, vol. 14, no. 6, pp. 27–
35, May 2025, doi: 10.35940/ijitee.f1092.14060525. Available:
[Link]

26

You might also like