Example 1
Example 1
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.
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.
2
Figure 3: Arduino Nano.
Figure 4: IMU MPU6050
2.4 Assemble
Assemble all components.
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.
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