0% found this document useful (0 votes)
73 views9 pages

Chappie Self Balancing Robot

This document describes the process of building a self-balancing robot called Chappie. It discusses selecting materials like an acrylic sheet chassis and electronics like an Arduino, MPU-6050 sensor, Bluetooth module, and motor driver. It explains how the robot balances like a stick, using the PID control algorithm and sensor data to accelerate the wheels based on the robot's tilt. Code is provided on GitHub to read sensor data, calculate tilt angles, and control motors in response using tuned PID parameters to balance the robot.

Uploaded by

Chamadi Baba
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)
73 views9 pages

Chappie Self Balancing Robot

This document describes the process of building a self-balancing robot called Chappie. It discusses selecting materials like an acrylic sheet chassis and electronics like an Arduino, MPU-6050 sensor, Bluetooth module, and motor driver. It explains how the robot balances like a stick, using the PID control algorithm and sensor data to accelerate the wheels based on the robot's tilt. Code is provided on GitHub to read sensor data, calculate tilt angles, and control motors in response using tuned PID parameters to balance the robot.

Uploaded by

Chamadi Baba
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/ 9

technology workshop living food play outside

Chappie- Self-Balancing Robot


by manpreetsingh80 on May 26, 2015

Table of Contents

Chappie- Self-Balancing Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: Chappie- Self-Balancing Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: Concept/Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

What is Self-balancing robot? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

How it works? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 2: Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 3: Chassis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 4: Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Now why these components? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 5: Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 6: APP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 7: PID Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Important Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

What P, I & D values means practically? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 8: What’s next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
Author:manpreetsingh80 Electronics2Work
If you like my work,Please visit my Website for more awesome things

Intro: Chappie- Self-Balancing Robot


After getting so much frustrated over PID tuning of quadcopter, I decided to master PID first on some basic project. Self-balancing robot seems an idle
choice. Since it’s not new and still challenging, I decided to go for it.

I never thought it will be easy and I am not disappointed. I learned a lot from it and decided to share it with others.

Step 1: Concept/Theory
What is Self-balancing robot?

Self-Balance Robot is somewhat which balances itself and automatically corrects its position on disturbance.

How it works?

It will be prevented from falling by giving acceleration to the wheels according to its inclination from the vertical. If the bot gets tilts by an angle, than in the frame of the
wheels, the center of mass of the bot will experience a pseudo force which will apply a torque opposite to the direction of tilt.

That’s the technical answer. If you want to know in simple terms, recall the stick balancing game which you used to play in your childhood.Yeah, the one in which you
balance stick in your hand. If stick falls forward, you move your hand forward and vice-versa. Now consider the stick your robot and the 2 tire’s as your hands. The same
technique you used to balance stick will now be used to balance robot.

Step 2: Materials
First we need some materials to build our chassis. I choose Acrylic sheet. Some screws will be needed according to design which we will discuss shortly plus 2 tires.

For remaining Electronics part, here’s the list

1x Arduino UNO

1x HC-05 Bluetooth Module

1x MPU 6050

1x L293D

1x IC7805

1x Battery

2x 500 rpm Motors

2x Motor clamps with screws

Some jumper wires and breadboard/PCB

We will talk about the choices of these components later

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
Step 3: Chassis
I designed my chassis using acrylic sheet (just to save trouble of drilling holes). However, it can be designed using Wooden plank, plastic sheet etc. too. In my opinion,
wooden plank will be good choice if you want to build a stable chassis and plan to mount something on it. Anyways, I cut sheet to form 3 levels/floors. It’s not mandatory,
but is a good practice. No. of levels can be increased if desired. After markings, holes has to be made for screws. For making holes, I simply use Solder iron. (Here
acrylic sheet comes to rescue. After making holes, I realized that I made mistakes which I corrected easily) If you are using, wood, double check your markings.

Choice of tires should be ones with good grip (rubber, if available) and large surface area.

Assemble the whole chassis and we are ready to move to electronics part.

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
Step 4: Connections
Now why these components?

MPU-6050 is used due to its DMP capability. It can process the Raw Accelerometer & Gyro values to give the Yaw, Pitch, and Roll. It greatly decreases the computation
overhead.

HC-05 Bluetooth module is used for communication between Bot and Android app.

L293d motor driver is used for controlling motor.

IC7805 voltage Regulator is used for providing 5V power supply to Arduino. However, using this IC is not necessary and battery can be directly plugged to Arduino. This
is just used for Safety Purposes

A fritizing file is attached to show the connections. Connect all as shown.

Now as everything set, we can dive into the code for our robot.

Step 5: Software
Arduino is known for its friendly coding environment and large open source user libraries which makes the prototyping really easy.

I first started with separate Accelerometer and Gyroscope. But as things progressed, I find it difficult to balance with computational overhead of calculating pitch & roll
(using kalman/Complementary filter).When I switched to MPU-6050, it drastically improved the balancing.

To use the DMP of MPU, I used Jeff Rowberg’s I2CDev libraries. To calibrate the mpu, I used Luis Rodenas’s sketch.

Now, we can determine the angle of bot with vertical. But how can we calculate the amount of force needed to push bot back to vertical when it is unbalanced by some
uncertain degrees from vertical. This is where PID kicks in.PID will specify this force which will change according to time and angle by which bot is unbalanced.

I will not go into technical details. Brett Beauregard wrote a nice PID library with explanation if you want.

To further speed up the motor response, I used digitalIOPerformance library for fast writing of pins.

Finally for storing PID values in EEPROM of Arduino, EEPROMex library for efficiency and clean code.

Complete code can be found on the GITHUB.

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
Step 6: APP
Re-uploading code every time to change PID values is very tiresome. So I decided to attach Bluetooth and change values from my Android phone. I saw many people
using MIT App Inventor for building apps for such purposes. I never used it before. So I thought, I must give it a shot. After watching some tutorials and some apps from
other people regarding Bluetooth connection, I was all set. I must admit,App inventor revolutionize the app creation by letting you make apps in a way even non-
programmers can make it without concerning what is happening behind the scenes.

MIT app inventor was fun except I have to deal large graphical blocks even for simpler tasks. Arrangements of these blocks was tiresome and reading it was pain.

You can find my app and Sample code from here.

Note-Although Multi-scene was introduced in App inventor 2, it treats every scene as separate app.For ex-you started some Bluetooth activity in scene1 and paired a
device and then switched to scene2.scene2 will be completely unaware of the the pairing and tries to pair (& obviously fails) a device. A good way of handling it is build a
single scene app and hide/show elements just like single page websites.

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
Step 7: PID Tuning
Frankly, this is the most difficult part of the process and also the most crucial. You will spend many days working on it and yelling “WTH am I supposed to
do?” How much frustrating it may be but there is no escaping it? Control engineers set the PID parameters by experience. It’s an art learnt through
experience.

There are various methods out there for PID tuning.

The best simple & easy method for PID tuning is-

· Set I and D term to 0, and adjust P so that the robot starts to oscillate (move back and forth) about the balance position. P should be large enough for the robot
to move but not too large otherwise the movement would not be smooth.
· With P set, increase I so that the robot accelerates faster when off balance. With P and I properly tuned, the robot should be able to self-balance for at least a
few seconds.
· Finally, increase D so that the robot would move about its balanced position more gentle, and there shouldn’t be any significant overshoots.
· If first attempt doesn’t give the satisfying results, reset PID values and start over again with different value of P.
· Repeat the steps until you find a certain PID value which gives the satisfactory results.
· A fine tuning can be done to further increase the performance of PID system.
· In fine tuning, PID values are restricted to neighboring values and effects are observed in practical situations.

Important Points

· There is no clear boundary for taking P, I or D values and is mostly taken based on experience.
· Theoretically, ID values depends on the state of the system.Ex. Mechanical Structure, Physical properties, Electrical properties (if any) etc.
· But practically, it also depends on the external conditions.Ex. Atmospheric conditions etc.
· PID values and method of choosing PID values depends largely on the characteristics of system. A method producing good result for a system may not work at
all for another system with different characteristics.

What P, I & D values means practically?


http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
In case of Self-Balancing Robot-

P-P determines the force with which the robot will correct itself. A lower P shows robot’s inability to balance itself and a higher P will shows the violent behavior.
I-I determines the response time of robot for correcting itself. Higher the P, Faster it will response.
D- D determines the sensitivity of robot to the error in its state. It is used to smoothen/depress the robot oscillations. A lower D is unable to remove oscillations
and a higher D will cause violent vibrations.

Depending on your PID tuning, the bot will be able balance itself now.

Congratulation!!! On your first self-balancing robot. Maybe you can name it now, I called mine Chappie.

Step 8: What’s next?


Well, now you have a self-balancing robot which you can control by Bluetooth. Maybe you can upgrade it to Wi-Fi or use it as replacement to your 4 wheel robot.

You can upgrade the Arduino to Raspberry pi to harness the power of mini-computer e.g. Image processing etc.

You can also use decoder motor or stepper motors.it will also significantly increases the performance. However, you will need to update the code accordingly.

Related Instructables

2-Wheel Self
Simple Self- Balancing Self Balancing Arduino Building a Balancing
balancing Robot Robot by using Robot with LCD Modular Robot segway with Instructable
w/ Galileo Gen 2 Arduino and by ferasf by 20b Raspberry Pi by Robot by
by dustnnotes MPU6050 by KevinK6 Naren_Murali
Ufactory

Advertisements

Comments
14 comments Add Comment

PranavN3 says: Jul 8, 2015. 10:20 AM REPLY


Heyy i"m really having truble with the software part.

First of all how must i add library I2CDev to arduino IDE

always getting this error..

SelfBalance_robot0_67.ino:10:20: fatal error: I2Cdev.h: No such file or directory

manpreetsingh80 says: Jul 10, 2015. 11:14 AM REPLY


well.here is the link-https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/I2Cdev

vjeyaraj1 says: Jun 28, 2015. 8:38 PM REPLY


Hi,

Im getting this error, Could you help me? :)

SelfBalance_robot0_67:84: error: no matching function for call to 'PID::PID(float*, float*, float*, int, int, double, int)'

C:\Users\Vahesan\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\Arduino-PID-Library-master/PID_v1.h:19: note: candidates are: PID::PID(double*,


double*, double*, double, double, double, int)

C:\Users\Vahesan\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\Arduino-PID-Library-master/PID_v1.h:6: note: PID::PID(const PID&)

SelfBalance_robot0_67:85: error: no matching function for call to 'PID::PID(float*, float*, float*, int, int, int, int)'

C:\Users\Vahesan\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\Arduino-PID-Library-master/PID_v1.h:19: note: candidates are: PID::PID(double*,


double*, double*, double, double, double, int)

C:\Users\Vahesan\Desktop\arduino-1.0.6-windows\arduino-1.0.6\libraries\Arduino-PID-Library-master/PID_v1.h:6: note: PID::PID(const PID&)

manpreetsingh80 says: Jun 28, 2015. 11:55 PM REPLY


Hmmm it looks like the PID library is updated.Changing float to double will remove all the errors. I already updated the code on GITHUB. There shouldn't
be any errors now.

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
vjeyaraj1 says: Jul 7, 2015. 10:59 PM REPLY
Thank You, it fixed the error :) There are errors with the EEPROM library in the newer Arduino IDE 1.6.3. In the old one it works perfectly fine! :)

fai.v.fai says: Jun 4, 2015. 2:35 PM REPLY


Hi manpreetsing80,

I'm trying to modify your code such that the EEPROM is not used, and all of the PID values are just in the code. Do you have a version of your code before you
added the EEPROM, that you would be able to share? My compiler is giving me too many errors so I need some help figuring this one out. Thanks in advance
for any insight that you can provide!

manpreetsingh80 says:
Hi fal,

i #define the pid values at the starting of code.if you dont want to load pid values from eeprom at start,then just replace
//first save pid values in EEPROM manually,otherwise it will give garbage valuesaddressFloat = EEPROM.getAddress(sizeof(float)); //reading from
EEPROMbal_kp=EEPROM.readFloat(addressFloat);bal_ki=EEPROM.readFloat((addressFloat+=sizeof(float)));bal_kd=EEPROM.readFloat((addressFloat+=sizeof
with this

addressFloat = EEPROM.getAddress(sizeof(float)); //reading from EEPROMbal_kp=BALANCE_KP;


bal_ki=BALANCE_KI;
bal_kd=BALANCE_KD;
rot_kp=ROTATION_KP;
rot_ki=ROTATION_KI;
rot_kd=ROTATION_KD;
this should load pid values from code defined earlier.if you want to completely eliminate the eeprom library,then PM me.i will prepare a version for you.

ajayr5 says: Jun 4, 2015. 7:07 AM REPLY


hi. i can't find softserial library anywhere. i used newsoftserial library instead.but the code is not working.can you help me??

manpreetsingh80 says: Jun 7, 2015. 1:50 AM REPLY


SoftwareSerial library is bundled with arduino package.i compiled this code with arduino IDE 1.0.5.you can download this version from arduino official
site.it will take care of the errors.

if error still occurs, PM me.i will share the libraries too!

Cassiope34 says: May 27, 2015. 4:23 AM REPLY


Hi manpreetsingh80

I'm sure you know the Kalman filter to use with PID regulator...

I havn't seen your code, but do you use this filter ?

Do you know http://remotexy.com/en/examples/ to use very easely with your nice and simpler Balancing Bot ?

Cheers.

Gilles

Cassiope34 says: May 27, 2015. 4:33 AM REPLY


Ooops ! sorry !

I had not read your article very well !!

Just to say that I saw Balancing bot with and without Kalman filter : with kalman filter, the balancing bot practically did not oscillated... instead of in your
video !

Cheers.

Gilles

manpreetsingh80 says: May 31, 2015. 1:10 AM REPLY


Hi,Thanks for the remotexy,will try it in next project.

As for kalman filter,it is generally used to filter out the pitch & roll values from accelerometer and gyroscope.As i was using DMP of mpu6050,there is
no need of kalman filter.Oscillations in video are mainly due to dc motors and tyres.You will notice,people generally use decoder motor's for better
motor control and lastly it is the pid parameters that controls the balance.

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/
tomatoskins says: May 27, 2015. 7:28 AM REPLY
So cool! I've always wanted to make a self ballanceing robot! This is awesome!

manpreetsingh80 says: May 31, 2015. 1:02 AM REPLY


Thanks

http://www.instructables.com/id/Chappie-Self-Balancing-Robot/

You might also like