You are on page 1of 79

The Control of a Two-wheeled

Self-Balancing robot
Graduation Project Class 2023
Submitted to
Electrical Power Engineering Department
Supervised by
Prof. Abdel-Latif Elshafei

Cairo University
Faculty of Engineering
Electric Power Dept.

2
Presented By
Omar Abdullah Hassan Ahmed

Asmaa Mohamed Ahmed Saad

Amr Salah Abdullah Abdel-rahem

Nadine Hatem Mohamed El-Mahdi


I

Outline II
III
MCM
Int
• ••
• Overview.
IV • ••
• Problem Description.
V • ••
• Inverted Pendulum.
• ••
VI
• Project motivation. • ••
VII

VIII
I

Introduction II
MCM
III
•• •
• Overview.
IV •• •
• Problem Description.
V •• •
• Inverted Pendulum.
•• •
VI
• Project motivation. •• •
VII
VIII
Introduction

Overview
Robotics is the field of designing, constructing
and using robots to perform tasks which were
usually done by humans.
Robots are provided with sensors that are
meant to simulate human senses.

Self-balancing robot is a two-wheeled robot


which balances itself to prevent itself from
falling.
Spring 2023 6
Introduction

Problem Description.
• Self-balancing robot is an unstable nonlinear
system by nature.
• There are different control methods to
achieve stabilization

Spring 2023 7
Introduction

Inverted Pendulum
• The inverted pendulum is a common problem
found in control system references.
• Self-balancing robots have a lot in common with
the inverted pendulum.
However, there are few differences between the
self-balancing robot and the inverted pendulum.

Spring 2023 8
Introduction

Project Motivations
• Hands-on experience in implementing
control system theories.
• Designing protection schemes.
• Exposure to mechanical issues.

Spring 2023 9
II
Main Components
III
• Stepper Motors.
• DRV8825 Stepper Motor Drivers. IV
• Arduino NANO Microcontroller. V
• MPU 6050 Gyroscope and Accelerometer.
VI
• HC-05 Bluetooth Module.
• Lithium-ion batteries. VII
VI
Main Components

Stepper Motors
• Stepper motors are chosen for its superior torque at low
speeds, accuracy, output characteristics and simple
controllability.
• The stepper motor working principle is electro-magnetism.
• Micro-controllers can be programmed to allow for micro-
stepping.
• Stepper motors are divided into uni-polar and bi-polar
stepper motors.
• We used a NEMA 17 bi-polar version.

Spring 2023 11
Main Components

MPU-6050
• The MPU-6050 is a micro-electrical-mechanical
system, also known as MEMS.
• MEMS accelerometer measures the linear acceleration
of the object they are attached to.
• MEMS gyroscope measures the angular motion of the
object they are attached to.

Spring 2023 12
Main Components

Arduino NANO
• Arduino boards are microcontroller boards that are
developed based on ATmega microcontrollers.
• The main reason behind choosing the NANO type is its
small size.
• Many educational materials can be found for programming
the Arduino NANO.

Spring 2023 13
Main Components

Stepper Motor Drivers


• The DRV8825, A4988, and TMC2208 all have similar pin diagram but different
properties and pricing.

A4988 DRV8825 TMC2208


offers up to 1/16-steps micro- offers up to 1/32-steps micro- offers up to 1/256-steps micro-
stepping stepping stepping
Has maximum supply voltage of 35 V has maximum supply voltage of 45 V Has maximum supply voltage of 35 V
which make it less affected by LC
voltage spikes.
can deliver 1 A without cooling can deliver 1.5 A without cooling can deliver 1.2 A without cooling
Maximum current output of 2A Maximum current output of 2.5A Maximum current output of 2A
Cheapest out of the three Moderate cost Expensive

Spring 2023 14
Main Components

HC-05 Bluetooth module


• HC-05 can be either a master or slave device and can transfer data from and to a
microcontroller.
• There are many android and IOS apps that can interface smart phone with Bluetooth
module.
• HC-05 Bluetooth module pin diagram

Spring 2023 15
Main Components

lithium-ion battery
• The rechargeable lithium-ion battery is made of
one or more compartments called cells.
• Each cell has a capacity of 4 volts.
• Lithium-ion batteries allowed for free motion
only constrained by range of Bluetooth.
• We used a 3 series cell setup providing a 11.4V
output can last for 1.5 hrs.

Spring 2023 16
Components interfacing M
III
• Stepper Motors Test. •
• Acquiring Gyroscope Readings. IV

• MPU as a Level Meter. V •
• MPU with Stepper motor. VI •
• Bluetooth Module With Stepper motor. •
VII
VIII
Components interfacing

Stepper Motor Test


• Motors were programmed to rotate one turn clockwise at
low speed, then two turns counterclockwise at high speed
and this sequence repeats.

Spring 2023 18
Components interfacing

Acquisition of MPU-6050 Readings


• We used the mpu-6050 to measure the angles in a three-dimensional
plane relative to a set point calculated by the gyroscope when
positioned in horizontal plan.

Spring 2023 19
Components interfacing

MPU-6050 As A Level Meter


• MPU-6050 Readings were transmitted to Arduino.
• Arduino was programed to activate specific led light when
MPU-6050 Readings entered particular range.

Spring 2023 20
Components interfacing

Integrating MPU-6050 with Stepper Motor


• MPU-6050 Readings were transmitted to Arduino.
• Arduino was programed to activate specific motor speed
when MPU-6050 Readings entered certain tilt angle range.

Spring 2023 21
Components interfacing

Bluetooth Module with Stepper Motor


• We created a mobile application to control the stepper
motors using Bluetooth module.
• The application control the motors rotation direction.

Spring 2023 22
Mechanical Structure E
• System Requirements For Materials.
IV
• System Estimation. •
• Structure Fabrication. V •
• Connection Elements. VI
• Wheels
VII
VIII
Mechanical Structure

Structure Requirements
• Light Weight

Spring 2023 24
Mechanical Structure

Structure Requirements
• Light Weight
• Weight Distribution

Spring 2023 25
Mechanical Structure

Structure Requirements
• Light Weight
• Weight Distribution
• Robustness

Spring 2023 26
Mechanical Structure

Structure Requirements
• Light Weight
• Weight Distribution
• Robustness
• Formability

Spring 2023 27
Mechanical Structure

Structure Requirements
• Light Weight
• Weight Distribution
• Robustness
• Formability
• Cost

Spring 2023 28
Mechanical Structure

Casing Materials
Advantages Disadvantages

Metals are heavy and its weight will be a great challenge to


Metals provide extra protection from
Metal overcome as it will negatively affect the stability of the
mechanical shocks and damage.
robot.

Plywood is stronger than MDF and can support


Plywood Harder to moulid.
heavier weights.

Can support more weights than plastic and


Acrylic Harder to Moulid without heavy machinery (laser cutting).
plywood while still being light weight.

• it can be vulnerable or fragile against mechanical strikes


lightest weight out of the alternatives; or rough terrain.
Plastics therefore, they don’t need too much energy to • Plastics are not usually used for the outer casing on the
move the robot. robot, rather, they are used as layers where PCBs,
Spring 2023
components, etc. are placed. 29
Mechanical Structure

Casing Materials
Advantages Disadvantages

Can support more weights than plastic and Harder to Moulid without heavy machinery (laser
Acrylic
plywood while still being light weight. cutting).

• it can be vulnerable or fragile against mechanical


lightest weight out of the alternatives; strikes or rough terrain.
Plastics therefore, they don’t need too much energy • Plastics are not usually used for the outer casing on
to move the robot. the robot, rather, they are used as layers where
PCBs, components, etc. are placed.

• We choose acrylic material as it was more durable and


easier to machine while being cost effective

Spring 2023 30
Mechanical Structure

Structure Fabrication
Manufacturing
Advantages Disadvantages
methods for casing:

a. Laser can cut through practically all a. Not fit for complex multidimensional
Laser cutting:
materials. geometry.
b. Works with high accuracy and precision b. Produce harmful fumes during production.

a. Flexible and accurate design


a. Require advanced design tools and
3D printing: b. Does not need specific tools or several tools
techniques.
to execute design.

Spring 2023 31
Mechanical Structure

System Estimation
Torque limits
Tmax = mg*l*sin(θmax)
Tmax = 1.5*9.8*0.08*sin(5⁰) = 0.2315 Nm
• Tmax is the maximum torque produced by the motor.
• m is the total mass of the robot.
• g is the constant of gravity.
• l is the height of the center of mass.
• θ is the maximum recovery angle.

Spring 2023 32
Mechanical Structure

System Estimation
Torque limits
Tmax = mg*l*sin(θmax)
Tmax = 1.5*9.8*0.08*sin(5⁰) = 0.2315 Nm

• Then the factor of safety is around 1.6

Spring 2023 33
Mechanical Structure

System Estimation
Dimensions
• Every rack has dimensions of 175mm

175mm X 115mm.
• Every rack has depth of 6mm.

Spring 2023 34
Mechanical Structure

Mechanical Structure Design


We used AutoCAD software as it was:
• Easy to Learn during a short period.
• Supports Laser cutting machinery format.

Spring 2023 35
Mechanical Structure

Mechanical Structure Design


First Rack features:
• Support rods sockets.
• Stepper Motors
L-channel sockets.
• Extra additions Socket.

Spring 2023 36
Mechanical Structure

Mechanical Structure Design


Second Rack features:
• Support rods sockets.
• PCB socket.
• Cable channel.

Spring 2023 37
Mechanical Structure

Mechanical Structure Design


Third Rack features:
• Support rods sockets.
• Battery unit socket.
• Cable channels.

Spring 2023 38
Mechanical Structure

Mechanical Structure Design


Final Printed Racks
First Rack Second Rack Third Rack

Spring 2023 39
Mechanical Structure

Connection Elements
Stepper motor L-channel
we used a metal L-channel to connect and
stabilize the stepper motors with the full
structure.

Spring 2023 40
Mechanical Structure

Connection Elements
We used M5 x 100mm 304 Stainless
Steel Fully Threaded Rod Bar for
supporting the rack.

Spring 2023 41
Mechanical Structure

Wheels
Wheel specifications that satisfy our need:
• We choose
Light Weight two tyre wheels each 85mm in diameter
• Stability
and 35mm in thickness.
• Highweight
The frictionofsurface
each wheel is 50gm and the coupler is
• Good
20 gm.coupling with the shaft

Spring 2023 42
Electrical Circuit Design
• Circuit Schematic Diagram.
• PCB Design
V
VI
VII
VIII
Electrical Circuit Design

Schematic Diagram
After becoming familiar with the hardware, now its time to combine all the
elements in one big circuit that house all the electronic components.
All elements were tested first to see if they
can work together in one configuration.

Spring 2023 44
Electrical Circuit Design

Schematic Diagram
A schematic design was made on EasyEDA software to implement a PCB
The Schematic diagram can be divided into 3 sections included:
• Input Protection elements.
• Stepper Motor Driving components.
• The gyroscope and Bluetooth components.

Spring 2023 45
Electrical Circuit Design

Schematic Diagram
The Input protection elements include:
• 2200uf input Filter capacitor.
• 3 Amps overcurrent DC fuse.
• 12V to 5V Voltage regulator.
• Diode for input reverse polarity protection.
• A voltage divider resistors to for undervoltage protection.

Spring 2023 46
Electrical Circuit Design

Schematic Diagram
Stepper Motor Driving components are:
• The Arduino NANO microcontroller.
• Two DRV8825 motor drivers (1 per motor).
• One 100uF filter capacitor per driver.
• Two 4 pins output sockets (from the PCB to
the Motors).

Spring 2023 47
Electrical Circuit Design

Schematic Diagram
• Each driver is connected individually with the microcontroller to
have sperate control action for each motor.

• The microstepping pins are connected


to specify the degree of the drivers
through the Arduino.

Spring 2023 48
Electrical Circuit Design

Schematic Diagram
The Gyroscope and Bluetooth components:
• The Arduino NANO microcontroller.
• MPU-6050 Gyroscope and Accelerometer.
• HC-05 Bluetooth Module.

Spring 2023 49
Electrical Circuit Design

Schematic Diagram
The Bluetooth module can send and receiving data
from any Bluetooth capable device (Android/iOS,
laptops,…etc.).

The MPU is constantly feeding the microcontroller


with its current Position data through the analog
pins on the Arduino.

Spring 2023 50
Electrical Circuit Design

Schematic Diagram

Spring 2023 51
Electrical Circuit Design

PCB Design
PCB Specification
• Designed on EasyEDA Software.
• Board Type: Double sided PCB 1.6mm.
• PCB Material : we choose FR4.
• Solder mask : Green.
• Board dimensions: 135 x 75 mm.
• Board area: 101.25 cm^2.
• Copper trace width: 1.5 mm.
• Clearance : 0.5 mm.
Electrical Circuit Design

PCB Design

Spring 2023 53
Electrical Circuit Design

PCB Design

Spring 2023 54
Bluetooth controller
• Alternative Control Techniques.
• Mobile application iterations.
• Final Application Version.
VI
VII
VIII
Bluetooth controller

Control methods
Physical connection

• By directly connecting a device capable of reading


and writing serial data to the Robot

• Despite being the best communication technique,


it is impractical in non-schedule-based operations.

Spring 2023 56
Bluetooth controller

Control methods
Non-chuck controller
• This Method removes the need for a
physical connection with the Robot.

• However, is imposes the need for extra


hardware configurations and in term,
more costs.

Spring 2023 57
Bluetooth controller

Control methods
Mobile Application
• By far the best and the most customizable mean of communication
with the Bluetooth module as any Bluetooth capable device can easily
connect to the robot provided it has the application.

• Despite having a seemingly hard learning curve, there are some


websites that provide a more simplified app making algorithms for
starters like ourselves.

Spring 2023 58
Bluetooth controller

Control methods
Mobile Application
• A great example is the MIT App
Invertor website by the
Massachusetts Institute of
Technology

Spring 2023 59
Bluetooth controller

Application Versions
We made multiple versions of the mobile application throughout the entire
project and here are some of them for example:

Spring 2023 60
Bluetooth controller

Application Versions
Final Version Features:
• More robust directional control keypad.
• An emergency stop button.
• Variable speed control levels.
• Battery voltage indicator.

Spring 2023 61
PID Controller
• Working Principles.
• PID Tuning Techniques.
• Trial and Error
• Mechanical Model.

VII
VIII

Spring 2023 62
PID Controller

Working Principle
• A PID (Proportional-Integral-Derivative) controller is a widely
used control algorithm for self-balancing robots.

• It uses feedback from sensors, such as accelerometers and gyroscopes, to


calculate an error signal that represents the difference between the
robot's current orientation and its desired position.

• The controller then uses this error signal to adjust the motor commands
and maintain the robot's balance state.

Spring 2023 63
PID Controller

The PID Parameters

𝒕
𝒅𝒆(𝒕)
𝑻𝒉𝒆 𝒐𝒖𝒕𝒑𝒖𝒕 𝒄𝒐𝒏𝒕𝒓𝒐𝒍 𝒔𝒊𝒈𝒏𝒂𝒍 = 𝒖 𝒕 = 𝑲𝒑 𝒆 𝒕 + 𝑲𝒊 න 𝒆 𝒕 𝒅 𝒕 + 𝑲𝒅
𝟎 𝒅𝒕

Spring 2023 64
PID Controller

PID Design
• There are two main position for the
robot: balanced and tilted.

• The control signal is sent from the


PID to the motors to minimize the
error and maintain the robot
balanced state under any
disturbances.

Spring 2023 65
PID Controller

Trial and Error Tuning


We can tune the PID controller the conventional way by manually
changing the gain values and see the Robot response to such change

Here is a table that shows the system response to certain Gain changes
Parameter Rise Time Overshoot Settling Time Steady-State Stability
error

𝐾𝑝 Decrease Increase Small Change Decrease Degrade

𝐾i Decrease Increase Increase Eliminate Degrade

𝐾d Small Change Decrease Decrease No effect Improve

Spring 2023 66
PID Controller

Trial and Error Tuning


What are the typical starting values for kp, ki, and kd for our code?
• Kp should be the highest gain, followed by kd then ki.
• kp between 5 to 10 is a good starting point. Then incrementally increase kd and ki while testing
the response.

• Start with ki at around 0.1 to 0.5, and kd around 0 to 10.


• Then slowly increase them if the response is underdamped.

• The optimal gains will depend on your robot's mass, motor torque, sampling rate, …etc.
• If the robot is oscillating too much, reduce the gains. If the response is slow, increase the gains.

Spring 2023 67
PID Controller

Trial and Error Tuning


After trial and error, we reached a balance using the following PID
values with the best response and suitable output.

float pid_p_gain = 8.5;


float pid_i_gain = 0.4;
float pid_d_gain = 4.0;

Spring 2023 68
PID Controller

Mechanical Model
• This the
Build model
physical
can model
help ofidentify
the robota
using mechanical
starting Gain values
components
for the actual
such
as the chassis,
system or approach
wheels,
themotors,
true Gain
and
sensors.
values.

• Use Multibody library to add these


components to the model and
connect them using joints and
constraints.

Spring 2023 69
PID Controller

Mechanical Model

Spring 2023 70
How to Balance a Balancing Robot.
• Weight and torque limitations
• Height Limitations
• Wheels Limitations
• Center of gravity calculations

VIII

Spring 2023 71
How to Balance a Balancing Robot.

Weight And Torque Limitations


Calculating the robot’s weight before selecting the motors used to get a
suitable torque able to balance the robot.
Using Newton’s Law:

𝑇𝑖𝑛𝑒𝑟𝑡𝑖𝑎𝑙 = 𝑇𝑔𝑟𝑎𝑣𝑖𝑡𝑦 +𝑇𝑎𝑝𝑝𝑙𝑖𝑒𝑑


𝑡_𝑚𝑎𝑥=𝑚𝑔𝐿𝑠𝑖𝑛𝜃_𝑚𝑎𝑥

Spring 2023 72
How to Balance a Balancing Robot.

Height Limitations
• The robot’s body length has an impact on the robot’s stabilization, if
the length was so too tall the robot may have a violent reaction to the
control action, and it may be unsuitable in the torque calculations.

• The height of a self-balancing robot can have an impact on its balance.


A taller robot will have a higher center of gravity, which can make it
more difficult to balance compared to a shorter robot with a lower
center of gravity.

Spring 2023 73
How to Balance a Balancing Robot.

Wheels Limitations
• There are multiple types of wheels, but in our robot’s structure off-
road wheels where the most suitable to make the robot balance
properly on Rough environments.

• The material of the wheels can affect their grip and traction on
different surfaces.

Spring 2023 74
How to Balance a Balancing Robot.

Center of Gravity
• The center of gravity is the point at which the weight of an object is
concentrated.

• In a self-balancing robot, the center of gravity should be located above the


wheels to ensure that the robot remains upright. If the center of gravity is
located below the wheels, the robot will tend to tip over.

• Horizontal wise adjusting the placement of components; by moving heavy


components closer to the center of the robot, the center of gravity can be
shifted towards the midpoint.

Spring 2023 75
How to Balance a Balancing Robot.

Center of Gravity
• It is important to position the heavy components of the robot as close to the
top of the robot as possible to left up the CoG as it reduces the angular
acceleration needed to react.

Spring 2023 76
Conclusion
• The project aims to build a self-balancing robot that uses the concept
of inverted pendulum theory to maintain balance for a two-wheeled
robot.
• The project gives a clear understanding of mechanical structure
design, component selection, and interfacing with Arduino, electrical
circuit design.
• Implementation of a mobile application and using MATLAB and
Simulink to model the mechanical system.
• The project effectively uses a PID controller to design and tune a
control algorithm for the self-balancing robot.

Spring 2023 77
Any Questions ?

Spring 2023 78
Thank You!

Spring 2023 79

You might also like