You are on page 1of 14

Project Report

on

Ball Follower Robot using Image


Processing
Contents:

S.No. TOPIC

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

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:

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
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
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

Software used:

BASCOM-AVR
MATLAB

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
 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
$baud = 9600
$prog &HFF , &HC3 , &HD9 , &H00 ' generated. Take care that the
chip supports all fuse bytes.

Config Lcd = 16 * 2

Config Porta = Input


Config Portb = Output
Config 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 * 10
Start Adc
Start Timer1
Cls

Do
A = Waitkey()

If A = "l" Then
Cls
Print " moving left "
Lcd "left"
Lowerline
Lcd "NEXTSAPIENS"
Pwm1b = 0
Portd.3 = 0
Pwm1a = 200
Portd.6 = 0
Waitms 180
Pwm1b = 0
Portd.3 = 0
Pwm1a = 0
Portd.6 = 0

Elseif A = "r" Then


Print " moving right "
Cls
Lcd "right"
Lowerline
Lcd "NEXTSAPIENS"
Pwm1b = 200
Portd.3 = 0
Pwm1a = 00
Portd.6 = 0
Waitms 180
Pwm1b = 0
Portd.3 = 0
Pwm1a = 0
Portd.6 = 0

Elseif A = "s" Then


Cls
Lcd "stop"
Lowerline
Lcd "NEXTSAPIENS"
Print " stop moving "
Pwm1b = 0
Portd.3 = 0
Pwm1a = 0
Portd.6 = 0
Waitms 180
Cls

Elseif A = "f" Then


Cls
Lcd "forward"
Lowerline
Lcd "NEXTSAPIENS"
Print " moving forward "
Pwm1b = 200
Portd.3 = 0
Pwm1a = 200
Portd.6 = 0
Waitms 180

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

Elseif A = "b" Then


Cls
Lcd "backward"
Lowerline
Lcd "NEXTSAPIENS"
Print " moving backward"
Pwm1b = 0
Portd.3 = 1
Pwm1a = 0
Portd.6 = 1
Waitms 180

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

End If

Loop
End
Code for making a ballfollower robot using color recognition principle

function ballfollower
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
end
end

[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)
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
end
end
fclose(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 imshow
But 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);

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.

You might also like