0% found this document useful (0 votes)
124 views25 pages

Updated Self Balancing Report (F16mte28)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 25

MEHRAN UNIVERSITY OF ENGINEERING

&
TECHNOLOGY, JAMSHORO

Department of Mechanical Engineering

CERTIFICATE
This is to certify that Mr. S/O
bearing Roll no. has carried
out all practical work of the in Semester,
Year of his B.E Mechatronic Engineering degree program during
the session .

Subject teacher Dated


SELF BALANCING ROBOT

BY
NAME ROLL NO
ATHAR HUSSAIN (GL) F16MTE28
MOHAMMAD ALI F16MTE05
PRITHVI RAJ F16MTE12
MOHAMMAD BILAL F16MTE14

SUBJECT
MECHATRONICS SYSTEM
DESIGN

SUBMITTED TO
YOUSUF JAMAL

Department of Mechatronics Engineering


Contents
1 INTRODUCTION
2 STATEMENT OF PURPOSE
3 LAB EQUIPMENTS AND TOOLS

4 HARDWARE & SOFTWARE DESCRIPTION


5 METHODOLOGY & WORKING PRINCIPLE (BLOCK DIAGRAM + FLOW CHART)
6 PROCEDURE (CIRCUIT DIAGRAM)

7 RESULTS & CONCLUSIONS


SELF BALANCING ROBOT

Introduction

In the previous decade, versatile robots have ventured out of the


military and modern settings, and entered regular citizen and
individual spaces, for example, medical clinics, schools and
standard homes. While a considerable lot of these robots for
common applications are precisely steady, for example, Aibo the
Sony automated canine, or four-wheel vacuum cleaners, one that
standard on-lookers would discover spectacular is the Segway
individual vehicle, a precisely temperamental, two-wheel self-
adjusting vehicle that has seen organization for law-requirement,
the travel industry, and so on This vehicle can be legitimately
called a robot on the grounds that, without the tactile ability and
wise control that go with each robot, the Segway can never
remain upstanding. An A self-adjusting robot is making a robot
that is a copy of a human body. Two – wheeled or self-adjusting
robot is a temperamental powerful framework dissimilar to other
four wheeled lifeless robots that are in balance state. By shaky,
here, we imply that the robot is allowed to fall ahead or reverse
way with no utilization of power. Self-adjusting implies the robot
adjusting itself in a balance state, 90 degrees upstanding position.
This venture chips away at the altered pendulum idea. We are
utilizing Arduino Uno to assemble oneself adjusting robot. We are
utilizing the inertial estimation unit MPU6050 for estimating the
current tilt point.
Statement of purpose

The aim of a self-balancing robot is to balance itself on two


wheels, being able to drive around without toppling over. Self-
balancing robots use a “closed-loop feedback control” system; this
means that real-time data from motion sensors is used to control
the motors and quickly compensate for any tilting motion in order
to keep the robot upright. Similar self-balancing feedback control
systems can be seen in many other applications. Some of the
obvious examples include Segway’s, bipedal robots and space
rockets A few rockets have been lost due to a faulty balancing
system.
LAB EQUIPMENTS AND TOOLS

Hand saw

It is tool generally used for cutting wood and plastics we have used
this saw.

Screwdriver

Screwdriver, tool, usually hand-operated, for turning screws with


slotted heads.
Soldering iron

A soldering iron is a hand tool used to heat solder, usually from an


electrical supply at high temperatures above the melting point of
the metal alloy.

Sandpaper

Sandpaper is produced in a range of grit sizes and is used to


remove material from surfaces, either to make them smoother.

Triangular file

A triangular file is a specialized tool for trimming and sharpening


edges.
Glue gun

Glue gun is an electrical device that uses a heating element to heat


up and melt specially made solid hot glue sticks.

Computer

Uses for uploading program in Arduino uno board.


HARDWARE & SOFTWARE DESCRIPTION

Arduino uno

Arduino is an open source arrange used for structure devices


adventures. Arduino contains both a physical programmable
circuit board (consistently insinuated as a microcontroller) and a
touch of programming, or IDE (Integrated Development
Environment) that continues running on your PC, used to create and
exchange PC code to the physical board. Arduino Uno is a
microcontroller board dependent on the ATmega328P.It has 14
advanced information/yield pins (of which 6 can be utilized as
PWM yields), 6 simple data sources, a 16 MHz quartz gem, a USB
association, a power jack, an ICSP header and a reset catch. It
contains everything expected to help the microcontroller;
essentially associate it to a PC with a USB link or power it with an
AC-to-DC connector or battery to begin.
L298n (motor driver)

This L298N Motor Driver Module is a high-power motor driver


module for driving DC and Stepper Motors. This module consists
of an L298 motor driver IC and a 78M05 5V regulator. L298N
Module can control up to 4 DC motors, or 2 DC motors with
directional and speed control.

MPU 6050 (gyroscope sensor)

The MPU6050 is a Micro Electro-Mechanical Systems (MEMS)


which consists of a 3-axis Accelerometer and 3-axis Gyroscope
inside it. This helps us to measure acceleration, velocity,
orientation, displacement and many other motion related
parameter of a system or object. This module also has a (DMP)
Digital Motion Processor inside it which is powerful enough to
perform complex calculation and thus free up the work for
Microcontroller.
Gear Motor

DC motors convert electrical energy to mechanical energy, and


the speed of the motor can be changed with variable supply
voltage.

Jumper wires

Jumper wires are simply wires that have connector pins at each
end, allowing them to be used to connect two points to each
other without soldering.

9v battery

The nine-volt battery, or 9-volt battery, is a common size of


battery that is used as a source in replacement of power adapters
Switch

A toggle button allows the user to change a setting between two


states, that is either on or off.

Acrylic sheet

It's any type of plastic that contains derivatives of acrylic acid, but
PMMA is by far the most common type of plastic.
Arduino software (version 1.8.5)
The Arduino Integrated Development Environment (IDE) is a cross-
platform application that is written in functions from C and C++. It
runs on Windows, macOS, and Linux. It is used to write and
upload programs to Arduino compatible boards, but also, with the
help of third-party cores, other vendor development boards.
We have used the open-source Arduino IDE software for writing
and uploading the program into the Arduino Nano board. The
environment is written in Java and based on Processing and other
open-source software.
METHODOLOGY & Working Principle

In order to keep the robot balanced, the motors must counteract


the robot falling. This action requires feedback and correcting
elements. The feedback element is the MPU6050 gyroscope +
accelerometer, which gives both acceleration and rotation in all
three axes. The Arduino uses this to know the current orientation
of the robot. The correcting element is the motor and wheel
combination. The self-balancing robot is essentially an inverted
pendulum and can be balanced better if the center of mass is
higher relative to the wheel axles. A higher center of mass means
a higher mass moment of inertia, which corresponds to
lower angular acceleration (slower fall).
Inner-loop Control for Wheel-Synchronization:

Ideally, if the same motor control signal is sent to the motors


control board, both motors should rotate at the same speed. But
in the real environment there are many reasons for which the
motors rotate at different velocities under the same input signal,
such as defects of the motors, terrain, and hindrance on the
ground. Thus, a method to synchronize both motors is needed.
This controller adjusts the PWM inputs to the motors so that the
difference between the left and right encoders tracks zero. It
shows the experimental results of wheel travel distances with and
without wheel synchronization and shows the motor control
signals under wheel synchronization. Wheel synchronization is
effective.
Block Diagram
Flow chart
PROCEDURE
Design and structure
In the beginning, the robot frame or body is made by using the
acrylic sheet and two wheels were attached with two geared DC
motors separately in order to make the two sets of the wheel for
the vehicle or robot. After that, those wheel sets were joined to
the main frame of the vehicle in order to complete the entire
robot body or vehicle.
Hardware components
The components were assembled and combined through jumper
wires to complete the controlling circuit.
CIRCUIT DIAGRAM
Interfacing with software
Arduino program was uploaded in the arduino nano board in
order to test or run and verify it. Finally, kp, ki and kd values were
adjusted to lessen the oscillations until the robot is almost steady,
and to stabilize it in time. Tuning of the pid values has done
manually using the following procedure:
STEPS FOR THE ADJUSTMENT OF THE PID VALUES:

1. Make Kp, Ki, and Kd equal to zero.


2. Adjust Kp. Too little Kp will make the robot fall over because
there's not enough correction. Too much Kp will make the
robot go back and forth wildly. A good enough Kp will make the
robot go slightly back and forth (or oscillate a little).
3. Once the Kp is set, adjust Kd. A good Kd value will lessen the
oscillations until the robot is almost steady. Also, the right
amount of Kd will keep the robot standing, even if pushed.
4. Lastly, set the Ki. The robot will oscillate when turned on, even
if the Kp and Kd are set, but will stabilize in time. The correct Ki
value will shorten the time it takes for the robot to stabilize.
CODE
//youtube.com/TARUNKUMARDAHAKE
//facebook.com/TARUNKUMARDAHAKE
#include <PID_v1.h>
#include <LMotorController.h>
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
#define MIN_ABS_SPEED 20
MPU6050 mpu;
// MPU control/status vars
bool dmpReady = false; // set true if DMP init was successful
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
uint8_t devStatus; // return status after each device operation (0 =
success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
// orientation/motion vars
Quaternion q; // [w, x, y, z] quaternion container
VectorFloat gravity; // [x, y, z] gravity vector
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity
vector
//PID
double originalSetpoint = 173;
double setpoint = originalSetpoint;
double movingAngleOffset = 0.1;
double input, output;
//adjust these values to fit your own design
double Kp = 60;
double Kd = 1.4 ;
double Ki = 70;
PID pid(&input, &output, &setpoint, Kp, Ki, Kd, DIRECT);
double motorSpeedFactorLeft = 0.6;
double motorSpeedFactorRight = 0.6;
//MOTOR CONTROLLER
int ENA = 5;
int IN1 = 6;
int IN2 = 7;
int IN3 = 8;
int IN4 = 9;
int ENB = 10;
LMotorController motorController(ENA, IN1, IN2, ENB, IN3, IN4,
motorSpeedFactorLeft, motorSpeedFactorRight);
volatile bool mpuInterrupt = false; // indicates whether MPU interrupt
pin has gone high
void dmpDataReady()
{
mpuInterrupt = true;
}
void setup()
{
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
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);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip

// make sure it worked (returns 0 if so)


if (devStatus == 0)
{
// turn on the DMP, now that it's ready
mpu.setDMPEnabled(true);

// enable Arduino interrupt detection


attachInterrupt(0, dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();

// set our DMP Ready flag so the main loop() function knows it's okay to
use it
dmpReady = true;

// get expected DMP packet size for later comparison


packetSize = mpu.dmpGetFIFOPacketSize();

//setup PID
pid.SetMode(AUTOMATIC);
pid.SetSampleTime(10);
pid.SetOutputLimits(-255,
255);
}
else
{
// ERROR!
// 1 = initial memory load failed
// 2 = DMP configuration updates failed
// (if it's going to break, usually the code will be 1)
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
}
void loop()
{
// if programming failed, don't try to do anything
if (!dmpReady) return;

// wait for MPU interrupt or extra packet(s) available


while (!mpuInterrupt && fifoCount < packetSize)
{
//no mpu data - performing PID calculations and output to motors
pid.Compute();
motorController.move(output, MIN_ABS_SPEED);

}
// reset interrupt flag and get INT_STATUS byte
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();

// get current FIFO count


fifoCount =
mpu.getFIFOCount();

// check for overflow (this should never happen unless our code is too
inefficient)
if ((mpuIntStatus & 0x10) || fifoCount == 1024)
{
// reset so we can continue cleanly
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));

// otherwise, check for DMP data ready interrupt (this should happen
frequently)
}
else if (mpuIntStatus & 0x02)
{
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

// read a packet from FIFO


mpu.getFIFOBytes(fifoBuffer, packetSize);

// track FIFO count here in case there is > 1 packet available


// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
input = ypr[1] * 180/M_PI + 180;
}
}
RESULTS & CONCLUSION

RESULTS

In control theory, keeping some variable (the position of the


robot) steady needs a special controller called a PID (stands for
proportional integral derivative), which provides correction
between the desired value (or input) and the actual value (or
output). The difference between the input and the output is called
"error", and the proportional integral derivative controller
reduces the error to the smallest value possible by continually
adjusting the output.
The graph or the result obtained is given below:
CONCLUSION
The purpose of this project was to build a two-wheeled vehicle or
robot which can balance itself so that it prevents itself from falling
as two–wheeled or self-balancing robot is an unstable dynamic
system unlike other four wheeled stale robots that are in
equilibrium state. The robot can balance itself in an equilibrium
state, 90-degrees upright position, and works on the inverted
pendulum concept. The use of Arduino Nano made it possible to
build the self-balancing robot and MPU6050 was also used for
measuring the current tilt angle.

You might also like