0% found this document useful (0 votes)
29 views4 pages

Example 1

Uploaded by

Tùng Thanh
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)
29 views4 pages

Example 1

Uploaded by

Tùng Thanh
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/ 4

PID Controller for a Two-Wheeled Balancing Vihicle

Vuong Thanh Tung


Faculty of Engineering Mechanics and Automation (FEMA), VNU-University of
Engineering and Technology

August 1, 2024

Abstract
This paper explores the design of a Proportional-Integral-Derivative (PID) controller for
a two-wheeled self-balancing vehicle. Although various control techniques exist, selecting an
appropriate control theory is crucial for effective balance. The PID controller is implemented
to regulate the vehicle’s tilt angle and maintain stability. Simulation and experimental re-
sults validate the controller’s performance, demonstrating its efficacy in ensuring balance and
responsiveness to disturbances.

1 Introduction
The inverted pendulum on a cart is a classic control system problem widely used in both education
and testing of control algorithms. This problem involves a pendulum mounted on a cart. The
objective is to balance the pendulum in an upright position by applying a force to the cart on a
horizontal plane as the control input, as illustrated in Figure 1.
The inverted pendulum problem is often compared to balancing a stick on one’s hand. It has
many similarities to real-world applications such as two-wheeled balancing devices, commercially
known as the Segway. From a control system perspective, the IPC system has many interesting
properties. Due to the pendulum’s rotation, the system is non-linear. It is a Single Input, Multiple
Output (SIMO) system with one input (the horizontal force) and two degrees of freedom (the cart’s
position and the pendulum’s angle). With the pendulum in the upright position, the system is
unstable and therefore requires active control to maintain this state.

Figure 1: Inverted Pendulum.

1
2 Hardware
2.1 Stepper Motor
Stepper motors are manufactured with permanent magnets and a stator consisting of multiple
coils. The changing magnetic field created by the coils causes the motor to rotate, which results
in the stepping characteristic of the motor. This means that the activation of the coils must be
continuously alternated to keep the motor running. Therefore, a stepper motor driver is needed
to control the direction and speed of the motor. The stepping characteristic of stepper motors
and the use of controllers with stepper motors imply that rotation angle, angular velocity, and
angular acceleration are controlled, rather than output torque. The torque generated is assumed
to be sufficient to move the load attached to the motor. If it is not sufficient, the motor will not
move. This means that the combination of the motor and the controller must be able to generate
enough torque to meet all possible requirements. The torque of the motor reaches its maximum at
zero angular velocity. In this state, there is no change in the activation of the motor coils or any
movement of the motor. As the angular velocity of the motor increases, the torque of the stepper
motor decreases. Therefore, it is necessary to limit the angular velocity of the motor within a
range where it has sufficient torque to pull the load. With a stepper motor, the control input will
always produce the same movement output due to the precision of stepper motors compared to DC
motors, thus minimizing ambiguity in the system’s coordinates and reducing the need for devices
to monitor the DC motor, such as encoders.

Figure 2: Stepper Motor NEMA 17.

2.2 Controller Unit


The Atmega328p is an 8-bit microcontroller from the AVR family produced by Atmel (Microchip).
It is widely used in embedded applications because of its low cost, ease of use, and good perfor-
mance. The Atmega328p has 32 KB of flash memory, 2 KB of RAM, and 1 KB of EEPROM. It
also has 23 versatile I/O pins that can be used for various purposes such as digital input/output,
A/D conversion, serial communication, etc.
The Arduino Nano is a microcontroller board based on the Atmega328p. It is a miniaturized
version of the Arduino Uno, but retains basic features such as programming with the Arduino
language, USB communication, and support for multiple Arduino shields. The Arduino Nano is
designed for projects that require compactness and flexibility.

2.3 IMU Sensor MPU6050


The IMU MPU6050 is a 6 DoF (Degree of Freedom) inertial measurement unit sensor manufactured
by InvenSense. It combines a 3-axis accelerometer and a 3-axis gyroscope on a single compact chip,
providing users with accurate motion and orientation data.

2
Figure 3: Arduino Nano.
Figure 4: IMU MPU6050

2.4 Assemble
Assemble all components.

Figure 5: Two-Wheeled Vihicle.

3 Modeling
An inverted pendulum mounted on a motor-driven car is shown in Figure 6. This is a model of the
attitude control of a space booster on takeoff. The objective of the attitude control problem is to
keep the space booster in a vertical position. The inverted pendulum is unstable in that it may fall
over any time in any direction unless a suitable control force is applied. Here we consider only a
two-dimensional problem in which the pendulum moves only in the plane of the page. The control
force u is applied to the cart. Assume that the center of gravity of the pendulum rod is at its
geometric center. Obtain a mathematical model for the system. Define the angle of the rod from
the vertical line as θ. Define also the (x, y) coordinates of the center of gravity of the pendulum
rod as (xG , yG ). Then
xG = x + l sin θ
yG = l cos θ
To derive the equations of motion for the system, consider the free-body diagram shown in
Figure 7. The rotational motion of the pendulum rod about its center of gravity can described by

I θ̈ = V l sin θ − Hl cos θ

whereI is the moment of inertia of the rod about the center of gravity.
The horizontal motion of center of gravity of pendulum rod is given by
d2
m (x + l sin θ) = H
dt2

3
Figure 6: Inverted pendulum system. Figure 7: Free-body diagram.

The vertical motion of the center of gravity of pendulum rod is


d2
m (l cos θ) = V − mg
dt2
The horizontal motion of cart is described by
d2 x
M =u−H
dt2
Since we must keep the inverted pendulum vertical, we can assume that θ(t) and θ̇(t) are small
quantities such that sin θ = 0 , cos θ = 1 and θθ̇2 = 0. The linearized equations are

I θ̈ = V lθ − Hl

m(ẍ + lθ̈) = H
0 = V − mg
We obtain
(M + m)ẍ + mlθ̈ = u
and
(I + ml2 )θ̈ + mlẍ = mglθ
Two equations above describe the motion of the inverted pendulum on the cart system. They
constitute a mathematical model of the system.

4 Model Validation
4.1 Model Parameter Estimation
4.2 Model Verification
4.3 Mathematical Model of the System

5 PID Controller
5.1 Block Diagram of the Control System
5.2 Discretization
5.3 Implementing

6 Conclusion

You might also like