0% found this document useful (0 votes)
84 views14 pages

Self Balancing Robot: Fatima Abbas, Hasnain Irshad, Hafiz Muhammad Faisal and Eman Ahmed December 17, 2018

This document describes a self-balancing robot project. It discusses the hardware components used, including a microcontroller, motor driver, sensors, and Bluetooth module. It also covers the control system design, which uses principles of an inverted pendulum and PID control to keep the robot upright through active balancing of its wheels. The goal is to develop a reliable control system to maintain stability as the robot moves.

Uploaded by

Arbab Haider
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)
84 views14 pages

Self Balancing Robot: Fatima Abbas, Hasnain Irshad, Hafiz Muhammad Faisal and Eman Ahmed December 17, 2018

This document describes a self-balancing robot project. It discusses the hardware components used, including a microcontroller, motor driver, sensors, and Bluetooth module. It also covers the control system design, which uses principles of an inverted pendulum and PID control to keep the robot upright through active balancing of its wheels. The goal is to develop a reliable control system to maintain stability as the robot moves.

Uploaded by

Arbab Haider
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/ 14

Self Balancing Robot

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)

`θ̈ − g sin θ = ẍ cos θ (3)

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.

The inverted pendulum control essentials are shown in Figure 1

Figure 1: Control Essentials of Inverted Pendulum

2.2 Hardware
The components required for hardware are:

• Microcontroller STM32F401VCTx

• Optocoupler 4N35

• Motor Driver L298N

• 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

2.2.2 Optocoupler 4N35


It has a LED that produces infra-red light and it shorts the collector and emitter of its
transistor, when given a high pulse at the input terminals. Basically it is used for electrical
isolation of two circuits. Pin configuration of Optocoupler is shown in Figure 3. PWM is
given to four optocouplers.

Figure 3: Pin Configuration

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:

2.2.4 Bluetooth HC05


The HC-05 is a module which can add two-way (full-duplex) wireless functionality to
projects. This module is used to communicate between two microcontrollers like Arduino
or communicate with any device with Bluetooth functionality like a Phone or Laptop. Pin
TXD is connected with PA10 of STM while Pin RXD is connected to PA9. HC05 is given
3.3V and ground through STM. Figure 5 shows a bluetooth module.

Figure 5: Bluetooth HC05

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.

Figure 6: MPU 6050

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:

1. Measuring Angles with MPU6050

2. Complementary filter

3. PID for compensation

4. PWM generation

5. Communication through Android mobile app

2.3.1 Measuring Angles with MPU6050


The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the
same silicon die, together with an onboard Digital Motion Processor (DMP).Accelerometer
measure magnitude of gravity, while Gyroscope measures speed of rotation. We can get
three angles (as seen in Figure 8) from accelerometer and Gyroscope to measure the precise
position and orientation of the object, which are: 1. Roll 2. Pitch 3. Yaw
In our code we are using Pitch as reference angle and controlling our robot on its basis.
We can simply find the pitch from accelerometer using the following formula:

P itch = arctan(−ax/az) (4)

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

2.3.2 Complementary Filter


We can get angles from Accelerometer and gyroscope but alone they cannot do a good
job, as accelerometer cant tell the difference between moving and stationary angles i.e it
is bad for fast changes. On the other hand Gyroscope is bad for slow changes .So using
complementary filter we can use accelerometer for static angles and Gyroscope for changing
angles i.e combining accelerometers low pass filter and gyros high pass filter. [9] This can
be done using the following formula:

Angle = 0.98 ∗ (Angle + gyroAngle ∗ dt) + 0.02 ∗ (accAngle) (5)

2.3.3 PID (Proportional, Integral and Derivative Control)


A proportional-integral-derivative controller (PID controller) is a control loop feedback
mechanism widely used in industrial control systems. In a PID Algorithm the current
speed of motor is measured and compared with our desired speed. Then by calculating the
error and performing calculations it restores the actual speed to the desired speed in the
optimum way i.e here the speed is continuously checked and controlled. PID uses three
basic control behaviors as shown in figure 9. [10]

Figure 9: PID Controller

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.

2.3.4 PWM generation


Pulse width modulation (PWM) is a method to control the amount of power delivered to
a load without dissipating any wasted power. Its literal mean is to vary the width of pulse.
PWM does this by changing the pulse width, which in turn, changes the duty Cycle. Duty
cycle is the percentage or the fraction during which the input signal is on in an interval.
So the larger the duty cycle percentage, the larger the output signal will be. For example
if the signal is on for half of the total period, the duty cycle is 50 percent. Duty cycle can
be calculated as:
D = (P W/T ) ∗ 100 (6)
Where D is the duty cycle, PW is the pulse width (pulse active time), and T is the total
period of the signal. The reason why we used the PWM to control the speed is due to
its greater efficiency and less heat dissipation. We are generating PWM on four pins PE9,
PE11, PE13 and PE14 to move the two motors in all directions i.e forward, backward, right
and left.

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:

Figure 10: Approach

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.

3.1 Control Loop Performance


The control loop frequency is the largest number of times the control loop can run in one
second. The higher this value is, the better the accuracy of the sensor integration and the
better the balancing. Our target for the control loop frequency was 1000Hz. While running
our STM board at its maximum of 84M Hz, it allowed 1000ms time to receive sensor data,
process it, and output the motor duty cycle. Upon implementing the code, we discovered
that the algorithm could easily run at over 1000Hz. This was much better as it allowed us

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.

3.2 Complementary Filter Accuracy


The complementary filter was very successful at combining the readings from the gyroscope
and the accelerometers while eliminating drift. Data was collected from the robot at a
frequency of 1000Hz. The robot was rotated on either side. The robot was also moved
horizontal to the ground to simulate acceleration without rotation. The data collected was
then run through the complementary filter on the desktop machine and the results were
observed. As a result, the filter successfully eliminates all gyroscopic drift.
The accelerometer records a lot of jitter and vibration, even when the robot is not
rotating. When these readings are processed, the estimate for the angle has quite a bit of
variation within a short period. The gyroscope, however, records accurately the rotation
but has the problem of the drift.
Combining the two sensors with the complementary filer having 99 percent weightage of
the gyroscope angle and 1 percent of the accelerometer readings yields the filtered estimate
which has none of the problems of the two individual sensors.

3.3 Balancing Performance


We set about tuning the PID controller to achieve the best balance. With only the pro-
portional gain, we managed to get the robot to oscillate about the 0-degree reference point
vertically which resulted in a lot amount of jitter. The robot could balance completely
on its own for about 15 seconds. After this time, the steady state error and oscillation
amplitude grew exponentially which would make the robot fall on one side.
Reducing the proportional gain and adding in the integral gain allowed the oscillation
amplitude to be dampened and gave somewhat smoothened response. The robot would now
balance with minimal jitter. The robot also responded to external disturbances (pushing
with a finger) very well. The robot regained balance very quickly. However, an excessive
disturbance caused it to oscillate wildly and then fall over. Adding in the derivative gain
reduced the overshoot but resulted in the jitter and oscillation. At this state in the tuning,
one effect that was very noticeable was that the robot could follow a finger with minimal
force.
Further tuning would allow the robot to balance indefinitely. However, there was a lot
of play in the gear motors and the angle sensor we were using. Hence further tuning did
not affect the balance performance.

12
Figure 12: Self Balancing Robot

4 Conclusion and Improvement


We have constructed the chases of two-wheel self-balancing robot using low-cost compo-
nents, and implemented a tilt-angle estimator that is capable of measuring the angle of
robot with fine accuracy and precision and a stabilizing PID controller for the balancing
motion. The Bluetooth installed is handling the navigation of.com the robot remotely with
fine accuracy.

4.1 Conclusion and Improvement


The following are some future goals for improvement.
1. Design improvement:
Design improvement for better balancing motion will require optimization of the
mechanical design such as relocating the center of mass, better sensor placement,
modification of the complementary filter to reject disturbances due to translational
motion, and a robust control design.
2. Hardware improvement:
High quality stepper motors can be used for better actuation of the self-balancing of
the robot. The chassis can be modified to have less weight for better response. High
performance and light weight batteries i.e. LiPo may be installed to produce much
better results.
3. Obstacle avoidance and perimeter following:
A possible extension in the self-balancing robot is to combine it with other sensors
such as ultrasonic sensors, IR sensors, GPS, digital compass and a camera to address
other advanced applications, e.g. obstacle avoidance, line following, location following
and autonomous etc.

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

You might also like