17
Project Report on Ball Follower Robot using Image Processing

Project Report on Ball Follower Robot

Embed Size (px)

Citation preview

Page 1: Project Report on Ball Follower Robot

Project Report

on

Ball Follower Robot using Image Processing

Page 2: Project Report on Ball Follower Robot

Contents:

S.No.S.No. TOPICTOPIC

1 Introduction

2 Introduction to robots and robotics

3 Requisites : Software tools Hardware tools

4 Introduction to Image processing

5 Introduction to Project

6 Codes for basic and matlab

7 Explanation and implementation

Introduction

Page 3: Project Report on Ball Follower Robot

About Ball Follower Robot

The project deals with a robot that locates and follows a ball across mounted with a web camera above and being controlled by a pc.

The robot specified uses a Atmel microcontroller ATMega16 with a web camera mounted on it which is having video stream in a running mode where actually it sees the ball and where ever the ball is moving it just follows it automatically without any external control.

For using a web cam we need to include a software which is MATLAB, it helps in taking images in current stream and allows camera to locate the ball and follow it using the concept of threshold.

Introduction to Robot and Robotics:

Page 4: Project Report on Ball Follower Robot

Robotics - Robotics is the science and technology of robots, and their design, manufacture, and application. Robotics is related to electronics, mechanics, and software.

A robot is a virtual or mechanical artificial agent. In practice, it is usually an electro-mechanical system.

Robotics requires a working knowledge of electronics, mechanics and software, and is usually accompanied by a large working knowledge of many subjects.

Although the appearance and capabilities of robots vary vastly, all robots share the features of a mechanical, movable structure under some form of autonomous control. The structure of a robot is usually mostly mechanical and can be called a kinematic chain (its functionality being similar to the skeleton of the human body). The chain is formed of links (its bones), actuators (its muscles) and joints which can allow one or more degrees of freedom. Most contemporary robots use open serial chains in which each link connects the one before to the one after it. These robots are called serial robots and often resemble the human arm. Some robots, such as the Stewart platform, use closed parallel kinematic chains. Other structures, such as those that mimic the mechanical structure of humans, various animals and insects, are comparatively rare. However, the development and use of such structures in robots is an active area of research (e.g. biomechanics). Robots used as manipulators have an end effector mounted on the last link. This end effector can be anything from a welding device to a mechanical hand used to manipulate the environment.

Components of robots

Actuation

A robot leg in the form of wheels with the help of motors

The actuators are the 'muscles' of a robot; the parts which convert stored energy into movement. By far the most popular actuators are electric motors, but there

Page 5: Project Report on Ball Follower Robot

are many others, some of which are powered by electricity, while others use chemicals, or compressed air.

Motors: By far the vast majority of robots use electric motors, of which there are several kinds. DC motors, which are familiar to many people, spin rapidly when an electric current is passed through them. They will spin backwards if the current is made to flow in the other direction.

Stepper motors: As the name suggests, stepper motors do not spin freely like DC motors, they rotate in steps of a few degrees at a time, under the command of a controller. This makes them easier to control, as the controller knows exactly how far they have rotated, without having to use a sensor. Therefore they are used on many robots and CNC machining centres.

Manipulation

Robots which must work in the real world require some way to manipulate objects; pick up, modify, destroy or otherwise have an effect. Thus the 'hands' of a robot are often referred to as end effectors, while the arm is referred to as a manipulator. Most robot arms have replaceable effectors, each allowing them to perform some small range of tasks. Some have a fixed manipulator which cannot be replaced, while a few have one very general purpose manipulator, for example a humanoid hand.

A simple gripper Grippers: A common effector is the gripper. In its simplest manifestation

it consists of just two fingers which can open and close to pick up and let go of a range of small objects. See End effectors.

Control and sensing

The mechanical structure of a robot must be controlled to perform tasks. The control of a robot involves three distinct phases - perception, processing and action (robotic paradigms). Sensors give information about the environment or the robot itself (e.g. the position of its joints or its end effector). This information is then processed to calculate the appropriate signals to the actuators (motors) which move the mechanical structure.

The processing phase can range in complexity. At a reactive level, it may translate raw sensor information directly into actuator commands. Sensor fusion may first be used to estimate parameters of interest (e.g. the position of the

Page 6: Project Report on Ball Follower Robot

robot's gripper) from noisy sensor data. An immediate task (such as moving the gripper in a certain direction) is inferred from these estimates. Techniques from control theory convert the task into commands that drive the actuators.

Dynamics and kinematics

The study of motion can be divided into kinematics and dynamics. Direct kinematics refers to the calculation of end effector position, orientation, velocity and acceleration when the corresponding joint values are known. Inverse kinematics refers to the opposite case in which required joint values are calculated for given end effector values, as done in path planning. Some special aspects of kinematics include handling of redundancy (different possibilities of performing the same movement), collision avoidance and singularity avoidance. Once all relevant positions, velocities and accelerations have been calculated using kinematics, methods from the field of dynamics are used to study the effect of forces upon these movements. Direct dynamics refers to the calculation of accelerations in the robot once the applied forces are known. Direct dynamics is used in computer simulations of the robot. Inverse dynamics refers to the calculation of the actuator forces necessary to create prescribed end effector acceleration. This information can be used to improve the control algorithms of a robot.

Requisites of Project

Page 7: Project Report on Ball Follower Robot

Software used:

BASCOM-AVRMATLAB

Programming language:

Basic language in BASCOM: BASIC (an acronym for Beginner's All-purpose Symbolic Instruction Code) is a family of high-level programming languages

Matlab: MATLAB is a numerical computing environment and fourth generation programming language. Developed by The MathWorks, MATLAB allows matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. Although it is numeric only, an optional toolbox uses the MuPAD symbolic engine, allowing access to computer algebra capabilities.

Key Features

High-level language for technical computing Development environment for managing code, files, and data Interactive tools for iterative exploration, design, and problem solving Mathematical functions for linear algebra, statistics, Fourier analysis,

filtering, optimization, and numerical integration 2-D and 3-D graphics functions for visualizing data Tools for building custom graphical user interfaces Functions for integrating MATLAB based algorithms with external

applications and languages, such as C, C++, Fortran, Java, COM, and Microsoft Excel

Hardware used:

Nextsapiens basic robot with atmega16 microcontroller and all other features like:

Development board of nextsapiens with lcd DC geared motor Chassis

Page 8: Project Report on Ball Follower Robot

2 Tyres Web Camera

Specifications of Development board :

40 pin Atmel ATmega16/32 microcontroller with internal system clock upto 8 MHz and externally upto 16 MHz.

16/32 KB Flash RAM memory for programs ½ KB of SRAM 512/1024 Bytes of EEPROM Dual 7805 Voltage regulator Dual power input options Two programmable LEDs Lcd for display

Code in BASIC language for Ball follower robot in pc control

$regfile = "m16def.dat"$crystal = 4000000

Page 9: Project Report on Ball Follower Robot

$baud = 9600$prog &HFF , &HC3 , &HD9 , &H00 ' generated. Take care that the chip supports all fuse bytes.

Config Lcd = 16 * 2

Config Porta = InputConfig Portb = OutputConfig Portd = Output

Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portl = B.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down

Dim A As String * 10Start AdcStart Timer1Cls

DoA = Waitkey()

If A = "l" ThenClsPrint " moving left "Lcd "left"LowerlineLcd "NEXTSAPIENS"Pwm1b = 0Portd.3 = 0Pwm1a = 200Portd.6 = 0Waitms 180Pwm1b = 0Portd.3 = 0Pwm1a = 0Portd.6 = 0

Page 10: Project Report on Ball Follower Robot

Elseif A = "r" ThenPrint " moving right "ClsLcd "right"LowerlineLcd "NEXTSAPIENS"Pwm1b = 200Portd.3 = 0Pwm1a = 00Portd.6 = 0Waitms 180Pwm1b = 0Portd.3 = 0Pwm1a = 0Portd.6 = 0

Elseif A = "s" ThenClsLcd "stop"LowerlineLcd "NEXTSAPIENS"Print " stop moving "Pwm1b = 0Portd.3 = 0Pwm1a = 0Portd.6 = 0Waitms 180Cls

Elseif A = "f" ThenClsLcd "forward"LowerlineLcd "NEXTSAPIENS"Print " moving forward "Pwm1b = 200Portd.3 = 0Pwm1a = 200Portd.6 = 0Waitms 180

Page 11: Project Report on Ball Follower Robot

Pwm1b = 0Portd.3 = 0Pwm1a = 0Portd.6 = 0

Elseif A = "b" ThenClsLcd "backward"LowerlineLcd "NEXTSAPIENS"Print " moving backward"Pwm1b = 0Portd.3 = 1Pwm1a = 0Portd.6 = 1Waitms 180

Pwm1b = 0Portd.3 = 0Pwm1a = 0Portd.6 = 0

End If

LoopEnd

Code for making a ballfollower robot using color recognition principle

function ballfollower

Page 12: Project Report on Ball Follower Robot

pause(1)Vid=video input(‘winvideo’); Preview(vid);Im=get snapshot(vid);

%in case you are using matlab R13 or below% use

%vfm('show');v%fm('preview');%Im=vfm('grab');

[a b c]=size(im);im1=im(:,:,1);im2=im(:,:,2);im3=im(:,:,3);for m=1:a for n=1:b if(im1(m,n)>80 && im1(m,n)<160 && im2(m,n)>40 && im2(m,n)<80 && im3(m,n)<75 && im3(m,n)>40) I(m,n)=1; else I(m,n)=0; end endend

[x,y]=centroid(I)

X=160;Y=120;Xmin=X-40;Xmax=X+40;Ymin=Y-40;Ymax=Y+40;

ser=serial('com6');fopen(ser);if (x<Xmax && x>Xmin) if(y<Ymax && y>Ymin) fprintf(ser,'s'); disp('success!!!'); else if(y<Ymin)

Page 13: Project Report on Ball Follower Robot

fprintf(ser,'f'); else if(y>Ymax) fprintf(ser,'b'); end end end

else if(x<Xmin) fprintf(ser,'l'); else if(x>Xmax) fprintf(ser,'r'); end endendfclose(ser);

Explanation

First of all for running the function it is necessary to calibrate I.e. know the exact values of pixel elements of the ball to be followed. This is done by capturing the image of ball and checking the value of its pixels at various points bu using command imview

Imview(i)Shows the image just like imshowBut it also displays the value of pixel where the cursor is currently located at the bottom of the screen.For more accuracy take atleast ten images at different angles and find minimum and maximum pixel value for the ball and put it in the code given.

Now the function moves as follows

The camera attached to the robot takes images at frequent intervals and processes it by converting the image to binary image such that image is white if pixel value lies in desired range and black otherwise. Next we determine the centroid of the image so that robot moves towards the centroid as found out.The algorithm for finding the centroid is self explanatory .Next after finding the centroid we open the serial port for communication with the robot. This is achieved by command

Ser(’com1’);Fopen(ser);

Note:- after your work with serial port is over always close the port using command fclose(ser);

Page 14: Project Report on Ball Follower Robot

When the serial port is open and we know the centroid, we send the direction to be followed by robot over the serial port and the robot follows accordingly when programmed as a simple pc controlled algorithm.