Академический Документы
Профессиональный Документы
Культура Документы
Bachelor of Technology
(Electronics and Communication Engineering)
Supervisor:
Er. INDERPREET SINGH
Submitted by:
MITUL TAKIAR
(2011ECA1760)
PRANAV SHARMA
(2011ECA1069)
DECLARATION
We hereby declare that the project work entitled as TWO WHEEL BALANCING
ROBOT USING MICROCONTROLLER ATMEGA 328P is an authentic record of our own
work carried out at Guru Nanak Dev University, Amritsar as required for the six months project
semester for the award of degree of B.Tech (Electronics and Communication Engineering), under
the guidance of Er. Inderpreet Singh, during Jan 2014 to April 2014.
Date:
ACKNOWLEDGEMENT
Acknowledgement is not a mere formality but a genuine attempt to remember all those people without
whose cooperation we would not have been able to complete our project.
We want to thank the Department of Electronics Technology, Guru Nanak Dev University, Amritsar
for giving us such a golden opportunity to commence this project in the first instance. We express our
sincere gratitude to Dr. Maninder Lal Singh, Head of the department, Electronics Technology who
helped us turn this opportunity into true results.
We extend our thanks to Er. Inderpreet Singh who encouraged us to go ahead with our project.
Without his able guidance and counsel it would have been impossible for us to complete this project.
We would like to thank GOD, the Almighty, for having made everything possible by giving us strength
and courage to do this work. Lastly, we wish to express our sincere appreciation to our parents for their
patience and encouragement during this work.
ABSTRACT
The project is designed to build a two wheel balancing
MPU6050 for its movement. A microcontroller of AVR family is used to achieve the
desired operation.
A robot is a machine that can perform task automatically or with guidance. Robotics
is generally a combination of computational intelligence and physical machines
(motors). Computational intelligence involves the programmed instructions.
The balancing robot platform proved to be an excellent test bed for sensor fusion
using the Kalman filter . An indirect Kalman filter configuration combining a piezo
rate gyroscope sensor and an accelerometer is implemented to obtain an accurate
estimate of the tilt angle and its derivative.
Depending on the input signal received, the microcontroller redirects the robot to
move in an alternate direction by actuating the motors interfaced to it through a motor
driver IC.
TABLE OF CONTENTS
Declaration...................................................................................................................... 02
Acknowledgement............................................................................................................. 03
Abstract ............................................................................................................................ 04
List of figures..................................................................................................................... 07
List of tables ...................................................................................................................... 07
1. Introduction ..............................................................................................................08
1.1. Project Description .............................................................................................08
1.2. Applications ........................................................................................................08
2. Literature Review .....................................................................................................09
2.1. Complementary Filter..........................................................................................09
2.2. Kalman Filter.......................................................................................................11
2.3. PID Controller.....................................................................................................14
2.3.1.
2.3.2.
Block Diagram........................................................................................20
3.1.2.
Pin Diagram............................................................................................21
3.1.3.
Features...................................................................................................23
3.2. MPU6050.............................................................................................................24
3.3. Bidirectional level converter................................................................................27
3.3.1.
Circuit.....................................................................................................27
3.3.2.
Features...................................................................................................27
3.4. L293D..................................................................................................................29
3.4.1.
Block Diagram........................................................................................29
3.4.2.
Pin Diagram............................................................................................30
3.4.3.
Features...................................................................................................31
3.4.4.
Circuit Diagram......................................................................................31
3.5. LM7805................................................................................................................32
3.5.1.
Pin Description........................................................................................32
3.5.2.
Circuit......................................................................................................32
3.6. LM317..................................................................................................................33
3.6.1.
Features....................................................................................................33
5
3.6.2.
Circuit......................................................................................................34
LIST OF FIGURES
Figure no.
Caption
Page no.
1.
2.
3.
4.
5.
6.
7.
ATmega328.........................................................................................................................19
8.
9.
10. MPU6050............................................................................................................................24
11. Bidirectional level converter...............................................................................................27
12. I2C using MOSFET.............................................................................................................28
13. L293D block diagram..........................................................................................................29
14. L293D pin diagram..............................................................................................................30
15. L293D Circuit diagram.........................................................................................................31
16. LM7805................................................................................................................................32
17. LM7805 Connection diagram...............................................................................................32
18. LM317...................................................................................................................................33
19. LM317 Circuit Diagram.......................................................................................................34
20. Creating a new AVR Studio-4 project..................................................................................39
21. Creating a new AVR Studio-4 project..................................................................................40
22. Building a project with AVR Studio.....................................................................................40
23. Connecting to the programmer with AVR Studio.................................................................41
24. AVR Studio-4s programmer selection dialog box................................................................41
25. Selecting the device for ISP programming............................................................................42
26. Reading the device signature.................................................................................................42
27. AVR Studios program ISP tab.............................................................................................43
LIST OF TABLES
Table no.
Caption
Page no.
1.
2.
3.
CHAPTER 1
INTRODUCTION
1.1
Project Description
The research on balancing robot has gained momentum over the last decade in a number of
robotics laboratories around the world. This is due to the inherent unstable dynamics of the
system. Such robots are characterised by the ability to balance on its two wheels and spin on
the spot. This additional manoeuvrability allows easy navigation on various terrains, turn
sharp corners and traverse small steps or curbs. These capabilities have the potential to solve a
number of challenges in industry and society.
A balancing robot is built as a platform to investigate the use of a Kalman filter for sensor
fusion. The Kalman filter approach to sensor fusion is unprecedented. This would be a new
avenue to explore the filter for future potential applications of the Kalman filter.
Apart from the above, this thesis will delve into the suitability and performance of linear state
space controllers namely the Linear Quadratic Regulator (LQR) and a Pole placement
controller in balancing the system. The robot utilises a Proportional-Integral- Derivative (PID)
controlled differential steering method for trajectory control. A gyroscope and inclinometer is
used to measure the tilt of the robot and the encoders on the motors to measure the wheels
rotation.
1.2
Applications
A motorised wheelchair utilising this technology would give the operator great
manoeuvrability and thus access to places most able-bodied people take for granted.
Climbing up the staircase can be accomplished by using this robot to balance on two
wheels.
Small carts built utilising this technology allows humans to travel short distances in a
small area or factories as opposed to using cars or buggies which is more polluting.
CHAPTER 2
LITERATURE REVIEW
Introduction
The term complementary filter is often casually used in the literature to refer to any digital algorithm
that serves to blend or fuse similar or redundant data from different sensors to achieve a robust
estimate of a single state variable. For example, in aerospace navigation systems, a complementary
filter is often utilized to estimate the position in space of an airframe by combining the high resolution
position information obtained from integrating acceleration and velocity data with the low resolution
position information obtained directly from the GPS satellite network. The data available from an
inertial navigation systems is very good information for a short period of time. However, as integration
errors grow in an unbounded fashion, they can no longer be tolerated. On the other hand, the position
errors associated with GPS data, though quite large, are bounded and well characterized. A
complementary filter combines the excellent high frequency position information derived from the
integration of inertial sensor data with the good low
frequency position information from GPS data, while rejecting the errors peculiar to each method. The
reader should note that complementary filters are in a class by themselves. While filters in general act
on a signal, the complementary filter does not. It acts only on the different kinds of noise associated
with different kinds of measurements of the same signal. It is a solution waiting for a very special
problem - that of estimating a state variable from data from multiple sources, which exhibit noise with
different frequency content.
Mathematical definition
The complementary filter is a frequency domain filter. In its strictest sense, the definition of a
complementary filter refers to the use of two or more transfer functions, which are mathematical
complements of one another. Thus, if the data from one sensor is operated on by G(s), then the data
from the other sensor is operated on by I-G(s), and the sum of
the transfer functions is I, the identity matrix. In the case of a one-dimensional filter as will be
described in this paper, the identity matrix reduces to the scalar number one.
In a typical two -input system, one input will provide information with high frequency noise, and is
thus low-pass filtered. The other input provides information with low frequency noise, and is high-pass
filtered. If the low-pass and high-pass filters are mathematical complements, then the output of the
filter is the complete reconstruction of the variable being sensed, minus the noise associated with the
sensors.
A block diagram illustrating this process with perfect 1st-order low-pass and high-pass filters is
shown below:
A simple estimation technique that is often used in the flight control industry to combine measurements
is the complementary filter . This filter is actually a steady state Kalman filter (i.e., a Wiener filter) for
a certain class of filtering problems. This relationship does not appear to be well known by many
practitioners of either complementary or Kalman filtering. One exception is the tutorial paper by
Brown which discusses this relationship without going into the mathematical details. The
complementary filter users do not consider any statistical description for the noise corrupting the
signals, and their filter is obtained by a simple analysis in the frequency domain. The proponents of the
Kalman filtering approach work in the time domain and do not pay much attention to the transfer
function or frequency domain (Wiener filter) approach to the filtering problem, since it is a less general
approach to the filtering problem. The Wiener filter solution to this class of multiple-input estimation
problems appeared in the literature, well before Kalman published his classic paper. This paper reviews
complementary filtering and shows how this technique is related to Kalman and Wiener filtering. Since
both Kalman and complementary filtering are under consideration for use in the Space Shuttle Reentry
and Landing Navigation System, the relationship between them should be well understood.
10
In applying Kalman filtering to the problem of combining noisy measurements, the philosophy used is
that the processing of one class of measurements defines the basic process equations. The other
measurements, sometimes referred to as augmenting measurements, define the measurement equations
for the filter. After discussing the basic equations, the two examples of the previous section are
reworked using the steady-state Kalman filter approach. These examples can also be solved by the
Wiener filter approach using spectrum factorization. The relationship between the steady-state or
stationary Kalman filter and the Wiener filter is discussed in the book by Sage and Melsa [6].
Basically, there are two measurements, one of which serves as an input to a differential equation which
serves as the process model. The ideal equations are
xI = FxI + gu (process)
zI = hxI (measurement)
where u is one noiseless measurement and zI is the other. F, g, h, and x are n*n, n*1, 1*n, and n*1
matrixes, respectively; zj and u are scalars. In actuality, we have two noisy measurements, so that the
equations are
x = Fx + g(u + w)
z =hxI + v
where w and v are zero-mean, white, Gaussian noise.
The error equations are
11
where 6k is the estimate of the error vector and k is the Kalman filter gain. k, an n*1 matrix, is obtained
from the equations
where P, the n*n error covariance matrix, is the solution of the Riccati equation
in which R = u2 is the variance of the measurement noise and Q = u2 is the variance of the process
noise. The stationary Kalman filter is obtained by setting P = 0 in the Riccati equation. The actual
estimates of the signals are
In order to show the relationship with the complementary filters, the above equations can be
manipulated to produce a differential equation for
directly:
As is shown below, this equation is identical to the differential equations of the complementary filters
for the example under consideration.
12
Example 1
The process equation from Fig. 2(A) is
This equation is identical to the equation of the complementary filter in Fig. 2(B), where the time
constant of the filter is now
filter, means that the barometric signal is assumed to be much noisier than the accelerometer signal. In
the complementary filter, the time constant is chosen to get most of the information from the
accelerometer signal and use the barometric information only as along-term reference.
13
A proportional-integral-derivative
derivative
mechanism (controller))
widely
controller (PID
used
in industrial
controller)
control
is
a control
loop feedback
systems (Programmable
Programmable
Logic
Controllers, SCADA systems, Remote Terminal Units etc). A PID controller calculates an "error" value
as the difference between a measured process variable and a desired set point.. The controller attempts
to minimize the error in outputs by adjusting the process control inputs.
The PID controller algorithm involves
involves three separate constant parameters, and is accordingly
sometimes
called three-term
term
control
control:
the proportional,
denoted P, I, and D. Simply put, these values can be interpreted in terms of time: P depends on
the present error, I on the accumulation of past errors, and D is a prediction of future errors, based on
current rate of change. The weighted sum of these three actions is used to adjust the process via a
control element such as the position of a control valve, a damper,, or the power supplied to a heating
element.
In the absence of knowledge of the underlying process, a PID controller has historically been
considered to be the best controller. By tuning the three parameters in the PID controller algorithm, the
controller can provide control action designed for specific process requirements. The response of the
controller
troller can be described in terms of the responsiveness of the controller to an error, the degree to
which the controller overshoots the set point, and the degree of system oscillation. Note that the use of
the PID algorithm for control does not guarantee optimal control of the system or system stability.
Some applications may require using only one or two actions to provide the appropriate system control.
This is achieved by setting the other parameters to zero. A PID controller will be called a PI, PD, P or I
controller in the absence of the respective control actions. PI controllers are fairly common, since
derivative action is sensitive to measurement noise, whereas the absence of an integral
integral term may
prevent the system from reaching its target value due to the control action.
14
The PID control scheme is named after its three correcting terms, whose sum constitutes the
manipulated variable (MV). The proportional, integral, and derivative terms are summed to calculate
the output of the PID controller. Defining
algorithm is:
where
: Proportional gain, a tuning parameter
: Integral gain, a tuning parameter
: Derivative gain, a tuning parameter
: Error
: Time or instantaneous time (the present)
: Variable of integration; takes on values from time 0 to the present
Proportional Term
The proportional term produces an output value that is proportional to the current error value. The
proportional response can be adjusted by multiplying the error by a constant Kp, called the proportional
gain constant.
The proportional term is given by:
A high proportional gain results in a large change in the output for a given change in the error. If the
proportional gain is too high, the system can become unstable. In contrast, a small gain results in a
small output response to a large input error, and a less responsive or less sensit
sensitive
ive controller. If the
proportional gain is too low, the control action may be too small when responding to system
disturbances. Tuning theory and industrial practice indicate that the proportional term should contribute
the bulk of the output change.
15
Figure 4Plot
Plot of PV vs time, for three values of Kp (Ki and Kdheld constant)
Integral Term
The contribution from the integral term is proportional to both the magnitude of the error and the
duration of the error. The integral in a PID controller is the sum of the instantaneous error over time
and gives the accumulated offset that should have been corrected previously. The accumulated error is
then multiplied
ed by the integral gain (
The integral term accelerates the movement of the process towards set point and eliminates the residual
steady-state
state error that occurs with a pure proportional controller. However, since the integral term
responds to accumulated errors from the past, it can cause the present value to overshoot the set point
value
Figure 5Plot
Plot of PV vs time, for three values of Ki (Kp and Kdheld constant)
16
Derivative Term
The derivative of the process error is calculated by determining the slope of the error over time and
multiplying this rate of change by the derivative
derivat
gain Kd. The magnitude of the contribution of the
derivative term to the overall control action is termed the derivative gain, Kd.
The derivative term is given by:
Derivative action predicts system behaviour and thus improves settling time and stabil
stability of the
system. An ideal derivative is not causal, so that implementations of PID controllers include an
additional low pass filtering for the derivative term, to limit the high frequency gain and
noise. Derivative action is seldom used in practice though
thou - by one estimate in only 20% of deployed
controllers - because of its variable impact on system stability in real
real-world applications.
Figure 6Plot
Plot of PV vs time, for three values of Kd (Kp and Kiheld constant)
17
do not react to changing process behaviour (say, the process changes after it has warmed up), and have
lag in responding to large disturbances.
The most significant improvement is to incorporate feed-forward control with knowledge about the
system, and using the PID only to control error. Alternatively, PIDs can be modified in more minor
ways, such as by changing the parameters (either gain scheduling in different use cases or adaptively
modifying them based on performance), improving measurement (higher sampling rate, precision, and
accuracy, and low-pass filtering if necessary), or cascading multiple PID controllers.
Linearity
Another problem faced with PID controllers is that they are linear, and in particular symmetric. Thus,
performance of PID controllers in non-linear systems (such as HVAC systems) is variable. For
example, in temperature control, a common use case is active heating (via a heating element) but
passive cooling (heating off, but no cooling), so overshoot can only be corrected slowly it cannot be
forced downward. In this case the PID should be tuned to be over damped, to prevent or reduce
overshoot, though this reduces performance (it increases settling time).
Noise in derivative
A problem with the derivative term is that it amplifies higher frequency measurement or
process noise that can cause large amounts of change in the output. It does this so much, that a physical
controller cannot have a true derivative term, but only an approximation with limited bandwidth. It is
often helpful to filter the measurements with a low-pass filter in order to remove higher-frequency
noise components. As low-pass filtering and derivative control can cancel each other out, the amount of
filtering is limited. So low noise instrumentation can be important. A nonlinear median filter may be
used, which improves the filtering efficiency and practical performance. In some cases, the differential
band can be turned off with little loss of control. This is equivalent to using the PID controller as a PI
controller.
18
CHAPTER 3
COMPONENTS REVIEW
Microcontrollers are sometimes called embedded microcontrollers. This just means that they are part of
an embedded system; that is, one part of a larger device or system. Microcontrollers are used in
automatically controlled products and devices, such as automobile engine control systems, implantable
medical devices, remote controls, office machines, appliances, power tools, toys and other embedded
systems. The first integrated circuit was developed by Jack Kilby of Texas Instruments and Robert
Noyce of Fairchild Semiconductor in 1950.
Flash
EEPROM
RAM
ATmega48PA
4K Bytes
256 Bytes
512 Bytes
1 instruction word/vector
ATmega88PA
8K Bytes
512 Bytes
1K Bytes
1 instruction word/vector
ATmega168PA
16K Bytes
512 Bytes
1K Bytes
2 instruction words/vector
ATmega328P
32K Bytes
1K Bytes
2K Bytes
2 instruction words/vector
Table 1
19
20
VCC
Digital supply voltage.
GND
Ground.
Port B (PB7:0) XTAL1/XTAL2/TOSC1/TOSC2
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. If the Internal
Calibrated RC Oscillator is used as chip clock source, PB7..6 is used as TOSC2..1input for the
Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set.
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
21
activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not
running.
PC6/RESET
If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the electrical
characteristics of PC6 differ from those of the other pins of Port C. If the RSTDISBL Fuse is
unprogrammed, 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 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.
AVCC
AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It should be externally
connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC
through a low-pass filter. Note that PC6..4 use digital supply voltage, VCC.
AREF
AREF is the analog reference pin for the A/D Converter.
22
3.1.3 FEATURES
Atmel
Manufacturer:
Product Category:
Core:
AVR
8 bit
20 MHz
32 kB
2 kB
On-Chip ADC:
Yes
1.8 V to 5.5 V
+ 85 C
Package / Case:
PDIP-28
Mounting Style:
Through Hole
10 bit
Brand:
Atmel
SRAM
1 kB
EEPROM
Interface Type:
- 40 C
23
Number of Timers:
Packaging:
Tube
Processor Series:
megaAVR
Product Category:
Microcontrollers - AVR
Flash
Series:
ATMEGA328
5.5 V
1.8 V
23
3.2 MPU6050
Motion Interface is becoming a must-have function being adopted by smart phone and tablet
manufacturers due to the enormous value it adds to the end user experience. In smartphones , it finds
use in applications such as gesture commands for applications and phone control, enhanced gaming,
augmented reality, panoramic photo capture and viewing, and pedestrian and vehicle navigation. With
its ability to precisely and accurately track user motions, Motion Tracking technology can convert
handsets and tablets into powerful 3D intelligent devices that can be used in applications ranging from
health and fitness monitoring to location-based services. Key requirements for Motion Interface
enabled devices are small package size, low power consumption, high accuracy and repeatability, high
shock tolerance, and application specific performance programmability all at a low consumer price
point.
The MPU-60X0 is the worlds first integrated 6-axis Motion Tracking device that combines a 3-axis
gyroscope, 3-axis accelerometer, and a Digital Motion Processor (DMP) all in a small 4x4x0.9mm
package. With its dedicated I2C sensor bus, it directly accepts inputs from an external 3-axis compass
to provide a complete 9-axis Motion Fusion output. The MPU-60X0 Motion Tracking device, with its
6-axis integration, on-board Motion Fusion, and run-time calibration firmware, enables manufacturers
to eliminate the costly and complex selection, qualification, and system level integration of discrete
devices, guaranteeing optimal motion performance for consumers. The MPU-60X0 is also designed to
interface with multiple non-inertial digital sensors, such as pressure sensors, on its auxiliary I2C port.
The MPU-60X0 is footprint compatible with the MPU-30X0 family.
The MPU-60X0 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope
outputs and three 16-bit ADCs for digitizing the accelerometer outputs. For precision tracking of both
fast and slow motions, the parts feature a user-programmable gyroscope full-scale range of 250, 500,
1000, and 2000/sec (dps) and a user-programmable accelerometer full-scale range of 2g, 4g,
8g, and 16g.
24
An on-chip 1024 Byte FIFO buffer helps lower system power consumption by allowing the system
processor to read the sensor data in bursts and then enter a low-power mode as the MPU collects more
data. With all the necessary on-chip processing and sensor components required to support many
motion-based use cases, the MPU-60X0 uniquely enables low-power Motion Interface applications in
portable applications with reduced processing requirements for the system processor. By providing an
integrated Motion Fusion output, the DMP in the MPU-60X0 offloads the intensive Motion Processing
computation requirements from the system processor, minimizing the need for frequent polling of the
motion sensor output.
Communication with all registers of the device is performed using either I2C at 400kHz or SPI at
1MHz (MPU-6000 only). For applications requiring faster communications, the sensor and interrupt
registers may be read using SPI at 20MHz (MPU-6000 only). Additional features include an embedded
temperature sensor and an on-chip oscillator with 1% variation over the operating temperature range.
By leveraging its patented and volume-proven Nasiri-Fabrication platform, which integrates MEMS
wafers with companion CMOS electronics through wafer-level bonding, InvenSense has driven the
MPU-60X0 package size down to a revolutionary footprint of 4x4x0.9mm (QFN), while providing the
highest performance, lowest noise, and the lowest cost semiconductor packaging required for handheld
consumer electronic devices. The part features a robust 10,000g shock tolerance, and has
programmable low-pass filters for the gyroscopes, accelerometers, and the on-chip temperature sensor.
For power supply flexibility, the MPU-60X0 operates from VDD power supply voltage range of
2.375V-3.46V. Additionally, the MPU-6050 provides a VLOGIC reference pin (in addition to its
analog supply pin: VDD), which sets the logic levels of its I2C interface. The VLOGIC voltage may be
1.8V5% or VDD.
The MPU-6000 and MPU-6050 are identical, except that the MPU-6050 supports the I2C serial
interface only, and has a separate VLOGIC reference pin. The MPU-6000 supports both I2C and SPI
interfaces and has a single supply pin, VDD, which is both the devices logic reference supply and the
analog supply for the part.
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 userprogrammable full-scale range of 250, 500, 1000, and 2000/sec
External sync signal connected to the FSYNC pin supports image, video and GPS
synchronization
Enhanced bias and sensitivity temperature stability reduces the need for user calibration
25
Standby current: 5A
User self-test
Accelerometer Features
The triple-axis MEMS accelerometer in MPU-60X0 includes a wide range of features:
Digital-output triple-axis accelerometer with a programmable full scale range of 2g, 4g,
8g and 16g
Low power accelerometer mode current: 10A at 1.25Hz, 20A at 5Hz, 60A at 20Hz,
110A at 40Hz
Orientation detection and signaling
Tap detection
User-programmable interrupts
High-G interrupt
User self-test
Additional Features
The MPU-60X0 includes the following additional features:
9-Axis MotionFusion by the on-chip Digital Motion Processor (DMP)
Auxiliary master I2C bus for reading data from external sensors (e.g., magnetometer)
3.9mA operating current when all 6 motion sensing axes and the DMP are enabled
Flexible VLOGIC reference voltage supports multiple I2C interface voltages (MPU-6050
only)
Smallest and thinnest QFN package for portable devices: 4x4x0.9mm
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
26
3.3.1 Circuit:
3.3.2 Features:
Minimum Voltage: 3.3V and Maximum Voltage: 5V
Bi-directional Logic Level conversion is possible.
BreadBoard friendly.
27
28
3.4 L293D
The L293 and L293D are quadruple high-current half-H drivers. The L293 is designed to provide
bidirectional drive currents of up to 1 A at voltages from 4.5 V to 36 V. The L293D is designed to
provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V. Both devices are
designed to drive inductive loads such as relays, solenoids, dc and bipolar stepping motors, as well as
other high-current/high-voltage loads in positive-supply applications.
All inputs are TTL compatible. Each output is a complete totem-pole drive circuit, with a Darlington
transistor sink and a pseudo Darlington source. Drivers are enabled in pairs, with drivers 1 and 2
enabled by 1,2EN and drivers 3 and 4 enabled by 3,4EN. When an enable input is high, the associated
drivers are enabled, and their outputs are active and in phase with their inputs. When the enable input is
low, those drivers are disabled, and their outputs are off and in the high-impedance state. With the
proper data inputs, each pair of drivers forms a full-H (or bridge) reversible drive suitable for solenoid
or motor applications.
29
Pin Description:
Table 2
30
3.4.3 Features:
Motor Type:Half-H
No. of Outputs:4
No. of Pins:16
Output Current:600mA
Output Voltage:36V
31
3.5 LM7805
A voltage regulator is a circuit that supplies a constant voltage regardless of changes in load current.
7805 is a voltage regulator integrated circuit. It is a member of 78xx series of fixed linear voltage
regulator ICs. The voltage source in a circuit may have fluctuations and would not give the fixed
voltage output. The voltage regulator IC maintains the output voltage at a constant value. The xx in
78xx indicates the fixed output voltage it is designed to provide. 7805 provides +5V regulated power
supply. Capacitors of suitable values can be connected at input and output pins depending upon the
respective voltage levels.
Figure 16 LM7805
Function
Input voltage (5V-18V)
Ground (0V)
Regulated output; 5V (4.8V-5.2V)
Table 3
Name
Input
Ground
Output
3.5.2 Circuit:
Proper operation requires a common ground between input and output voltages. The difference
between input and output voltages is called dropout voltage. Acapacitorof 0.33F is required if the
regulator is located at an appreciable distance from the power supply filter. Even though capacitor of
0.1 F is not needed, it may be used to improve the transient response of the regulator.
32
3.6 LM317
The LM317 is an adjustable 3terminal positive voltage regulator capable of supplying in excess of 1.5
A over an output voltage range of 1.2 V to 37 V. This voltage regulator is exceptionally easy to use and
requires only two external resistors to set the output voltage. Further, it employs internal current
limiting, thermal shutdown and safe area compensation, making it essentially blowout proof. The
LM317 serves a wide variety of applications including local, on card regulation. This device can also
be used to make a programmable output regulator, or by connecting a fixed resistor between the
adjustment and output, the LM317 can be used as a precision current regulator.
Figure 18 LM317
3.6.1 Features
33
3.6.2 Circuit
*
*_Cin is required if regulator is located an appreciable distance from power supply filter.
**_CO is not needed for stability, however, it does improve transient response.
Since IAdj is controlled to less than 100 A, the error associated with this term is
negligible in most applications.
34
CHAPTER 4
ASSEMBLING THE ROBOT
Chassis
35
Tyres
36
37
Final Structure
38
CHAPTER 5
PROGRAMMING THE ROBOT
STEPS TO PROGRAM
1.
39
2.
Select AVR Simulator as the debug platform and then select the appropriate device for your
target AVR. For an Orangutan or 3pi Robot, this will either be ATmega48, ATmega168,
ATmega328P, ATmega324PA,
24PA, ATmega644P, or ATmega1284P depending on which chip
your Orangutan or 3pi Robot has. Click Finish.
3.
Write your program in BlinkLED.c as seen in the screen shot below and click the B
Build button
on the toolbar (or press F7).
F7
40
4.
Make sure your USB AVR programmer is connected to your computer via its USB A to mini
miniB cable and then click the Display the Connect Dialog button on the toolbar. You can also
accomplish this by going to the Tools menu and selecting Program AVR > Connect
Connect.
5.
If the ISP window does not appear when you click Connect, your computer cannot detect
the programmer. Please see Troubleshooting for help identifying and fixing the
the problem.
If AVR Studio brings up a dialog asking if you want to upgrade (or downgrade) your
programmers firmware, click Cancel to ignore the message and use your programmer. To
prevent this dialog from appearing in the future, use the Configuration Utilitychange
Utilitychange the
programmers hardware and software version numbers.
41
6.
Select the Main tab. In the dropdown box that lists AVR models, select the same device that
you selected when you created the project. For an Orangutan or 3pi Robot, this will either
be ATmega48, ATmega168,
ATmega168 or ATmega328P.
7.
If you have not done so already, connect the programmer to the target device using the 6-pin
6
ISP cable. Make sure the cable is oriented so that pin 1 on the connector lines up with pin 1 on
your target device! You can test the connection by going to the Main tab and clicking
the Read Signature button. This sends a command to the target AVR asking for its device
signature. If everything works correctly,
correctly, you should see Signature matches selected device.
If the signature does not match the selected device, you probably have the wrong device
selected (or possibly your target device is turned off). If reading the signature fails entirely,
please see Troubleshooting for help getting your connection working.
Figure 26 Reading the device signature in AVR studio's main ISP tab
8.
Now it is time to program your target device. Select the Program tab. Your Input HEX
File in the Flash section needs to be the hex file that was generated when you built your
program. You can browse for this using the "..." button to the right of the input file text box.
If you navigate to your projects folder, you should find it as default\<project
<project name
name>.hex.
Click the Program button (make sure you click the one in the Flash section, not one in the
EEPROM or ELF Production File Format sections!).
42
43
CHAPTER 6
TESTING THE ROBOT
Prior to programming the robot with final program, several test programs were burned in the
microcontroller to verify various discrete segments of the hardware structure. The robot was tested to
verify the functioning of the following segments for proper operation:
Motor assembly
Sensor Check
44
}
void loop()
{
val = analogRead(analog);
analogWrite ( Led, val/4);
}
45
pinMode(Motor1b, OUTPUT);
pinMode(Motor2a, OUTPUT);
pinMode(Motor2b, OUTPUT);
}
voidmForward()
{
digitalWrite(Motor1a, HIGH);
digitalWrite(Motor1b, LOW);
digitalWrite(Motor2a, HIGH);
digitalWrite(Motor2b, LOW);
}
void setup()
{
pinMode(Led, OUTPUT);
pinMode(analoga, INPUT);
pinMode(MotorEnable, OUTPUT);
pinMode(analog, INPUT);
pinMode(MotorEnable2, OUTPUT);
digitalWrite(MotorEnable2, LOW);
MotorSetup();
mForward();
}
void loop()
{
val = analogRead(analoga);
analogWrite ( Led, val/4);
// val = analogRead(analog);
analogWrite ( MotorEnable, val/4);
}
46
47
// for a human.
//#define OUTPUT_BINARY_ACCELGYRO
#define LED_PIN 13
boolblinkState = false;
void setup()
{
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(38400);
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050
connection failed");
// use the code below to change accel/gyro offset values
/*
Serial.println("Updating internal sensor offsets...");
// -76
-2359
1688
48
Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0
Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0
Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0
Serial.print("\n");
accelgyro.setXGyroOffset(220);
accelgyro.setYGyroOffset(76);
accelgyro.setZGyroOffset(-85);
Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76
Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359
Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688
Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0
Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0
Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0
Serial.print("\n");
*/
// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}
void loop()
{
// read raw accel/gyro measurements from device
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);
#ifdef OUTPUT_READABLE_ACCELGYRO
// display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
49
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
#endif
#ifdef OUTPUT_BINARY_ACCELGYRO
Serial.write((uint8_t)(ax>> 8)); Serial.write((uint8_t)(ax& 0xFF));
Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
Serial.write((uint8_t)(az>> 8)); Serial.write((uint8_t)(az& 0xFF));
Serial.write((uint8_t)(gx>> 8)); Serial.write((uint8_t)(gx& 0xFF));
Serial.write((uint8_t)(gy>> 8)); Serial.write((uint8_t)(gy& 0xFF));
Serial.write((uint8_t)(gz>> 8)); Serial.write((uint8_t)(gz& 0xFF));
#endif
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
50
Output Graphs:
51
BIBLIOGRAPHY
http://www.instructables.com/id/2-Wheel-Self-Balancing-Robot-by-usingArduino-and-/
http://en.wikipedia.org/wiki/Kalman_filter
http://forum.arduino.cc/index.php?topic=58048.0
http://www.instructables.com/id/PCB-Quadrotor-Brushless/step15/IMU-Part2-Complementary-Filter/
http://en.wikipedia.org/wiki/PID_controller
http://www.atmel.in/devices/ATMEGA328P.aspx
http://www.invensense.com/mems/gyro/mpu6050.html
http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter
http://www.ti.com/lit/ds/symlink/l293d.pdf
http://www.ti.com/lit/ds/symlink/lm317.pdf
http://www.engineersgarage.com/tutorials/avr-studio4-working
http://stackoverflow.com/tags/avr-studio4/info
http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter
http://www.atmel.in/tools/atmelstudio.aspx
52