0% found this document useful (0 votes)
6 views45 pages

Automatism

This project report details the design and implementation of a self-balancing inverted pendulum using PID and LQR control algorithms. The system incorporates an Arduino Uno, MPU6050 sensor, and various electronic components, with challenges faced during sensor data fusion addressed through filtering techniques. The report includes simulations, hardware design, and results demonstrating the effectiveness of the control strategies employed.

Uploaded by

khoild.23bi14231
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)
6 views45 pages

Automatism

This project report details the design and implementation of a self-balancing inverted pendulum using PID and LQR control algorithms. The system incorporates an Arduino Uno, MPU6050 sensor, and various electronic components, with challenges faced during sensor data fusion addressed through filtering techniques. The report includes simulations, hardware design, and results demonstrating the effectiveness of the control strategies employed.

Uploaded by

khoild.23bi14231
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
You are on page 1/ 45

AUTOMATISM

PROJECT REPORT:
CONTROLLED INVERTED PENDULUM

Phan Huy Hoang - ID: 23BI14174


Tran Anh Tuan - ID: 23BI14443
Le Duc Khoi - ID: 23BI14231
Trinh Phan Minh Khoi - ID: 23BI14232
Nguyen Hoang Nghia - ID: 23BI14339

Instructor: Tran Anh Tu Msc., USTH


May 20, 2025
Contents

Acknowledgements 3

List of abbreviations 4

List of tables 5

List of figures 6

Abstract 7

1 Introduction 8
1.1 Context and Significance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Project Motivation and Learning Objectives . . . . . . . . . . . . . . . . . 8
1.3 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2 Equation of Motion 10

3 Simulation and Validation 12


3.1 MATLAB model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Simulink model and simulation result . . . . . . . . . . . . . . . . . . . . . 12
a. PID Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
b. LQR Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
c. No Control model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
d. Combined control model . . . . . . . . . . . . . . . . . . . . . . . . 20

4 System Design - Hardware 21


4.1 General Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
a. Item List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
b. Problems &Troubleshooting . . . . . . . . . . . . . . . . . . . . . . 22
4.2 3D Printed Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
a. Item List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
b. Problems &Troubleshooting . . . . . . . . . . . . . . . . . . . . . . 29
c. Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

5 System Design - Electronics 32


5.1 Adruino R3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2 MPU-6050 six-axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.3 Stepper motor and Stepper motor driver . . . . . . . . . . . . . . . . . . . 33

6 System Design - Software 36

1
7 Results and Discussion 37

8 Conclusion 38

Bibliography 39

A Arduino Code 40

B Bill of Materials and Cost Breakdown 43

C Work Distribution between Members 44

2
Acknowledgements

Before we dive into the final project report, we would first like to extend our heartfelt
thanks and utmost gratitude to our Automatism Professor, Dr. Tran Anh Tu, who have
been our lecturer for the course as well as the concept of Automatic Control Theory as a
whole. His dedication to teaching, expertise in the subject as well as his lecturing methods
have been instrumental in shaping the trajectory of our project.

With that being said, we are grateful to USTH, our university for providing us this
amazing opportunity to be able to work on such subject and providing the tools and
environment to allow us to achieve our goals.

We also greatly appreciate Linh Kien Cau Giay hardware/electronics shop and SKF
Retails for providing us with the necessary materials and components required for the
project to be conducted.

In conclusion, this research stands as a collaborative effort and a very thought-provoking


scientific endeavor that has allowed us to further our knowledge regarding Control Theory
and our hands-on experience in working with practical projects like these.

3
List of Abbreviation

PID Proportional Integral Derivative


LQR Linear-quadratic Regulator
IMU Inertial Measurement Unit
MATLAB Matrix Laboratory

4
List of Tables

4.1 General Hardware list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22


4.2 3D parts (Page 1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.3 3D parts (Page 2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4 3D parts (Page 3). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.5 3D parts (Page 4). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.6 3D parts (Page 5). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.1 Specifications of the Arduino Uno R3 . . . . . . . . . . . . . . . . . . . . . 32


5.2 Specifications of the MPU-6050 Sensor . . . . . . . . . . . . . . . . . . . . 33
5.3 Specifications of the Stepper Motor . . . . . . . . . . . . . . . . . . . . . . 35
5.4 Specifications of A4988 Stepper Motor Driver . . . . . . . . . . . . . . . . 35

C.1 Work distribution table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

5
List of Figures

2.1 Inverted pendulum diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.1 Result 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 Result 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Result 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 LQR control Simulink diagram . . . . . . . . . . . . . . . . . . . . . . . . 17
3.5 Simulation result 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.6 Full terms system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.7 Result of each terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.8 Simulation animation 1 - Pendulum during swing-up. . . . . . . . . . . . . 20
3.9 Simulation animation 2 - Pendulum balanced. . . . . . . . . . . . . . . . . 20

4.1 The Gantry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29


4.2 The gantry with the pipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.3 The pendulum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.4 The Idle Pulley . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.5 Stepper Pulley . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5.1 Arduino R3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2 MPU-6050 sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.3 Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.4 A4988 Stepper Motor Driver . . . . . . . . . . . . . . . . . . . . . . . . . . 34

6
Abstract

This project studies and builds an pre-designed self-balancing inverted pendulum model
from an online tutorial which then presents its simulation and implementation. This is an
attempt to understand the inverted pendulum problem, where a pivoted pendulum per-
form a swing-up motion and keep itself in upward balance while mounted on a moving cart.

Beforehand, a PID and a LQR control algorithm was researched and simulated in MAT-
LAB and Simulink. The inverted pendulum model is constructed from available 3D
printed parts. The electronic system includes an Arduino Uno as the main board, ac-
companied by the MPU6050 sensor. Other electronic components are a HR4988 stepper
motor driver, a NEMA 17 servo and a 12V/10A power supply.

There exist troubleshooting during the sensor data fusion collection process of the gy-
roscope and accelerometer from the inertial measurement unit (IMU). Complementary
filters and the Kalman filter were utilized for this drift-correction process.

Our group’s experimental results reflect the simulation and achieved successful pendu-
lum stabilization for the model. Limitations such as drift, wiring inconveniences, and
electrical imperfections were encountered and addressed during implementation.

Keywords: inverted pendulum, feedback control systems, self-balancing, MATLAB, Simulink,


Arduino, PID, LQR, sensor data fusion, complementary filters, Kalman filter, drift.

7
Chapter 1

Introduction

1.1 Context and Significance


The inverted pendulum is a classical problem in control theory and dynamic, charac-
terized by its non-linear and open-loop instability system which requires active control.
Conceptually, the system presented in this project consists of a pivoting inverted pendu-
lum mounted onto a virtually frictionless sliding cart. The objective of the control system
is to keep the pendulum in the inverted position using a control system to monitor its
angle and applying the necessary forces to the cart that the pendulum is mounted upon.
Mathematically, balancing can be done either by applying a torque to the pivot point by
moving it horizontally (moving the cart), or by oscillating the pivot point vertically.

Stabilizing a pendulum in this inverted position is a perfect benchmark for various con-
trol algorithms (i.e. PID controllers, state-space representation, neural networks, LQR
controllers, etc.). The inverted pendulum has its root in rocket/missile guidance, where
the center of gravity is often located usually near the rear, behind the center of drag
which causes aerodynamic instability. This is comparable to the pivot point behind the
pendulum. Applications of this concept can be seen in other fields such as robotics in
self-balancing. Segways, hoverboard or uni-cycles are prime examples, to name but a few.

1.2 Project Motivation and Learning Objectives


For the Automatism course’s final project, we decided to replicate this rather common
version of the inverted pendulum problem but nonetheless challenging cart-pole appara-
tus, which is demonstrated in a tutorial from Instructables: ”Inverted Pendulum: Control
Theory and Dynamics”. The tutorial at first emphasizes the control theory behind the
inverted pendulum, its equation of motion and applicable controllers which then lead to
implementing various Arduino electronics as sensors and actuators. This lead to tuning
a PID controller for the system. The tutorial also provided a pre-designed physical rig,
including all the required hardware and 3D parts to be printed.

Through this project, we aim to understand the control system and dynamics behind
the inverted pendulum problem by real-time applications. We also want to get hands-on
experience in implementing different feedback controllers when performing simulation for
the machine itself. Though not being our initial goals, addressing certain problems in
data fusion - precisely accelerometer and gyroscope reading - such as drift or revising

8
parts of the tutorial itself in terms of electronic parts redundancy/inefficiency for better
performance are all notable efforts made in working towards this project.

1.3 Overview
In this report, we will firstly demonstrate our initial theoretical approach to this problem
with theoretical modeling and accompanied mathematical representations. The control
design has been programmed in MATLAB and simulated via Simulink with clear tun-
ing for the controllers and stability outputs. Afterwards, practical implementation will
present the hardware used for the project, namely parts for the physical rig of the model
and the electronics used for Arduino-based controls. This is followed by the assembling of
the model with the wiring of the entire electronic system. The latter part will demonstrate
and explain the software - the Arduino programming for the machine - and implemen-
tation of filtering algorithms to avoid drift. Finally, we will discuss the results of the
experiment, our execution of the project and any further complications that occured dur-
ing the development of the project.

9
Chapter 2

Equation of Motion

In the pendulum motion, we consider it in two motions, the change in angularity of the
pendulum and the displacement in the x axis:

Figure 2.1: Inverted pendulum diagram

The force acting on the x-axis is:


mẍ = F − N − cẋ
And the equation of motion on the angular θ is:
I θ̈ = −N l cos(θ) − P l sin(θ) − bθ̇
where the inertia momentum I = 31 ml2 , c is efficient in resistance and b is the damping
of the pendulum.
But for more precise calculation and modeling, we will use the Lagrangian which describes
the energy of the system:
L=T +V
The Kinetic energy T:
1 1 1 1
T = Mc ẋ2 + mẋ2 + ml2 θ̇2 + mlẋθ̇ cos θ + I θ̇2
2 2 2 2

10
The Potential energy V:
V = mgl cos(θ)
Then the Lagrangian of the system is:
1 1 1 1
L = Mc ẋ2 + mẋ2 + ml2 θ̇2 + mlẋθ̇ cos θ + I θ̇2 + mgl cos(θ)
2 2 2 2
Using this Lagrangian and the equation of motion in the previous part we have:
d ∂L ∂L
− = F − cẋ
dt ∂ ẋ ∂x

d ∂L ∂L
− = −bθ̇
dt ∂ θ̇ ∂θ
As the modeling of the system.

11
Chapter 3

Simulation and Validation

3.1 MATLAB model


At first we have the kinematics components:
   
xp x + l sin θ
= (3.1)
yp −l cos θ

Using the result in the Equation of Motion, we can now create a mathematics model for
the inverted pendulum:

(M + m)ẍ + mlθ̈ cos θ − mlθ̇2 sin θ = F − cẋ


(3.2)
I + ml2 θ̈ + mlẍ cos θ + mgl sin θ = −bθ̇


So we can put the equation into MATLAB for simulating:


1 % State - space representation
2 % x = [ x ; x_dot ; theta ; theta_dot ]
3 A = [0 , 1 , 0 , 0;
4 0 , -( c /( M + m ) ) , -( m * g /( M + m ) ) , 0;
5 0 , 0 , 0 , 1;
6 0 , ( c * l /( I + m * l ^2) ) , ( m * g * l /( I + m * l ^2) ) , -( b /( I + m * l ^2) ) ];
7
8 B = [0;
9 1/( M + m ) ;
10 0;
11 -( l /( I + m * l ^2) ) ];

3.2 Simulink model and simulation result


a. PID Control
We will linearize the equations about the vertically upward equilibrium position, θ = π
Let ϕ represent the deviation of the pendulum’s position from equilibrium, that is, θ = π
+ ϕ. Again, presuming a small deviation (ϕ) from equilibrium, we can use the following
small angle approximations of the nonlinear functions in our system equations:

cos θ = cos(π + ϕ) ≈ −1

12
sin θ = sin(π + ϕ) ≈ −ϕ

θ̇2 = ϕ̇2 ≈ 0

Apply this term to the Equation of Motion, we get the following system:

(M + m)ẍ − mlϕ̈ = F − cẋ


(3.3)
I + ml2 ϕ̈ − mlẍ − mglϕ = −bϕ̇


And using this we can generate the transfer function:

(M + m)X(s)s2 − mlΦ(s)s2 = U (s) − cX(s)s


(3.4)
I + ml2 Φ(s)s2 − mlX(s)s2 − mglΦ(s) = −bΦ(s)s


We have the relation between Φ and X:


I + ml2
 
g b
− 2+ Φ=X (3.5)
ml s mls

For q = (M + m)(I + ml2 ) − (ml)2 , we get the transfer function:


ml 2
Φ(s) q
s
= c(I+ml2 ) 3
(3.6)
U (s) s4 + q
s − ( (M +m)mgl
q
− bc 2
q
)s − c mgl
q
s

The resulting transfer function T (s) for the closed-loop system from an input of force U
to an output of pendulum angle ϕ is then determined to be the following.

Φ(s) Ppend (s)


T (s) = =
U (s) 1 + C(s)Ppend (s)
After that we build a MATLAB system:
1 M = 0.5;
2 m = 0.2;
3 b = 0.05;
4 c = 0.1
5 I = 0.006;
6 g = 9.8;
7 l = 0.3;
8 q = ( M + m ) *( I + m * l ^2) -( m * l ) ^2;
9 s = tf ( ’s ’) ;
10 P_pend = ( m * l * s / q ) /( s ^3 + ( c *( I + m * l ^2) -b * c ) * s ^2/ q - (( M + m ) * m * g * l ) * s /
q - c*m*g*l/q);

Then add the PID control properties: Kp = Ki = Kd = 1

1 Kp = 1;
2 Ki = 1;
3 Kd = 1;
4 C = pid ( Kp , Ki , Kd ) ;

13
5 T = feedback ( P_pend , C ) ;
6 t =0:0.01:10;
7 impulse (T , t )
8 title ({ ’ Response of Pendulum Position to an Impulse Disturbance ’; ’ under
PID Control : Kp = 1 , Ki = 1 , Kd = 1 ’ }) ;

And get the result, the system was not balanced, so we need to change the control prop-
erties:

Figure 3.1: Result 1

14
Then we change to Kp = 100, Ki = Kd = 1:

1 Kp = 100;
2 Ki = 1;
3 Kd = 1;
4 C = pid ( Kp , Ki , Kd ) ;
5 T = feedback ( P_pend , C ) ;
6 t =0:0.01:10;
7 impulse (T , t )
8 axis ([0 , 2.5 , -0.2 , 0.2]) ;
9 title ({ ’ Response of Pendulum Position to an Impulse Disturbance ’; ’ under
PID Control : Kp = 100 , Ki = 1 , Kd = 1 ’}) ;

And get the following result. It contains a big overshoot at start, which made the final
result can not reaches the perfect balance point as expected.

Figure 3.2: Result 2

15
Then continue the simulation with Kp = 100, Ki = 1, Kd = 20:
1 Kp = 100;
2 Ki = 1;
3 Kd = 20;
4 C = pid ( Kp , Ki , Kd ) ;
5 T = feedback ( P_pend , C ) ;
6 t =0:0.01:10;
7 impulse (T , t )
8 axis ([0 , 2.5 , -0.2 , 0.2]) ;
9 title ({ ’ Response of Pendulum Position to an Impulse Disturbance ’; ’ under
PID Control : Kp = 100 , Ki = 1 , Kd = 20 ’ }) ;

And then we get the result. With this control, the oscillation has been damped, and the
overshoot has reduced.

Figure 3.3: Result 3

The final result reached the perfect balance point as expected, and a small overshoot.
The system has been successfully controlled.

16
b. LQR Control
System modeling
Base on the theory of the equation of motion, we generate the system matrices to perform
state space representation:
x = −Kx, x = [θ, θ̇, x, ẋ]T
And control matrices, which are based on LQR control. With p = I(M + m) + M ml2
 
0 1 0 0
0 − c(I+ml2 ) − m2 gl2 0
p p
A=
 
0 0 0 1

 
mgl(M +m)
0 − mlc
p p
0

0
 
 I+ml2 
B= p 
 0 
ml
p
 
1 0 0 0
0 1 0 0
C=
0

0 1 0
0 0 0 1
 
0 0 0 0
0 0 0 0
D=
0

0 0 0
0 0 0 0
Then we have the Simulink diagram below.

Figure 3.4: LQR control Simulink diagram

After a short test, we have the result below:

17
Figure 3.5: Simulation result 1

Result discussion
The pendulum starts with small overshoot, and get to the balance point after 3 seconds.
The system has been successfully controlled.

c. No Control model
In no control model, it required that we have to build a full system with all the terms of
pendulum motion. So we have the Simulink diagram and the simulation result below:

18
Figure 3.6: Full terms system

Figure 3.7: Result of each terms

At the displacement of the cart, it starts with a small overshoot and damped oscilla-
tion. The cart exhibited rapidly, then settled to a stop.

In angular behavior, the pendulum starts with a sharp oscillation at the beginning, the
pendulum was undergoing a large swing, then the converted angle closed to the steady
value, which is 180o , which means that the pendulum is upright and balanced.

At the velocity of the cart, it starts with a sharp oscillation, reaches a sharp peak at
about 7th seconds, then slows down to 0. Where the pendulum is balance.

For the behavior of the angular velocity, it starts to oscillate with high frequency at
the beginning, then slowing down to 0 at the steady point of the pendulum.

19
This graph shows that the simulation is successfully controlled, but still requires more
time to damp out the oscillation.

d. Combined control model


Here is some of our simulation animation of the inverted pendulum using Simscape.

Figure 3.8: Simulation animation 1 - Pendulum during swing-up.

Figure 3.9: Simulation animation 2 - Pendulum balanced.

20
Chapter 4

System Design - Hardware

Since the tutorial has already provided us with a list of required hardware supplies as well
as a zipped folder containing all the 3D parts, it was relatively simple in purchasing and
printing these items.

There were some difficulties when it comes to acquiring these items due to numerous
reasons: unreliable providers, unclear/wrong instructions from the tutorial and also the
sparsity of certain items. They will be further explained later.

4.1 General Hardware


The general hardware required to assemble the physical model though little in amount,
was the most problematic process during acquisition compared to the rest of the items in
this chapter.

a. Item List
First, we have a compiled lists of these items:

21
Table 4.1: General Hardware list.

NO. NAME AMOUNT NOTE


The dimensions of these bearings are
1 626 Bearings 16 6x19x6mm for inner diameter, outer
diameter and thickness.
These teethed timing pulley has 20
2 GT2 Timing Pulleys 2 teeth and an inner diameter of 5mm,
accommodating 6mm thick timing belts.
We bought a total of one meter in length
3 GT2 Timing Belts 1 meter
of these belts to be used with the pulleys.
These are used to screw in/connect/fix
most of the 3D printed parts together as
4 M4 Bolts and Nuts 40
well as providing mounting spots for the
bearings and the pendulum.
4 pairs were needed to fix the NEMA 17
5 M3 Bolts and Nuts 4
Step motor to the assembly.
The pipes were cut in half to provide as
6 ϕ 27 PVC piping ∼2 meters
railing for the cart.
These pipes were cut and made to be
7 ϕ 6 Silicon piping ∼30 centimeters fittings for the bearings so that they can
be tightly fitted when screwed with M4 bolts.
Some WD-40 were applied to some bearings
8 WD-40 Lubricant 1 can to lower friction for the cart wheels and
pendulum pivot point.

It should be noted that this was the required and used amount, certain items like
bearings, pulleys, bolts and nuts were bought in excess were there to be any cases of lost,
breakage or unexpected usage.

The silicon piping and lubricant were our team’s own resolves and were not included
in the tutorial list of required hardwares.

b. Problems & Troubleshooting


One of the biggest problem was the bearings. Initially, the tutorial didn’t clearly spec-
ify which bearing to use, only leaving a Amazon store purchasing link and mentioning
”...I used skateboard bearings and they worked great...”. The Amazon link lead to a
7x22x8mm bearing, which is indeed the standard/universal bearing used for skateboards.

When these were to be slotted and screwed into the 3D printed models, they did not
fit. It turns out they were too big and we have to do further research to find the right
bearings. Measuring the slots for the parts and comparing with the feedbacks of the
tutorial showed us that we needed a bearing of the dimensions 6x19x6mm, which is the
626 bearings.

Acquiring these were rather difficult as most shops in online stores are international or
have ran out of these bearings. The official retail store of SKF (who sells industrial grade

22
bearings) do sells these bearings but were at an incredibly high price at 50.000 - 60.000
VND/bearing.

It took us up to 5 days of searching through the city to find a shop that finally had
an available stock for civilian grade ones to use for these types of project. This single
item was a logistical nightmare and greatly delayed our realization of the project’s model.

4.2 3D Printed Parts


There weren’t any complications regarding the 3D files for the parts of the model, so
acquiring these core components were relatively easy. It is notable that all of the parts
were printed in one single session as they are somewhat small, combined with their simple
structures.

While STL files contained no measurements in exports, we had initial concerns regarding
wrong sizing when printing, however after opening them and checking with AutoDesk
Fusion, the models were up to measure and the prints were perfect.

a. Item List
First, we have a compiled lists of these items:

23
MODEL AMOUNT DESCRIPTION
2 GANTRY ROLLER

• Encircles the pipes

• Act as wheels

• Drive with bearing

1 GANTRY PLATE

• Carries pendulum

• Platform for cart

• Connected to belts

2 BELT ATTACHMENT

• Attach belts to gantry

Table 4.2: 3D parts (Page 1).

24
NAME AMOUNT DESCRIPTION
1 PENDULUM HOLDER

• Attach pendulum to gantry

• Pivots pendulum

1 PENDULUM-BEARING
HOLDER (A)

• Holds the pendulum along with


Part B

• Acts as secondary bearing place-


ment

• Inner part facing the gantry

1 PENDULUM-BEARING
HOLDER (B)

• Holds the pendulum along with


Part A

• Acts as primary bearing place-


ment

• Outer part facing environment

• Houses the pendulum

Table 4.3: 3D parts (Page 2).

25
NAME AMOUNT DESCRIPTION
1 PENDULUM (A)

• Fitted with a bearing inside pen-


dulum holders

• Housed in pendulum holders

1 PENDULUM (B)

• Extended from part A

• Fitted with the MPU6050 IMU


sensor

4 END CAPS

• Acts as caps for the pipe and end


of rail

• Provide placement for the


idle/stepper plate

Table 4.4: 3D parts (Page 3).

26
NAME AMOUNT DESCRIPTION
2 IDLE PULLEY BEARING
HOLDER

• Houses bearing and the pulley for


the return pulley

• Attached to the idle pulley plat-


form

1 IDLE PULLEY HOLDER PLATE

• Placed upon one pair of end caps

• Act as the idle pulley platform

1 STEPPER BRACKET

• Houses the NEMA17 step motor

• Fitted to the stepper holder plate

Table 4.5: 3D parts (Page 4).

27
NAME AMOUNT DESCRIPTION
1 STEPPER HOLDER PLATE

• Placed upon one pair of end caps

• Act as the stepper pulley plat-


form

1 PULLEY HOLE SPACER

• Fitted in the GT2 pulleys

14 BEARING HOLE SPACER

• fitted in the all of the bearings

Table 4.6: 3D parts (Page 5).

28
b. Problems & Troubleshooting
There weren’t any problems with the 3D parts save for some replacement. We had to
replace all the spacer/fitings in the bearings with silicon piping instead as due to printing
limitations, the Pulley/Bearing hole spacer proved to be difficult to print and were to
rough to even be able to work with in the first place. Despite our efforts to sand the
model, they still easily break after a short while after being screwed in and fitted.

The Silicon piping was perfect to be made into fittings for the bearings as they were
easy to work with. Small cylinders were easily cut from the pipe with similar dimensions
to the bearing hole spacer with and can be slotted in smoothly. The inner diameter
were a perfect fit for the M4 bolts also. This cheap replacement was one of the better
improvement we made upon the tutorial’s guidance.

c. Assembly
The total physical rig is made up of 3 different part: the gantry, the idle pulley section,
and the stepper pulley section.

The Gantry

(a) Front face (b) Rear

Figure 4.1: The Gantry

Then we assemble it with the pipe.

29
Figure 4.2: The gantry with the pipe

The Pendulum

Figure 4.3: The pendulum

Idle Pulley and Stepper Pulley


Here is the Idle Pulley:

30
Figure 4.4: The Idle Pulley

And the Stepper Pulley with Motor:

Figure 4.5: Stepper Pulley

31
Chapter 5

System Design - Electronics

5.1 Adruino R3
In this project, we utilised the Arduino R3 kit as the controller for the system. Its
specifications are shown in the following table.

Category Details
Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage (recommended) 7–12V
Input Voltage (limits) 6–20V
Digital I/O Pins 14 (6 provide PWM output)
PWM Digital I/O Pins 6
Analog Input Pins 6
DC Current per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328P)
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz

Table 5.1: Specifications of the Arduino Uno R3

Figure 5.1: Arduino R3

32
Figure 5.2: MPU-6050 sensor

5.2 MPU-6050 six-axis


The pendulum requires a sensor to track its motion. The MPU-6050 six-axis was employed
to measure the angle and angular velocity of the pendulum using the 3-axis gyroscope
and accelerometer. The following table indicates the sensor’s specifications.

Specification Value
Sensor Type 3-axis Gyroscope + 3-axis Accelerometer
Communication Interface I2C (up to 400 kHz)
Operating Voltage 2.3V – 3.4V (typ. 3.3V)
Logic Level 3.3V (5V tolerant on breakout boards)
Gyroscope Range ±250, ±500, ±1000, ±2000 °/s
Accelerometer Range ±2g, ±4g, ±8g, ±16g
Resolution 16-bit for both gyro and accelerometer
Power Consumption ˜3.9 mA (active mode)
Default I2C Address 0x68 (or 0x69 with AD0 high)

Table 5.2: Specifications of the MPU-6050 Sensor

5.3 Stepper motor and Stepper motor driver


As for the system’s actuator, a stepper motor (Fig 5.3) was used to drive the belt, which
is attached to the gantry. The specifications of the stepper motor are shown in table 5.3.
However, we need a ’translator’ to make the motor understand the arduino’s commands.
Thus, the stepper driver was utilised, and for this project, we used the HR4988 stepper
motor driver. Its figure and specifications are shown below (Fig 5.4 and table 5.4).

33
Figure 5.3: Stepper Motor

Figure 5.4: A4988 Stepper Motor Driver

34
Specification Value
Motor Type Bipolar Stepper
Step Angle 1.8◦ (200 steps/revolution)
Holding Torque 59 N·cm (83.6 oz·in)
Rated Current/Phase 2.0 A
Phase Resistance 1.4 Ω
Inductance 3.0 mH ± 20% (1 kHz)

Table 5.3: Specifications of the Stepper Motor

Specification Value
Motor Supply Voltage (VMOT) 8 V to 35 V
Logic Voltage (VDD) 3 V to 5.5 V
Continuous Current per Phase Up to 1 A (without heat sink)
Maximum Current per Phase Up to 2 A (with sufficient cooling)
Microstepping Resolutions Full, 1/2, 1/4, 1/8, 1/16 steps
Control Interface STEP and DIR pins

Table 5.4: Specifications of A4988 Stepper Motor Driver

35
Chapter 6

System Design - Software

Arduino code structure.


Sensor filtering (e.g., complementary or Kalman).
Real-time control loop and sampling.
Synchronization issues, latency, etc.

36
Chapter 7

Results and Discussion

Experimental results: plots, measurements, observed behavior.


Comparison to simulation.
Performance evaluation (stability, robustness, error).
Discussion of errors and limitations.
Summary of what was achieved.
Key takeaways and learning outcomes.
Suggestions for future work (e.g., improved filtering, wireless telemetry, adaptive con-
trol).

37
Chapter 8

Conclusion

38
Bibliography

39
Appendix A

Arduino Code

1 # include " I2Cdev . h "


2 # include < AccelStepper .h >
3 # include " MPU6050 . h " // <-- Use raw data , not DMP for Kalman
4 # include < PID_v1 .h >
5 # include < Kalman .h > // <-- Kalman filter library
6
7 # if I 2 C D EV _ I M P L E M E N T A T I O N == I 2 C DE V _ AR D U IN O _ WI R E
8 # include " Wire . h "
9 # endif
10
11 double Setpoint , Input , Output ;
12
13 MPU6050 mpu ;
14 AccelStepper stepper (1 ,4 ,3) ;
15 PID myPID (& Input , & Output , & Setpoint ,2 ,5 ,1 , DIRECT ) ;
16 Kalman kalmanX ; // Kalman filter for roll
17

18 # define INTERRUPT_PIN 2
19 # define LED_PIN 13 // ( Arduino is 13 , Teensy is 11 , Teensy ++ is 6)
20 bool blinkState = false ;
21
22 // For time calculations
23 unsigned long prevTime = 0;
24 float dt = 0;
25
26 // Sensor data
27 int16_t ax , ay , az ;
28 int16_t gx , gy , gz ;
29
30 void setup () {
31 # if I2 C D E V _ I M P L E M E N T A T I O N == I 2 C DE V _ AR D U IN O _ WI R E
32 Wire . begin () ;
33 Wire . setClock (400000) ; // 400 kHz I2C clock
34 # elif I 2 C D E V _ I M P L E M E N T A T I O N == I 2 C D E V _ B U I L T I N _ F A S T W I R E
35 Fastwire :: setup (400 , true ) ;
36 # endif
37
38 Serial . begin (115200) ;
39 while (! Serial ) ;
40

41 Serial . println ( F (" Initializing I2C devices ...") ) ;


42 mpu . initialize () ;
43 pinMode ( INTERRUPT_PIN , INPUT ) ;

40
44
45 Serial . println ( F (" Testing device connections ...") ) ;
46 Serial . println ( mpu . testConnection () ? F (" MPU6050 connection
successful ") : F (" MPU6050 connection failed ") ) ;
47
48 Setpoint = 0; // Keep pendulum upright ( roll = 0)
49
50 stepper . setMaxSpeed (1000) ;
51 stepper . setAcceleration (10000) ;
52 stepper . setSpeed (1000) ;
53
54 myPID . SetMode ( AUTOMATIC ) ;
55
56 pinMode ( LED_PIN , OUTPUT ) ;
57
58 prevTime = millis () ;
59
60 // Initial Kalman angle set
61 mpu . getMotion6 (& ax , & ay , & az , & gx , & gy , & gz ) ;
62 float roll = atan2 ( ay , az ) * 180 / M_PI ;
63 kalmanX . setAngle ( roll ) ;
64 }
65
66 void loop () {
67 // Calculate dt
68 unsigned long now = millis () ;
69 dt = ( now - prevTime ) / 1000.0; // seconds
70 prevTime = now ;
71
72 // Read raw sensor data
73 mpu . getMotion6 (& ax , & ay , & az , & gx , & gy , & gz ) ;
74
75 // Calculate roll from accelerometer ( change axis if your hardware
is different )
76 float accelRoll = atan2 ( ay , az ) * 180 / M_PI ;
77

78 // Gyro rate in deg / s ( change sign if the direction is opposite )


79 float gyroRate = gx / 131.0;
80
81 // Kalman filter : fused angle estimate
82 float kalmanRoll = kalmanX . getAngle ( accelRoll , gyroRate , dt ) ;
83

84 // Use filtered angle as PID input


85 Input = kalmanRoll ;
86 myPID . Compute () ;
87
88 // Use PID output as stepper speed ( tune limits for your hardware )
89 int stepperSpeed = constrain ( Output , -1000 , 1000) ;
90 stepper . setSpeed ( stepperSpeed ) ;
91 stepper . runSpeed () ;
92
93 // Debug output
94 Serial . print (" Accel roll : ") ; Serial . print ( accelRoll ) ;
95 Serial . print ("\ tGyro rate : ") ; Serial . print ( gyroRate ) ;
96 Serial . print ("\ tKalman roll : ") ; Serial . print ( kalmanRoll ) ;
97 Serial . print ("\ tStepper speed : ") ; Serial . println ( stepperSpeed ) ;
98
99 // Blink LED to indicate activity

41
100 blinkState = ! blinkState ;
101 digitalWrite ( LED_PIN , blinkState ) ;
102 }

42
Appendix B

Bill of Materials and Cost


Breakdown

43
Appendix C

Work Distribution between Members

Table C.1: Work distribution table.

NO. ID NAME WORK DONE


Wrote Latex report for the following
sections:
- Introduction
- Abstract
- System Design - Hardware
1 23BI14174 PHAN HUY HOANG
- System Design - Software
- Results and Discussion
- Conclusion

Worked on the code and hardware


Found and purchased electronics
Provided the main working tools
2 23BI14443 TRAN ANH TUAN
Worked on wiring and software
Keeper of Bills
Wrote Latex report for the following
sections:
- Theoretical Background
3 23BI14231 LE DUC KHOI
- Simulation and Validation

Worked on theory and simulation


Made the Powerpoint Presentation
4 23BI14232 TRINH PHAN MINH KHOI
Worked on hardware
Found and purchased hardware
5 23BI14339 NGUYEN HOANG NGHIA 3D printed the components
Worked on hardware and housing

44

You might also like