Self Balancing Robot: Fatima Abbas, Hasnain Irshad, Hafiz Muhammad Faisal and Eman Ahmed December 17, 2018
Self Balancing Robot: Fatima Abbas, Hasnain Irshad, Hafiz Muhammad Faisal and Eman Ahmed December 17, 2018
Fatima Abbas, Hasnain Irshad, Hafiz Muhammad Faisal and Eman Ahmed
December 17, 2018
Abstract
Two wheeled balancing robots are an area of research that may well provide the
future locomotion for everyday robots. The control system that is required to keep
the robot upright with stability differentiates it from traditional forms of robotics. It
involves a control system of simple inverted pendulum which is utilized to develop and
implement a suitable control system that is responsive, stable, timely and successful
in achieving the objective of self-balancing.
Making the design and development phase of the robot requires careful consid-
eration of all aspects including operating conditions, materials, hardware, physical
parameters, sensors and software. This process provides an ongoing opportunity of
implementing continued improvements to its perceived operation whilst also ensuring
that obvious problems and potential faults are removed before construction.
The construction phase entails the manufacture and assembly of the robot circuits,
hardware and chassis with the software and programming aspects then implemented.
The later concludes the robots production where the final maintenance considerations
can be determined. These are essential for ensuring the robots continued serviceabil-
ity.
The analysis and evaluation of the completed robot provides the ability to assess
the robots effectiveness and efficiency in maintaining stability. This allows a compar-
ison to be undertaken between the actual system performances and the anticipated
project objectives. The opportunity to calibrate and perform additional fine tuning
of the design is also explored. The project is concluded with comments on each as-
pect of the project with recommendations for improvement, additional capabilities
and future areas of investigation.
1 Introduction
Robotics has always played an integral part of the human psyche. The dream of creating
a machine that replicates human thought and physical characteristics extends throughout
the existence of mankind. Robotics is now achievable through the miniaturisation of the
microprocessors which performs the processing and computations. New forms of sensor
devices are being developed all the time further providing machines with the ability to
identify the world around them in so many different ways.[1]
1
Inverted pendulum applications are plenty; for example, the human body is an inverted
pendulum balancing the upper body around our ankle joints in every step. To develop a
reliable and capable control system for a two-wheeled balancing robot, an understanding
of the parameters within the system is essential. Representation of these can be achieved
through a mathematical model. Inverted pendulum theory is more traditionally known
as Pole and Cart theory and although the two-wheeled balancing robot does not directly
compare to the Pole and Cart, the same principles are in effect.[2] Within the system
model, the cart equates to the wheels while the pole equates to the robots chassis. Friction
coefficients have been neglected in this project as the robot will be expected to transverse
across numerous types of terrains and surfaces. If the coefficients were to be considered
during the control systems design and implementation, then additional sensors, circuitry
and power consumption would be required to derive these new values whilst in operation.
The time, effort and resources required to create this capability far exceed any benefits
that could be expected with there inclusion. [3]
The robot is driven by two DC motors and is equipped with an STM32-f401-Vctx. To
compensate for gyro drifts a complementary filter is implemented; for a single-axis problem
such as this balancing robot, the complementary filter approach is significantly simpler than
the Kalman filter.[4]
Proportional-integral-differential (PID) control is used to deal with small tilt angles.
2 System Implementation
An inverted pendulum is a pendulum that has its center of mass above its pivot point. It
is often implemented with the pivot point mounted on a cart that can move horizontally
and may be called a cart and pole. Whereas a normal pendulum is stable when hanging
downwards, an inverted pendulum is inherently unstable, and must be actively balanced
in order to remain upright; this can be done either by applying a torque at the pivot
point, by moving the pivot point horizontally as part of a feedback system, changing the
rate of rotation of a mass mounted on the pendulum on an axis parallel to the pivot axis
and thereby generating a net torque on the pendulum, or by oscillating the pivot point
vertically.
g
θ̈ = sin θ (1)
`
Thus, the inverted pendulum will accelerate away from the vertical unstable equilibrium
in the direction initially displaced, and the acceleration is inversely proportional to the
length. Tall pendulums fall more slowly than short ones. Following kinetic equations
describe the non-linear behavior of an inverted pendulum. They are known as Lagrange’s
Equations.[5]
(M + m) ẍ − m`θ̈ cos θ + m`θ̇2 sin θ = F (2)
2
2.1 Essentials of Stabilization
The aim of the inverted pendulum principle is to keep the wheels beneath the centre of the
robot chassis mass.
• If the robot begins to tilt forward, then to maintain stability, the wheel will need to
move in the inclined direction with a speed proportional to angle and acceleration
of falling to correct the inclination angle. So when the deviation from equilibrium
is small, it should move gently and when the deviation is large it should move more
quickly. If this is not maintained, the robot will simply fall over.
• If the tilt angle is to the right, the cart must accelerate to the right and vice versa.
2.2 Hardware
The components required for hardware are:
• Microcontroller STM32F401VCTx
• Optocoupler 4N35
• MPU
• Bluetooth hc05
• DC Motor
3
2.2.1 Microcontroller STM32F401VCTx
The STM32F401 microcontrollers are part of the STM32 Dynamic Efficiency device range.
These devices offer the best balance of dynamic power consumption (in run mode) and
processing performance. it has data bus width of 32 bit. Maximum clock frequency is upto
168 MHz. There are 82 I/O pins as shown in Figure 2 and several interfaces are integrated
such as CAN, I2C, SPI etc.1.8 to 3.6V is the operating voltage and the it’s current rating
is 24 mA. [6]
Figure 2: STM32F401VCTx
4
2.2.3 Motor Driver L298N
H-Bridge is a motor driving circuit. It consists of four switches. It can be used to drive
the motor either in clockwise direction or counter clockwise direction. When the diagonal
switches are closed then the current path is complete and motor moves in either of the
direction accordingly. One H-Bridge can drive two motors at a time. H-Bridge circuit, at
its input, has three pins as shown in Figure 4,
first input pin is for 12V supply, middle pin is for Ground and the last pin can supply
5V. At its output, it has four pins, two pins to energize each motor. [7]
Figure 4:
5
2.2.5 MPU-6050
IMU sensors are one of the most common types of sensors used today in all kinds of
electronic gadgets. IMU sensors help us in getting the attitude of an object, attached to
the sensor in three-dimensional space. These values are usually in angles to help us to
determine its attitude. They are used in smartphones to detect their orientation or in
wearable gadgets like the Fit Bit, which use IMU sensors to track movement. IMU sensors
usually consist of two or more parts. Listing them by priority, they are the accelerometer,
gyroscope, magnetometer, and altimeter. The MPU 6050 is a 6 DOF (Degrees of Freedom)
or a six-axis IMU sensor, which means that it gives six values as output. Three values
from the accelerometer and three from the gyroscope. The MPU 6050 is a sensor based on
MEMS (Micro Electro Mechanical Systems) technology. Both the accelerometer and the
gyroscope are embedded inside a single chip. This chip uses I2C (Inter-Integrated Circuit)
protocol for communication. [8] Figure 6 shows a MPU.
The accelerometer measures theta (angle of tilt) and consequently it sends data to the
controller card. Another component he explained was a gyroscope that measures angular
velocity. Due to inherent noise factor in both of these components, a complementary filter
use was suggested. This filter takes fifty percent data from gyroscope and fifty percent
from accelerometer and calculates error signal to be sent to the controlling function. VCC
and GND are given through STM. PA8 of STM is connected to SCL and PC9 is connected
to SDA.
2.2.6 DC Motor
A small DC motor is used which has wider applications all over the world ranging from
small toys to large industries. It converts DC energy into mechanical energy. Figure 7
shows a DC motor
6
Figure 7: DC Motor
2.3 Software
The software part can be divided into further sections for better understanding:
2. Complementary filter
4. PWM generation
Pitch = arctan (-ax/az) And to measure angle from gyroscope, all we have to do is to
integrate the angular velocity over time. These angles are measured after every 1 milli
second, which is done using a timer with prescaler set as 84 and reload value equal to 1000
at frequency of 84 MHz.
7
Figure 8: Angles measured through MPU6050
8
Kp:
Proportional controller gives output which is proportional to current error. It compares
desired point with actual value. Speed of the response is increased when the proportional
constant Kp increases. It reduces the rise time, increases the overshoot, and reduces the
steady-state error.
Ki:
I-controller provides necessary action to eliminate the steady state error. It integrates
the error over a period of time until error value reaches to zero. It limits the speed of
response and affects stability of the system. Speed of the response is increased by decreasing
integral gain Ki. It decreases the rise time while increases both overshoot and settling time.
Kd:
Its output depends on rate of change of error with respect to time, multiplied by deriva-
tive constant. It improves the stability of system by compensating phase lag caused by
I-controller. Increasing the derivative gain increases speed of response. Kd has no effect
on rise time or steady state error but it increases settling time and decreases overshoot of
the system.
Tuning of PID:
Here we are using the first method i.e Trial and Error Method to calculate the Kp,
Ki, Kd values as the transfer function is unknown. In this method, first we have to set
Ki and Kd values to zero and increase Kp until system reaches to oscillating behavior.
Once it is oscillating, adjust Ki so that oscillations stops and finally adjust Kd to get
fast response. Advantages: PID is easier to implement and gives a better response to
unmeasured disturbances. Once its designed for a given system, it does not require further
tuning. Moreover it is not heavy on hardware.
9
2.3.5 Communication through Android mobile app
A mobile application is designed using MIT App Inventor through which we can control the
directions of our self-balancing robot. It also allows you to change the reference position
as well as duty cycle of PWM.
2.3.6 Approach
The tentative approach that was used to make the robot balance itself is as follows:
2.3.7 Flowchart
The control of the SBR is given in a owchart as follows: Complementary
lter takes the values from the MPU and estimate the tilt angle, error in which is sent
to PID for duty cycle calculation to compensate that error, thus balancing the robot.
10
Figure 11: Flow Chart
3 Results
This section describes in detail the results of the project.
11
to add even more complexity to the loop. We added in a serial communications interface
for the navigation of the robot. Serial communication of the Stm with the STM Studio via
USB cable allowed us to tune the PID values while observing the performance of the robot.
12
Figure 12: Self Balancing Robot
13
References
[1] Balasubramanian, Siddhartha and Lathiff, Nabil. ”SELF BALANCING
ROBOT” [Online]. Available: Research Gate, https://www.researchgate.net
[Accessed: 16- Dec- 2018].
[2] Hau-Shiue, Juang and Lum, Kai-Yew ”Design and control of a two-wheel self-
balancing robot using the arduino microcontroller board” [Online]. Available:
Research Gate, https://www.researchgate.net [Accessed: 16- Dec- 2018].
[3] Shanmugavel, Baskaran and Raja, Karthik ”Development of Self Balancing
Robot” [Online]. Available: Research Gate, https://www.researchgate.net [Ac-
cessed: 16- Dec- 2018]
[4] Kth.diva-portal.org, 2018. [Online]. Available: https://kth.diva-
portal.org/smash/get/diva2:916184/FULLTEXT01.pdf. [Accessed: 17- Dec-
2018].
[5] ”Inverted pendulum”, En.wikipedia.org, 2018. [Online]. Available:
https://en.wikipedia.org/wiki/Invertedpendulum. [Accessed: 17- Dec- 2018].
[6] ”STM32”, En.wikipedia.org, 2018. [Online]. Available:
https://en.wikipedia.org/wiki/STM32STM32F4. [Accessed: 17- Dec- 2018].
[7] ”H-Bridges” 2018. [Online]. Available: http://www.modularcircuits.com/blog/h-
bridges-the-basics [Accessed: 17- Dec- 2018].
[8] www-robotics.cs.umass.edu, 2018. [Online]. Available: http://www-
robotics.cs.umass.edu/ grupen/503/Projects/ArduinoMPU6050-Tutorial.pdf.
[Accessed: 17- Dec- 2018].
[9] Control.isy.liu.se, 2018. [Online]. Available: https://www.control.isy.liu.se [Ac-
cessed: 17- Dec- 2018].
[10] Loucif, Fatiha. ”DC MOTOR SPEED CONTROL USING PID CON-
TROLLER,” in Conf. ICCAS2005 June 2-5, KINTEX, Gyeonggi-Do, Korea
[Online]. Available: Research Gate, http://www.researchgate.net. [Accessed: 18
Nov. 2018].
14