Report Main File _Self balancing robot project report
Report Main File _Self balancing robot project report
CHAPTER: 1
INTRODUCTION
The self balancing robot, concept of two-wheel inverted pendulum has gained
momentum in research over the last few years. Inherently self balancing robot is unstable and it
would roll around the wheels’ rotation axis without external control and eventually fall.
The robot returns to right position if motor driving occurs in right direction. The robot is
naturally unstable although, it has many favors over the statically stable multi wheeled robots. A
special electromechanical system in which the robot has to be based on balances itself onto a pair
of wheels while standing tall. If the base on which the robot stand is not stable or the
platform is not balanced, the robot tend to falling off from the vertical axis. This time a gyro
chip is needed to provide the PID controller about the angular position of the base of the self
balancing robot. A self balancing algorithm is programmed into the controller and the controller
drives the motors either clockwise or anticlockwise to balance the basement by a pulse width
modulation (PWM) control signal. The robot has to be work upon any type of surface based on
two motors constructed with wheel one for each.
For the rider's convenience, we have also introduced remote sensing, implementing it
using the HC-05 Bluetooth module. Thus a rider can access his/her vehicle from a certain
distance. This device self- balances based on the inverted pendulum principle.
Page 1
CHAPTER: 2
INVERTED PENDULUM SYSTEM
Page 2
CHAPTER: 3
METHODOLOGY
The block diagram shown below consists of all the important blocks that are needed for
the working of this prototype. The source of power is a rechargeable battery. The sensor unit is
the MPU6050 block which has both gyroscope and accelerometer to sense the axis of tilt. As a
rider moves front or back the angle of inclination is sensed by the MPU6050 and the data is
given to the arduino.
By reading the data if the control unit feels that the device is falling out of balance then it
instructs the L298N motor driver so that it can direct the motors. The motors in turn control the
wheels. Therefore, the balance is maintained as the device balances itself. All the components
i.e. the MPU6050, motor driver, HC-05 module are all interfaced with the Arduino in order to
Page 3
run the device. To make sure of the convenience of the rider, we have introduced the concept of
remote accessing using the Bluetooth module. Therefore, one can access his/her vehicle from a
distance using this method of communication which does not need wires. Since it is a prototype
of a Segway that is used for transportation of humans, thus we have also introduced an indicator
to notify the battery left.
Interface the MPU6050 with Arduino and connect the motors though the Motor driver module.
The whole set-up is powered by the battery. The circuit diagram for the same is shown above.
The Arduino and the L298N Motor driver module is directly powered through the Vin pin and
the 12V terminal respectively. The on-board regulator on the Arduino board will convert the
input 7.4V to 5V and MPU6050 will be powered by it.
Page 4
Fig 4: Circuit Diagram with Bluetooth Module
Page 5
CHAPTER: 4
DESIGN PROCESS
The self balancing robot gets balanced on a pair of wheels having the required grip
providing sufficient friction. For maintaining vertical axis two things must be done, one is
measuring the inclination angle and other is controlling of motors to move forward or backwards
to maintain 0˚angle with vertical axis. For measuring the angle, two sensors, accelerometer and
gyroscope are used. Accelerometer can sense either static or dynamic forces of acceleration and
Gyroscope measures the angular velocity. The outputs of the sensors are fused using a
Complementary filter. Sensors measure the process output say α which gets subtracted
from the reference set-point value to produce an error. Error is then fed into the PID where the
error gets managed in three ways. After the PID algorithm processes the error, the controller
produces a control signal μ. PID control signal then gets fed into the process under control.
Process under PID control is two wheeled robot. PID control signal will try to drive the process
to the desired set-point value that is 0˚ in vertical position by driving the motors in such a way
that the robot is balanced.
Page 6
CHAPTER: 5
TECHNIQUE CONTROL
Page 7
CHAPTER: 6
DATA ACQUISITION AND FILTERING
Both the accelerometer and gyroscope data are used to obtain the angular position of the
object. Gyroscope does this by integrating the angular velocity over time. From the
position of the gravity vector (g-force) angular position is obtained using the
accelerometer. In both these cases, it is very hard to use without a filter.
Accelerometer measures all forces that are working on an object, as well as it will also
see a lot more than just the gravity vector. Every small force working on the object
disturbs measurements in a great amount. While working on an actuated system the
forces that drive the system will also be visible on the sensor as well. The accelerometer
data is reliable in case of a long term, for that reason a "low pass" filter is required.
In the case of Gyro, it is very easy to obtain an accurate data which is not susceptible to
external forces. But because of the integration over time, the measurement has a tendency
to drift, not returning to level zero when the system went back to its original position.
This data is reliable only for a short term; it shows drift on the long term.
The complementary filter provides data both for short and long term from gyroscope and
accelerometer respectively.
Page 8
Fig 5: Complementary Filter Block
Arduino Mega and MPU 6050 are used to acquire data and filter. Basic
connection diagram is shown in Figure.
Page 9
CHAPTER: 7
CONTROL SYSTEM AND ALGORITHM
The control system of the two wheels balancing robot in this project is illustrated by the
block diagram in Figure.
The robot control software is inside the microcontroller module and the program
flowchart is shown in Figure.
Page 10
Fig 8: Program flowchart
Page 11
CHAPTER: 8
MOTOR CONTROL
The speed of the motor can be able to adjust by the PWM by adjusting the duty cycle and
hence the voltage supplied to the motor. Using the PWM method saves the cost of acquiring a
Digital to Analogue Converter. Another benefit of using the PWM is that the signal remains
digital and no digital-to-analogue conversion is necessary, by doing so the noise effects are
minimized.
Changing the set point for the PID controller individually for two motors can control the
translational motion of the robot. The motor power increases by the proportional term as the
system leans further over and decreases the motor power as the system approaches the upright
position. A gain factor, Kp, determines how much power to apply to the motor for any given
lean, as follows:
The differential term of the PID algorithm acts as a damper reducing oscillation. Another
gain factor, Kd, determines how much power is applied to the motor according to the following
equation:
Finally, neither the proportional nor differential terms of the algorithm will remove all of
the lean because both terms go to zero as the orientation of the system settles near vertical. The
integral term sums the accumulated error tries to drive the lean to zero as follows:
Page 12
The output of the PID Controller is
The output of the motor PWM as Above will be used as the set-point for the motor.
Error of Motor Speed = Motor Set point – current speed reading of motor output Proportional term of
motor
Output Differential term of motor = kd * (Error of motor speed – last error of motor speed)
And Finally
Motor Speed = Proportional term of motor + Integral Term of motor + Differential term of motor.
For tuning the PID control of motor speed, the value of Kp, Ki and Kd is get by trial and
error method.
The H-Bridge amplifier amplifies the signal from the pulse-width modulator channel to
produce voltage that is sufficient enough to drive the motor. Under the command of the software
the H-Bridge swaps the motor terminals to drive the motor in a different direction. Using the H-
Bridge saves the cost of using two voltage sources for bidirectional control of the motor. The H-
Bridge has got two logic inputs for the direction control of the motor.
Page 13
CHAPTER: 9
COMPONENTS
Page 14
Fig :9 Arduino Uno
9.1.2 Features
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Pre scalar and Compare Mode
– One 16-bit Timer/Counter with Separate Pre scalar, Compare Mode, and Capture
Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel 10-bit ADC in TQFP and QFN/MLF package
Temperature Measurement
– 6-channel 10-bit ADC in PDIP Package
Temperature Measurement
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Byte-oriented 2-wire Serial Interface (Philips I2C compatible)
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
Page 15
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby, and
Extended Standby
• Operating Voltage:
– 1.8 - 5.5V
• Temperature Range:
– -40°C to 85°C
• Speed Grade:
– 0 - 4 [email protected] - 5.5V, 0 - 10 [email protected] - 5.5.V, 0 - 20 MHz @ 4.5 - 5.5V
Page 16
Fig 10 :TQFP Top View
PDIP
Page 17
Fig 12: MLF Top
View
Page 18
Fig 13: 32 MLF Top View
9.1.4 Pin Descriptions
GND- Ground
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). The Port B output buffers have symmetrical drive characteristics with both high sink
and source capability. As inputs, Port B pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running. Depending on the clock
selection fuse settings, PB6 can be used as input to the inverting Oscillator amplifier and
input to the internal clock operating circuit. Depending on the clock selection fuse
settings, PB7 can be used as output from the inverting Oscillator amplifier.
.
Port C (PC5:0)
Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). The PC5...0 output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port C pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port C pins are tri-stated when a
reset condition becomes active, even if the clock is not running.
PC6/RESE
If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that n the
electrical characteristics of PC6 differ from those of the other pins of Port C. If the
RSTDISBL Fuse is un programmed, PC6 is used as a Reset input. A low level on this pin
for longer than the minimum pulse length will generate a Reset, even if the clock is not
running.
Port D (PD7:0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each
bit). The Port D output buffers have symmetrical drive characteristics with both high sink
and source capability. As inputs, Port D pins that are externally pulled low will source
Page 19
current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset
condition becomes active, even if the clock is not running.
9.2 MPU6050
MPU6050 is a module which consists of a gyroscope and an accelerometer together in it.
Both are 3-axis micro electro-mechanical systems.
Page 20
Fig 15: MPU6050
This is the sensor module which senses the angle of inclination of the rider and hence the
device while in motion. It then sends this data to the Arduino to process it and balance the device
as required. This module takes in a supply voltage of 3.3-5V.
9.2.1 Application
Page 21
9.2.2 Features
Gyroscope Features
The triple-axis MEMS gyroscope in the MPU-60X0 includes a wide range of features:
Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-
programmable full-scale range of ±250, ±500, ±1000, and ±2000°/sec
External sync signal connected to the FSYNC pin supports image, video and GPS
synchronization
Integrated 16-bit ADCs enable simultaneous sampling of gyros
Enhanced bias and sensitivity temperature stability reduces the need for user calibration
Improved low-frequency noise performance
Digitally-programmable low-pass filter
Gyroscope operating current: 3.6mA
Standby current: 5μA
Factory calibrated sensitivity scale factor
User self-test
Accelerometer Features
Additional Features
Page 22
Flexible VLOGIC reference voltage supports multiple I2C interface voltages (MPU-
6050 only)
Smallest and thinnest QFN package for portable devices: 4x4x0.9mm
Minimal cross-axis sensitivity between the accelerometer and gyroscope axes
1024 byte FIFO buffer reduces power consumption by allowing host processor to read
the data in bursts and then go into a low-power mode as the MPU collects more data
Digital-output temperature sensor
User-programmable digital filters for gyroscope, accelerometer, and temp sensor
10,000 g shock tolerant
400kHz Fast Mode I2C for communicating with all registers
1MHz SPI serial interface for communicating with all registers (MPU-6000 only)
20MHz SPI serial interface for reading sensor and interrupt registers (MPU-6000 only)
Internal Digital Motion Processing (DMP) engine supports 3D Motion Processing and
gesture recognition algorithms
The MPU-60X0 collects gyroscope and accelerometer data while synchronizing data
sampling at a user defined rate. The total dataset obtained by the MPU-60X0 includes 3-
Axis gyroscope data, 3-Axis accelerometer data, and temperature data. The MPU’s
calculated output to the system processor can also include heading data from a digital 3-
axis third party magnetometer.
The FIFO buffers the complete data set, reducing timing requirements on the system
processor by allowing the processor burst read the FIFO data. After burst reading the
FIFO data, the system processor can save power by entering a low-power sleep mode
while the MPU collects more data.
Low-power pedometer functionality allows the host processor to sleep while the DMP
maintains the step count.
9.2.4 Clocking
On-chip timing generator ±1% frequency variation over full temperature range
Optional external clock inputs of 32.768kHz or 19.2MHz
Page 23
9.3 L298N Motor Driver
L298N motor driver is a high voltage and high current dual H-bridge, called so for the
structure of its circuit. It consists of an onboard 5v voltage regulator and is quite pockets friendly
module. This driver module is used to control two motors bi-directionally.
Page 24
Fig16 : L298N Motor Driver
The L298N is an integrated monolithic circuit in a 15- lead Multi watt and
PowerSO20 packages. It is a high voltage , high current dual full-bridge driver de-signed to
Page 25
accept standard TTL logic level sand drive inductive loads such as relays, solenoids, DC and
stepping motors. Two enable inputs are provided to enable or disable the device independently of
the in-put signals .The emitters of the lower transistors of each bridge are connected together
rand the corresponding external terminal can be used for the connection of an external sensing
resistor. An additional Supply input is provided so that the logic works at a lower voltage.
Page 26
Fig 18: Pin Diagram
9.3.3 Features
Page 27
1) High operating voltage, which can be up to 40 volts;
2) Large output current, the instantaneous peak current can be up to 3A;
3) With 25W rated power;
4) Two built in H-bridge, high voltage, large current, full bridge driver, which can be used to
drive DC motors, stepper motors, relay coils and other inductive loads.
5) Using standard logic level signal to control.
6) Able to drive a two-phase stepper motor or four-phase stepper motor, and two-phase DC
motors.
7) Adopt a high-capacity filter capacitor and a freewheeling diode that protects devices in the
circuit from being damaged by the reverse current of an inductive load, enhancing reliability
8) The module can utilize the built-in stabilivolt tube 78M05 to obtain 5v from the power supply.
But to protect the chip of the 78M05 from damage, when the drive voltage is greater than 12v, an
external 5v logic supply should be used.
9) Drive voltage: 5-35V; logic voltage: 5V
10) PCB size: 4.2 x 4.2 cm
Motor driver IC (L298D) has input pins, output pins, enable pin, logic supply voltage
pin, and Main supply voltage pin. L298N is a 15 pin motor driver IC that can drive two motors at
a time. It allows high current (2A per motor) to flow through it. So it is useful for driving motors
which need high current to run. Pin connections for the IC L298N are given in the above
diagram. Input pins are connected to the micro controller (in this case it is Arduino). Arduino
applies PWM across these pins. Output pins are connected to the motors. Enable pin and logic
supply pin are given the voltage that is defined as logic high (here it 5 V). Main supply voltage
pin is joined to the main power supply (max 46V for L298N, here it is 12 V).
Page 28
9.4 Bluetooth Module (HC-05)
HC-05 which is the Bluetooth module is used for accessing the device by means of
wireless technology. This module functions on the basis of master and slave principal. The
configuration of master is implemented using attention commands. This can be extended using
Global positioning system.
HC‐05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for
transparent wireless serial connection setup. Serial port Bluetooth module is fully qualified
Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio
transceiver and baseband. It uses CSR Bluecore 04‐External single chip Bluetooth system with
CMOS technology and with AFH (Adaptive Frequency Hopping Feature). It has the footprint as
small as 12.7mmx27mm. Hope it will simplify your overall design/development cycle.
Page 29
9.4.1 Hardware features
Page 30
9.4.3 Pin Configuration
1 Enable/key This pin is used to toggle between Data Mode (set low) and AT
command mode (set high). By default it is in Data mode
5 RX Receive Serial Data. Every serial data given to this pin will be
Receiver broadcasted via Bluetooth
8 BUTTON
Used to control the Key/Enable pin to toggle between Data and
command Mode
Page 31
9.5 Geared Direct current Electrical Motor
A geared direct current electrical motor is driven by the motor driver to rotate both
clockwise and anti-clockwise and in turn rotate the wheels. They require a certain power to be
driven. Here we have used brush-less motor because they have a comparatively lower
maintenance and mechanically less complex.
9.5.1
A DC motor is any of a class of electrical machines that converts direct current electrical
power into mechanical power. The most common types rely on the forces produced by magnetic
fields. Nearly all types of DC motors have some internal mechanism, either electromechanical or
electronic; to periodically change the direction of current flow in part of the motor. Most types
produce rotary motion; a linear motor directly produces force and motion in a straight line.
Page 32
CHAPTER: 10
RESULT
The final implementation of the self balancing robot is figured bellow. As mentioned
earlier it is a static linear model. It can handle tilt angle maximum 12 degree. The robot moves
forward and backward continuously within a range of about -3 cm and +3cm around the
balancing spot in order to balance itself on the flat surfaces. Compared with the smooth flat
surfaces, the stability of the robot is better when balancing on the rough flat surfaces like carpet.
This can be explained by the relatively small moment of inertia of the wheels compared to the
moment of inertia of the robot’s body and the extra damping effect produced by the carpet. The
final implementation is shown in Figure.
Page 33
CHAPTER: 11
APPLICATION
2. Monocycle Is the World’s First Self Balancing Bike: The Monocycle is a perfect city
Bike that can be used for short distance travels and can be parked in the least available of
spaces. Moreover, the bicycle comes with a strong electric motor to support the riders, so
they need not push too hard to speed up the bike.
3. Electric self-balance bike scooter/with Remote switch/balance bike: it’s a self balancing
Robot, which balance itself on its two wheels.
Page 34
CONCLUSION
To study results in a prototype of a Segway, that includes basic features like self-
balancing, rechargeable, battery level indicator and leisure features like remote sensing. This
prototype gives a vision of future transportation where fuel is going to be problem and so is
population. Our study is based on finding a solution to these problems and thus making our
prototype a futuristic transportation medium. This prototype offers remote sensing which upscale
its value and provide easy remote access from anywhere (within a distance of 10 meters, which
can be extended with use of different wireless technology). The self-balancing mechanism is
achieved using a proportional-integral-derivative controller which is set up manually while
coding. The value of proportional, integral and derivative is attained by trial and error method.
These values determine the stability factor of this segway model.
Page 35
FUTURE SCOPE
Since our study focuses on constructing a prototype therefore it has few limitations that
can be improved in future.
1) Greater RPM and Torque can be used in direct current electric motor for greater load and
speed.
2) The motor driver can be changed to higher powered driver, as we are making a prototype
we don’t need high voltage driver but an actual product would need a greater powered
motor driver.
3) Instead of manually setting up proportional gain , integral gain and derivative gain we
can use PID controller as a component to avail extra flexibility and quick response time.
4) One can make use of two 3-axis gyroscope (instead of one) to attain better angle
precision.
5) The wireless technology can be changed for greater range coverage.
Page 36
Annexure-1
LIST OF COMPONENTS
Page 37
REFERENCES
1) Hau- Shiue Juang and Kai-Yew Lum, “Design and control of a two wheel self-balancing
robot using the arduino microcontroller board”, IEEE International Conference on
Controls and Automation, China, June 2013
2) Wei An and Yangmin Li, “Simulation and Control of a Two-Wheeled Self-Balancing
Robot”, IEEE International Conference on ROBIO, December 2013
3) Mayukh Sharma, Rahul Sharma, Vikrant Sinha, Kshitj Singh, Shakil Tadavi, “Segway-
The Human Transporter”, IJIRST, Volume 1, Issue 11, April 2015.
4) Mr. Velaji Hadiya, Mr. Aakash Rai, Mr. Sushant Sharma, Ms. Ashwini More, “Design
and Development of Segway”, IRJET, Volume 3, Issue 5, May 2016.
5) Mrs.Lekshmy.S, Aleesha George, Athira C.V, “Self Balancing Robot” International
Journal of Computer Engineering in Research Trends, Volume 2, Issue 12, December-
2015, pp.1091-1095
6) Sulabh Kumra, Shipa Mehta, “ Singular Axis Self Balancing Robot”, International
Journal of Image Processing and Vision Sciences (IJIPVS) ISSN (Print): 2278 – 1110,
Vol-1 Iss-3,4, 2012
7) R.S.Meena,Vikas Kumawat, “Controller Design For Servo Motor Using MATLAB,” .In
Proceeding of National Conferences on Advances & Research in Electrical System
Technology ( AREST 2011)
Page 38