Self Balancing Robot12345 PDF
Self Balancing Robot12345 PDF
ABSTRACT
DEPARTMENT OF ECE,RGM 1
Self-Balancing Robot
CHAPTER-1
INTRODUCTION
Robotics has always been 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.
Developments in technology over the past fifty years have established the
foundations of making these dreams come true. 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 many different ways.
Effective and efficient control system designs provide the robot with
the ability to control itself and operate autonomously. Artificial intelligence
(AI) is becoming a definite possibility with advancements in non-linear
control systems such as neural networks and fuzzy controllers. Improved
synthetics and materials allow for robust and cosmetically aesthetic
designs to be implemented for the construction and visual aspects of the
robot.
Two wheeled robots are one variation of robot that has become a
standard topic of research and exploration for young engineers and robotic
enthusiasts. They offer the opportunity to develop control systems that are
capable of maintaining stability of an otherwise unstable system. This type
of system is also known as an inverted pendulum. This project aims to
bring this, and many of the previously mention aspects of a robot together
into the building of a two wheeled balancing robot with a Arduino based
controller.
DEPARTMENT OF ECE,RGM 2
Self-Balancing Robot
DEPARTMENT OF ECE,RGM 3
Self-Balancing Robot
CHAPTER-2
AIM & OBJECTIVES
Aim: -
An aim of this project is for the design and develop a two wheeled
robot capable of recovering deliberate tilt caused by physical force. This
could be caused in the real world by an ill adult or child falling over or even
passing out thus bumping into the robot. This would allow the robot to
maintain stability and seek assistance from other people by raising the
alarm. Beyond this project timeline, it is anticipated that the robot will also
become capable of remote control trajectory and multimedia interaction.
Objectives: -
1. The design motor control board responsible for calibrating each
motor to perform self-balancing and directional movements.
2. To develop an algorithm for the robot to perform self-balancing, using
the input of an accelerometer and gyroscope module.
3. The geographic control board provides directional movement the
robot must execute such as turn left, go forward, stop, etc.
4. The sensors are used to override user control for obstacle avoidance.
DEPARTMENT OF ECE,RGM 4
Self-Balancing Robot
CHAPTER-3
METHODOLOGY
• Form transfer functions for the angle deviation, ψ and position, x • Find
a controller that can control these two conditions
DEPARTMENT OF ECE,RGM 5
Self-Balancing Robot
• Investigate the accuracy of the sensor that delivers the angular data With
an accurate model of the system and a functioning demonstrator this
provides a platform for experiments in a simulated environment. The
simulated model in comparison to the demonstrator will be validated by
implementation of a PID-controller in both in order to compare impulse
responses.
DEPARTMENT OF ECE,RGM 6
Self-Balancing Robot
dimensions and the tilt angle of the robot. The module also consists of a
magnetometer (compass).
DC Motor: the DC motors to actuate the robot, that is to balance itself the
robot has to move in forward and reverse direction, the DC motors can
rotate in clockwise and anti-clockwise by reversing the polarity of the power
source.
L293D Motor driver: This needs a motor driver to run the motors, L293D
is a typical motor driver IC which allows the motor to run in both the
directions, you can control two motors with one IC.
Robot chassis:Build a strong two-wheeled chassis for the robot with ample
space for the electronics.
3.2.SYSTEMATIC DIAGRAM:-
DEPARTMENT OF ECE,RGM 7
Self-Balancing Robot
3.3. Working:
DEPARTMENT OF ECE,RGM 8
Self-Balancing Robot
3.4 Flowchart
DEPARTMENT OF ECE,RGM 9
Self-Balancing Robot
3.5 Functionality:
ALGORITHM:
#include <MPU6050.h>
#include <L298N.h>
#include "Wire.h"
#endif
#define MIN_ABS_SPEED 30
MPU6050 mpu;
// orientation/motion vars
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
//PID
DEPARTMENT OF ECE,RGM 10
Self-Balancing Robot
double Kp = 60;
double Kd = 2.2;
double Ki = 270;
//MOTOR CONTROLLER
int ENA = 5;
int IN1 = 6;
int IN2 = 7;
int IN3 = 9;
int IN4 = 8;
void dmpDataReady()
mpuInterrupt = true;
DEPARTMENT OF ECE,RGM 11
Self-Balancing Robot
void setup()
Wire.begin();
Fastwire::setup(400, true);
#endif
mpu.initialize();
devStatus = mpu.dmpInitialize();
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
if (devStatus == 0)
mpu.setDMPEnabled(true);
DEPARTMENT OF ECE,RGM 12
Self-Balancing Robot
mpuIntStatus = mpu.getIntStatus();
// set our DMP Ready flag so the main loop() function knows it's okay to
use it
dmpReady = true;
packetSize = mpu.dmpGetFIFOPacketSize();
//setup PID
pid.SetMode(AUTOMATIC);
pid.SetSampleTime(10);
pid.SetOutputLimits(-255, 255);
else
// ERROR!
Serial.print(devStatus);
Serial.println(F(")"));
DEPARTMENT OF ECE,RGM 13
Self-Balancing Robot
void loop()
if (!dmpReady) return;
while (!mpuInterrupt&&fifoCount<packetSize)
pid.Compute();
motorController.move(output, MIN_ABS_SPEED);
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();
// check for overflow (this should never happen unless our code is too
inefficient)
DEPARTMENT OF ECE,RGM 14
Self-Balancing Robot
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
// otherwise, check for DMP data ready interrupt (this should happen
frequently)
mpu.getFIFOBytes(fifoBuffer, packetSize);
fifoCount -= packetSize;
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
DEPARTMENT OF ECE,RGM 15
Self-Balancing Robot
CHAPTER-4
HARDWARE COMPONENTS
DEPARTMENT OF ECE,RGM 16
Self-Balancing Robot
The Arduino Uno board is the most popular board and mostly
referred for the beginners as they are super easy to begin with, it does
not require any specific Arduino Uno software instead of that all you need
is to select the Arduino Uno in the device option before uploading your
program.
1. Crystal Oscillator:
There is certain case when the processor has to deal with time-
signal issues, in order to balance it the crystal oscillator is used. The
crystal oscillator is the only way the Arduino is able to calculate the time.
There is a number printed on the top of the crystal. The number indicates
the frequency of the crystal, in most of them the frequency is 16 MHZ or
16,000,000 hertz.
DEPARTMENT OF ECE,RGM 17
Self-Balancing Robot
2.Reset Button:
You can connect your own reset button at the pin labelled as Reset.
Pin description:
The Arduino Uno board has 6 analog input and output pins from
A0 to A5. The pins are best used in case of the analog sensors. The analog
pins can read the analog signals from them like temperature, proximity,
humidity etc and converts them into digital values that can be read and
processed by the microcontroller.
DEPARTMENT OF ECE,RGM 18
Self-Balancing Robot
3.SPI Ports:
DEPARTMENT OF ECE,RGM 19
Self-Balancing Robot
Arduino Uno board does have 14 digital i/o pins (input/output pins)
out of which contains 6 PWM output (Pulse width modulation). The digital
pins can be configured to read logic values such as 0 and 1 or can give logic
(0 and 1) output for different modules such as LEDs, Relays, etc. there is a
symbol “~” corresponding to the PWM pins.
Specifications:
Microcontroller: ATmega328
Operating Voltage: 5V
SRAM: 2 KB (ATmega328)
EEPROM: 1 KB (ATmega328)
DEPARTMENT OF ECE,RGM 20
Self-Balancing Robot
DEPARTMENT OF ECE,RGM 21
Self-Balancing Robot
This module has some famous features which are easily accessible,
due to its easy availability it can be used with a famous
microcontroller like Arduino
This module uses the I2C module for interfacing with Arduino.
MPU6050
Features of MPU6050
MPU6050 is the world’s first integrated six motion tracking device
DEPARTMENT OF ECE,RGM 22
Self-Balancing Robot
It has the smallest and thinnest QFN package for portable devices,
4x4x0.9 mm.
Its operating current is 3.9 mA when its six motion sensing axes and
DMP are in motion.
It also has gyroscope feature like its Gyroscope operating current is 3.6
mA.
The L298N is a dual H-Bridge motor driver which allows speed and
direction control of two DC motors at the same time. The module can drive
DC motors that have voltages between 5 and 35V, with a peak current up
to 2A.
DEPARTMENT OF ECE,RGM 23
Self-Balancing Robot
Let’s take a closer look at the pinout of L298N module and explain
how it works. The module has two screw terminal blocks for the motor A
and B, and another screw terminal block for the Ground pin, the VCC for
motor and a 5V pin which can either be an input or output.
This depends on the voltage used at the motors VCC. The module
have an onboard 5V regulator which is either enabled or disabled using a
jumper. If the motor supply voltage is up to 12V we can enable the 5V
regulator and the 5V pin can be used as output, for example for powering
our Arduino board. But if the motor voltage is greater than 12V we must
disconnect the jumper because those voltages will cause damage to the
onboard 5V regulator. In this case the 5V pin will be used as input as we
need connect it to a 5V power supply in order the IC to work properly.
We can note here that this IC makes a voltage drop of about 2V. So for
example, if we use a 12V power supply, the voltage at motors terminals will
be about 10V, which means that we won’t be able to get the maximum
speed out of our 12V DC motor.
DEPARTMENT OF ECE,RGM 24
Self-Balancing Robot
Next are the logic control inputs. The Enable A and Enable B pins
are used for enabling and controlling the speed of the motor. If a jumper is
present on this pin, the motor will be enabled and work at maximum speed,
and if we remove the jumper we can connect a PWM input to this pin and
in that way control the speed of the motor. If we connect this pin to a
Ground the motor will be disabled.
DEPARTMENT OF ECE,RGM 25
Self-Balancing Robot
Next, the Input 1 and Input 2 pins are used for controlling the
rotation direction of the motor A, and the inputs 3 and 4 for the motor B.
Using these pins we actually control the switches of the H-Bridge inside the
L298N IC. If input 1 is LOW and input 2 is HIGH the motor will move
forward, and vice versa, if input 1 is HIGH and input 2 is LOW the motor
will move backward. In case both inputs are same, either LOW or HIGH the
motor will stop. The same applies for the inputs 3 and 4 and the motor B.
4.5 DC MOTORS
Figure11 : DC Motor
DEPARTMENT OF ECE,RGM 26
Self-Balancing Robot
Features:
DEPARTMENT OF ECE,RGM 27
Self-Balancing Robot
CHAPTER-5
SOFTWARE REQUIREMENTS:
Arduino:
Plug in the board and wait for Windows to begin its driver installation
process
After a few moments, the process will fail, despite its best efforts
DEPARTMENT OF ECE,RGM 28
Self-Balancing Robot
Look under Ports (COM & LPT). You should see an open port named
“Arduino UNO (COMxx)”. If there is no COM & LPT section, look
under ‘Other Devices’ for ‘Unknown Device
DEPARTMENT OF ECE,RGM 29
Self-Balancing Robot
ARDUNIO IDE:
IDE stands for Integrated Development Environment. Pretty fancy
sounding, and should make you feel smart any time you use it. The IDE is
a text editor-like program that allows you to write Arduino code. When you
open the Arduino program, you are opening the IDE. It is intentionally
streamlined to keep things as simple and straightforward as possible. When
you save a file in Arduino, the file is called a sketch – a sketch is where you
save the computer code you have written. The coding language that Arduino
uses is very much like C++ (“see plus plus”), which is a common language
in the world of computing. The code you learn to write for Arduino will be
very similar to the code you write in any other computer language – all the
basic concepts remain the same – it is just a matter of learning a new dialect
should you pursue other programming languages. The code you write is
“human readable”, that is, it will make sense to you (sometimes), and will
be organized for a human to follow. Part of the job of the IDE is to take the
human readable code and translate it into machine-readable code to be
executed by the Arduino. This process is called compiling. The process of
compiling is seamless to the user. All you have to do is press a button. If
you have errors in your computer code, the compiler will display an error
message at the bottom of the IDE and highlight the line of code that seems
to be the issue. The error message is meant to help you identify what you
might have done wrong – sometimes the message is very explicit, like
saying, “Hey – you forget a semicolon”, sometimes the error message is
vague.
DEPARTMENT OF ECE,RGM 30
Self-Balancing Robot
Chapter – 6
Result and Conclusion
6.1 RESULT
In the first instance the bot was balanced and a small jerk was created,
the PID algorithm generated the necessary control signals on the motor to
balance the position and prevent collapsing of the robot.
DEPARTMENT OF ECE,RGM 31
Self-Balancing Robot
6.2 Conclusion
DEPARTMENT OF ECE,RGM 32
Self-Balancing Robot
REFERENCES
1. Lin SC, Tsai CC, and Huang HC. Adaptive robust self balancing and
steering of a two-wheeled human transportation vehicle. J Intell Robot
Syst 2011; 62(1):103–123.
3. Han HY, Han TY, and Jo HS. Development of omni directional self-
balancing robot. In: 2014 IEEE international symposium on robotics
and manufacturing automation (ROMA), Kuala Lumpur, 2014, pp. 57–
62. IEEE.
5. http://www.bbc.com/news/uk-england-14167868
DEPARTMENT OF ECE,RGM 33
Self-Balancing Robot
DEPARTMENT OF ECE,RGM 34
Self-Balancing Robot
DEPARTMENT OF ECE,RGM 35