a vision based robot has an image acquisition device like a webcam as its eyes
TRANSCRIPT
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
1/69
A VISION BASED ROBOT
A vision based robot has an image acquisition device like awebcam as its eyes. Then we need a processor that can make
sense out of those captured images and actuators like dc motorsfor navigation. One key point to note is that Image Processing hashuge computational requirements, and it is not possible to run animage processing code directly on a small microcontroller.Hence, for our purpose, the simplest approach would be to runthe code on a computer, which has a webcam connected to it totake the images, and the robot is controlled by the computer viaserial or parallel port. The code is written in software thatprovides the tools for acquiring images, analyzing the content in
the images and deriving conclusions.This Project will introduce the complete knowledge of Imageprocessing using Matlab and development of the hardware whichcan do desired task using a web cam. The take away will be thefundamental knowledge with best practices and design strategiesto build a Robot based on Image processing.
Basic Mathematical operation by Matlab.
Making GUI (Graphical User Interface) with Matlab (ForPractical uses).
Type of data types used for Image Processing.
Conversion between Data types.
Type of Images.
Theory of conversion between images.
Conversion between images with Matlab.
Practical uses of binary and gray scale images.
Basic Features of images for Practical purpose.
Extraction of Features of image by Matlab like:-
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
2/69
Objectives
1. Finding area of particular sized spot or particular shapedspot or particular color spot.2. Finding circumference of Featured Areas3. Finding Gravitational point of particular featured Area etc(Many others features are there which can be extracted forpractical purposes)
Making negatives of images by Matlab
Making Binary image using cut off value.
Basics of Communication b/w computer and Hardware.
Features of Motor Driver IC.
Handling Parallel Port.
Block Diagram
Matlab codes
Webcam
Motor
Parallel Port Motor Driver
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
3/69
Project process
A vision based robot has an image acquisition device like awebcam as its eyes. Then we need a processor that can makesense out of those captured images and actuators like dc motorsfor navigation. One key point to note is that Image Processing hashuge computational requirements, and it is not possible to run animage processing code directly on a small microcontroller. Hence,for our purpose, the simplest approach would be to run the codeon a computer, which has a webcam connected to it to take theimages, and the robot is controlled by the computer via serial orparallel port. The code is written in software that provides thetools for acquiring images, analyzing the content in the imagesand deriving conclusions. MATLAB is one of the much such
software available which provide the platform for performingthese tasks.
MATLAB
What does MATLAB stand for?
MATLAB stands for MATrix LABoratory. Hence, as the name
suggests, here you play around with matrices. Hence, an image(or any other data like sound, etc.) can be converted to a matrixand then various operations can be performed on it to get thedesired results and values.Image processing is quite a vast field to deal with. We can identifycolors, intensity, edges, texture or pattern in an image.
Getting acquainted with MATLAB environment
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
4/69
For those who have just finished installing MATLAB on theirsystem and cant figure out from where to start, no need toworry! This tutorial will first make you well acquainted with itsvery basics and then move further.
So, a typical MATLAB 2009 window looks like:
There are 4 main windows:1. Command window: This is the main window where you write
the commands, as well as see the outputs. In other words,here is your interaction with the software.
2. Command History: As the name suggests, it shows the list ofthe commands recently used in chronological order. Hence,you can double click on a command to execute it again.
3. Current directory: It is the default directory (folder) forsaving your files. All the files which you make (like m-files, as
discussed later) are saved here and can be accessed from
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
5/69
here directly. The location of the current directory is shownin the toolbar at the top. You can change it by changing theaddress here.
4. Workspace: It displays the list of the variables defined by
you in the current session of MATLAB.
The Menu bar and Toolbar:
The toolbar has buttons for common operations like cut, copy,
paste, undo, redo. The most important button here is the HELP
button. It opens the MATLAB help window which has looks
somewhat like this:
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
6/69
You can get the details of any MATLAB command/function hereand many demos of some commonly used applications. Locatethe four tabs: Contents, Index, Search Results and Demos on theleft. One of the best ways to learn by yourself is to look for demosof your interest and type the command/ function which youencounter there as the search term. You will then get the
complete details of the function like its use, syntax, as well as fewexamples on how to use it. You can also have a look at some ofthe related functions at the end of page under the heading SeeAlso. The demos related to Image Processing can be found underImage Processing Toolbox and Image Acquisition Toolbox.Now once we are done with knowing the essential features of
MATLAB, lets start typing something in the command window,
say: a=5 and press enter.
Yes as you can see that MATLAB creates a variable with namea, stores value 5 in it and displays it in the command windowitself. Hence you can see how user-friendly MATLAB is.Variables are stored in the form of Matrices in MATLAB. Hence, a
is a 1X1 matrix in the above example. Similarly, you can makeone dimensional, two dimensional, etc. matrices as follows:>> a= [1 3 5 7 9]a =1 3 5 7 9>> b= [1 2 3; 4 5 6; 7 8 9]b =1 2 34 5 6
7 8 9
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
7/69
To avoid the display of the variable, we use semi-colon (;) at theend of instruction.>> b= [1 2 3; 4 5 6; 7 8 9];The indices of matrices in MATLAB start from 1 (unlike C/C++ andJava where they start from 0).We refer to a particular element of the matrix by giving its indices
in parenthesis ().>> b(2,1)Ans =4
Now with the variables in hand, you can perform variousmathematical operations on them directly.>> a= [1 2 3];>> b= [6 7 8];
>> a+bAns =7 9 11Ans is the default variable of MATLAB. You can also store theresult in another variable as>> c=a+bc =7 9 11
General functions/commands
clc:To clear the command window, giving you a clear screen.clear: To remove all variables from the workspace. This frees up
system memory.
Trigonometric functionsFor angle in radians->> sin(1)
Ans =0.8415For angle in degrees->> sind(30)Ans =0.5000Inverse trigonometric->> asin(1)ans =
1.5708
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
8/69
>> asind(.5)Ans =30.0000Similarly we have cos(), cosd(), acos(), tan()etc.
The colon operator (:) The colon is one of the most usefuloperators in MATLAB. It can create vectors, subscript arrays, andspecify for iterations. In a very crude language, we can say thatthe colon (:) means throughout the range.
j:k is the same as [j,j+1,...,k]j:i:k is the same as [j,j+i,j+2i, ...,k]A(:,j) is the jth column of AA(:,j:k) is A(:,j), A(:,j+1),...,A(:,k)A(:) is all the elements of A, regarded as a single column.
Example,>> a= [1 2 3; 4 5 6; 7 8 9]a =1 2 34 5 67 8 9
>> a(:,2:3)Ans =2 35 68 9
Relational operatorsOperator
Description
== Equal to~= Not equal to
< Less than More than
>= More than or equal to*Note: As a block is contained in braces {} in C/C++/Java, a blockis terminated by the end statement in MATLAB.
for: To create a loop, i.e., execute a block of code specified
number of times.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
9/69
Syntax:Statement...StatementendExample,
>>c=[1 2 3 4 5]; b=0;>>for i=1:5b=b+c(i);end>> bb =15
while: Again to create loop, that executes till a specifiedcondition is true.
Syntax:while conditionstatementsendExample,>> c=2009; i=1;while c>1b(i)=mod(c,10);c=c/10; i=i+1;end>> bb =9.0000 0.9000 0.0900 2.0090
zeros(): Create array/matrix of all zeros.
B = zeros(n) returns an n-by-n matrix of zeros.B = zeros(m,n) returns an m-by-n matrix of zeros.Example,>> z=zeros(2,4)z =0 0 0 00 0 0 0Similarly we have ones() function for all values 1.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
10/69
size(): Returns matrix dimensions.
Syntax:statement...statement
endExample,>>c=[1 2 3 4 5]; b=0;>>for i=1:5b=b+c(i);end>> bb = 15while: Again to create loop, that executes till a specified
condition is true.
Syntax:while conditionstatementsendExample,>> c=2009; i=1;while c>1b(i)=mod(c,10);
c=c/10; i=i+1;end>> bb =9.0000 0.9000 0.0900 2.0090
zeros(): Create array/matrix of all zeros.
B = zeros(n) returns an n-by-n matrix of zeros.
B = zeros(m,n) returns an m-by-n matrix of zeros.Example,>> z=zeros(2,4)z =0 0 0 00 0 0 0Similarly we have ones() function for all values 1.
size(): Returns matrix dimensions.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
11/69
A Binary Image
A Grayscale Image
Grayscale Image:It contains intensity values ranging from aminimum (depicting absolute black) to a maximum (depictingabsolute white) and in between varying shades of gray. Typically,this range is between 0 and 255.*Note- In daily language what we refer to as black-and-white (asin old photos) are actually grayscale. Hence avoid confusion herein technical terms.
Color Image: We all have seen this! Such an image iscomposed of the three primary colors, Red, Green and Blue,
hence also called an RGB image.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
12/69
RGB value: All colors which we see around us can be made byadding red, green and blue components in varying proportions.
Hence, any color of the world can uniquely be described by its
RGB value, which stands for Red, Green and Blue values. Thistriplet has each value ranging from 0 to 255, with 0 obviouslymeaning no component of that particular color and 255 meaningfull component. For example, pure red color has RGB value [255 0
0], pure white has [255 255 255], pure black has [0 0 0] and hasRGB value [55 162 170].
Representation of an Image in MATLABAn image in MATLAB is stored as a 2D matrix (of size mxn) whereeach element of the matrix represents the intensity of light/colorof that particular pixel. Hence, for a binary image, the value ofeach element of the matrix is either 0 or 1 and for a grayscaleimage each value lies between 0 and 255. A color image is stored
as an mxnx3 matrix where each element is the RGB value of thatparticular pixel (hence its a 3D matrix). You can consider it asthree 2D matrices for red, green and blue intensities.
Reading and displaying Images
imread():To read an image and store in a matrix.
Syntax:IM=imread(filename)
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
13/69
Where IM is a matrix. If the file is in the current directory (asdescribed above), then you only need to write the filename, elseyou need to write the complete path. Filename should be withextension (.jpg, .bmp...). There are some default images ofMATLAB like peppers.png, cameraman.tif, etc.You can try reading them as
>>im=imread ('peppers.png');It is always advised to use a semi-colon (;) at the end of thestatement of reading an image, otherwise you can try yourselfwhat happens!
imshow(): Displays the image.
Syntax:
imshow(filename)orimshow(im)Example,>>imshow('cameraman.tif');OK, now lets make our own image, try this:>>a(1,1)=0;>>for i=1:200;for j=1:200a(i+1,j+1)=1-a(i,j);endend
>>imshow(a);
Data cursor:To see the values of the colors in the figurewindow, go to Tools>Data Cursor (or select from the toolbar), and
click over any point in the image. You can see the RGB values of
the pixel at location (X,Y).
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
14/69
A better option of data cursor is the function imtooli(). Type thefollowing>>imtool(peppers.png);and see the pixel info on lower left corner as you move mousepointer over different pixels.
Making M-files and functionsM-fileIt is a provision in MATLAB where you can execute multiplecommands using a single statement. Here the group ofcommands is stored as a MATLAB file (extension .m).Go to File->New->Blank M-fileMATLAB editor window opens where you can write the statements
which you want to execute and save the file.
Here we have saved the m-file by the name test.m. Now as youtype>>testin MATLAB command window, all the above commands willexecute.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
15/69
Comments:As we have comments in C/C++/ Java using doubleslash (//), in MATLAB we use symbol % to write comments, i.e.,statements that are not considered for execution. You can seecomments in green in the snapshot above.
FunctionsFunctions, as some of you might know, are written to organize thecode efficiently and make debugging easier. The set ofstatements within a function can be executed as and whenrequired by just calling it, thereby avoiding repetitions. The datawhich is needed within the function can be passed as argumentsand then the required values can be returned. You can return anyno. of values and they can be matrices also.A function is saved as an m-file with the same name as the nameif the function.
For Example, the following function takes the input as a coloredimage and returns a binary image where the green pixels have
been replaced as white, rest are black and also returns the total
no. of green pixels. (This task is required frequently whose use is
described later)
function [bingreen, num]=green(im)[m,n,t]=size(im);
bingreen=zeros(m,n); num=0;for i=1:mfor j=1:nif(im(i,j,1)==0 && im(i,j,2)==255 && im(i,j,3)==0)%Red and Blue components must be zero and Green must be fullbingreen(i,j)=1;num=num+1;endend
end
Now suppose the input image is 'shapes.bmp' (not a default
image of MATLAB, hence you can save it in the working directory
to perform the following operations or make yourself in paint)
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
16/69
So, you first read the image and then call the function by typing inthe command window
>> I=imread('shapes.bmp');>>[img, n]=green(I);>> nn =28753>>imshow(img);
As you can see, this is a binary image with white pixels at thosecoordinates which were green in input image.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
17/69
Now this was an ideal image where each color was perfect. But inpractice, you dont have images with perfect colors. So, we give arange of RGB values to extract our required region of image.Suppose the image at hand is the following (again its not a
default image) and we need to extract the red region.
So, we use the same function with the main conditional statement
changed as
function bw=red(im)[m,n,t]=size(im);bw=zeros(m,n);for i=1:mfor j=1:nif(im(i,j,1)>150 && im(i,j,2)
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
18/69
*Tip: To get an idea of what range of RGB values you must define,use imtool() function (or data cursor) with the original file, movethe cursor over the region which you need to extract and notedown the RGB values. Expand/ Contract the range as per your
requirement by trying several times. This is actually how thecalibrationis done.
Removing Noise
As you can see, the binary image obtained above has quite a lotof noise. You need to smoothen the edges, remove the tiny dotsscattered here and there so that at last you have some countablenumber of objects to work upon. There are several functionsavailable in MATLAB to remove noise in an Image. Some of themare (bw is the above binary image):
imclose(): Performs morphological closing operation. It fills in thegaps between two objects and smoothens the edges. The degreeand type of smoothening and joining depend on the structuringelement, i.e., the basic shape which is used to perform theoperation. The structuring element can be a disk, a diamond, aline, etc. To create a structuring element, use strel() function.
For example,>> se=strel('disk',5); % a disk of radius 5
>>bw=imclose(bw,se); %Perform the closing operation on
original image itself
>>imshow(bw);
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
19/69
imfill(): Remove holes from the imageHoles are background pixels surrounded by foreground (image)pixels.
>>bw=imfill(bw,'holes');>>imshow(bw);
Now you need to remove the spatters. For that you can use thefunction imopen().
imopen(): Morphologically open the image.>>se=strel('disk',2);>>bw=imopen(bw,se);>>imshow(bw);
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
20/69
*Note: The purpose of these functions might not be clear at fist. Hence,it is strongly recommended that you explore these functions
yourself by trying out on different images and have a look atthese functions in MATLAB Help section also. The sequence of performing these operations is very significant,as the subsequent operation is performed on the converted imageand not the original image. The sequence I have adopted is NOTnecessary, and you must try yourself which sequence suits yourrequirement. The size and shape of structuring element is also to bedetermined experimentally, so that the number of objects you get
in the binary image is same as what you require. This final imageobtained in this example is still not workable, and you can tryyourself to get a consolidated image. There are many other functions available for noise removal likeimerode(), imdilate(), etc. Please refer to MATLAB Help section fordetails. An object is defined as a connected region in a binary image.
The use of making a binary file:
In most of problem statements of robotics based on imageprocessing, we are required to find the centroid, area, and no. of
objects of a particular color. MATLAB has in-built functions for
these tasks which operate on binary images only. Hence we
create binary images corresponding to different colors. For
example, in the problem statement Brooklyn Builder of
Techkriti10, the image from the top (overhead camera) looks
somewhat like (again its an ideal image; the real one will be far
different and full of noise)
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
21/69
Now we first take a sample image of arena, note down the RGB
values (using imtool()) and then extract the regions of differentcolor by making binary images. Then we can find the centre ofdifferent objects using the function bwboundaries() andregionprops(). The piers and decks can be differentiated on thebasis of their area.
Getting the properties of different regionsbwboundariesIt traces the exterior boundaries of objects in a binary image.
B=bwboundaries(bw)bwboundaries returns B, a P-by-1 cell array, where P is thenumber of objects and holes.(A cell array is one where eachelement of the array is a matrix itself). Each cell in the array Bcontains a Q-by-2 matrix. Each row in the matrix contains thecoordinates (row and column indices) of a boundary pixel. Q is thenumber of boundary pixels (perimeter) for the correspondingregion. In other words, B contains the coordinates of pixelsconstituting the perimeter of each object and hole.
For example, suppose there are four objects in a binary image.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
22/69
Then the matrix B can be understood as shown in the diagram
below
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
23/69
*Note: In the coordinate matrix, the first coordinate is the rownumber (y - coordinate) and second coordinate is thecolumn number (x-coordinate) of the boundary pixel. Takethis always into consideration as it can create a lot of confusion.
bwboundaries(bw) will trace the hole boundaries too. So, abetter option is to use bwboundaries(bw,'noholes')
Label Matrix (L)A label matrix(L) corresponding to binary image is a 2D matrix ofthe same size as that of the image. Each object in the binaryimage is numbered 1,2,3,. and all the pixels of L correspondingto the objects in binary image have value respectively 1,2,3.The background pixels are 0 by default. In other words, the region
in L corresponding to first object in the image is marked 1,corresponding to second object is marked 2 and so on.The label matrix corresponding to the above binary image would
look somewhat like this (colors are just representative, the matrix
will consist of values 0,1,2,3 and 4 only)
The label matrix(L) is can either be obtained from the functionbwboundaries() as[B L]=bwboundaries(bw,'noholes');or from function bwlabel() as
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
24/69
L=bwlabel(bw);
Now why is this label matrix needed? It is required to use the
following function
regionprops: It is used to measure properties of imageregions.Once we have an image consisting of all the objects labeled, wemust now know the centroid, area, etc. of each.
Syntax:STATS =regionprops(L,properties)Where STATS is a structure array with length equal to the numberof labeled objects in L. The fields of the structure array denote
different properties for each region, as specified by properties.propertiesare be a comma-separated list of strings. See the helpsection of
MATLAB for all the properties available. We will use Centroid andArea.
Example,>>stats=regionprops(L,'Area','Centroid');The properties in the array stats are obtained by dot(.) operator.
>>a=stats(3).Area; %to get area of 3rd object>>c=stats(2).Centroid; %to get centroid of 2nd object
*Note: length(stats) = length(B) = max(L(:)) = no. of objects in bw
Working in Real TimeGetting Hardware information
Till now we have been working on images already saved on ourcomputer. But in actual practice, we need to work in real time,i.e., we need to take images continuously from the currentenvironment using a webcam and then process them. Hence, theImage Acquisition toolbox of MATLAB provides support in thisregard.To start with working in real time, you must have a functional USBwebcam connected to your PC and its driver installed. MATLABhas built-in adaptors for accessing these devices. An adaptor is
software that MATLAB uses to communicate with an image
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
25/69
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
26/69
Most probably you would have 'winvideo'installed and use that. Ifit is not available, use whichever adapter is shown byimaqhwinfo.If you are using a laptop, you may also have a webcam in it. Sonote down the Device Name shown as above. If it is not the USBwebcam, then probably DeviceID = 2 should work.
Hence, type>>dev_info = imaqhwinfo('winvideo',2)
*Note: From now onwards, I will refer Adapter by winvideo andDeviceID by 1. You must check yourself what is available on yoursystem and change the commands described further accordingly.Note down the supported formats by your camera as>>dev_info = imaqhwinfo('winvideo',1);
>>dev_info.SupportedFormats
As you can see, there are 5 supported formats in my camera. Thenumbers (160x120, 176x144.) denote the size of the image tobe captured by the camera.Previewing video
You can preview the video captured by the camera by defining anobject (say by the name vid) and associate it with the device.>>vid=videoinput('winvideo',1, 'YUY2_160x120')or>>vid=videoinput('winvideo',1, 'RGB24_160x120')% depends on availability
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
27/69
It should give information somewhat like this
vid is has been declared as the video input object, and now thecamera can be referenced by this name.To see a preview of the video through your camera, use previewcommand>> preview(vid)
You can check out the preview with different formats. You will seethat the size of preview window changes. Use a format that suitsyour size requirement. A larger size gives greater clarity and iseasier to work with, but consumes more memory and therefore isslow. But in a smaller image, it is difficult to differentiate betweentwo objects.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
28/69
Capturing Images
Now you have a video stream available and you need to capturestill images from it. For that, use getsnapshot() command.
>>im=getsnapshot(vid); % where vid is video input objectHere im is the 3D matrix and you can see the image by the usualimshow() command
>>imshow(im);If you get an unexpected image (with shade of violet/green/pinkand low clarity), there is nothing to worry. You must be using aformat starting with YUY2_... which means that your image is inYCbCr format and not RGB format. Therefore, you must convert itin RGB format by using
>>im=ycbcr2rgb(im);
>>imshow(im);If a format somewhat like RGB24_160x120 (anything startingwith RGB24_....) is used, then you directly get the image in RGBformat.If you want to store an image captured, so that you can view itlater (like .jpg, .png, .bmp), you can use imwrite()
>>imwrite(im,'myimage.jpg');The file myimage.jpgis saved in the current working directory.
*Note: It takes time for the camera to be active and sufficientlight to enter it after giving preview() command. Hence, thereshould be a time gap of 2-3 seconds between preview() andgetsnapshot(). If you are typing in command window, then youcan maintain this time gap manually. But generally you will usethese commands in an m-file, hence, the delay must be givenusing pause() command. Also in a vision based robot, the images
have to be taken continuously, so use an infinite loop.
vid=videoinput('winvideo',1, 'YUY2_160x120');preview(vid);pause(3);while(1)img=getsnapshot(vid);% Do all image processing and analysis hereend
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
29/69
Once you have the image matrix im, you can perform all theoperations like extracting region of particular colors, finding theircentroid and area, etc. by the methods described previously.
SIGH! Now sufficient Image Processing has been learnt. Great!What next?
Something apart from image processing must be known to makeand run the robot. How to interface your computer with yourrobot via serial/parallel port? How can you send instructions fromMATLAB to your robot and control it?The control of the robot is a dynamic process. You continuouslytake images using webcam, process them, find the requiredinformation like position of an object, orientation of robot (if thereis an overhead camera) and finally the task to be performed(move robot left / right / forward / backward / pick object, etc.).
According to the task at hand, some data is output on theserial/parallel port.
Interfacing via PC PortsThe Instrument Control toolbox of MATLAB provides support toaccess serial port (also called as COM port) and parallel port (alsocalled as printer port or LPT port) of a PC.If you are using a desktop PC or an old laptop, you may have
both, parallel and serial ports. However in newer laptops, none of
them may be available and you will have to use USB to SerialConverter cable. Please note that USB to Parallel converter is not
recognized as a virtual parallel port.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
30/69
Parallel Port
A tutorial on Parallel port Interfacing
A tutorial on Parallel port interfacing and programming forbeginners. This tutorial covers both hardware and softwareaspects about programming the parallel port. It also includes asample schematic and test program in Visual C++. You can make
your first parallel port application running straight away.
Introduction
Parallel port is a simple and inexpensive tool for buildingcomputer controlled devices and projects. The simplicity and easeof programming makes parallel port popular in electronicshobbyist world. The parallel port is often used in Computercontrolled robots, Atmel/PIC programmers, home automation,etc... Here a simple tutorial on parallel port interfacing and
programming with some examples.
The primary use of parallel port is to connect printers to computerand is specifically designed for this purpose. Thus it is often calledas printer Port or Centronics port (this name came from a popularprinter manufacturing company 'Centronics' who devised somestandards for parallel port). You can see the parallel portconnector in the rear panel of your PC. It is a 25 pin female(DB25) connector (to which printer is connected). On almost all
Parallel Port
http://logix4u.net/parallel-port/15-a-tutorial-on-parallel-port-interfacinghttp://logix4u.net/parallel-port/15-a-tutorial-on-parallel-port-interfacing -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
31/69
the PCs only one parallel port is present, but you can add more bybuying and inserting ISA/PCI parallel port cards.
I don't have parallel port on my machine! What do Ido?
Unfortunately, as of today parallel port is a completelydeprecated interfacing standard. It is impossible finding a newlaptop with parallel port these days. Even almost all branded PCsalready shead Parallel Ports from their back panels. Otheralternative available in market such as PCI parallel port expansioncards and USB to Parallel Port converters aren't good for anythingother than connecting your old printer because of theirarchitectural difference.
As of now the only possible alternative is to use serial ports alongwith serial to parallel converters (Unfortunately serial ports aren'tavailable on laptops these days) or use USB which is the mostpopular interface standard in the market as of today. But inherentcomplexities of implementing USB protocol and hardwarerequirements keep the hobbyists away for experimenting withUSB.
But there are great alternatives in market which uses USB but aseasy as using parallel port. One such device is Numato Lab's 8
Channel USB GPIO Module. Though this is a USB based module,the user doesn't have to worry about the intricacies andcomplexities of USB protocol.
A Parallel Port Mode
http://numato.com/8-channel-usb-gpio-modulehttp://numato.com/8-channel-usb-gpio-modulehttp://numato.com/8-channel-usb-gpio-modulehttp://numato.com/8-channel-usb-gpio-modulehttp://numato.com/8-channel-usb-gpio-module -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
32/69
The IEEE 1284 Standard which has been published in 1994defines five modes of data transfer for parallel port. They are,
1) Compatibility Mode2) Nibble Mode
3) Byte Mode4) EPP5) ECP
The programs, circuits and other information found in this tutorialare compatible to almost all types of parallel ports and can beused without any problems (Not tested, just because ofconfidence!).
Hardware
the pin outs of DB25 connector is shown in the picture below
The lines in DB25 connector are divided in to three groups, theyare
1) Data lines (data bus)2) Control lines3) Status lines
As the name refers, data is transferred over data lines, Controllines are used to control the peripheral and of course, theperipheral returns status signals back computer through Statuslines. These lines are connected to Data, Control and Statusregisters internally. The details of parallel port signal lines aregiven below
http://www.fapo.com/ieee1284.htmhttp://www.fapo.com/ieee1284.htm -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
33/69
PinNo(DB25)
Signalname
Direction
Register - bit
Inverted
1 nStrobe OutControl-
0
Yes
2 Data0 In/Out Data-0 No
3 Data1 In/Out Data-1 No
4 Data2 In/Out Data-2 No
5 Data3 In/Out Data-3 No
6 Data4 In/Out Data-4 No
7 Data5 In/Out Data-5 No
8 Data6 In/Out Data-6 No
9 Data7 In/Out Data-7 No
10 nAck InStatus-6
No
11 Busy InStatus-7
Yes
12Paper-Out
InStatus-5
No
13 Select InStatus-4 No
14Linefeed
OutControl-1
Yes
15 nError InStatus-3
No
16nInitialize
OutControl-2
No
17
nSelect-
Printer Out
Control-
3 Yes
18-25 Ground - - -
Parallel port registersthe Data, Control and status lines are connected to theircorresponding registers inside the computer. So by manipulating
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
34/69
these registers in program , one can easily read or write toparallel port with programming languages like 'C' and BASIC.
The registers found in standard parallel port are,
1) Data register
2) Status register3) Control register
As their names specifies, Data register is connected to Data lines,Control register is connected to control lines and Status register isconnected to Status lines. (Here the word connection does notmean that there is some physical connection betweendata/control/status lines. The registers are virtually connected tothe corresponding lines.). So whatever you write to theseregisters, will appear in corresponding lines as voltages, Of
course, you can measure it with a multimeter. And whatever yougive to Parallel port as voltages can be read from these registers(with some restrictions). For example, if we write '1' to Dataregister, the line Data0 will be driven to +5v. Just like this, we canprogrammatically turn on and off any of the data lines and Controllines.
Where these registers are?In an IBM PC, these registers are IO mapped and will have unique
address. We have to find these addresses to work with parallelport. For a typical PC, the base address of LPT1 is 0x378 and ofLPT2 is 0x278. The data register resides at this base address ,status register at baseaddress + 1 and the control register is atbaseaddress + 2. So once we have the base address , we cancalculate the address of each registers in this manner. The tablebelow shows the register addresses of LPT1 and LPT2.
Register LPT1 LPT2data registar(baseaddress+ 0)
0x378
0x278
status register(baseaddress + 1)
0x379
0x279
control register(baseaddress + 2)
0x37a
0x27a
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
35/69
Programming Conceptsalmost all programming languages allow programmers to accessparallel port using some library functions. For example , Borland Cis providing "Inportb" and "Outportb" functions to read or write IOmapped peripherals. But the examples provided here in thistutorial is written VC++ and can be easily ported to othercompilers like Borland C and Turbo C. Visual Basic does not haveany functions or support to access parallel port directly, but it ispossible to add such capabilities to your VB application by writinga dll in VC++ and calling its exported functions from VB. VC++provides two functions to access IO mapped peripherals, '_inp' forreading and '_outp' for writing. These functions are declared in"conio.h".
Hardware for testing sample programs
The schematic diagram of the test circuit is shown below. It isrecommended to build this circuit before testing the sampleprograms
Sample program in VC++
Writing a parallel port interfacing program in VC++ is very easy.Here are the steps to write your first parallel port interfacingapplication in VC++.
Start VC++ IDE, Select 'New' from File menu. Then select Win32Console Application from Projects tab (picture-3). Enter projectname as partest1, then click OK button.
http://www.logix4u.net/paralleltest.gif -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
36/69
Picture-3
Now you can see a dialog box with caption Win32 ConsoleApplication - step 1 of 1 (picture-4).
Picture-4
Select a simple Application and click Finish. Now openexample1.cpp from file view and replace the existing code withthe code given below.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
37/69
#include "stdafx.h"#include "conio.h"#include "stdio.h"#include "string.h"
#include "stdlib.h"
int main(int argc, char* argv[]){short data;
if(argc
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
38/69
Build the project and copy partest1.exe to "c:\".
How to Test the Program?
Connect the assembled hardware shown above to your PC's
parallel port. Open DOS command window Move to "C:\" and type"partest1 write 888 255" and press enter. If everything is correct,LED1 to LED8 in the hardware will glow. You may be doubtfulabout the command line parameters passed to the program. Here888(0x378) is the address of the parallel port data register and255 is the data to be written to parallel port data register. If youenter "partest1 read 888" to command line, the program will readparallel port data register and display it. This will blindly read thecontents of parallel port data register, but not the data present on
data lines. To read the data from the data lines, we will have to
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
39/69
enable the bidirectional data transfer first. To enable Bidirectionaldata transfer just set the "Bidirectional" bit (bit 5) in controlregister. This is done by writing 32 to control register. Thecommand "partest1 write 890 32" will do this. After entering thiscommand you can read the status of switches in the hardwareusing the command "partest1 read 888"
Tried the Inpout32.dll..? Then learn how Inpout32.dll does thethings. This brief tutorial explains about the working ofInpout32.dll in simple steps, with the help of a flow chart. Thiscould help you much if you want to modify the Inpout32 dll sourcecode
If you don't know what is Inpout32.dll, please read it here andthen continue.
How it works
The outstanding feature of Inpout32.dll is , it can work with all thewindows versions without any modification in user code or theDLL itself. This tutorial describes how it is achieved, whatprogramming methods used, what are the APIs used, etc.... TheDll will check the operating system version when functions arecalled, and if the operating system is WIN9X, the DLL will use_inp() and _outp functions for reading/writing the parallel port. On
the other hand, if the operating system is WIN NT, 2000 or XP, itwill install a kernel mode driver and talk to parallel port throughthat driver. The user code will not be aware of the OS version onwhich it is running. This DLL can be used in WIN NT cloneoperating systems as if it is WIN9X. The flow chart of the programis given below.
http://logix4u.net/parallel-port/inpout32.htmhttp://logix4u.net/parallel-port/inpout32.htm -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
40/69
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
41/69
The functions in the DLL are implemented in two source files,"inpout32drv.cpp" and "osversion.cpp". osversion.cpp checks theversion of operating system. "inpout32drv.cpp" does installing thekernel mode driver, loading it , writing/ reading parallel port etc...The two functions exported from inpout32.dll are
1) Inp32(), reads data from a specified parallel port register.
2) Out32(), writes data to specified parallel port register.
the other functions implemented in Inpout32.dll are
1) DllMain(), called when dll is loaded or unloaded. When the dll isloaded , it checks the OS version and loads hwinterface.sys ifneeded.
2) Closedriver(), close the opened driver handle. called beforeunloading the driver.
3) Opendriver(), open a handle to hwinterface driver.
4) inst() , Extract 'hwinterface.sys' from binary resource to'systemroot\drivers' directory and creates a service. This functionis called when 'Opendriver' function fails to open a valid handle to'hwinterface' service.
5) start() , starts the hwinterface service using Service ControlManager APIs.
6) SystemVersion() Checks the OS version and returnsappropriate code.
What is hwinterface.ocx ActiveX control
It is an activex control with same features of Inpout32.dll. It canbe used either with VC++ or VB. But it gives great conveniencewhen used with VB. Data can be written to parallel port usingOutport method and can be read using Inport method.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
42/69
MATLAB has an adaptor to access the parallel port (similar toadaptor for image acquisition). First you must check from theDevice Manager of your system (My Computer->SystemProperties->Device Manager->Ports) that what is the name given
to the parallel port of your computer. Lets say it is LPT1.To access the parallel port in MATLAB, define an object; lets sayby the name parport>> parport = digitalio('parallel','LPT1');You may obtain the port address using,>> get(parport,'PortAddress')>> daqhwinfo('parallel'); % To get data acquisition hardwareinformationYou have to define the pins 2-9 as output pins, by using
addline() function
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
43/69
>> addline(parport,0:7,'out')Now put the data which you want to output (depends on motionsof robot required) to the parallel port into a matrix (See functionlogical() in MATLAB Help); e.g.>> dataout = logical([1 1 0 1 0 1 0 1]);Now to output these values, use the putvalue() function
>> putvalue(parport,dataout);Alternatively, you can write the decimal equivalent of the binarydata and output it.>> data = 213;>> putvalue(parport,data);
You can connect the pins of the parallel port to the driver IC forthe left and right motors of your robot, and control the motion ofthe vehicle. You will need an H-bridge for driving the motor in
both clockwise and anti-clockwise directions (like L293 or L298).L293D
Fig: A DC Motor
DC Motor (Intermediate and Advance users can skip this)
A DC motor is electromechanical device that converts electrical
energy into mechanical energy that can be used to do many
useful works. It can produce mechanical movement like moving
the tray of CD/DVD drive in and out (you may like to try it out Go
to My Computer, right click the drive icon and click "Eject"). This
shows how software controls a motor. DC motors comes in
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
44/69
various ratings like 6V and 12V. It has two wires or pins. When
connected with power supply the shaft rotates. You can reverse
the direction of rotation by reversing the polarity of input.
Control with MCUs
As the MCUs PORT are not powerful enough to drive DC motors
directly so we need some kind of drivers. A very easy and safe is
to use popular L293D chips. It is a 16 PIN chip. The pin
configuration is as follows.
L293D Dual DC Motor Controller.
This chip is designed to control 2 DC motors. There are 2 INPUT
and 2 OUTPUT PINs for each motors. The connections is as
follows.
http://store.extremeelectronics.co.in/L293D-Dual-DC-Motor-Driver.htmlhttp://store.extremeelectronics.co.in/L293D-Dual-DC-Motor-Driver.html -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
45/69
Fig: Motor Controller Using L293d chip.
The behavior of motor for various input conditions are as follows
A B
StopLow Low
ClockwiseLow High
Anticlock
wise High Low
StopHigh High
So you saw you just need to set appropriate levels at two PINs of
the microcontroller to control the motor. Since this chip controls
two DC motors there are two more output pins (output3 and
output4) and two more input pins(input3 and input4). The INPUT3
and INPUT4 controls second motor in the same way as listed
above for input A and B. There are also two ENABLE pins they
must be high(+5v) for operation, if they are pulled low(GND)
http://www.extremeelectronics.co.in/avrtutorials/images/motor-controller.gif -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
46/69
motors will stop.The following program starts the motor runs it
one direction for some time and then reverses the direction.
#include #include
void Wait(){ char i; for (i=0;i
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
47/69
Insert the L293D chip into the
breadboard. And connect as per the
circuit diagram. Now connect the DC
motor. Then connect the 9V supply
to the breadboard this supply is
used to run he motor. Also connectthe 5V supply to the breadboard this
is the logical supply i.e. it defines a
HIGH or 1 is 5V. This 5V is
available in the xBoard itself. Use a
2pin connector to access this. Then connect the PD4 and PD5 pins of the
MCU to the breadboard. These will provide signals to control the motor.
Use a 8 PIN connecter to get PD4 and PD5. Connect PD4 to A and PD5
to B Now burn the program into the MCU and power on the system.The motor will rotate and will change directions after some times.
CAPACITORS
It is an electronic component whose function is to accumulate
charges and then release it.
To understand the
concept of capacitance,
consider a pair of metal plates which all are placed near to each
other without touching. If a battery is connected to these plates
the positive pole to one and the negative pole to the other,
electrons from the battery will be attracted from the plate
connected to the positive
terminal of the battery. If the
battery is then disconnected,
one plate will be left with an
excess of electrons, the other
Items Required.
DC Motor 12V
L293D chip
Breadboard.
Some wires
http://store.extremeelectronics.co.in/L293D-Dual-DC-Motor-Driver.htmlhttp://store.extremeelectronics.co.in/L293D-Dual-DC-Motor-Driver.htmlhttp://store.extremeelectronics.co.in/L293D-Dual-DC-Motor-Driver.html -
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
48/69
with a shortage, and a potential or voltage difference will exists
between them. These plates will be acting as capacitors.
Capacitors are of two types: - (1) fixed type like ceramic,
polyester, electrolytic capacitors-these names refer to the
material they are made of aluminium foil. (2) Variable type like
gang condenser in radio or trimmer. In fixed type capacitors, it
has two leads and its value is written over its body and variable
type has three leads. Unit of measurement of a capacitor is farad
denoted by the symbol F. It is a very big unit of capacitance.
Small unit capacitor are pico-farad denoted by pf
(Ipf=1/1000,000,000,000 f) Above all, in case of electrolyticcapacitors, it's two terminal are marked as (-) and (+) so check it
while using capacitors in the circuit in right direction. Mistake can
destroy the capacitor or entire circuit in operational.
DIODE
The simplest semiconductor device is made up of a sandwich
of P-type semiconducting material, with contacts provided to
connect the p-and n-type layers to an external circuit. This is a
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
49/69
junction Diode. If the positive terminal of the battery is connected
to the p-type material (cathode) and the negative terminal to the
N-type material (Anode), a large current will flow. This is called
forward current or forward biased.
If the connections are reversed, a very little current will flow.
This is because under this condition, the p-type material will
accept the electrons from the negative terminal of the battery
and the N-type material will give up its free electrons to the
battery, resulting in the state of electrical equilibrium since the N-
type material has no more electrons. Thus there will be a small
current to flow and the diode is called Reverse biased.
Thus the Diode allows direct current to pass only in one
direction while blocking it in the other direction. Power diodes are
used in concerting AC into DC. In this, current will flow freely
during the first half cycle (forward biased) and practically not at
all during the other half cycle (reverse biased). This makes the
diode an effective rectifier, which convert ac into pulsating dc.
Signal diodes are used in radio circuits for detection. Zener diodes
are used in the circuit to control the voltage.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
50/69
Some common diodes are:-
1. Zener diode.
2. Photo diode.
3. Light Emitting diode.
1. ZENER DIODE:-
A zener diode is specially designed junction diode, which can
operate continuously without being damaged in the region of
reverse break down voltage. One of the most important
applications of zener diode is the design of constant voltage
power supply. The zener diode is joined in reverse bias to d.c.
through a resistance R of suitable value.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
51/69
2. PHOTO DIODE:-
A photo diode is a junction diode made from photo- sensitive
semiconductor or material. In such a diode, there is a provision to
allow the light of suitable frequency to fall on the p-n junction. It is
reverse biased, but the voltage applied is less than the break
down voltage. As the intensity of incident light is increased,
current goes on increasing till it becomes maximum. The
maximum current is called saturation current.
3. LIGHT EMITTING DIODE (LED):-
When a junction diode is forward biased, energy is released
at the junction diode is forward biased, energy is released at the
junction due to recombination of electrons and holes. In case of
silicon and germanium diodes, the energy released is in infrared
region. In the junction diode made of gallium arsenate or indium
phosphide, the energy is released in visible region. Such a
junction diode is called a light emitting diode or LED.
RESISTANCE
Resistance is the opposition of a material to the current. It is
measured in Ohms ( ). All conductors represent a certain amount
of resistance, since no conductor is 100% efficient. To control the
electron flow (current) in a predictable manner, we use resistors.
Electronic circuits use calibrated lumped resistance to control the
flow of current. Broadly speaking, resistor can be divided into two
groups viz. fixed & adjustable (variable) resistors. In fixed
resistors, the value is fixed & cannot be varied. In variable
resistors, the resistance value can be varied by an adjuster knob.
It can be divided into (a) Carbon composition (b) Wire wound (c)
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
52/69
Special type. The most common type of resistors used in our
projects is carbon type. The resistance value is normally indicated
by colour bands. Each resistance has four colours, one of the
band on either side will be gold or silver, this is called fourth band
and indicates the tolerance, others three band will give the value
of resistance (see table). For example if a resistor has thefollowing marking on it say red, violet, gold. Comparing these
coloured rings with the colour code, its value is 27000 ohms or 27
kilo ohms and its tolerance is 5%. Resistor comes in various
sizes (Power rating). The bigger, the size, the more power rating
of 1/4 watts. The four colour rings on its body tells us the value of
resistor value as given below.
COLOURS CODE
Black----------------------------------------0
Brown--------------------------------------1
Red------------------------------------------2
Orange-------------------------------------3
Yellow--------------------------------------4
Green---------------------------------------5
Blue-----------------------------------------6
Violet---------------------------------------7
Grey-----------------------------------------8
White---------------------------------------9
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
53/69
The first rings give the first digit. The second ring gives thesecond digit. The third ring indicates the number of zeroes to be
placed after the digits. The fourth ring gives tolerance (gold 5%,
silver 10%, No colour 20%).
In variable resistors, we have the dial type of resistance
boxes. There is a knob with a metal pointer. This presses over
brass pieces placed along a circle with some space b/w each ofthem.
Resistance coils of different values are connected b/w the
gaps. When the knob is rotated, the pointer also moves over the
brass pieces. If a gap is skipped over, its resistance is included in
the circuit. If two gaps are skipped over, the resistances of both
together are included in the circuit and so on.
A dial type of resistance box contains many dials depending
upon the range, which it has to cover. If a resistance box has to
read upto 10,000 , it will have three dials each having ten gaps
i.e. ten resistance coils each of resistance 10 . The third dial
will have ten resistances each of 100
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
54/69
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
55/69
MINIATURE TRANSFORMER
CONVENTIONAL POWER TRANSFORMER
POWER SUPPLY
In flow in one direction only. When the anode of the diode is
positive with respect to its cathode, it is forward biased, allowing
current to flow. But when its anode is negative with alternating
current the electron flow is alternate, i.e. the electron flow
increases to maximum in one direction, decreases back to zero. It
then increases in the other direction and then decreases to zero
again. Direct current flows in one direction only. Rectifier converts
alternating current to respect to the cathode, it is reverse biased
and does not allow current to flow. This unidirectional property of
the diode is useful for rectification. A single diode arranged back-
to-back might allow the electrons to flow during positive half
cycles only and suppress the negative half cycles. Double diodes
arranged back-to-back might act as full wave rectifiers as they
may allow the electron flow during both positive and negative half
cycles. Four diodes can be arranged to make a full wave bridge
rectifier. Different types of filter circuits are used to smooth out
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
56/69
the pulsations in amplitude of the output voltage from a rectifier.
The property of capacitor to oppose any change in the voltage
applied across them by storing energy in the electric field of the
capacitor and of inductors to oppose any change in the current
flowing through them by storing energy in the magnetic field of
coil may be utilized. To remove pulsation of the direct currentobtained from the rectifier, different types of combination of
capacitor, inductors and resistors may be also be used to increase
to action of filtering.
NEED OF POWER SUPPLY
Perhaps all of you are aware that a power supply is a
primary requirement for the Test Bench of a home
experimenters mini lab. A battery eliminator can eliminate orreplace the batteries of solid-state electronic equipment and the
equipment thus can be operated by 230v A.C. mains instead of
the batteries or dry cells. Nowadays, the use of commercial
battery eliminator or power supply unit has become increasingly
popular as power source for household appliances like
transreceivers, record player, cassette players, digital clock etc.
THEORY
U SE OF DIODES IN RECTIFIERS:
Electric energy is available in homes and industries in India,
in the form of alternating voltage. The supply has a voltage of
220V (rms) at a frequency of 50 Hz. In the USA, it is 110V at 60
Hz. For the operation of most of the devices in electronic
equipment, a dc voltage is needed. For instance, a transistor radiorequires a dc supply for its operation. Usually, this supply is
provided by dry cells. But sometime we use a battery eliminator
in place of dry cells. The battery eliminator converts the ac
voltage into dc voltage and thus eliminates the need for dry cells.
Nowadays, almost all-electronic equipment includes a circuit that
converts ac voltage of mains supply into dc voltage. This part of
the equipment is called Power Supply. In general, at the input of
the power supply, there is a power transformer. It is followed by a
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
57/69
diode circuit called Rectifier. The output of the rectifier goes to a
smoothing filter, and then to a voltage regulator circuit. The
rectifier circuit is the heart of a power supply.
RECTIFICATION
Rectification is a process of rendering an alternating currentor voltage into a unidirectional one. The component used for
rectification is called Rectifier. A rectifier permits current to flow
only during the positive half cycles of the applied AC voltage by
eliminating the negative half cycles or alternations of the applied
AC voltage. Thus pulsating DC is obtained. To obtain smooth DC
power, additional filter circuits are required.
A diode can be used as rectifier. There are various types of
diodes. But, semiconductor diodes are very popularly used as
rectifiers. A semiconductor diode is a solid-state device consisting
of two elements is being an electron emitter or cathode, the other
an electron collector or anode. Since electrons in a semiconductor
diode can flow in one direction only-from emitter to collector- the
diode provides the unilateral conduction necessary for
rectification. Out of the semiconductor diodes, copper oxide and
selenium rectifier are also commonly used.
FULL WAVE RECTIFIER
It is possible to rectify both alternations of the input voltage
by using two diodes in the circuit arrangement. Assume 6.3 V rms
(18 V p-p) is applied to the circuit. Assume further that two equal-
valued series-connected resistors R are placed in parallel with the
ac source. The 18 V p-p appears across the two resistorsconnected between points AC and CB, and point C is the electrical
midpoint between A and B. Hence 9 V p-p appears across each
resistor. At any moment during a cycle of vin, if point A is positive
relative to C, point B is negative relative to C. When A is negative
to C, point B is positive relative to C. The effective voltage in
proper time phase which each diode "sees" is in Fig. The voltage
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
58/69
applied to the anode of each diode is equal but opposite in
polarity at any given instant.
When A is positive relative to C, the anode of D1 is positive
with respect to its cathode. Hence D1 will conduct but D2 will not.
During the second alternation, B is positive relative to C. Theanode of D2 is therefore positive with respect to its cathode, and
D2 conducts while D1 is cut off.
There is conduction then by either D1 or D2 during the entire
input-voltage cycle.
Since the two diodes have a common-cathode load resistor
RL, the output voltage across RL will result from the alternate
conduction of D1 and D2. The output waveform vout across RL,
therefore has no gaps as in the case of the half-wave rectifier.
The output of a full-wave rectifier is also pulsating direct
current. In the diagram, the two equal resistors R across the input
voltage are necessary to provide a voltage midpoint C for circuit
connection and zero reference. Note that the load resistor RL is
connected from the cathodes to this center reference point C.
An interesting fact about the output waveform vout is that
its peak amplitude is not 9 V as in the case of the half-wave
rectifier using the same power source, but is less than 4 V. The
reason, of course, is that the peak positive voltage of A relative toC is 4 V, not 9 V, and part of the 4 V is lost across R.
Though the full wave rectifier fills in the conduction gaps, it
delivers less than half the peak output voltage that results from
half-wave rectification.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
59/69
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
60/69
voltage are reduced considerable. Filter network circuits may be
of two types in general:
CHOKE INPUT FILTER
If a choke coil or an inductor is used as the first-
components in the filter network, the filter is called choke input
filter. The D.C. along with AC pulsation from the rectifier circuit at
first passes through the choke (L). It opposes the AC pulsations
but allows the DC to pass through it freely. Thus AC pulsations are
largely reduced. The further ripples are by passed through the
parallel capacitor C. But, however, a little nipple remains
unaffected, which are considered negligible. This little ripple may
be reduced by incorporating a series a choke input filters.
CAPACITOR INPUT FILTER
If a capacitor is placed before the inductors of a choke-input
filter network, the filter is called capacitor input filter. The D.C.
along with AC ripples from the rectifier circuit starts charging the
capacitor C. to about peak value. The AC ripples are then
diminished slightly. Now the capacitor C, discharges through theinductor or choke coil, which opposes the AC ripples, except the
DC. The second capacitor C by passes the further AC ripples. A
small ripple is still present in the output of DC, which may be
reduced by adding additional filter network in series.
CIRCUIT DIAGRAM
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
61/69
PROCEDURE FOR MAKING PROJECT
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
62/69
Building project in the proper manner is really an art,
something which must be practiced and learned through trial and
error, it is not all that difficult. The main thing is to remember to
take each step slowly and carefully according to the instructions
giving making since that everything at it should be before
proceeding further.
TOOLS: The electronics workbench is
an actual place of work with
comfortably & conveniently &
should be supplied with
compliment of those tools must
often use in project building.Probably the most important device is a soldering tool. Other tool
which should be at the electronic work bench includes a pair of
needle nose pliers, diagonal wire cutter, a small knife, an
assortment of screw driver, nut driver, few nuts & bolts, electrical
tape, plucker etc. Diagonal wire cutter will be used to cut away
any excess lead length from copper side of P.C.B. 7 to cut section
of the board after the circuit is complete. The needle nose pliers
are most often using to bend wire leads & wrap them in order toform a strong mechanical connection.
MOUNTING & SOLDERING:
Soldering is process of joining
together two metallic parts. It is
actually a process of function in
which an alloy, the solder, with a
comparatively low melting point
penetrates the surface of the
metal being joined & makes a
firm joint between them on cooling & solidifying.
THE SOLDERING KIT
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
63/69
1. SOLDERING IRON:
As soldering is a process of joining together two
metallic parts, the instrument, which is used, for doing this job is
known as soldering Iron. Thus it is meant for melting the solder
and to setup the metal parts being joined. Soldering Iron is rated
according to their wattage, which varies from 10- 200 watts.
2. SOLDER:
The raw material used for soldering is solder. It is
composition of lead & tin. The good quality solder (a type of
flexible naked wire) is 60% Tin +40% Lead which will melt
between 180 degree to 200 degree C temperature.
3. FLUXES OR SOLDERING PASTE:
When the points to solder are heated, an oxide film forms.
This must be removed at once so that solder may get to the
surface of the metal parts. This is done by applying chemical
substance called Flux, which boils under the heat of the iron
remove the oxide formation and enable the metal to receive the
solder.
4. BLADES OR KNIFE:
To clean the surface & leads of components to be soldered is
done by this common instrument.
5. SAND PAPER:
The oxide formation may attack at the tip of your soldering
iron & create the problem. To prevent this, clean the tip with the
help of sand paper time to time or you may use blade for doing
this job. Apart from all these tools, the working bench for
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
64/69
soldering also includes desoldering pump, wink wire (used for
desoldering purpose), file etc.
HOW TO SOLDER?
Mount components at their appropriate place; bend the
leads slightly outwards to prevent them from falling out when theboard is turned over for soldering. No cut the leads so that you
may solder them easily. Apply a small amount of flux at these
components leads with the help of a screwdriver. Now fix the bit
or iron with a small amount of solder and flow freely at the point
and the P.C.B copper track at the same time. A good solder joint
will appear smooth & shiny. If all appear well, you may continue
to the next solder connections.
TIPS FOR GOOD SOLDERING
1. Use right type of soldering iron. A small efficient soldering iron
(about 10-25 watts with 1/8 or 1/4 inch tip) is ideal for this
work.
2. Keep the hot tip of the soldering iron on a piece of metal so
that excess heat is dissipated.
3. Make sure that connection to the soldered is clean. Wax frayed
insulation and other substances cause poor soldering
connection. Clean the leads, wires, tags etc. before soldering.
4. Use just enough solder to cover the lead to be soldered. Excess
solder can cause a short circuit.
5. Use sufficient heat. This is the essence of good soldering. Applyenough heat to the component lead. You are not using enoughheat, if the solder barely melts and forms a round ball of roughflaky solder. A good solder joint will look smooth, shining andspread type. The difference between good & bad soldering isjust a few seconds extra with a hot iron applied firmly.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
65/69
PRECAUTIONS
1. Mount the components at the appropriate places before
soldering. Follow the circuit description and components
details, leads identification etc. Do not start soldering beforemaking it confirm that all the components are mounted at the
right place.
2. Do not use a spread solder on the board, it may cause short
circuit.
3. Do not sit under the fan while soldering.
4. Position the board so that gravity tends to keep the solderwhere you want it.
5. Do not over heat the components at the board. Excess heat
may damage the components or board.
6. The board should not vibrate while soldering otherwise you
have a dry or a cold joint.
7. Do not put the kit under or over voltage source. Be sure about
the voltage either dc or ac while operating the gadget.
8. Do spare the bare ends of the components leads otherwise it
may short circuit with the other components. To prevent this
use sleeves at the component leads or use sleeved wire for
connections.
9. Do not use old dark color solder. It may give dry joint. Be sure
that all the joints are clean and well shiny.
10. Do make loose wire connections especially with cell holder,
speaker, probes etc. Put knots while connections to the circuit
board, otherwise it may get loose.
MAKING PRINTED CIRCUIT BOARD (P.C.B.)
INTRODUCTION--
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
66/69
Making a Printed Circuit Board is the first step towards buildingelectronic equipment by any electronic industry. A number ofmethods are available for making P.C.B., the simplest method isof drawing pattern on a copper clad board with acid resistant(etchants) ink or paint or simple nail polish on a copper cladboard and do the etching process for dissolving the rest of copper
pattern in acid liquid.
MATERIAL REQUIRED
The apparatus needs for making a P.C.B. is :-
*Copper Clad Sheet
*Nail Polish or Paint
*Ferric Chloride Powder. (FeCl)
*Plastic Tray
*Tap Water etc.
PROCEDURE
The first and foremost in the process is to clean all dirt from
copper sheet with say spirit or trichloro ethylene to remove traces
grease or oil etc. and then wash the board under running tap
water. Dry the surface with forced warm air or just leave the
board to dry naturally for some time.
Making of the P.C.B. drawing involves some preliminary
consideration such as thickness of lines/ holes according to thecomponents. Now draw the sketch of P.C.B. design (tracks, rows,
square) as per circuit diagram with the help of nail polish or
enamel paint or any other acid resistant liquid. Dry the point
surface in open air, when it is completely dried, the marked holes
in P.C.B. may be drilled using 1Mm drill bits. In case there is any
shorting of lines due to spilling of paint, these may be removed by
scraping with a blade or a knife, after the paint has dried.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
67/69
After drying, 22-30 grams of ferric chloride in 75 ml of water may
be heated to about 60 degree and poured over the P.C.B.; placed
with its copper side upwards in a plastic tray of about 15*20 cm.
stirring the solution helps speedy etching. The dissolution of
unwanted copper would take about 45 minutes. If etching takes
longer, the solution may be heated again and the process
repeated. The paint on the pattern can be removed P.C.B. may
then be washed and dried. Put a coat of varnish to retain the
shine. Your P.C.B. is ready.
REACTION
Fecl3 + Cu ----- CuCl3 + Fe
Fecl3 + 3H2O --------- Fe (OH)3 + 3HCL
PRECAUTION
1. Add Ferric Chloride (Fecl3) carefully, without any splashing.
Fecl3 is irritating to the skin and will stain the clothes.
2. Place the board in solution with copper side up.
3. Try not to breathe the vapors. Stir the solution by giving see-
saw motion to the dish and solution in it.
4. Occasionally warm if the solution over a heater-not to
boiling. After some time the unshaded parts change their
color continue to etch. Gradually the base material will
become visible. Etch for two minutes more to get a neat
pattern.
5. Don't throw away the remaining FeCl3 solution. It can be
used again for next Printed Circuit Board P.C.B.
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
68/69
USES
Printed Circuit Board is used for housing components to make a
circuit for compactness, simplicity of servicing and case of
interconnection. Thus we can define the P.C.B. as : Printed Circuit
Boards is actually a sheet of Bakelite (an insulating material) onthe one side of which copper patterns are made with holes and
from another side, leads of electronic components are inserted in
the proper holes and soldered to the copper points on the back.
Thus leads of electronic components terminals are joined to make
electronic circuit.
In the boards copper cladding is done by pasting thin copper foil
on the boards during curing. The copper on the board is about 2
mm thick and weights an ounce per square foot.
The process of making a Printed Circuit for any application has
the following steps (opted professionally):
* Preparing the layout of the track.
* Transferring this layout photographically M the copper.
* Removing the copper in places which are not needed, by the
process of etching (chemical process)
* Drilling holes for components mounting.
PRINTED CIRCUIT BOARD
Printed circuit boards are used for housing components to make a
circuit, for comactness, simplicity of servicing and ease of
-
7/28/2019 A Vision Based Robot Has an Image Acquisition Device Like a Webcam as Its Eyes
69/69
interconnection. Single sided, double sided and double sided with
plated-through-hold (PYH) types of p.c boards are common today.
Boards are of two types of material (1) phenolic paper based
material (2) Glass epoxy material. Both materials are available as
laminate sheets with copper cladding.
Printed circuit boards have a copper cladding on one or both
sides. In both boards, pasting thin copper foil on the board during
curing does this. Boards are prepared in sizes of 1 to 5 metre
wide and upto 2 metres long. The thickness of the boards is 1.42
to 1.8mm. The copper on the boards is about 0.2 thick and weighs
and ounce per square foot.