+ All Categories
Home > Documents > Project Report

Project Report

Date post: 07-Nov-2015
Category:
Upload: harminder-singh-oassan
View: 6 times
Download: 0 times
Share this document with a friend
Description:
Our self balancing bot was created using ARM board (Raspberry pi) using IMU sensor (MPU-6050). The Raspberry Pi provides us with GPIO(General Puprose Input Output)Ports that could be easily used to make the connections for the L298 which further controls the Motors.
Popular Tags:
48
Project Report On Design of SELF BALANCING ROBOT (Using ARM) Submitted in partial fulfillment of the requirement for the award of the degree of Bachelor of Technology In Electronics & Communication Engineering By Harminder Singh(04913202811) Samardeep Singh(04813202811) Jasmeet Singh(05513202811) Under the guidance of: Mr. Gagandeep Singh
Transcript

Project ReportOnDesign ofSELF BALANCING ROBOT(Using ARM)

Submitted in partial fulfillment of therequirement for the award of the degree of

Bachelor of TechnologyInElectronics & Communication Engineering

ByHarminder Singh(04913202811)Samardeep Singh(04813202811)Jasmeet Singh(05513202811)Under the guidance of: Mr. Gagandeep Singh

Department of Electronics and Communication EngineeringGuru Tegh Bahadur Institute of TechnologyGuru Gobind Singh Indraprastha UniversityDwarka, New DelhiYear 2014-2015DECLARATION

This is to certify that the report entitled self-balancing robot which is submitted by us in partial fulfillment of the requirement for the award of degree B. Tech in Electronics and Communication Engineering to Guru Tegh Bahadur Institute of Technology, GGSIPU Delhi, comprises only our original work and due acknowledgement has been made in the text in all other materials used.

DATE:HARMINDER SINGH (04913202811)SAMARDEEP SINGH (04813202811)JASMEET SINGH (05513202811)

CERTIFICATE

This is to certify that the project report entitled SELF BALANCING ROBOT (Using ARM) submitted by Mr. Harminder Singh, Roll No. 04913202811, Mr. Jasmeet Singh, Roll No. 05513202811 and Mr. Samardeep Singh, Roll No. 04813202811 in partial fulfillment of the requirement for the award of the degree in B.Tech in Electronics & Communication Engineering from GGSIP University, Dwarka, Delhi embodies work carried out by him under my supervision at Department of Electronics and Communication Engineering, GTBIT, Delhi during the period January 2015 to May 2015.

Mr. Amrik Singh Ms. Manpreet Kaur(Overall Project Coordinator) (Project Coordinator)

Mr. Gagandeep Singh Mrs.Vidhisha Khetarpal(Project Guide) (Project Coordinator)

Mr. Vaneet Singh Ms. Prachi Dewaan(HOD, ECE) (Project Coordinator)

ACKNOWLEDGEMENT

An Endeavour over long period can be successful only with the advice and guidance of many well wishers.We take this opportunity to express our profound gratitude and deep regards to Mr. Gagandeep Singh, for his exemplary guidance, monitoring, constant encouragement and motivation in thin and thick throughout the course of this training. The blessings help and guidance given by him from time to time shall carry us a long way in life in the journey of life on which we are about to embark.Our heartily gratitude goes to Mr. Vaneet Singh, H.O.D, electronics and communication Department, Guru Tegh Bahadur Institute of Technology, Delhi, for encouraging us to go for such live projects. We would also like to thank our project coordinators Ms. Manpreet Kaur, Ms. Vidhisha Khetarpal and Ms. Prachi Dewaan for sparing their most precious time in providing constant guidance and motivation toward the completion of this project.

HARMINDER SINGH (04913202811)SAMARDEEP SINGH (04813202811)JASMEET SINGH (05513202811)

ABSTRACT

Self balancing Robot is a collective implementation of core concepts CONTROL ENGINEERING and EMBEDDED SYSTEMS.The basic concept is to use Gyroscopic sensing to drive the actuators (motors) and in turn balance the structure.Our self-balancing bot was created using ARM board (Raspberry pi) using IMU sensor (MPU-6050). The Raspberry Pi provides us with GPIO (General Purpose Input Output) Ports that could be easily used to make the connections for the L298 which further controls the Motors.

Two Gear motors of 200 RPM (rotations per minute) are also applied. The signaling of motors was done through L298 IC .L298 was used instead of L293D due to heating problems.

The code is written in NANO editor using PYTHON. Python is used because it is the default language that can be used in the Raspberry Pi board. The Raspberry Pi board uses Python as well as scratch as their default language.

The battery used for operating the motors and making all the connections between Raspberry Pi , L298 and Gear motors is Li-Po(Lithium pol) battery. The reason we used Li-Po battery is that it is very lightweight as compared to other batteries and provide more wattage than the other batteries when compared, so it was a better choice.

CONTENTS

Introduction (Basic aim, How was it done, How do we get the Idea)7 Mechanical Structure 8 Raspberry Pi B+ ..13 6 DOF IMU (3-AXIS Accelerometer ADXL345 Gyroscope Gyro ITG3200) ..16. I2C Protocol ....18. Complementary Filter ....20 PID Control..22 Accelerometer - Gives the components of acceleration (g) along its three axis28 Gyroscope- Gives the components of angular velocity along its three axis29 Source Code30 Project Images.34

xii

Page 6

HOW WAS IT DONE :-

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

HOW DO WE GET THE IDEA:-

Keeping in mind of our ultimate aim, the unicycle, we had to complete the basics in summer and need to understand what efforts would it require. Also at the very first we thought of making a self balancing platform, which used data from accelerometer and gyroscope. A self balancing bot is an advanced version of this platform. Self balancing bot includes the basic signal processing part of the unicycle.

HOW DID WE IMPLEMENT :-

Our self balancing bot was created using ARM board (Raspberry pi) using IMU sensor (MPU-6050). The Raspberry Pi provides us with GPIO(General Puprose Input Output)Ports that could be easily used to make the connections for the L298 which further controls the Motors.

Two Gear motors of 200 RPM (rotations per minute) are also applied. The signaling of motors was done through L298 IC .L298 was used instead of L293D due to heating problems.

The code is written in NANO editor using PYTHON. Python is used because it is the default language that can be used in the Raspberry Pi board. The Raspberry Pi board uses Python as well as scratch as their default language.

The battery used for opearing the motors and making all the connections between Raspberry Pi , L298 and Gear motors is Li-Po(Lithium pol) battery.The reason we used Li-Po battery is that it is very lightweight as compared to other batteries and provide more wattage than the other batteries when compared, so it was a better choice.

MECHANICAL STRUCTURE

The whole bot gets balanced on two wheels having the required grip providing sufficient friction (as there are large chances for wheels to skid).The bot will balance itself on these two tires only . Here is a pic of the bot:

Figure 1: Self balancing robotARM (Advance RISC Machines)ARM stands for Advance RISC machines.We have used the Raspberry Pi board from ARM during the whole course of our project.ARM is a family of instruction set architecture for computer processors based on a reduced instruction set computing (RISC) architecture developed by British companyARM Holdings.A RISC-based computer design approach means ARM processors require significantly fewer transistors than typical CISC x86 processors in most personal computers. This approach reduces costs, heat and power use. Such reductions are desirable traits for light, portable, battery-powered devicesincluding smartphones,laptops ,tablets and notepad computers, and other embedded systems . A simpler design facilitates more efficient multi-core CPUs and higher core counts at lower cost, providing improved energy efficiency for servers.ARM Holdings develops the instruction set and architecture for ARM-based products, but does not manufacture products. The company periodically releases updates to its cores. Current cores from ARM Holdings support a 32-bit address space and 32-bit arithmetic; the ARMv8-A architecture, announced in October 2011, adds support for a 64-bit address space and 64-bit arithmetic. Instructions for ARM Holdings' cores have 32bits wide fixed-length instructions, but later versions of the architecture also support a variable-length instruction set that provides both 32 and 16bits wide instructions for improved code density. Some cores can also provide hardware execution of Java Bytecodes.ARM Holdings licencesthe chip designs and the ARM instruction set architectures to third parties, who design their own products that implement one of those architecturesincluding system-on-chip (SoC) that incorporate memory, interfaces, radios, etc. Currently, the widely used Cortex cores, older "classic" cores, and specialized Securcorecores variants are available for each of these to include or exclude optional capabilities. Companies that make chips that implement an ARM architecture includeApple,AppliedMicro, Atmel, Broadcom, Cypress Semiconductor, Freescale Semiconductor, Nvidia, NXP, Qualcomm, Samsung Electronics, ST Microelectronics and Texas Instruments. Qualcomm introduced new three-layer 3D chip stacking in their 2014-15 ARM SoCs such as in their first 20nm 64-bitocta-core.

Figure 2: ARMGlobally ARM is the most widely used instruction set architecture in terms of quantity produced. The low power consumption of ARM processors has made them very popular: over 50 billion ARM processors have been produced as of 2014[update], of which 10 billion were produced in 2013 and "ARM-based chips are found in nearly 60 percent of the worlds mobile devices". The ARM architecture (32-bit) is the most widely used architecture in mobile devices, and most popular 32-bit one in embedded systems. In 2005, about 98% of all mobile phones sold used at least one ARM processor, According to ARM Holdings, in 2010 alone, producers of chips based on ARM architectures reported shipments of 6.1billion ARM-based processors, representing 95% of smartphones, 35% of digital televisions and set-top boxes and 10% of mobile computers.

32-Bit Architecture of ARM

32-bit ARM architecture, such as ARMv7-A, is the most widely used architecture in mobile devices.Since 1995, the ARM Architecture Reference Manual has been the primary source of documentation on the ARM processor architecture and instruction set, distinguishing interfaces that all ARM processors are required to support (such as instruction semantics) from implementation details that may vary. The architecture has evolved over time, and version seven of the architecture, ARMv7, that defines the architecture for the first of the Cortex series of cores, defines three architecture "profiles": A-profile, the "Application" profile: Cortex-A series R-profile, the "Real-time" profile: Cortex-R series M-profile, the "Microcontroller" profile: Cortex-M seriesAlthough the architecture profiles were first defined for ARMv7, ARM subsequently defined the ARMv6-M architecture (used by the Cortex M0/M0+/M1) as a subset of the ARMv7-M profile with fewer instructions.Instruction Set

The original (and subsequent) ARM implementation was hardwired without microcode, like the much simpler 8-bit6502 processor used in prior Acorn microcomputers.The 32-bit ARM architecture (and the 64-bit architecture for the most part) includes the following RISC features: Load/store architecture. No support for unaligned memory accesses in the original version of the architecture. ARMv6 and later, except some microcontroller versions, support unaligned accesses for half-word and single-word load/store instructions with some limitations, such as no guaranteed atomicity. Uniform 16 32-bit register file (including the Program Counter, Stack Pointer and the Link Register). Fixed instruction width of 32bits to ease decoding and pipelining, at the cost of decreased code density. Later, the Thumb instruction set added 16-bit instructions and increased code density. Mostly single clock-cycle execution.To compensate for the simpler design, compared with processors like the Intel 80286 and Motorola 68020, some additional design features were used: Conditional execution of most instructions reduces branch overhead and compensates for the lack of a branch predictor. Arithmetic instructions alter condition codes only when desired. 32-bit barrel shifter can be used without performance penalty with most arithmetic instructions and address calculations. Has powerful indexed addressing modes. A link register supports fast leaf function calls. A simple, but fast, 2-priority-level interrupt subsystem has switched register banks.RegistersRegisters R0 through R7 are the same across all CPU modes; they are never banked.R13 and R14 are banked across all privileged CPU modes except system mode. That is, each mode that can be entered because of an exception has its own R13 and R14. These registers generally contain the stack pointer and the return address from function calls, respectively.Aliases include: R13 is also referred to as SP, the Stack Pointer. R14 is also referred to as LR, the Link Register. R15 is also referred to as PC, the Program Counter.The Current Program Status Register (CPSR) has the following 32bits:- M (bits 04) is the processor mode bits. T (bit 5) is the Thumb state bit. F (bit 6) is the FIQ disable bit. I (bit 7) is the IRQ disable bit. A (bit 8) is the imprecise data abort disable bit. E (bit 9) is the data endianness bit. IT (bits 1015 and 2526) is the if-then state bits. GE (bits 1619) is the greater-than-or-equal-to bits. DNM (bits 2023) is the do not modify bits. J (bit 24) is the Java state bit. Q (bit 27) is the sticky overflow bit. V (bit 28) is the overflow bit. C (bit 29) is the carry/borrow/extend bit. Z (bit 30) is the zero bit. N (bit 31) is the negative/less than bit.

Raspberry PiThe Board that we used for programming in our self balancing robot is Raspberry Pi B+. The Raspberry Pi is a series of credit card-sized single-board computers developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.The original Raspberry Pi and Raspberry Pi 2 are manufactured in several board configurations through licensed manufacturing agreements with Newark element14 (Premier Farnell), RS Components and Egoman. These companies sell the Raspberry Pi online.[6]Egoman produces a version for distribution solely in China and Taiwan, which can be distinguished from other Pis by their red colouring and lack of FCC/CE marks. The hardware is the same across all manufacturers.The original Raspberry Pi is based on the Broadcom BCM2835 system on a chip (SoC),[1] which includes an ARM1176JZF-S 700MHz processor, VideoCore IV GPU,[7] and was originally shipped with 256megabytes of RAM, later upgraded (models B and B+) to 512MB. The system has Secure Digital (SD) (models A and B) or MicroSD (models A+ and B+) sockets for boot media and persistent storage. In 2014, the Raspberry Pi Foundation launched the Compute Module, which packages a BCM2835 with 512MB RAM and an eMMC flash chip into a module for use as a part of embedded systems.The Foundation provides Debian and Arch Linux ARM distributions for download Tools are available for Python as the main programming language, with support for BBC BASIC (via the RISC OS image or the Brandy Basic clone for Linux), C, C++, Java, Perl and Ruby. As of 18 February 2015[update], over five million Raspberry Pis have been sold. While already the fastest selling British personal computer, it has also shipped the second largest number of units behind the Amstrad PCW, the "Personal Computer Word-processor", which sold eight million.In early February 2015, the next-generation Raspberry Pi, Raspberry Pi 2, was officially announced.The new computer board will initially be available only in one configuration (model B) and features a Broadcom BCM2836 SoC, with a quad-core ARM Cortex-A7 CPU and a VideoCore IV dual-core GPU; 1GB of RAM with remaining specifications being similar to those of the previous generation model B+. Crucially, the Raspberry Pi 2 will retain the same US$35 price point of the model B with the US$25 model A remaining on sale. The Raspberry-Pi primarily uses Linux Kernel Operating Systems. The Operating Systems that we used for implementing our project was Raspbian(Based on Debian).

Figure 3: R-Pi Model B+

Specifications

Figure 4: SpecificationThe full Specification of Raspberry Pi B+ model is shown on the previous page.

Operating Systems Support

The Raspberry Pi primarily uses Linux-kernel-based operating systems.The ARM11 chip at the heart of the Pi (pre-Pi 2) is based on version 6 of the ARM. The current releases of several popular versions of Linux, including Ubuntu, will not run on the ARM11. It is not possible to run Windows on the original Raspberry Pi,though the new Raspberry Pi 2 will be able to run Windows 10 .The Raspberry Pi 2 currently only supports Ubuntu Snappy Core, Raspbian, OpenELEC and RISC OS.The install manager for the Raspberry Pi is NOOBS. The operating systems included with NOOBS are: Archlinux ARM OpenELEC Pidora (Fedora Remix) Puppy Linux Raspmc and the XBMC open source digital media center RISC OS The operating system of the first ARM-based computer Raspbian (recommended for Raspberry Pi 1) Maintained independently of the Foundation;based on the ARM hard-float(armhf) Debian 7 'Wheezy' architecture port originally designed for ARMv7 and later processors (with Jazelle RCT/ThumbEE, VFPv3, and NEONSIMD extensions), compiled for the more limited ARMv6 instruction set of the Raspberry Pi. A minimum size of 4GBSD card is required. There is a Pi Store for exchanging programs. The Raspbian Server Edition is a stripped version with fewer software packages bundled as compared to the usual desktop computer oriented Raspbian. The Wayland display server protocol enable the efficient use of the GPU for hardware accelerated GUI drawing functions. On 16 April 2014 a GUI shell for Weston called Maynardwas released. PiBang Linux is derived from Raspbian. Raspbian for Robots - A fork of Raspbian for robotics projects with LEGO, Grove, and Arduino

6 DOF INERTIAL MEASUMENT UNIT

Figure 5: MPU-6050Features:

Tiny Two mounting holes MEMS accelerometer MEMS Gyrosensor 3.3V input I2C interface Accelerometer - Gives the components of acceleration (g) along its three axis (More sensitive and noisy data). Gyroscope - Gives the components of angular velocity along its three axis (Less sensitive but its output gets DRIFTED along with the time).

Description:

The InvenSense MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip. It is very accurate, as it contains 16-bits analog to digital conversion hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The sensor uses the I2C-bus to interface with the Raspberry-Pi B+. The MPU-6050 is not expensive, especially given the fact that it combines both an accelerometer and a gyro.

Hooking it up:

The both components of the Digital IMU 6DOF are I2C devices on a single bus. I2C is a 2-wire serial connection, so we just need to connect the SDA (Data) and SCL (Clock) lines to your ARM for communication. On our Raspberry Pi, SDA is digital 20, and SCL is digital 21. . Other than these 2 lines, we just need to connect power (3.3v), ground and we are all set.

I2C INTERFACING:

Inter-Integrated Circuit (IC pronounced I- Squared- C) is a 2 wire serial bus typically used to communicate with sensors and other small components.

The two lines of the I2C bus are SDA (Data) and SLC (clock) which can be run in parallel to communicate with several devices at once. I2C allows up to 112 "slave" (such as a sensor) devices to be controlled by a single "master" (such as ARM, in our case). Each slave device on the bus must have its own unique address so the master can communicate directly with the intended device. These addresses are typically hard-coded into the slave device, but often allow it to be changed by simply pulling one of the pins of the sensor high or low. This allows more than one of the same device to be on the same bus without conflicting addresses.

I2C is often referred to as TWI or 2-wire-serial.

I2C BASIC COMMAND SEQUENCE

1. Send the START bit (S).2. Send the slave address (ADDR). 3. Send the Read(R)-1 / Write(W)-0 bit. 4. Wait for/Send an acknowledge bit (A). 5. Send/Receive the data byte (8 bits) (DATA).6. Expect/Send acknowledge bit (A).

7. Send the STOP bit (P).

Reading the Raw Values from MPU-6050 :-

Reading the raw values for the accelerometer and gyro is easy. The sleep mode has to be disabled, and then the registers for the accelerometer and gyro can be read. But the sensor also contains a 1024 byte FIFO buffer. The sensor values can be programmed to be placed in the FIFO buffer. And the buffer can be read by the Raspberry Pi. The FIFO buffer is used together with the interrupt signal. If the MPU-6050 places data in the FIFO buffer, it signals the Raspberry Pi with the interrupt signal so the Raspberry - Pi knows that there is data in the FIFO buffer waiting to be read.

A little more complicated is the ability to control a second I2C-device.The MPU-6050 always acts as a slave to the Raspberry Pi with the SDA and SCL pins connected to the I2C-bus.But beside the normal I2C-bus, it has it's own I2C controller to be a master on a second (sub)-I2C-bus. It uses the pins AUX_DA and AUX_CL for that second (sub)-I2C-bus.

It can control, for example, a magnetometer. The values of the magnetometer can be passed on to the Raspberry Pi. Things get really complex with the "DMP".The sensor has a "Digital Motion Processor" (DMP), also called a "Digital Motion Processing Unit". This DMP can be programmed with firmware and is able to do complex calculations.

L298N Motor Driver Board

Figure 6: L298N motor driver circuit

Double H driver module uses ST L298N dual full-bridge driver, an integrated monolithic circuit in a 15- lead Multiwatt and PowerSO20 packages. It is a high voltage, high current dual full-bridge driver designed to accept standard TTL logic levels and drive inductive loads such as relays, solenoids, DC and stepping motors. Two enable inputs are provided to enable or disable the device independently of the input signals. The emitters of the lower transistors of each bridge are connected together and the corresponding external terminal can be used for the connection of an external sensing resistor. An additional supply input is provided so that the logic works at a lower voltage.Specifications Driver: L298N Driver power supply: +5V~+46V Driver Io: 2A Logic power output Vss: +5~+7V (internal supply +5V) Logic current: 0~36mA Controlling level: Low -0.3V~1.5V, high: 2.3V~Vss Enable signal level: Low -0.3V~1.5V, high: 2.3V~Vss Max power: 25W (Temperature 75 cesus) Working temperature: -25C~+130C Dimension: 60mm*54mm Driver weight: ~48g Other extensions: current probe, controlling direction indicator, pull-up resistoer switch, logic part power supply.

Hardware Diagram

Figure 7: top view(l298n)

CSA: The current test pin for motor A, this pin can be wired a resistor for current testing or tied a jumper to disable it. CSB: The current test pin for motor B, this pin can be wired a resistor for current testing or tied a jumper to disable it. VMS: VMS is the 5V-35V power source for motor. VMS is positive, GND is negtive. 5V: Power input for the logic circuit on the board. 5V-EN: 5V source jumper. When the jumper is put on, The 78M05 supplies the 5V power for logic circuit on the board from the VMS port(7V < VMS < 18V). The power of logic circuit of the board is supplied by the 5V port when this jumper put off. U1/2/3/4: Pull up resistor for IN1/2/3/4. Putting on the jumper enable the pull up resistor for the microcontroller, putting off it disable it. EA/EB: EA/EB is the enable pin for the two motor A/B, the motor speed also can be controlled by the PWM of this pin. IN1/2/3/4: IN1/2/3/4 is the pin for the motor control. Motor B is same as Motor A.

L298N Connections

Figure 8: l298n driver circuit connections

LITHIUM-POLYMER BATTERY

Figure 9- Lipo- Battery

A lithium polymer battery, or more correctly lithium-ion polymer battery (abbreviated variously as LiPo, LIP, Li-poly and others), is a rechargeable battery of lithium-ion technology in a pouch format. Unlike cylindrical and prismatic cells, LiPos come in a soft package or pouch, which makes them lighter but also lack rigidity.The denomination "lithium polymer" has caused confusion among battery users. It may be interpreted in two ways. Originally, "lithium polymer" stood for a developing technology using a polymerelectrolyte instead of the more common liquid electrolyte. The result is a "plastic" cell, which theoretically could be thin, flexible, and manufactured in different shapes, without risk of electrolyte leakage. These batteries are available although the technology has not been fully developed and commercialized and research is ongoing.

Design Origin and TerminologyThe original kind of cell named "lithium polymer" has technologically evolved from lithium-ion and lithium-metal batteries. The primary difference is that instead of using a lithium-salt electrolyte (such as LiPF) held in an organic solvent (such as EC/DMC/DEC), the battery uses a solid polymer electrolyte (SPE) such as poly(ethylene oxide) (PEO), poly(acrylonitrile) (PAN), poly(methyl methacrylate) (PMMA) or poly(vinylidene fluoride)(PVdF).The solid electrolyte can be typically classified as one of three types: dry SPE, gelled SPE and porous SPE. The dry SPE was the first used in prototype batteries, around 1978 by Michel Armand, Domain University, and 1985 by ANVAR and Elf V Aquitaine of France, and Hydro Quebec of Canada.From 1990 several organizations like Mead and Valence in the United States and GS Yuasa in Japan developed batteries using gelled SPEs. In 1996, Bellcore in the United States announced a rechargeable lithium polymer cell using porous SPE, but without success in commercialization.In parallel to the development of these "polymer electrolyte" batteries, the term "lithium polymer" started being used for liquid electrolyte Li-ion cells in pouch format. These cells started appearing in consumer electronics around 1995, eventually becoming known as "LiPo" for some applications.The confusion in the names may stem from the construction of the basic lithium-ion cell. A typical cell has four main components: positive electrode, negative electrode, separator and electrolyte. The separator itself may be a polymer, such as a microporous film of polyethylene(PE) or polypropylene (PP); thus, even when the cell has a liquid electrolyte, it will still contain a "polymer" component. In addition to this, the positive electrode can be further decomposed in three parts: the lithium-transition-metal-oxide (such as LiCoO2 or LiMn2O4), a conductive additive, and a polymer binder of poly(vinylidene fluoride) (PVdF) The negative electrode material may have the same three parts, only with carbon replacing the lithium-metal-oxide.Therefore, even if a bare, unfinished cell lacks a polymer separator, or any liquid or solid electrolyte, it may still have a "polymer" component in the active materials of the electrodes. This polymer, however, is just a small fraction, typically less than 5% by weight, and does not participate in the electrochemical reactions, being only useful for binding the active particles together to maintain good conductivity, and help make the slurry mix adhere well to the copper and aluminium foils that compose the current collectors of the battery cell.Working principleJust as with other lithium-ion cells, LiPos work on the principle of intercalation and de-intercalation of lithium ions from a positive electrode material and a negative electrode material, with the liquid electrolyte providing a conductive medium. To prevent the electrodes from touching each other directly, a microporous separator is in between which allows only the ions and not the electrode particles to migrate from one side to the other.ChargingJust as with other lithium-ion cells, LiPos work on the principle of intercalation and de-intercalation of lithium ions from a positive electrode material and a negative electrode material, with the liquid electrolyte providing a conductive medium. To prevent the electrodes from touching each other directly, a microporous separator is in between which allows only the ions and not the electrode particles to migrate from one side to the other.

Figure 10: Lipo Battery Charger

The Capacity ratings for discharge, the Capacity rating for charge tells you at what amperage you can safely charge your battery. This information is generally listed on the back of the battery with all the safety information.

Gear MotorsGearmotors are electric motors that utilize a type of gear system on the output of the motor. This gearing arrangement is called a gear reducer or gearbox. The combination of an electricmotor and gearbox reduces designcomplexity and lowers cost,particularly for motorsbuilt for high torque and low speed applications. In addition, gearboxes can be used as a means to reorient the output shaft in a different direction.

A gearmotor can be classified in a number of different ways, but the primary distinction is whether it is an AC motor or DC motor. This designationdefines thepower source requirementsof the motor (AC or DC) and can affect a number of other performancefactors such as cost, reliability,and speed control complexity

Figure 11: 200 RPM 10kg torq

KALMAN FILTER

The Kalman filter is a set of mathematical equations that provides an efficient computational (recursive) means to estimate the state of a process, in a way that minimizes the mean of the squared error. The filter is very powerful in several aspects: it supports estimations of past, present, and even future states, and it can do so even when the precise nature of the modelled system is unknown.

The filter is used in control engineering to remove measurement noise that can affect the performance of system under control. It also provides an estimate of the current state of the process or system. The Kalman filter is a tool that can estimate the variables of a wide range of processes. In mathematical terms we would say that a Kalman filter estimates the states of a linear system. The Kalman filter not only works well in practice, but it is theoretically attractive because it can be shown that of all possible filters, it is the one that minimizes the variance of the estimation error.

The process or system that is being measured must be modelled by linear system. A linear system can best be described by the following two state space representation equations:

x(k) = Bu(k-1) + w(k-1) z(k) = Hx(k) + v(k)

First equation represents the process state equation. A, B, and H represent the state matrices, thew(k-1)represents the process noise, k is the time index, x(k-1) is the state of the process, and u(k-1) is the known input to the process. Second equation above represents the output state equation. The z(k) represents the measured process output and the v(k) represents the measurement noise. The sensor data for the system are taken at discrete time sample points. The measurements are dependent on the state of the process or system.

Finally what we conclude about Kalman Filter is:

It is being used for the fusion of the outputs of the two sensors used. Will reduce the noise of the two sensors by taking appropriate weightage which will vary according to time. Estimate the optimal state using the prediction from the last stage and current state measurement.

Why is Kalman Filter necessary:

Based on recursive process so consume less memory of processor. Gives theoretically and practically accurate data. It is based on weighted average giving more weightage to the reading which is more certain.

PID CONTROL SYSTEM

The control algorithm that was used to maintain it balance on the autonomous self-balancing two wheel robot was the PID controller. The proportional, integral, and derivative (PID) controller, is well known as a three term controller.

The input to the controller is the error from the system. The Kp, Ki, and Kd are referred as the proportional, integral, and derivative constants (the three terms get multiplied by these constants respectively). The closed loop control system is also referred to as a negative feedback system. The basic idea of a negative feedback system is that it measures the process output y from a sensor. The measured process output gets subtracted from the reference set-point value to produce an error. The error is then fedinto the PID controller, where the error gets managed in three ways. The error will be used on the PID controller to execute the proportional term, integral term for reduction of steady state errors, and the derivative term to handle overshoots. After the PID algorithm processes the error, the controller produces a control signal u. The PID control signal then gets fed into the process under control.

The process under PID control is the two wheeled robot. The PID control signal will try to drive the process to the desired reference setpoint value. In the case of the two wheel robot, the desired set-point value is the zero degree vertical position. The PID control algorithm can be modelled in a mathematical representation.

PID is used to calculate the correction term

Correction = Kp*error + Ki* error + Kd* d/dt(error)

Kp , Ki and Kd are constants which are set experimentally.

If only the first term had been used to calculate the correction, the robot would have reacted in the same way as in the classical line following algorithm. The second term forces the robot to move towards the mean position faster. The third term resists sudden change in deviation.

The integral term is simply the summation of all previous deviations. Call this integral- totalerror. The derivative is the difference between the current deviation and the previous deviation. Following is the code for evaluating the correction.

These lines should run in each iteration :

correction = Kp*deviation + Ki*totalerror + Kd*(deviation previousdeviation)

totalerror += correctionpreviousdeviation = deviation

PID Tuning :

Here are some steps which will help to get Kp, Ki and Kd faster

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 shouldnt be any significant overshoots.

SOURCE CODE

#! /usr/bin/python

importsmbus#Import sumbus library for i2c communicationimport math #Import Math library for math operationsimport time as t #Import time library for delay functions importRPi.GPIO as gp#Import GPIO library for L298Ngp.setmode(gp.BOARD)#Initiate the GPIO on the raspberry pi boardmt1a = 16#Using pin 16,11,13 and 15 for motor driving signalsmt1b = 11mt2a = 13mt2b = 15

gp.setup(mt1a,gp.OUT)gp.setup(mt1b,gp.OUT)gp.setup(mt2a,gp.OUT)gp.setup(mt2b,gp.OUT)#Setting the 4 pins as outputm1ap = gp.PWM(16,50)m1bp = gp.PWM(11,50)m2ap = gp.PWM(13,50)m2bp = gp.PWM(15,50)#Initiating the pins for inbuilt PWM operationsad = 1

#Function to Drive the Motors Clockwisedefmotors_clock(t1,duty):gp.output(mt1a,gp.HIGH)gp.output(mt1b,gp.LOW)gp.output(mt2a,gp.HIGH)gp.output(mt2b,gp.LOW)t.sleep(t1)if flag == 0:motors_clear(t1/2)

#Function to Drive the Motors Anti-Clockwisedefmotors_anticlock(t1,duty):gp.output(mt1a,gp.LOW)gp.output(mt1b,gp.HIGH)gp.output(mt2a,gp.LOW)gp.output(mt2b,gp.HIGH)t.sleep(t1)if flag==0:motors_clear(t1/2)

#Function to clear motorsdefmotors_clear(t1):gp.output(mt1a,gp.LOW)gp.output(mt1b,gp.LOW)gp.output(mt2a,gp.LOW)gp.output(mt2b,gp.LOW)t.sleep(t1)

#Function to read 16 bit data from MPU6050defread_reg(address,add):a_h = bus.read_byte_data(address,add)#read 8bit data lower significant bytea_l = bus.read_byte_data(address,add+1)#read 8bit data most significant byte

#This logic serves the purpose of calibrating the the 16 bit data and use the 327678 as the 0 #reading ,the readings above this value are treated as positive and ,below this value are #treated as negative

ret = ((a_h 0):ax = read_reg(address,0x3b)ay = read_reg(address,0x3d)az = read_reg(address,0x3f)#acquiring the Three dimensional accelerometer datagy = read_reg(address,0x45)#Gyroscopic data around the y axisgy_s = gy/131;#calibrating the Gyro datarot_y = get_rotation(ax,ay,az)-9prev_error = error;#recording the previous error for calculating the #derivative

error = 0.35*(-gy_s) + 0.65*rot_y#Current error value

integral = integral+error#Integral by summing up all the errors

derivative = error - prev_error#Derivative as the difference of current error and prev #error

sig = (kp * error) + (ki * integral) + (kd * derivative)#Implementing the PID algorithm using the calibrated values of the three contants

print 'y_rot = ',rot_y,' gy=',gy_s,' sig =', sig#Debugging statement printing the gyro rotaion and accelero-metric dataflag = 0#print 'error =',error,'integral =',integral,' deriv=', derivative#print 'signal =',sig,'duty=',sig%100#Logic to control the Balancing using the signal value from the sensorsif sig>limit2 or sig < -limit2:flag = 1if sig-limit:passelif sig > limit:motors_anticlock(sig*0.0001,flag)elif sig < -limit:motors_clock(-(sig*0.0001),flag)count = count-1if(count/100==0):integral = 0flag = 0;

gp.cleanup()

PROJECT IMAGES

Figure 12: Front View

Figure 13: Right one quarter view

Figure 14: Motor attachment

Figure 15: lipo battery

Figure 16: raspberry pi attached

Figure 17: MPU 6050 attached

8Figure 18: initial stagesPage 36


Recommended