You are on page 1of 90

DE 28 (MTS)

PROJECT REPORT
STRATEGIC MONITORING USING RFID & REAL-TIME
TARGET TRACKING
Submitted to the Department of Mechatronics Engineering in partial fulfillment of the
requirements for the degree of
Bachelor of Engineering
in
Mechatronics
2010

Sponsoring DS: Submitted By:
Gp. Capt Arif Ejaz Adnan Munawer
Dr. Khurram Kamal Areeb Qaisar
Ahmed Mateen
M. Qasim Zia






ACKNOWLEDGMENTS
Allah, the most beneficial and the most magnificent, was of course the largest source
of support in this project. We are very thankful to God for granting us the will and ability to
surmount the difficulties in this project and gracing us with the honor of completing our Final
Year Project.
We would like to thank our Project Supervisors Gp Capt (R) Arif Ejaz & Dr.
Khurram Kamal for their support and help during the project. We are especially thankful to
Maj Dr Kunwar Faraz for helping us throughout the project whenever we needed it. We
would specially like to mention the help and support offered to us by our degree mates Khalid
Ahmed, Jazel Ashraf, Umer Ilyas, Ghayur Ahmed, Abdul Haseeb who contributed with
valuable advice and suggestions during the various design & development stages of
SMARTrax.
We are all thankful to our Parents who have been a source of great support and inspiration
in pursuing our work. This project would not have been completed without their prayers and
support.

















ABSTRACT

Computing optical flow in low level computer vision is a handy problem since a
compromise has to be made at the end of accuracy and speed of tracking. In our work we
required both accuracy as well as speed for the tracking of intruder object. Two pan tilt
assemblies had to be controlled. One used for the camera and the other for the weapon. The
locked objects coordinates had to be scaled for the weapons pan tilt assembly after which two
separate control system made the two pan tilts follow the target. The camera had a broader
field of view so it had a relatively easier and slower movement while the weapons pan tilt had
to strictly follow the coordinates predicted by the tracking algorithm. Therefore both speed
and accuracy were required at both the tracking algorithms end as well as the pan tilts control
system.




















TABLE OF CONTENTS:
Title Page No.
Acknowledgments i
Abstract ii
1 - Introduction 1
1.1 - Background 1
1.2 - Project Goals & Objectives 2
1.3 - Anticipated Benefits 2
1.4 - Project Plan 2
1.5 Work Distribution 3
2 - Literature Review 5
2.1 - Flowchart of System Architecture 5
2.2 Features of Electronics Control Box 6
2.3 Image Capturing Devices 7
2.3.1 USB Webcam 7
2.3.2 CCD Camera 7
2.4 Image Acquisition & Processing 8
2.4.1 Open CV Library on MS Visual Studio 08 8
2.4.2 Image Processing Toolbox on MATLAB v09 9
2.4.3 A comparison of OpenCV & Image processing Toolbox 9
2.5 Graphical User Interface (GUI) 10
2.6 Authorization of Target 12
2.7 AVR Microcontroller & Comm. Protocols 12
2.7.1 The AVR Microcontroller 12
2.7.2 User Defined Protocols 13
2.7.3 Communication Protocols 13
3 - Target Tracking using Real-time Digital Image Processing 14
3.1 Connected Component Labeling Algorithm 15
3.1.1 Difference Image 15
3.1.2 Median Filter 15
3.1.3 Thresholding 16
3.1.4 Distinguishing Features 16
3.1.5 Noise Elimination 17
3.1.6 Marking the Boundary 17
3.2 Segmented Correlation Tracking Algorithm 18
3.2.1 Distinguishing Features 19
3.2.2 Differences between two methods of Static Camera Tracking 20
3.3 Lucas Kanade Flow Algorithm 21
4 - Mean-Shift Tracking Algorithm 23
4.1 Object Model Histogram 24
4.2 Object Candidates Histogram 24
4.3 Measure of Similarity 25
4.4 Selection of Kernel 26
4.4.1 The Epanechnikov Kernel 26
4.4.2 The Gaussian Kernel 27
4.4.3 The Flat Kernel 27
5 Embedded Electronics System for Control 28




5.1 - Overview 28
5.2 Power Supply Unit 29
5.3 AC/DC Motor Drives 30
5.4 Ground Isolation 30
5.5 - Logic Circuitry & Manual Control 30
5.6 RFID Control Unit 31
5.7 Communication Standards 31
6 - Control System Design 32
6.1 Pan-Tilt Control System for the Gun 32
6.2 Proportional Integral Derivative Control 33
6.3 PID Parameters 34
6.3.1 The Proportional Error 34
6.3.2 The Integral Error 35
6.3.3 The Derivative Error 36
6.3.4 Summary 37
7 - Radio Frequency Identification 38
7.1 Introduction to RFID 38
7.2 Why we chose RFID? 38
7.3 Comparison of RFID with Bar-Code Technology 38
7.4 Active & Passive RFID Tags 39
7.5 RFID Frequencies 39
7.6 RFID Building Blocks 40
8 - Design of Pan-Tilt Gun Mount 41
8.1 - Introduction 41
8.2 Commercial Availability 41
8.3 Camera Pan Tilt 41
8.4 Gun Pan Tilt 42
8.5 The Design 42
8.5.1 Design 1 42
8.5.2 Design 2 43
8.6 Position Control & Gear Ratio 44
8.7 - Motors 44
8.8 Stress Analysis 45
Operating Instructions 46
Results 47
Summary 48
Future Work 49
List of Soft wares used 50
References 51
Annex A 52
Annex B 54
Annex C 78
Annex D 79
Annex E 81

LIST OF FIGURES:





Figure
No
Title Page No.
1 Project Timeline 2
2 Resource Allocation 3
3 Flowchart of System Architecture 5
4
C
Control Box Snapshots 6
5 Control Box Snapshots 7
6 CCD Camera with Pan Tilt 8
7 Graphical User Interface (GUI) 11
8 Effect of Median Filter 16
9 Histogram before & after applying Median Filter 17
10 The Epanechnikov Kernel 26
11 The Gaussian Kernel 27
12 Flowchart of Embedded System Electronics 28
13 The Electronics Control Box 29
14 Block diagram of Power Supply Unit 29
15 Block Diagram of AC/DC Motor Drives 30
16 RFID Control Unit 31
17 The Control Loop 32
18 The Vector Field 33
19 Gradient of Vector Field 33
20 The PID Control Loop 34
21 The Effect of Proportional constant 35
22 The Effect of Integral Constant 36
23 The Effect of Derivative Constant 37
24 First Design 43
25 Second Design 43
26 The Fabricated Pan Tilt for Gun 44



LIST OF TABLES:

Table No. Title Page No.
1 Work Distribution 3
2 A Comparison of Speed between MATLAB & OpenCV Library 10
3 A Comparison between the two Approaches of Segmentation 19
4 A Comparison between the two Approaches OF Static Camera
Tracking
20
5 A Comparison between RFID & Bar-Code Technology 38
6 Primary Differences between Passive and Active Tags 39
7 RFID Frequencies 39
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

1


CHAPTER 1 INTRODUCTION

1.1: Background:
In the present era the need for automating many tasks previously done by man has
become a very popular field of interest. The reasons for automation are mostly to provide a
better task to be done at the ease of human labor and at the expense of machine and computer
intelligence. The need for this Project arose due to the recent security issues in the country,
e.g. Suicide Bombing. The current task is another dimension of automation, the automation
that will be provided is not only to provide ease to humans but is a very essential tool in
handling the security of almost every site being military, private, government etc.
The project being done is a security system that identifies the subject i.e. personnel
and then depending upon the security level takes necessary action to ensure the security of the
site. The identification is provided by the popular RFID (Radio Frequency Identification).
The subject is observed by a camera and tracked using computer vision. In addition, a weapon
is mounted to track and eliminate the unauthorized subject in case of the extreme security
level. For the current project we have used a high power water gun and a laser beam to do the
work of targeting.
The project when done would be a great relief for the security guards and companies
willing to adapt it, since it would do the work of a watchman and prevent loss of friendly
lives in case of an encounter or a terrorist attack. The camera and weapon are assembled on a
pan-tilt assembly.
1.2: Project Goals & Objectives:
1) To design a low-cost, versatile, indigenous security system.
2) Auto-Focus and Target Locking
3) Efficient and more precise than humanly operated weapons.
4) Works at night as well.
5) This technology will take over the work of security guards, and manned inspection;
hence the fear of loss of friendly lives can be minimized.
6) Ability to read data from individual RFID tags.
7) Complete information about the persons arrival and departure from observation site.
Chapter 1: Introduction
2010

2


1.3: Anticipated Benefits:
1) It will minimize the man-power required to maintain a given security system.
2) It will also reduce the chances of loss of life due to suicidal bombing and vulnerability
to open encounter.
3) It would be utilized to differentiate authorized personnel from unauthorized ones.
1.4: Project Plan:
This project was planned and monitored using Microsoft Office Project Professional
v2007. A snapshot of the Project plan and Timeline, which was implemented successfully is
shown in Figure 1.

Figure 1: Project Timeline (Microsoft Project)
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

3


Figure 2 Resource Allocation
1.5: Work Distribution:
Table 1: Work Distribution
Tasks Responsible person(s)
1. Project proposal Adnan Munawar / Areeb Qaisar / Ahmed
Mateen
2. Working out strategy Adnan Munawar / Areeb Qaisar / Ahmed
Mateen
/Qasim Zia
3. Research work on the RFID module Ahmed Mateen
4. Research work on Digital Image
Processing
Adnan Munawar
5. Studying Visual Studio with reference
to
Open CV
Areeb Qaisar
6. Implementation of Back ground
subtraction algorithm in MATLAB
Areeb Qaisar
7. Implementation of Segmented
Correlation Algorithm in MATLAB
Areeb Qaisar / Adnan Munawar
8. Implementation of the Lucas
Kanade Algorithm in MATLAB
Adnan Munawar
9. Implementation of the Mean Shift
Algorithm in MATLAB
Adnan Munawar
10. Design of the electronics Areeb Qaisar
11. Design of power unit for the control Areeb Qaisar
Chapter 1: Introduction
2010

4


system
12. Design and implementation of the
safety
unit of the control box
Adnan Munawar / Areeb Qaisar
13. Survey of electronic components /
connector / special ICs
Areeb Qaisar / Ahmed Mateen
14. Procurement of electronic components Ahmed Mateen / Areeb Qaisar
15. Fabrication of electronics Adnan Munawar / Areeb Qaisar / Qasim Zia
/ Ahmed Mateen
16. Development of the control box Adnan Munawar / Areeb Qaisar / Ahmed
Mateen
/Qasim Zia
17. First mechanical design of the Pan Tilt
in PRO-E
Adnan Munawar / Ahmed Mateen
18. Second mechanical design of the Pan
Tilt in PRO-E
Qasim Zia
19. Supervision of the Fabrication of the
Pan Tilt
Qasim Zia / Ahmed Mateen
20. Mathematical modeling of the Pan Tilt Adnan Munawar
21. Control of both the Pan Tilts Adnan Munawar
22. Development of the communication
protocol
Adnan Munawar / Ahmed Mateen
23. Programming of AVR 1 (Master
Controller)
Adnan Munawar
24. Programming of AVR 2 (G-LCD and
A-LCD, Bridge for RFID data)
Adnan Munawar
25. Programming of AVR 3 (Manual
Control / Analog Control)
Ahmed Mateen
26. Programming of AVR 4 Ahmed Mateen
27. Responsibility of RFID modules
trouble shooting
Ahmed Mateen
28. Development of the 1
st
GUI
in MFC
Areeb Qaisar
29. Development of second GUI in
MFC with CDHTMLDialog Classes
Areeb Qaisar
30. Development of the segmented
correlation algorithm in Visual C++
Areeb Qaisar
31. Development of the Mean Shift
Algorithm in Visual C++
Areeb Qaisar
32. Application development in Visual
C++
Areeb Qaisar
33. Design of the Poster Ahmed Mateen
34. Documentation / Paper work Ahmed Mateen / Areeb Qaisar
35. Formulating Research Paper Adnan Munawar
36. Linking the modules Adnan Munawar/Areeb Qaisar


Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

5


CHAPTER 2 LITERATURE REVIEW

A handsome amount of literature concerning different methods for image acquisition
and processing, Target Authorization using Radio Frequency Identification etc was studied.
Initially a flowchart of the System Architecture was planned and work was assigned to
different Group Members. The overall flowchart of System Architecture and details of
literature are explained below:
2.1: Flowchart of System Architecture:










Figure 3: Flowchart of System Architecture


CAMERA AND WEAPON
ON PAN-TILT
CONTROL UNIT

RFID MODULE
DETECTION OF INCOMING
ENTITY BY CAMERA

ALLOW THE
ENTITY TO PASS
LOCK THE ENTITY
AND KEEP TRACKING

CHECK FOR
AUTHORIZATION TO
ENTER
AUTHORIZED UNAUTHORIZED

WARN THE ENTITY TO
LEAVE PREMESIS
TRIGGER THE ALARMS
AND INFORM CONTROL
ROOM
AIM THE TARGET AND
ELIMINATE

Chapter 2: Literature Review
2010

6


2.2: Features of Electronics Control Box:
Following are the main features of the electronics control box unit;
1) We have tried our best to give SMARTrax a professional form. A complete embedded
system was designed and developed for the electronics of SMARTrax. The electronics
control box is made of dark transparent acrylic with numerous button and slots for
different purposes.
2) Safety / Protection: Safety purposes all incoming & outgoing signals are rerouted at
the side of the control box. Appropriate fuses have been placed throughout the system.
3) Manual Control for initial positioning: Buttons for manual control have been added at
the front side to adjust the initial position of the system before startup. This applies for
both camera & gun pan tilt.
4) Status Display: A 128*64 Graphical LCD is installed at the front side to show the
status of the different electronic components and microcontrollers. It also shows the
direction of motion when manual control using the gamepad is implemented. An
alphanumeric LCD is also used to assist the Graphical LCD in showing the status of
SMARTrax.
5) Independent Power Supply: To make SMARTrax a professional product an
independent power supply is designed and included in the electronics control box so
that it can be used anywhere without the need for special power supplies, a simple
220V 60 Hz from a normal wall socket will suffice.

Figure 4 Control Box snapshots
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

7



Figure 5 Control Box Snapshots
2.3: Image Capturing Device:
We had two options for the selection of an Image Capturing Device, a USB Webcam
and CCD Camera. We opted for a CCD Camera as explained in article 2.2.2.

2.3.1: USB Webcam:
A USB Webcam is a video capture device connected to a computer using a
USB (Universal Serial Bus) port. Webcams are known for low manufacturing costs and
flexibility. USB Webcams typically include a lens, an image sensor, and some support
electronics. They usually have fixed focus lenses, which have no provision for adjustment.
Most consumer webcams are capable of providing VGA-resolution video at a frame rate
of 25 frames per second. A USB Webcam is slow, and its frame rate varies drastically
depending on the intensity of light. It is slow in Dim lights and fast in bright light. Most
Webcams do not need any extra Drivers are supported by common operating Systems
such as various versions of Linux and Microsoft Windows.

2.3.2: CCD Camera:
A charge-coupled device (CCD) Camera is a single IC device, which consists
of an array of photosensitive cells. Its each cell produces an electric current dependent on
the incident light falling on it. It has a video signal output and has less geometric
distortion and more linear video output. A CCD Camera is fast, and its result is
independent of the amount of light. The CCD Camera that we are using is capable of
Chapter 2: Literature Review
2010

8


providing a Frame rate of 52, and can even provide a low-quality video in extremely dark
conditions. The drawback is that there is constant salt-and-pepper noise, which was
modeled in our system to remove this noisy effect. Moreover, a TV Card is required to
convert the analog video into the Digital video, and some extra drivers are needed to
interface a CCD Camera with a Computer. We opted for a CCD Camera, because of its
fast result, and because it is independent to lightening conditions.

Figure 6 CCD Camera with Pan Tilt
2.4: Image Acquisition & Processing:
Image Acquisition is the pre-requisite step for the any Image Processing Operation.
Once an image is available, it can be digitally processed and relevant information can be
extracted. We used the following two libraries for Image Acquisition & Processing.

2.4.1: OpenCV Library on Microsoft Visual Studio v2008:
OpenCV (Open Source Computer Vision) is a library of programming
functions for real time computer vision. Originally developed by Intel, it is a cross-
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

9


platform library supported by many Operating Systems, and free for Commercial and
Research use. It focuses mainly on Real-time Image processing, as such, if it finds Intel's
Integrated Performance Primitives on the system, it will use these commercial optimized
routines to accelerate itself. We used this library in conjunction with Microsoft Visual
Studio v2008 to develop our application.

2.4.2: Image Processing Toolbox on MATLAB v2009:
Image Acquisition Toolbox allows acquiring of images and video directly into
MATLAB and Simulink from PC-compatible imaging hardware. Image Processing
Toolbox software provides a comprehensive set of reference-standard algorithms and
graphical tools for image processing, analysis, visualization, and algorithm development.
You can restore noisy or degraded images, enhance images for improved intelligibility,
extract features, analyze shapes and textures, and register two images. Image Acquisition
& Image Processing Toolboxes were used while developing the Target Tracking
Algorithms using MATLAB.

2.4.3: A Comparison of OpenCV & Image Processing Toolbox:
Image Processing Toolbox works with MATLAB, and we used it for algorithm
development. However, MATLAB is slow, and the developed application is not portable
i.e. it can only run on a system where MATLAB is installed. However, applications
developed in Microsoft Visual Studio, are fast and portable (Pack-and-Go installation).
Therefore, we mainly used MATLAB for algorithm development, and used Visual Studio
for our application development. The following Table shows the comparison between
application developed in MATLAB and Visual Studio using Mean-Shift Tracking
Algorithm and a CCD Camera.







Chapter 2: Literature Review
2010

10



Table 2: A Comparison of Speed between MATLAB & OpenCV Library
MATLAB OpenCV



Frames per Sec: 24.13 Frames per Sec: 48.83
Mean Time per Frame: 0.0414 s Mean Time per Frame: 0.0205 s
Standard Deviation: 0.0054 s Standard Deviation: 0.0025 s


2. 5: Graphical User Interface (GUI):
A Graphical User Interface is necessary for an End-user, allowing him to give full
access to the controls of the system. Our complete application including the Image Processing
Algorithms, and its interaction with the Control Box via Serial Communication was designed
using Microsoft Visual Studio 9 v2008 using the OpenCV Library and Microsoft Foundation
Classes (MFC) with a DHTML (Dynamic Hyper-Text mark-up Language) Dialog support.
The use of DHTML Dialogs was made, because interactive and dynamic Graphical user
Interfaces can be designed using the CDHTMLDialog Classes. Image Acquisition is the pre-
requisite step for the any Image Processing Operation. Figure 2 shows our Graphical User
Interface.

Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

11



Figure 7 : Graphical User Interface for SMARTrax

Our GUI consists of the following:
1) Control Icons: A Set of Buttons, allowing a user to zoom, start or stop the system,
add RFID Record, manually select a target etc.
2) Target Selection: Along with the automatic selection of target, the application also
allows manual selection of target using the panel on the left side.
3) Tracking Area: The Centre portion shows the Real-time tracking video, of an
autonomously selected or manually selected target.
4) RFID Database: The Right Side contains the RFID Database of authorized users.
5) Information Panel: The Bottom layer shows miscellaneous information related to
Color Histograms, Frame Rate, Model etc.
6) Status Panel: On the center bottom a status panel is created. This panel shows the
status of the hardware in the electronics control box.
7) Histogram Panel: Just besides the status panel a histogram panel is added which
shows the color histogram of the targeting area.
Chapter 2: Literature Review
2010

12


8) Velocity Profile: A velocity profile is added which shows the velocity of the target
if it moves.
9) RFID Detail: Below the RFID database a small panel is added to show the details
corresponding to a RFID code eg picture, contact details etc.
2.6: Authorization of Target:
We needed a way to check whether the incoming entity is authorized or not. Several
technologies were available for this, including the Bar-Code Identification, Radio Frequency
Identification, and some advanced techniques like Retina Scans, Finger Print Identification
etc. We opted for Radio Frequency Identification, keeping in mind the project cost and the
range provided by RFID Technology.

2.7: AVR Microcontroller & Communication Protocols:
We had two choices of microcontrollers for our project: AVR ATMEGA Series and
PIC18F Series. Both these microcontrollers fulfilled our requirements of PWM Channels and
ADC Channels. We opted for AVR ATMEGA Series, because of its low cost.

2.7.1: The AVR Microcontroller
The AVR ATMEGA family of microcontrollers are feature rich yet not expensive,
which naturally became our first choice for use in the project. The 8-bit advanced RISC
architecture provided tremendous computing power (for a microcontroller) which enabled
us to implement PIDs on the actuators using Position Feedback from Potentiometers. The
main features which made us choose AVR ATMEGA16 were its high endurance non-
volatile memory, four PWM channels, 8 channel 10 bit ADC and numerous
communication modes (Programmable Serial USART Master/Slave SPI & Serial
Interface, Programmable Watchdog Timer with Separate On-chip Oscillator) etc. We
needed a microcontroller with ADC Channels and an alternative was PIC18F Series. We
opted for AVR because of its low-cost. Some brief details about the chosen
microcontroller are attached as Annexure A.

2.7.2: User Defined Protocols
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

13


The Computer, RFID Module and all the microcontrollers are communicating with
each other for different purposes. To keep every communicator coordinated and to avoid
misunderstandings some sort of order or protocol had to be developed. For this purpose a
custom user defined protocol was defined by us, a copy of which is attached in the
annexure B. A specific range of hex numbers was selected for the protocol where each
hex number represents a specific purpose or code.

2.7.3: Communication Protocols
The Serial Communication Protocols used in this project are RS485 for its long
range (1000m), RS232 for communication with Computer and RFID, and SPI (Serial
Peripheral Interface) for communication between the microcontrollers. The details of all
these Communication Protocols are given in article 5.7.
Chapter 3: Target Tracking using Real-time Digital Image Processing
2010

14


CHAPTER 3 TARGET TRACKING USING REAL-TIME DIGITAL
IMAGE PROCESSING

Real-time object tracking as a key technique in computer vision study has many
potential applications in the field of intelligent robot navigation, monitoring and surveillance,
human computer interfaces, smart rooms, vehicle tracking, Biomedical image analysis, Video
compression & Precise strike. Numerous algorithms have been proposed to track moving
objects in image sequences, such as the Kalman filter, the extended Kalman filter, the particle
filter, Algorithms based on Background Subtraction, Adaptive centroid tracking algorithm,
correlation tracking algorithm and matching tracking algorithm.
We used four different methods for object tracking and came up with some novel
ideas in these Target Tracking Techniques, and identified the pros and cons of each method.
We started our work with background extraction using Connected Component Labeling
Algorithm. It was slow but accurate, and marked the exact boundary of the object which was
NOT the primary requirement of our Project. Later we moved on to the segmented correlation
method which was both fast and accurate but it was prone to inherent uncertainty since it
assumed a constant background which was quite unrealistic assumption. Moreover, both of
these methods worked for a Static Camera, and our requirement was Tracking Algorithm
applicable to a movable Camera. Lucas Kanade algorithm was then adopted just for a study
point of view, it proved to be good for tracking rigid objects but since our targets were mostly
humans therefore we required an algorithm that tracked non-rigid objects. This led us to study
the mean shift algorithm which was first presented in 1975 by Fukunaga. Later a color based
mean shift tracking algorithm was proposed by Bradski. Commaniciu followed up and
proposed the first moving object tracking algorithm based on mean shift. The traditional mean
shift algorithm proposed by Commaniciu was a good tracking algorithm and was able to track
objects at a low computational cost providing real time tracking.
The following Tracking Algorithms were used:
1. Connected Component Labeling Algorithm.
2. Segmented-Correlation tracking Algorithm.
3. Lucas-Kanade Optical Flow Algorithm.
4. Mean-Shift Tracking Algorithm for Image Sequences.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

15


3.1: Connected-Component Labeling Algorithm:
This method makes use of conventional Image Processing Operations to mark the
boundary of the object. This method is slow, but under various circumstances, it marks the
exact boundary of the Object.
The method involves the following steps:
1. Gray-Scale Reference Image & Gray-Scale Image to be operated.
2. Taking the Difference Image.
3. Apply the Median Filter.
4. Thresholding.
5. Noise Elimination.
6. Marking the Boundary
At the Startup, a reference image is taken, and then the Difference Image is taken
repeatedly. If the number of pixels in which the change of intensity is observed, exceeds a
certain threshold, we continue to process the Image, else we take the next snapshot and repeat
the process. The reference Image is updated after a fixed interval of time say one hour just to
ensure that the effect of lights is minimized.

3.1.1: Difference Image:
Images are converted to Gray-Scale before processing. If I1 is the reference Image
and I2 is the image to be processed than the Difference Image I3 is given by the absolute
Image Subtraction of the intensities of the corresponding pixels.






3.1.2: Median Filter:
Applying the Median Filter reduces the overall gray-level of the noisy images but
the number of noise-pixels increases. The importance of this step is discussed later.
Chapter 3: Target Tracking using Real-time Digital Image Processing
2010

16



Figure 8: Effect of a Median Filter

3.1.3: Thresholding:
In Thresholding, we convert a gray-level image to a binary image. The pixels
above a certain Threshold are assigned a value 1 and those below the threshold are
assigned a value of 0. The computation of the threshold value is an important calculation
and this value of threshold varies with the overall image intensity. So the value of
threshold will vary depending upon the lightening conditions.
3.1.4: Distinguishing Features:
Our first distinguishing feature is that we compute a global threshold level that is a
normalized intensity value that lies in the range (0-255). We use Otsus method to find the
Threshold to minimize the interclass variance of the black and white pixels. With this we
also get an effectiveness metric ranging from 0 to 1 which indicates the effectiveness of
the thresholding process. By trial and error, it was observed that for effectiveness metric =
0.8 and above, good results were obtained. If during this process, we get a value lower
than 0.8, than we increase or decrease our threshold, and re-compute the effectiveness
metric. We repeat the iterations until we get a threshold for which our effectiveness metric
increases a value of 0.8.
The second distinguishing feature is that we apply a Median Filter before the
thresholding process. However, in most Digital Image Processing Techniques, the
difference Image is immediately thresholded. The advantage of this step is explained
below:
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

17


The noise is usually distributed in such a way that it occupies large intensity
values close to those of the object, and normally occupies a small number of pixels. If we
set a Threshold, say, x, than the noise will also be considered as an object in the
obtained binary image. To resolve this problem, we apply a median Filter, which reduces
the overall intensity of the noisy pixels, but the number of noisy pixels increases. Now we
have a noticeable difference, between the intensity of the Noisy Pixels and the Intensity of
the Object Pixels. Now we set a Threshold, which will have an intermediate value
between the two intensities.


Fig 9: Histograms before and after applying the Median Filter.

We can deduce this result from the Image Histograms. Before applying the
Median Filter, only 15,000 pixels were in the extreme dark range, whereas after applying
Median Filter, the number of pixels in the extreme dark range increases to 18,000.
3.1.5: Noise Elimination:
Since we applied the median filter before the thresholding process, we are left with
very low noise. To remove this noise, any object which contained less than the specified
number of pixels connected by the definition of N8 neighbours are eliminated.
3.1.6: Marking the Boundary:
Now we are left with a binary image, where 1 denotes an object and a 0
denotes the background. By scanning the image from left-to-right and from top-to-bottom,
we use Connected Component Labeling Algorithm to mark the pixels where a transition
from a 1 to 0 or a transition from 0 to 1 is observed. This way we get the boundary
of the object.
Chapter 3: Target Tracking using Real-time Digital Image Processing
2010

18


3.2: Segmented Correlation Tracking Algorithm:
The second method makes use of the Normalized Correlation Coefficient. The
Normalized Correlation Coefficient of two Images A & B is defined as:

The basic phenomenon is that, for two similar images, the value of the Correlation
Coefficient is equal to 1. In case of different images, this value is less than 1. We know that
the same image captured by a camera at two different intervals doesnt yield the same result.
There are minor fluctuations in the intensity values depending on the lightening conditions.
Therefore the Correlation Coefficient of the same image captured at two different intervals is
not 1. However, a Normalized Correlation Coefficient in the range 0.9<r1 is a reasonable
assumption; it represents the same image, keeping in mind the lightening issue.
Just like the first method, we capture a Background Image, which is updated after
regular intervals of time to minimize the effect of lightening. As soon as the new image is
captured, we split both the images into equal number of vertical segments. The Correlation
Coefficient of each vertical segment is computed with the corresponding segment of the
Background Image. If we dont get a value less than 0.9 for any of the segment, than we
assume that no object is detected. If one or more segments contain a value less than 0.9, than
we compute the mean of all the correlation values, and all those segments where the value of
correlation coefficient is less than mean are assumed to contain the object. The Required
Vertical Segments are than added, to compute the absolute Vertical Coordinates of the
Object.
Once we know the location of the Vertical Segments in which the object is located, we
further split those verticals segments in the horizontal direction and compute the correlation
coefficient and then the mean. All those horizontal Segments where the Correlation
Coefficient is less than the Mean, we assume that the Object is located in those Horizontal
Segments.

Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

19


3.2.1: Distinguishing Features:
The first distinguishing feature is that in most of the Correlation Tracking
Algorithms, Image is segmented in horizontal and vertical directions which take
considerable amount of time to process the Image. For Instance, if we split the image in
20 Vertical and 20 Horizontal segments, we need to compute 400 Correlation
Coefficients. However in our case we only compute 40 Correlation Coefficients.
The Table 2 shows the result. First Figure shows the progress when image is
processed by segmenting in equal horizontal & vertical strips and second figure shows the
result of our approach. In the first case, effective Frame rate is 17.2 and in the second case
it is 25.3. These results are from MATLAB.
The second distinguishing feature is that for the second time we dont start the
procedure the way it was done for the first time. Once we identify that object is in a
specified vertical segment, we start observing the object in the adjacent segments. This
saves computational time.

Table 3: A Comparison between the two Approaches of Segmentation
CONVENTIONAL APPROACH OUR APPROACH




Frames per Sec: 17.155 Frames per Sec: 25.294
Mean Time per Frame: 0.0583 s Mean Time per Frame: 0.0395 s
Standard Deviation: 0.0192 s Standard Deviation: 0.0095 s


Chapter 3: Target Tracking using Real-time Digital Image Processing
2010

20


3.2.2: Differences between two methods of Static Camera Tracking:
Table 4 shows the comparison between the two Methods of Static Camera
Tracking, as processed by MATLAB.

Table 4: A Comparison between the two Approaches OF Static Camera Tracking
METHOD 1 METHOD 2





Frames per Sec: 12.6422 Frames per Sec: 25.294
Mean Time per Frame: 0.0791 s Mean Time per Frame: 0.0395 s s
Standard Deviation: 0.0344 s Standard Deviation: 0.0095 s
Advantages:
1) Marks the exact boundary of the Objects, but
this is not the exact requirement of our project.
Disadvantages:
1) Slow Method (12.6 FPS)
Works only when there is a noticeable difference
between the objects color and the backgrounds color.
Advantages:
1) Marks a bounding Box for objects, which can be
used to point the weapon to the target.
2) Pretty fast (25.3 FPS) in Matlab and 52 FPS in
Visual C++ using OpenCV Library.
Disadvantages:
It cannot tag the identity of the object. Method# 3 and
Method#4 solves this problem.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

21


3.3: Lucas-Kanade Optical Flow Algorithm:
The Lucas-Kanade algorithm was proposed in 1981 and since then has evolved a great
deal. It is effectively used for image alignment, mosaic-ing, optical flow, layered tracking etc.
It is basically derived from the sum squared difference error that is computed between two
image patches of the same size.
[ ]


It is this equation that formed the basis of the Lucas Kanade algorithm. This equation is
expanded according to the second order Taylor series expression. First order Taylor series
function is as follows.


The second order Taylor series function takes the form.

]
Only the first order terms are taken.


Applying the same to equation [] results in.
[ ]


Taking partial derivates of equation [] and setting them to zero.


Chapter 3: Target Tracking using Real-time Digital Image Processing
2010

22


Rearranging the equations and form a matrix form results in.
[

] [

] [

]
This equation is solved by the method of least squares.










Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

23


CHAPTER 4 MEAN-SHIFT TRACKING ALGORITHM

The mean shift algorithm is basically a non parametric statistical method. It was
derived from the Parzen window estimation method and the second order Taylor series
expansion of the Bhattacharyya coefficient. The parzen window estimation technique uses a
kernel to estimate the density of a set of data samples. By convoluting the kernel at all the
data points a density estimate is obtained. This is also called kernel density estimation (KDE).
The following equation denotes the parzen window estimation.


In this equation n denotes the number of data points that are being sampled by the
kernel K. P(x) denotes the estimated probability density of those set of data points. The kernel
K must have the following properties:
i. Normalized


ii. Symmetric



iii. Should have exponential weight decay


Estimating the density is done by this kernel density estimation technique but we need a way
of finding the modes in the set of data samples. Thus instead of the kernel density estimation
we use the gradient of kernel density estimate. This provides us a way of climbing up a
contour and finding the modes. Thus the equation that follows is as under.


For this we use the kernel of the form.
Chapter 4: Mean Shift Tracking Algorithm
2010

24


)
Where k another KDE and h is the bandwidth. The final form that results is.

] [


The kernel g is simply.


4.1: Object Model Histogram:
We used quantized color space as the objects representation feature. A weighted color
histogram is formed from the parzen window estimation technique with the difference that in
this probability distribution the set of data points, that are the images pixels are located at
uniform spatial distance so original parzen window estimation has a meaningless probability
estimate. Thus to estimate a suitable density for these pixels a corresponding weight is
assigned to each pixel which corresponds to the intensity of the pixel and its distance from the
centre pixel when convoluted with the mean shift kernel. Thus the objects model histogram is
formed from the following equation.

]
Where u = 1, 2m. m is the number of quantized binary levels chosen for the color space. C
is the normalization constant,

is the color binary index of pixel

, where i = 1, 2 . n.
is the kronecker delta function. (0) = 1and for all the other values of a other
than 0.

is the initial position where the kernel K is centered. It is normally taken as zero.
is the bandwidth matrix.
4.2: Object Candidates Histogram:
After the object models histogram has been calculated, an initial estimate of the
targets location

is given over which the kernel K is convoluted according to the parzen


Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

25


window estimation technique and the candidates histogram is computed by the following
equation.

]
Here again

is the normalization constant. It should be noted that both the probability


distributions are normalized i.e.

and

.
4.3: Measure of Similarity:
Commaniciu used the Bhattacharyya coefficient as the measure of absolute similarity
between two histograms. The Bhattacharyya coefficient produces a scalar value denoting the
amount of match between two probability distributions resulting in a larger value for a better
match. Thus the goal is to maximize its value in the vicinity of the region of interest. The
expression is as follows.


This expression is expanded according to the second order Taylor series which results in the
expression.


The term

in the above equation is called the weight term. It is expressed as.

]

The first term in equation [ ] does not depend upon y so only the second term in equation [ ]
has to be maximized. Thus the mode of the second term is found by the mean shift iterations.
The expression that results is as follows.

Chapter 4: Mean Shift Tracking Algorithm
2010

26


In the equation above (

) is another kernel and is related to the kernel k by the


expression.


This justifies why the kernel k had to be differentiable. From expression [ ] a new value of

is obtained. The previous value of y is updated by this new value and the iterations are
continued until either one or both of the following conditions are satisfied.


4.4: Selection of the Kernel:
The selection of the right kernel is an important task in the result of the mean shift
algorithm since computational cost, accuracy and complexity of the algorithm depends
somewhat on the selection of the kernel itself. Following are the three kernels that are
generally used.
4.4.1: The Epanechnikov Kernel:
The epanechnikov kernel is a
symmetric, differentiable normalized
kernel and is represented by the
following equation.

{




Fig 10: The Epanechnikov Kernal.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

27



It can be seen that the data points at the centre of the kernel are given the
maximum weight age while the distant data points are given minor weight age. The
periphery pixels are given 0 weight age. The main idea is to give higher weight age to the
objects pixels while the pixels at the kernels edges are normally the background pixel so a
lower weight age is given to them. Epanechnikov kernel minimizes the AMISE
(asymptotic mean integrated squared error) and therefore an optimum solution. The
efficiency of this kernel is one and the efficiency of all the other kernels is compared to
the epanechnikov kernel.
4.4.2: The Gaussian Kernel:
The Gaussian kernel is a normalized kernel represented by the following equation:
{





Fig 11: The Gaussian Kernel.
As can viewed from the equation the image pixel that fall inside the kernel are
given an exponential weight age with the maximum weight at the centre. This provides a
more preference to the objects pixels and reducing the effect of the background pixels.
4.4.3: The Flat Kernel:
The flat kernel is represented by the following equation. This assigns equal
weights to all the pixels inside the kernel window.
{



Chapter 5: Embedded Electronics System for the Control
2010

28


CHAPTER 5 EMBEDDED ELECTRONICS SYSTEM FOR THE
CONTROL

5.1: Overview:
A handsome amount of electronics is involved in this project which includes an
independent power supply, H-bridges, Microcontrollers, Gamepad, ISP Burner and Serial
communication modules etc all of which have to coordinate with each other without any error
to ensure successful operation of SMARTRAX. To achieve successful operation we designed
an embedded system that could be used in readymade product form or in other words plug
and play. An acrylic box was made to adjust all the electronics and to give it a product form.
At the side of the box a small panel was made to accommodate all incoming and outgoing
signals, and on the front side of the box numerous buttons are attached for secondary manual
control. Given below is chart of the electronics of the embedded system:

Fig 12 Flowchart OF Embedded Electronics system.


Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

29



Figure 13 The Electronics Control Box
5.2: Power Supply Unit:
A handsome amount of electronics is involved in this project which includes an
independent an independent power supply unit was developed for SMARTRAX, the input
being the standard 60Hz AC from any wall socket. The power supply unit consists of two step
down transformers, the reason we used two transformers was to keep the logic and motor
drives isolated from each other. After step down the voltage is fed into bridge rectifiers which
create a DC signal with ripples. To cater the ripples filtering capacitors were used which
resulted in a smooth DC voltage, separate for logic and motor drives. Given below is an
outline of the power supply unit integrated in the embedded system.

Fig 14: Block Diagram of Power Supply Unit.

220VAC
60Hz
220VAC
60Hz
Transformer,
Stepdown to 16VAC
for motor drives
Transformer,
Stepdown to 20VAC
for Logic
Bridge Rectifiers
Bridge Rectifiers
Filtering Capacitors to
remove ripples.
Output 20VDC
Filtering Capacitors
to remove ripples.
Output 28VDC
Chapter 5: Embedded Electronics System for the Control
2010

30


5.3: AC / DC Motor Drives:
The control signals for the DC motors come from AVR 1 into the optocouplers and
from the optocouplers to the H-Bridges and then finally into the respective motors. The h
bridges used are LMD 18201. The control signals for the AC motors also generate from AVR
1, they go into the optocouplers then into relays and then to the AC motors. The control
signals for the motors are namely brake, direction & PWM.







Fig 15: Block Diagram of AC / DC Drives.
5.4: Ground Isolation:
Large current spikes are sometimes generated in the power supply unit, such
unexpected current spikes cause anomalies in logical operations. To avoid all this we have to
separate the logics voltage and the motor drive voltage, thats why we used two transformers
in the power supply unit to generate separate voltages for the logic and motor drive circuits,
and secondly we used optocouplers between control signals of motors and the drive voltage of
the motors.
5.5: Logic Circuitry & Manual Control:
The logical circuitry consists of three AVR ATMEGA16 and one ATMEGA168
micro controllers. AVR1 is used for communication with PC and SPI with AVR2,
additionally its the only micro controller responsible for driving all the motors and
implementing PID on them. AVR 2 controls two LCDs used for displaying data and
Optocoupl
ers
Optocoupl
ers
H-Bridge,
LMD
1829
Relays
DC Motors
Gun pan, tilt &
Trigger
AC Motors
Camera pan &
tilt
Signal
Signal
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

31


receiving the data sent from the RFID end. A gamepad is also interfaced using AVR 3 for
manual control of the gun & camera as well.
5.6: RFID Control Unit
The RFID module used in SMARTrax is a system 3000 model purchased from a local
vendor CNS (Computer Networking & Systems). Whenever a card is brought into the vicinity
of the reader, it reads data from it and sends it to AVR 4 via RS 232 at 9600bps. AVR 4 then
extracts the relevant data and sends it to AVR 2 via RS 485. AVR 2 communicates the newly
received data to AVR 1 via SPI. The AVR 1 sends it to the control PC where it is processed
upon to check the authenticity of the user. Given below is block diagram of this process;




Fig 16:RFID Control Unit.

5.7: Communication Standards
Numerous communication standards have been adopted in this project. Since the PC
has a serial port which communicates using RS 232 standard, AVR 1 communicates with the
PC via RS 232. SPI (serial peripheral interface) is a high speed communication mode for
micro controllers, AVR 1 and AVR 2 communicate with each other via SPI. RS 485 is an
enhanced version of serial communication with the advantage of communication over long
distances (up to 1000meters), AVR 4 and AVR 2 communicate with each other using RS 485.
The RFID module which we utilized in this project communicates using RS 232, hence RS
232 is implemented between the RFID module and AVR 4. AVR 3 which is used for
interfacing the gamepad communicates with AVR 1 using RS 232 standards.


RFID
Module
AVR 4 AVR 2 AVR 1 Control
PC
RS 232 RS 485 SPI RS 232
Chapter 6: Control System Design
2010

32


CHAPTER 6 CONTROL SYSTEM DESIGN

The equipment that consisted of the two pan tilts had to be controlled. Since both the
pan tilts had separate movement thus two separate control systems had to be designed. The
problem at hand was the accurate and efficient following of the target by the guns pan tilt.
The guns aim was supposed to lock on the target. This was being handled in a two way
indirect process.

Fig 17: The Control Loop.
Thus there was no direct connection between the guns pan tilt and the camera. Only an
indirect connection existed via cameras input and dip algorithms targets coordinates
estimation. This called for a more complex control system since it formed a non linear
system.
6.1: Pan-Tilt Control System for the Gun:
The guns movement can be denoted by a vector field that denoted the destination of
the guns nozzle. This vector field shown the path to be followed and the magnitude of the
acceleration followed by the velocity required to reach its apex or maximum. The vector field
forms a surface that looks like a hill. The required position that is always the tip of the hill can
be mathematically achieved by the gradient of the vector field.



SCALING OF THESE
COORDINATES
THEN FOLLOWING
THEM BY THE GUNS
PAN-TILT
FEEDBACK
TARGET TRACKING
AND COORDINATES
ESTIMATION BY THE
CAMERA
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

33


This shows the two dimensional nature of the vector field. The vector field is shown
below.


Fig 18: The Vector Feild.
The length of the arrows is proportional to the magnitude of the pan tilts input. The
gradient of this vector field is shown below.

Fig 19: The Gradient of the Vector Feild.
6.2: Proportional-Integral-Derivative Control:
The selection of the right control system was of great importance in view of the
problems presented above. The PID control system was finally chosen for the guns pan tilt. A
proportionalintegralderivative controller (PID controller) is a generic control loop feedback
mechanism (controller) widely used in industrial control systems a PID is the most
commonly used feedback controller. A PID controller calculates an "error" value as the
difference between a measured process variable and a desired set point. The controller
attempts to minimize the error by adjusting the process control inputs. In the absence of
knowledge of the underlying process, a PID controller is the optimal controller. However, for
Chapter 6: Control System Design
2010

34


best performance, the PID parameters used in the calculation must be tuned according to the
nature of the system while the design is generic, the parameters depend on the specific
system.

Fig 20: The PID Control Loop.
6.3: PID Parameters:
The PID controller calculation (algorithm) involves three separate parameters, and is
accordingly sometimes called three-term control: the proportional, the integral and derivative
values, denoted P, I, and D. The proportional value determines the reaction to the current
error, the integral value determines the reaction based on the sum of recent errors, and the
derivative value determines the reaction based on the rate at which the error has been
changing. The weighted sum of these three actions is used to adjust the guns position control
element. Heuristically, these values can be interpreted in terms of time: P depends on the
present error, I on the accumulation of past errors, and D is a prediction of future errors, based
on current rate of change.
By tuning the three constants in the PID controller algorithm, the controller provides
control action designed for the guns accurate target locking. The response of the controller
can be described in terms of the responsiveness of the controller to an error, the degree to
which the controller overshoots the set point and the degree of system oscillation.
6.3.1: The Proportional Error:
The proportional term (sometimes called gain) makes a change to the output that is
proportional to the current error value. The proportional response can be adjusted by
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

35


multiplying the error by a constant K
p
, called the proportional gain. The proportional term
is given by:


Where

denotes the proportional output generated in time,

is the
proportional constant and is the percentage error. This error is equal the percentage
difference between the required output to the current output.
A high proportional gain results in a large change in the output for a given change
in the error. If the proportional gain is too high, the system can become unstable. In
contrast, a small gain results in a small output response to a large input error, and a less
responsive (or sensitive) controller. If the proportional gain is too low, the control action
may be too small when responding to system disturbances.

Fig 21: The Effect of Proportional Constant.
6.3.2: The Integral Error:
The contribution from the integral term is proportional to both the magnitude of
the error and the duration of the error. Summing the instantaneous error over time
(integrating the error) gives the accumulated offset that should have been corrected
previously. The accumulated error is then multiplied by the integral gain and added to the
controller output. The magnitude of the contribution of the integral term to the overall
control action is determined by the integral gain, K
i
. The integral term is given by.
Chapter 6: Control System Design
2010

36


Where

denotes the integral output generated in time,

is the integral
constant and is the percentage error. The integral term (when added to the
proportional term) accelerates the movement of the process towards set point and
eliminates the residual steady-state error that occurs with a proportional only controller.
However, since the integral term is responding to accumulated errors from the past, it can
cause the present value to overshoot the set point value (cross over the set point and then
create a deviation in the other direction).

Fig 22: The Effect of Integral Constant.
6.3.3: The Derivative Error:
The rate of change of the process error is calculated by determining the slope of
the error over time and multiplying this rate of change by the derivative gain K
d
. The
magnitude of the contribution of the derivative term to the overall control action is termed
the derivative gain, K
d
. The derivate term is given by.


The derivative term slows the rate of change of the controller output and this effect
is most noticeable close to the controller set point. Hence, derivative control is used to
reduce the magnitude of the overshoot produced by the integral component and improve
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

37


the combined controller-process stability. However, differentiation of a signal amplifies
noise and thus this term in the controller is highly sensitive to noise in the error term, and
can cause a process to become unstable if the noise and the derivative gain are sufficiently
large. Hence an approximation to a differentiator with a limited bandwidth is more
commonly used. Such a circuit is known as a Phase-Lead compensator.

Fig 23: The Effect of Derivative Constant.
6.3.4: Summary:
The proportional, integral, and derivative terms are summed to calculate the output
of the PID controller. Defining u(t) as the controller output, the final form of the PID
algorithm is:





Chapter 7: Radio Frequency Identification
2010

38


CHAPTER 7 RADIO FREQUENCY IDENTIFICATION

7.1: Introduction to RFID:
RFID, short for Radio Frequency Identification, is a technology that enables
identification of a tag (that is normally attached with an entity) by using electromagnetic
waves. The function served by RFID is similar to bar code identification, but line of sight
signals are not required for operation of RFID. Important components of an RFID system are:
1) An RFID reader (also called transceiver) with an antenna and a transceiver,
2) A transponder (Also called a tag) that includes an antenna and a chip)
7.2: Why we chose RFID:
We choose RFID over the many of the technologies in use today because of several
reasons; the user doesnt has to particularly swipe the card or make any log entry of some
sort, the RFID automatically takes care of that. One of the main reasons we chose RFID was
because of cheap maintenance & implementation cost, convenience for people, time saving,
to save operating costs (i.e. no requirements for hiring of staff just to keep log of entry &
exit). Thirdly RFID is being inoculated into our daily lives in many different ways (use of
RFID in stores, inventory of products, livestock, e-passports etc), by choosing RFID we are
giving SMARTrax the ability to integrate in new environments and most importantly future
proofing for longer life of the product.
7.3: Comparison of RFID with Bar-Code Technology:

Table 5: A Comparison between RFID & Bar-Code Technology
Parameter Bar Code RFID
Frequencies used
for tag reading
Optical frequencies Radio frequencies
Type of
communication
Line of sight communication Non-line of sight communication
Data Volume Physical limitation exists. It is
very difficult to read a very long
barcode.
Can carry relatively large volume
of data.
Range of data
readability
Very limited range, less than a
feet or two.
Can be read up to several feet.
Cost Cheap Expensive, but likely to cost less
as more industries adopt the
technology.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

39



7.4: Active and Passive RFID Tags:
There are primarily two types of RFID tags. One is active and the other is passive. An
active tag is powered using internal battery, where a passive tag gets energized using the
power from a tag reader. A passive RFID tag will not have a battery or any kind of power
source by itself. It extracts the required energy from a reader. Hence, a passive RFID tag
reader must be able to emit stronger electromagnetic signals, and in return, identify very weak
signals from the passive RFID tag.
Given below are the primary differences between a Passive and Active RFID tags:

Table 6: Primary Differences between Passive and Active Tags
Parameter Passive Tags Active Tags

Power Source External (Reader provided) Internal (Battery)

Tag Readability
Only within the area covered by the reader,
typically up to 3 meters.
Can provide signals over an extended
range, typically up to 100 meters..

Energization
A passive tag is energized only when there is a
reader present.
An active tag is always energized.

Magnetic Field Strength
High, since the tag draws power from the
electromagnetic field provided by the reader.
Low, since the tag emits signals
using internal battery source.

Shelf Life
Very high, ideally does not expire over a life
time.
Limited to about 5 years, the life of a
battery.

Data storage Limited data storage, typically 128 bytes. Can store larger amounts of data.

Cost Cheap Expensive

Size Smaller Slightly bulky (due to battery)

7.5: RFID Frequencies:
There are several frequencies that are used for RFID. These include LF, HF, UHF, and
Microwave frequencies. The exact frequencies may vary depending on the country where it is
used.

Table 7: RFID Frequencies
Frequency Description Typical Applications

<135KHz Low Frequency, Inductive coupling
Access Control & Security
Widgets identification through manufacturing
processes
Chapter 7: Radio Frequency Identification
2010

40


Ranch animal identification
OEM applications

13.56 MHz High Frequency, Inductive coupling
Access Control
Library books
Laundry identification
OEM applications
868 to 870 MHz
902 to 928 MHz
Ultra High Frequencies (UHF),
Backscatter coupling
Supply chain tracking

2.400 to 2.483 GHz SHF, Backscatter coupling
Asset tracking
Highway toll tags
Vehicle tracking

7.6: RFID Building Blocks:
Tags:
A tag is the data carrier and normally contains the ID number, and unique EPC code
programmed into the Tag.
Tag Antenna:
The tag antenna is connected to the chip in tag. It could be wire or printed using conductive
ink.
Reader Antenna:
It is a coil included in plastic or similar case, and normally measures 12 -18 inches square
Reader:
A reader captures the data provided by the tag within the detectable area of the Reader. There
can be one or more tags within the capture area. A reader is typically capable of reading
multiple tags simultaneously.
Savant:
This is normally a middleware that interacts with the readers, and communicate with
External database
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

41


CHAPTER 8 MECHANICAL DESIGN OF PAN-TILT FOR GUN
8.1: Introduction:
The basic concept of a pan tilt mechanism is to design a mechanism that has two degrees
of freedom. Both are rotation one along the x-axis, giving the pan motion and the other is
along the y-axis giving it the tilt motion. To make SMARTrax both efficient and cost
effective the main task in mechanical area was to come up with a light weight yet strong pan
tilt for mounting the gun. Since there arent many commercial pan tilt designs for gun
mounting available we had to study the commercially available pan tilt mechanism for
cameras. After going through a number of Pan Tilt Camera Mount designs that are
commercially available, the conclusion drawn was to rethink the whole mechanism to cater
for two main tasks light weight and strength. The pan tilt mechanism for the gun mounting
was designed in Pro E Wildfire 4.0.

8.2 : Commercial Availability:
There are many sorts of pan tilt mechanisms commercially available but there are a few
draw backs. Some of them are:
1. They are fitted with AC motors.
2. It is hard to control.
3. Speed is normally very slow.
4. They are unable to handle large amount of weight.
5. Fitting for the gun is not available.
8.3 : Camera Pan Tilt:
For the camera high speed and agile motion was not required. Since limited pan and tilt
motion gives us a wide enough field of view. So to keep SMARTrax cost effective it was
decided to purchase a commercially available pan tilt. The purchased pan tilt has the
following specifications,
1. Its fitted with AC motors.
2. The speed of pan motion is 2 degrees per second.
3. The speed of tilt motion is 4 degrees per second.
4. Camera fitting assembly was already present so no modifications were required.
Chapter 8 Pan Tilt for Gun
2010

42


8.4 : Gun Pan Tilt:
For the gun mechanism the basic requirements were;
1. A low weight assembly that can undergo swift & agile motion.
2. The weight of the gun was assumed to be 7Kg. so the pan-tilt capable of handling
that much weight and maintaining the agility was required
Since pan tilt mechanisms are generally not available in the market, at least not at cheap
rates. So we decided to design and build one ourselves.
8.5 : The Design
It was a top priority to make the mechanism as light weight, stable and as fast as possible and
also keeping it under control at all times. The software used to design the mechanical
assembly was ProE, which is the top end software as far as the mechanical designing is
concerned. A stress analysis was also performed on the mechanism to evaluate the strength of
the mechanism at critical points and to reduce the chances of failure. Two designs were made
and finally one was selected after serious consideration.
8.5.1: Design 1
The first design as shown in the figure was very simple and was capable of serving our
purpose well but it had one very big disadvantage it made the size of the entire assembly
large. Since we were interested in using the water gun as a test weapon and it had a water tank
attached with the gun so it was important to keep the size under control. Also the connecting
shaft was not strong enough to hold large amounts of weight. In order to counter these issues
we moved to a second design.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

43



Figure 24. First Design
8.5.2: Design 2
In the second design these problems were resolved by tackling the problem with a completely
different approach instead of keeping the bottle attached with the gun at all the times it was
decided to use the disc as a base to support the bottle it has two advantages one is that it
reduced the weight of the disc also it provided sufficient space for the gun while keeping the
mechanism small. Finally the pressure on the gun increased due to gravity giving water gun a
flat range of above 6m.

Figure 25. Second Design
Chapter 8 Pan Tilt for Gun
2010

44



Figure 26 The Fabricated Pan Tilt for Gun
8.6: Position control & Gear Ratio
One of the most important parts of the project was to control the direction of the gun. In order
to achieve the position control of the assembly potentiometers were employed with the shift
of both the pan and tilt part. The gear ratio for the pan part was maintained to 8:1 and for the
tilt it was 1:2. We added some potentiometers in the gun pan tilt mechanism for feedback
purposes. Adding a gear train provided us with a reasonable reading from the potentiometers
upon any change.
8.7: Motors
The motors selection was a crucial part of the assembly design. We required the motors small
in size yet powerful enough to carry the weight of the gun with it. It was decided to use the
motor D23232343. For the pan part which was strong enough to provide us with the torque of
0.8Nm. for the tilt part we have used the motors L34kjfdk which provides us with 1.8Nm of
torque, sufficient enough to lift the load of 7Kgs.


Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

45


8.8: Stress Analysis
Stress analysis was performed on the crucial parts of the mechanism first of all there were two
assumptions
Conditions:
No external Forces on complete assembly
Only its weight acting in downward direction
The entire assembly was constrained and it was supposed that no external force except the
stress was being applied on the assembly.

2010

46


Operating Instructions:
Operating instructions for SMARTrax are given below;
1) There is no need for any special power supply, a simple output from a standard wall
socket 220VAC 60Hz will suffice.
2) Currently SMARTrax is effective for a range of 20 meters. For optimum performance
SMARTrax should be installed at places with a relatively narrow or small entrance.
3) Shocks of any kind should be avoided to SMARTrax as it may interfere with the input
from the camera. Sudden changes or jerky image input can affect the digital image
processing at the computer end.
4) The range for the RFID reader to detect cards is small. The user has to bring the card
in proximity of about 4 inches in any direction around the RFID reader.
5) In free video mode the operator has to manually select the target using the control
panel in GUI otherwise the system wont track the target in manual mode. Once a
target is selected in free video running mode it will be tracked via Mean Shift
Tracking Mode.
6) When operating the manual target tracking the buttons on the gamepad have been
designated different tasks. The Start button initiates the manual tracking mode. The
analog button shifts the control to the two analog sticks present on the gamepad. The
turbo button increases the speed of the motors on the pan tilt mechanisms. The Select
button terminates the manual tracking mode and the system moves back into one of
the automatic modes.
7) In Segmented Correlation Tracking Mode the system first analyses the background
environment and then tracks any target depending upon the change in environment
compared with the initial environment analyzed. This mode is effective for narrow
entrance places and where there is no movement of the camera.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

47


Results:
1) All the objectives proposed upon undertaking this project have been achieved
successfully.
2) SMARTrax comprises of different fields which gave us the chance of research work
as well as implementing the research done.
3) During the development of SMARTrax we developed and implemented four different
algorithms for image processing for tracking the target.
4) This project made us realize the necessity & advantages of embedded systems in
engineering applications. We tried our best to produce a professional level product out
of SMARTrax in which we have succeeded.
5) SMARTrax was designed keeping portability in mind thats why we have tried our
best to make the electronics control box more like a plug and play device.
6) We had to develop an indigenous protocol for successful communication between the
microcontrollers, RFID reader and the control PC.
7) With the addition of the future work (mentioned in the Future Work section)
SMARTrax will get its final form, a complete professional level product from cradle
to grave.

2010

48


Summary / Conclusion:
The idea of SMARTrax originated during the numerous security related incidents in Pakistan
in 09. For any country securing its borders is a crucial and important task which demands a
lot of time and resources. However with the advancement in technology steps are being taken
towards making such tasks easy, SMARTrax being one of them. SMARTrax can also be
added to unmanned vehicles for reconnaissance & other purposes. This project still holds a lot
of room for further research work & innovation. The low cost of SMARTrax makes it ideal
for utilization in local vicinities which require a higher security level. The low cost,
convenience & versatility of RFID make it a technology which is being inculcated into daily
lives at quite a fast rate. The low cost & user friendliness make SMARTrax an efficient
security product.
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

49


Future Work:
Following are the main areas of future work in this project;
1) Implementation of Stereoscopic vision using two cameras to track target in pan
motion. Stereoscopic vision will be helpful to determine the actual position of the
target using only Digital Image Processing, further more it will also be helpful when
the target moves quite far away from the camera & gun.
2) Design & development of mounting for actual gun on pan tilt with proper mechanical
analysis & calculations keeping gun recoil & ammunition reloading in mind. The
system should be designed in such a way to keep the mechanical vibrations to a
minimum.
References
2010

50


LIST OF SOFTWARES USED:

1) Matlab v2008
a. For the Image Processing Algorithm Development.
2) Microsoft Visual Studio v2008
a. Complete Standalone Application Development using MFC & OpenCV
Library, incorporating all the requirements of the Project such as Graphical
User Interface, Serial Communication, Image Processing and RFID Database.
3) Open Computer Vision Library v2.0
a. OpenCV Library is a Computer Vision Library
4) ProEngineer Wildfire
a. Mechanical Design by Qasim Zia
5) AVR Studio 4
6) WinAVR
7) Proteus v7.6
8) Adobe Photoshop CS4 Extended
a. For the Design of Poster and Graphical User Interface of the Application
9) Pixel View Station
a. Software for Interfacing Camera with the Computer
10) Realterm Serial Capture Program v2.0
11) Novarm DipTrace
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

51


References:
[1] FAST OBJECT TRACKING IN DIGITAL VIDEO, Dong Kwon Park, Ho Seok Yoon, and
Chee Sun Won, Dep. of Electronic Engineering, Dongguk University, Seoul, 100-7 15, KOREA.
cswon@dgu.ac.kr
[2] High Speed and Wide Range Object Tracking System Using Pan-Tilt Cameras and Arm
Robot, Hiroyuki Ukida, Department of Mechanical Engineering, University of Tokushima, Via 21
Minamijosanjima-cho, Tokushima, Japan. ukida@me.tokushima-u.ac.jp
[3] Multi-Strategy Object Tracking in Complex Situation for Video Surveillance,
Ruijiang Luo, Liyuan Li, Weimin Huang, Qibin Sun
Institute for Infocomm Research, 21 Heng Mui Keng Terrace, Singapore
rjluo@i2r.a-star.edu.sg, lyli@i2r.a-star.edu.sg, wmhuang@i2r.a-star.edu.sg, qibin@i2r.a-star.edu.sg
[4] Real-Time Multiple Object Tracking in Smart Environments, Proceedings of the 2008 IEEE
International Conference on Robotics and Biomimetics, Bangkok, Thailand, February 21 - 26, 2009.
Wei You, Dept. of Elec. & Comp. Engineering, University of British Columbia, Vancouver, BC, V6T
1Z4, Canada. weiy@ece.ubc.ca.
Hao Jiang, Department of Computer Science Boston College Chestnut Hill, MA 02467, U.S.A.
hjiang@cs.bc.edu .
Ze-Nian Li, School of Computing Science, Simon Fraser University, Burnaby, BC, V5A 1S6, Canada
li@cs.sfu.ca.

[5] Smart Motion Detection Surveillance System
2009 International Conference on Education Technology and Computer
Li Fang, School of Computer Engineering, Nanyang Technological University, Singapore
Zhang Meng, Dunman High School, Claire Chen Qian Hui, River Valley High School, Singapore

[6] Digital Image ProcessingAn Object-Oriented Approach
IEEE TRANSACTIONS ON EDUCATION, VOL. 41, NO. 4, NOVEMBER 1998
Dan Roman, Mark Fisher, and James Cubillo
References
2010

52


ANNEX A
AVR ATMEGA 16 Specifications:
Features
High Performance, Low Power AVR 8-Bit Microcontroller
Advanced RISC Architecture
131 Powerful Instructions Most Single Clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Up to 20 MIPS Throughput at 20 MHz
On-chip 2-cycle Multiplier
High Endurance Non-volatile Memory segments
4/8/16K Bytes of In-System Self-programmable Flash program memory
256/512/512 Bytes EEPROM
512/1K/1K Bytes Internal SRAM
Write/Erase cyles: 10,000 Flash/100,000 EEPROM
Data retention: 20 years at 85C/100 years at 25C()
Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
Programming Lock for Software Security
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
Real Time Counter with Separate Oscillator
Six PWM Channels
8-channel 10-bit ADC in TQFP and QFN/MLF package
6-channel 10-bit ADC in PDIP Package
Programmable Serial USART
Master/Slave SPI Serial Interface
Byte-oriented 2-wire Serial Interface (Philips I2C compatible)
Programmable Watchdog Timer with Separate On-chip Oscillator
On-chip Analog Comparator
Interrupt and Wake-up on Pin Change
Special Microcontroller Features
DebugWIRE On-Chip Debug System
Power-on Reset and Programmable Brown-out Detection
Internal Calibrated Oscillator
External and Internal Interrupt Sources
Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and Standby
I/O and Packages
23 Programmable I/O Lines
28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
Operating Voltage:
1.8 - 5.5V for ATmega48V/88V/168V
2.7 - 5.5V for ATmega48/88/168
Temperature Range:
-40C to 85C
Speed Grade:
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

53


ATmega48V/88V/168V: 0 - 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V
ATmega48/88/168: 0 - 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 - 5.5V
Low Power Consumption
Active Mode:
250 A at 1 MHz, 1.8V
15 A at 32 kHz, 1.8V (including Oscillator)
Power-down Mode:
0.1A at 1.8V
ATMEGA 16 Pin Configuration:
References
2010

54


ANNEX B
AVR 1 Code

#include<avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>

// ******************************************************************
// ******************************************************************
// ******************************************************************
// **** THIS PIECE OF CODE HAS BEEN DEVELOPED FOR SMARTrax ****
// **** (STRATEGIC MANAGEMENT USING ADVANCE RFID AND TARGET ****
// **** TRACKING) AND IS STANDALONE APPLICATION. IT TRACKS THE ****
// **** TARGETS WHILE IT RECIEVES THEIR COORDINATES SERIALLY. ****
// **** THE COORDINATES ARE ESTIMATED USING DIGITAL IMAGE ****
// **** PROCESSING AT THE COMPUTER END. ****
// ******************************************************************
// ******************************************************************
// ******************************************************************
// ******************************************************************
// ******************************************************************
// ******************************************************************
// ******************************************************************
// ******************** AVR 1 **********************8
// ******************************************************************
// ******************************************************************
// *******DEPENDENCIES ON AVR 2 , AVR 3, AVR 4 , PC *******
// ******************************************************************
// ******************************************************************
// ******************************************************************
// ******************************************************************


// definition of the bits ...

#define GP_PWM PD4 //Gun Pan PWM (OC1B)
#define GT_PWM PD7 //Gun Tilt PWM (OC2)
#define GTR_PWM PD5 //Gun Trigger PWM (OC1A)
#define GP_DR PC3 //Gun Pan Direction
#define GT_DR PC1 //Gun Tilt Direction
#define GTR_DR PA7 //Gun Trigger Direction
#define GP_BR PC2 //Gun Pan Break
#define GT_BR PC0 //Gun Tilt Break
#define GTR_BR PD6 //Gun Trigger Break
#define CAM_LEFT PC7 //Camera Pan Left
#define CAM_RIGHT PC6 //Camera Pan Right
#define CAM_UP PC5 //Camera Tilt Up
#define CAM_DOWN PC4 //Camera Tilt Down
#define GPL_LEFT PD2 //Gun Pan Limit Switch - Left (INT0)
#define GPL_RIGHT PD3 //Gun Pan Limit Switch - Right (INT1)
#define GTL_UP PA4 //Gun Tilt Limit Switch - Left
#define GTL_DOWN PA5 //Gun Tilt Limit Switch - Right
#define GPL_CENTRE PB0 //Gun Pan Limit Switch - Center
#define GTL_CENTRE PB1 //Gun Tilt Limit Switch - Center
#define GP_POT PA0 //ADC0 - Gun Pan Feedback
#define GT_POT PA1 //ADC1 - Gun Tilt Feedback
#define CAMP_POT PA2 //ADC2 - Camera Pan Feedback
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

55


#define CAMT_POT PA3 //ADC3 - Camera Tilt Feedback
#define SPI_IN PB2 //INT2 - Interrupt which AVR2 will give to AVR1,
during Synchronous Communication. Connected to PD7 of AVR2
#define SPI_OUT PB3 //To give an Interrupt to AVR2. Connected to INT2
(PB2) of AVR2


int gunp_pot_left;
int gunp_pot_right;
int p_resolution_x=4; // STANDS FOR GAN PAN RESOLUTION AND IS A
MULTIPLE FACTOR THAT MULTIPLIES EACH SERIAL COORDINATE.
int p_resolution_y=4; // STANDS FOR GAN TILT RESOLUTION AND IS A
MULTIPLE FACTOR THAT MULTIPLIES EACH SERIAL COORDINATE.
int allowed_offset_x = 0x0000; // STANDS FOR THE ALLOWED ERROR THAT GUNS
OAN OR TILT CAN HAVE FROM THE REQUIRED POSITION
int allowed_offset_y = 0x0003; // STANDS FOR THE ALLOWED ERROR THAT GUNS
OAN OR TILT CAN HAVE FROM THE REQUIRED POSITION
char angle_x;
char angle_y;
char cam_angle_x;
char cam_angle_y;
char mode=1; // A MODE FOR SERIAL FUNCTION
char smode;
char recieved_data; // A MODE FOR SPI FUNCTION
char rfid = 0x77;
char avr3 = 0x77;
char lcd = 0x77;
char target_cord;
char target_cord_x;
char target_cord_y;
char camera_cord;
char camera_cord_x;
char camera_cord_y;
char rfid_byte;
char enter_rfid;
char Pp=20; // THE CONSTANT Kp IN PID FOR GUNS PAN
float Ip=0.5; // THE CONSTANT Ki IN PID FOR GUNS PAN
float Dp=0.1; // THE CONSTANT Kd IN PID FOR GUNS PAN
char Pt=2; // THE CONSTANT Kp IN PID FOR GUNS TILT
char It=1; // THE CONSTANT Ki IN PID FOR
GUNS TILT
char pc_control=1;
char man_control=0;
char man_speed_r=0;
char man_speed_l=0;
char man_speed_u=0;
char man_speed_d=0;
char cman_control=0;
float total_pan_pot_val = 0x03FF; // THE SPAN OF ADC VALUE FOR MAX POT
ROTATION IN GUNS PAN
float total_tilt_pot_val = 0x03FF;// THE SPAN OF ADC VALUE FOR MAX POT
ROTATION IN GUNS TILT
char enter_vector=0;
int initial_x;
int initial_y;
float req_angle_x=0;
float req_angle_y=0;
float integral_error_x=0;
float integral_error_y=0;
float derivative_error_x=0;
References
2010

56


float derivative_error_y=0;
float error0_x=0;
float error1_x=0;
float error0_y=0;
float error1_y=0;
float temp_pwm_x=0;
float temp_pwm_y=0;
float delta_t_x=0.0179;
char pwm_x=0;
char pwm_y=0;
int cur_angle_x=0;
int cur_angle_y=0;
char chk_r=1,chk_l=1,chk_u=1,chk_d=1,chk_p=1,chk_t=1;
char frst_chk = 1;

void interrupts_initialisation (void);
void devices_initialisation (void);
void gun_device_initialisation (void);
void cam_device_initialisation (void);
void devices_ready (void);
void spi_function (char);
void serial_function (char);
void pc_transfer (char);
void spi_transfer (char);


void gun_pan_left (char,char);
void gun_pan_right (char,char);
void gun_tilt_up (char,char);
void gun_tilt_down (char,char);
void gun_trigger (char,char);
void camera_pan_left (void);
void camera_pan_right (void);
void camera_tilt_up (void);
void camera_tilt_down (void);


void external_interrupts (void);
void pwm_initialisation (void);
void adc_interrupts (void);
void spi_interrupts (void);
void serial_interrupts (void);
void timer_initialisation (void);

int gun_pan_pot (void);
int gun_tilt_pot (void);
int camera_pan_pot (void);
int camera_pan_pot (void);
void gun_pan_pid (void);
void gun_tilt_pid (void);
void cam_pan_pid (void);
void cam_tilt_pid (void);
void gun_manual_pan (void);
void gun_manual_tilt (void);



//Interupt Sub Routines

// External Interrupt Request 0
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

57


ISR (_VECTOR(1))
{

//gun_pan_left(0x00,0x00);

}

// External Interrupt Request 1

ISR (_VECTOR(2))
{

//gun_pan_right(0x00,0x00);

}

// TIMER INTERRUPT
ISR (_VECTOR(9))
{
integral_error_x += error1_x * delta_t_x;

derivative_error_x = (error1_x - error0_x) / delta_t_x;

error0_x = error1_x;
}

// SPI Transfer Complete

ISR (_VECTOR(10))
{
char spi;
spi = SPDR;
spi_function(spi);

}

// USART, Rx Complete

ISR (_VECTOR(11))
{
char serial;
serial = UDR;
serial_function(serial);
}

// USART, Tx Complete



//ISR (_VECTOR(13))
//{

//}


//External Interrupt Request 2

//ISR (_VECTOR(18))
//{
//
References
2010

58


//}

int main()
{
interrupts_initialisation(); //initialise all interrupt
cam_device_initialisation(); //INITIALIZE THE CAMERA PAN TILT

initial_x = gun_pan_pot();
initial_x = gun_pan_pot();
initial_y = gun_tilt_pot();
gun_device_initialisation(); //INITIALIZE THE GUNS PAN TILT
devices_ready(); //INFORMS AVR2 OF THE ONLINE DEVICES
req_angle_x = initial_x;
req_angle_y = initial_y;


while(1)
{

while( pc_control == 1 && man_control == 0 )
{
gun_pan_pid();
gun_tilt_pid();
}


while( pc_control == 0 && man_control == 1 )
{
gun_manual_pan();
gun_manual_tilt();
}


}


return 0;
}

///////////////////////////////////////////////////////////////////

// THIS FUNCTION INITIALIZES ALL THE INTERRUPTS


void interrupts_initialisation()
{
cli();
external_interrupts();
adc_interrupts();
pwm_initialisation();
spi_interrupts();
serial_interrupts();
timer_initialisation();
sei();

}


void external_interrupts()
{// the LOW LEVEL on int0,int1 will trigger intrpt
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

59



MCUCR &= ~(1<<ISC10) &~ (1<<ISC11) &~ (1<<ISC00) &~ (1<<ISC01);
// the rising edge on int2 will trigger intrpt

DDRB &= ~(1<<PB2);
PORTB &= ~(1<<PB2);
MCUCSR |= (1<<ISC2);
//GICR |= (1<<INT1)|(1<<INT0)|(1<<INT2);

DDRD &= ~(1<<GPL_LEFT) &~(1<<GPL_RIGHT);
PORTD |= (1<<GPL_LEFT) | (1<<GPL_RIGHT);

}

void adc_interrupts()
{

DDRA &= ~(1<<PA0) & ~(1<<PA1) & ~(1<<PA2) & ~(1<<PA3);
// adc enabled,autotrigerring(free running) enabled,interrupt not enabled
ADCSRA |= (1<<ADEN);
}

void pwm_initialisation()
{
DDRD |= (1<<PD4) | (1<<PD5) | (1<<PD7);

TCCR2 |= (1<<WGM20)|(1<<WGM21)|(1<<COM21)|(1<<CS12);
// fast pwm,non-inverted,BOTH 16 BIT , edge,i/o clk/8
TCCR1A |= (1<<WGM10);
TCCR1B |= (1<<WGM12)|(1<<CS11);

}

void spi_interrupts()
{
DDRB &= ~(1<<PB4);
DDRB &= ~(1<<PB5);
DDRB |= (1<<PB6);
DDRB &= ~(1<<PB7);
// spi interrupt enabled,spi enabled,clk/64 frequency
SPCR |= (1<<SPIE)|(1<<SPE);

DDRB |= (1<<SPI_OUT);
PORTB &= ~(1<<SPI_OUT);
}

void serial_interrupts()
{
UCSRB |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
UCSRC |= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
UBRRL = 0x0B; //Baudrate 9600 @ 1.8432Mhz
}

void timer_initialisation()
{
TCCR0 |= (1<<CS00) | (1<<CS01);
TIMSK |= (1<<TOIE0);

}
///////////////////////////////////////////////////////////////////////////
References
2010

60


/

// THIS FUNCTION INITIALIZES THE CAMERAS PAN TILT



void cam_device_initialisation()
{
cli();
DDRA |= (1<<GTR_DR);
PORTA &= ~(1<<GTR_DR);
DDRC |= (1<<CAM_UP);
DDRC |= (1<<CAM_DOWN);
DDRC |= (1<<CAM_RIGHT);
DDRC |= (1<<CAM_LEFT);
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_LEFT);
sei();

_delay_ms(5000);
PORTC |= (1<<CAM_LEFT);
_delay_ms(20000);
PORTC &= ~(1<<CAM_LEFT);
_delay_ms(200);
PORTC |= (1<<CAM_RIGHT);
_delay_ms(10000);
PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_LEFT);
_delay_ms(200);
PORTC |= (1<<CAM_UP);
_delay_ms(15000);
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_LEFT);
_delay_ms(200);
PORTC |= (1<<CAM_DOWN);
_delay_ms(10000);
PORTC &= ~(1<<CAM_DOWN);

}

////////////////////////////////////////////////////////////////////
// THIS FUNCTION INITIALIZES THE GUNS PAN TILT



void gun_device_initialisation()
{
DDRA |= (1<<GTR_DR);
PORTA &= ~(1<<GTR_DR);
DDRD &= ~(1<<GPL_LEFT) & ~(1<<GPL_RIGHT);
PORTD |= (1<<GPL_LEFT) | (1<<GPL_RIGHT);

cli();
///////////////////////////////////
gun_pan_right(0x9F,0xFF);
//while ( PIND & (1<<GPL_RIGHT) );

_delay_ms(5000);
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

61


gun_pan_right(0x00, 0x00 );
gunp_pot_right = gun_pan_pot();

_delay_ms(5000);

gun_pan_left(0xBF, 0xFF );
//while ( PIND & (1<<GPL_LEFT) );
_delay_ms(30000);
gun_pan_left(0x00, 0x00 );
gunp_pot_left = gun_pan_pot();

//////////////////////////////////////////////////////////////////
/*
gun_tilt_up(0x2F,0xFF);


_delay_ms(2000);
gun_tilt_up(0x00, 0x00 );

_delay_ms(5000);

gun_tilt_down(0x2F, 0xFF );

_delay_ms(4000);
gun_tilt_down(0x00, 0x00 );
*/
_delay_ms(5000);

///////////////////////////////
//p_resolution_x = (gunp_pot_right-gunp_pot_left)/0x00FF;
//gun_pan_left(0x00, 0x00 );
sei();
}


///////////////////////////////////////////////////////////////////////////
//////////////
// THIS FUNCTION IS FOR MOVING THE GUNS PAN RIGHT
// gun_pan_right(char speed (THE PWM THAT CAN BE B/W 0X00 AND 0XFF),char
start(0XFF FOR MOVING AND 0X00 FOR BRAKES))




void gun_pan_right(char speed,char start)
{
if (start == 0xFF) //check for the direction enable i.e
start = 0xff
{
TCCR1A|= (1<<COM1B1); //enable pwm operation
DDRC |= (1<<GP_DR);
DDRC |= (1<<GP_BR); //configure these pins as outputs
PORTC &= ~(1<<GP_BR);
PORTC |= (1<<GP_DR); //release breaks,and set 1 for pan-tilt
direction(right)
DDRD |= (1<<GP_PWM); //configure this pins as outputs(pwm
pin)
OCR1BL = speed; //get the value of pwm
}
else
References
2010

62


{
DDRC |= (1<<GP_BR);
PORTC |= (1<<GP_BR);
TCCR1A &= ~(1<<COM1B1); //disable pwm mode for selected
direction
}
}


///////////////////////////////////////////////////////////////////////////
//////////////////
// THIS FUNCTION IS FOR MOVING THE GUNS PAN LEFT
// gun_pan_left(char speed (THE PWM THAT CAN BE B/W 0X00 AND 0XFF),char
start(0XFF FOR MOVING AND 0X00 FOR BRAKES))

void gun_pan_left(char speed,char start)
{
if (start == 0xFF) //check for the direction enable i.e
start = 0xff
{
TCCR1A |= (1<<COM1B1); //enable pwm operation
DDRC |= (1<<GP_DR);
DDRC |= (1<<GP_BR); //configure these pins as outputs
PORTC &= ~(1<<GP_BR);
PORTC &= ~(1<<GP_DR); //release breaks,and set 0 for pan-tilt
direction(left)
DDRD |= (1<<GP_PWM); //configure this pins as outputs(pwm
pin)
OCR1BL = speed; //get the value of pwm
}

else
{
DDRC |= (1<<GP_BR);
PORTC |= (1<<GP_BR);
TCCR1A &= ~(1<<COM1B1); //disable pwm mode for selected
direction
}
}




///////////////////////////////////////////////////////////////////////////
//////////////////////
// THIS FUNCTION IS FOR MOVING THE GUNS TILT UP
// gun_tilt_up(char speed (THE PWM THAT CAN BE B/W 0X00 AND 0XFF),char
start(0XFF FOR MOVING AND 0X00 FOR BRAKES))


void gun_tilt_up(char speed,char start)
{
if (start == 0xFF) //check for the direction enable i.e
start = 0xff
{
TCCR2 |= (1<<COM21); //enable pwm operation
DDRC |= (1<<GT_DR)|(1<<GT_BR); //configure these pins as outputs
PORTC &= ~(1<<GT_BR);
PORTC |= (1<<GT_DR); //release breaks,and set 0 for pan-tilt
direction(up)
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

63


DDRD |= (1<<GP_PWM); //configure this pins as outputs(pwm
pin)
OCR2 = speed; //get the value of pwm
}

else
{
DDRC |= (1<<GT_BR);
PORTC |= (1<<GT_BR);
TCCR2 &= ~(1<<COM21); //disable pwm mode for selected
direction
}
}

///////////////////////////////////////////////////////////////////////////
///////////////////
// THIS FUNCTION IS FOR MOVING THE GUNS TILT DOWN
// gun_tilt_down(char speed (THE PWM THAT CAN BE B/W 0X00 AND 0XFF),char
start(0XFF FOR MOVING AND 0X00 FOR BRAKES))

void gun_tilt_down(char speed,char start)
{
if (start == 0xFF) //check for the direction enable i.e
start = 0xff
{
TCCR2 |= (1<<COM21); //enable pwm operation
DDRC |= (1<<GT_DR)|(1<<GT_BR); //configure these pins as outputs
PORTC &= ~(1<<GT_BR);
PORTC &= ~(1<<GT_DR); //release breaks,and set 0 for pan-tilt
direction(down)
DDRD |= (1<<GP_PWM); //configure this pins as outputs(pwm
pin)
OCR2 = speed; //get the value of pwm
}
else
{
DDRC |= (1<<GT_BR);
PORTC |= (1<<GT_BR);
TCCR2 &= ~(1<<COM21); //disable pwm mode for selected
direction
}
}
///////////////////////////////////////////////////////////////////////////
/////////////////
// THIS FUNCTION IS FOR MOVING THE CAMERA PAN RIGHT

void camera_pan_right()
{
DDRC |= (1<<CAM_RIGHT);
PORTC |= (1<<CAM_RIGHT);
_delay_ms(10000);
PORTC &= ~(1<<CAM_RIGHT);
}

////////////////////////////////////////////////////////////////////////
// THIS FUNCTION IS FOR MOVING THE CAMERA PAN LEFT

void camera_pan_left()
{
DDRC |= (1<<CAM_LEFT);
References
2010

64


PORTC |= (1<<CAM_LEFT);
_delay_ms(10000);
PORTC &= ~(1<<CAM_LEFT);
}

///////////////////////////////////////////////////////////////////////////
THIS FUNCTION IS FOR MOVING THE CAMERA TILT UP
void camera_tilt_up()
{
DDRC |= (1<<CAM_UP);
PORTC |= (1<<CAM_UP);
_delay_ms(10000);
PORTC &= ~(1<<CAM_UP);
}
///////////////////////////////////////////////////////////////////////////
////`
// THIS FUNCTION IS FOR MOVING THE CAMERA TILT DOWN
void camera_tilt_down()
{
DDRC |= (1<<CAM_DOWN);
PORTC |= (1<<CAM_DOWN);
_delay_ms(10000);
PORTC &= ~(1<<CAM_UP);
}

///////////////////////////////////////////////////////////////////////////
//

// THIS FUNCTION IS FOR READING THE GUNS PAN POT

int gun_pan_pot()
{
int adc_val,adc_l,adc_h;
ADMUX = 0x00;
ADCSRA |= (1<<ADSC); //start conversion
while(( ADCSRA & (1<<ADSC))); //wait for the ADSC bit to go zero

adc_val = ADCL + (0x100*ADCH); //
adc_l = ADCL;
adc_h = ADCH;

return adc_val; //

}
///////////////////////////////////////////////////////////////////////////
// THIS FUNCTION IS FOR READING THE GUNS TILT POT

int gun_tilt_pot()
{
int adc_val,adc_l,adc_h;
ADMUX = 0x01;
ADCSRA |= (1<<ADSC); //start conversion
while(( ADCSRA & (1<<ADSC))); //wait for the ADSC bit to go zero

adc_val = ADCL + (0x100*ADCH);

adc_l = ADCL;
adc_h = ADCH;

return adc_val;
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

65


}

///////////////////////////////////////////////////////////////////////////
/////
// THIS FUNCTION IS FOR READING THE CAMERAS PAN POT


int camera_pan_pot()
{
int adc_val;
ADMUX = 0x02;
ADCSRA |= (1<<ADSC) | (1<<ADPS2) |(1<<ADPS1) | (1<<ADPS0);//start
conversion
while(( ADCSRA & (1<<ADSC))); //wait for the ADSC bit to go zero

adc_val = ADCL + (0x100*ADCH);
return adc_val;

}
///////////////////////////////////////////////////////////////////////////
/////////
// THIS FUNCTION IS FOR READING THE CAMERAS TILT POT

int camera_tilt_pot()
{
int adc_val;
ADMUX = 0x03;
ADCSRA |= (1<<ADSC); //start conversion
while(( ADCSRA & (1<<ADSC))); //wait for the ADSC bit to go zero

adc_val = ADCL + (0x100*ADCH);
return adc_val;

}


///////////////////////////////////////////////////////////
// PID FOR GUNS PAN


void gun_pan_pid()
{

cur_angle_x = gun_pan_pot();

if (req_angle_x == 0)
{
char do_nothing = 0;
}

else
{

error1_x = ( req_angle_x / total_pan_pot_val) - ( cur_angle_x /
total_pan_pot_val);
temp_pwm_x = (Pp*error1_x*0xFF) + (Ip*integral_error_x*0xFF) +
(Dp*derivative_error_x*0xFF);

if (temp_pwm_x > 0 + allowed_offset_x)
{
References
2010

66


if (temp_pwm_x >= 0xFF)
{
pwm_x = 0xFE;
}
else
{
pwm_x = temp_pwm_x;
}

gun_pan_right(pwm_x,0xFF);

}

else if (temp_pwm_x < 0 - allowed_offset_x)
{
if (temp_pwm_x <= -0xFF)
{
pwm_x = 0xFE;
}
else
{
pwm_x = -temp_pwm_x;
}

gun_pan_left(pwm_x,0xFF);
}

else
{
gun_pan_right(0x00,0x00);
}

}

}

//////////////////////////////////////////////////////
// PID FOR GUNS TILT

void gun_tilt_pid()
{

cur_angle_y = gun_tilt_pot();

if (req_angle_y == 0)
{
char do_nothing = 0;
}

else
{

error1_y = ( req_angle_y / total_tilt_pot_val) - ( cur_angle_y /
total_tilt_pot_val);
temp_pwm_y = (Pt*error1_y*0xFF) + (Ip*integral_error_y*0xFF);

if (temp_pwm_y > 0 + allowed_offset_y)
{
if (temp_pwm_y >= 0xFF)
{
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

67


pwm_y = 0xFE;
}
else
{
pwm_y = temp_pwm_y;
}

gun_tilt_up(pwm_y,0xFF);

}

else if (temp_pwm_y < 0 - allowed_offset_y)
{
if (temp_pwm_y <= -0xFF)
{
pwm_y = 0xFE;
}
else
{
pwm_y = -temp_pwm_y;
}

gun_tilt_down(pwm_y,0xFF);
}

else
{
gun_tilt_up(0x00,0x00);
}

}

}

///////////////////////////////////////////////////////////////////////////

void gun_manual_pan()
{

if (man_speed_r == 0 && man_speed_l ==0)
{
TCCR1A &= ~(1<<COM1B1);
OCR1BL = 0x00;
PORTD &= ~(1<<GP_PWM);
if (chk_p == 1)
{
spi_transfer(0x4A);
chk_p = 0;
chk_r = 1;
chk_l =1;
}
}

else if (man_speed_r > 0 && man_speed_l ==0)
{
TCCR1A|= (1<<COM1B1);
DDRC |= (1<<GP_BR) | (1<<GP_DR); //enable pwm operation
PORTC &= ~(1<<GP_BR);
PORTC |= (1<<GP_DR); //release breaks,and set 1 for pan-tilt
direction(right)
References
2010

68


DDRD |= (1<<GP_PWM); //configure these pins as outputs(pwm
pin)
OCR1BL = man_speed_r;
if (chk_r == 1)
{
spi_transfer(0x47);
chk_p = 1;
chk_r = 0;
chk_l =1;
}
}

else if (man_speed_r == 0 && man_speed_l > 0)
{
TCCR1A|= (1<<COM1B1);
DDRC |= (1<<GP_BR) | (1<<GP_DR); //enable pwm operation
PORTC &= ~(1<<GP_BR);
PORTC &= ~(1<<GP_DR); //release breaks,and set 0 for pan-tilt
direction(left)
DDRD |= (1<<GP_PWM); //configure these pins as outputs(pwm
pin)
OCR1BL = man_speed_l;
if (chk_l == 1)
{
spi_transfer(0x48);
chk_p = 1;
chk_r = 1;
chk_l =0;
}
}


}
///////////////////////////////////////////////////////
void gun_manual_tilt()
{

if (man_speed_u == 0 && man_speed_d ==0)
{
TCCR2 &= ~(1<<COM21);
OCR2 = 0x00;
if (chk_t == 1)
{
spi_transfer(0x49);
chk_t = 0;
chk_u = 1;
chk_d =1;
}
}

else if (man_speed_u > 0 && man_speed_d ==0)
{
TCCR2|= (1<<COM21); //enable pwm operation
DDRC |= (1<<GT_BR) | (1<<GT_DR);
PORTC &= ~(1<<GT_BR);
PORTC |= (1<<GT_DR); //release breaks,and set 1 for pan-tilt
direction(up)
DDRD |= (1<<GT_PWM); //configure these pins as outputs(pwm
pin)
OCR2 = man_speed_u;
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

69


if (chk_u == 1)
{
spi_transfer(0x45);
chk_t = 1;
chk_u = 0;
chk_d =1;
}
}

else if (man_speed_u == 0 && man_speed_d > 0)
{
TCCR2|= (1<<COM21); //enable pwm operation
DDRC |= (1<<GT_BR) | (1<<GT_DR);
PORTC &= ~(1<<GT_BR);
PORTC &= ~(1<<GT_DR); //release breaks,and set 0 for pan-tilt
direction(down)
DDRD |= (1<<GT_PWM); //configure these pins as outputs(pwm
pin)
OCR2 = man_speed_d;
if (chk_d == 1)
{
spi_transfer(0x46);
chk_t = 1;
chk_u = 1;
chk_d =0;
}
}

}


///////////////////////////////////////////////////////
void cam_pan_pid()
//{


//}

//////////////////////////////////////////////////////
//void cam_tilt_pid()
//{

//}



//////////////////////////////////////////////////////////////////

void serial_function(char recieved_data)
{
if(mode==0)
{
if(recieved_data==0x80) //Command
Start Protocol
{
mode = 1;
}
else if(recieved_data==0x81) //Command End
Protocol
{
References
2010

70


mode = 0;
}

}
else if(mode==1)
{
if (recieved_data == 0x81)
{
mode = 1;
spi_transfer(0x43);
frst_chk = 1;
}

else if (recieved_data == 0x70 )
{

pc_transfer(0x71);

pc_transfer(0x72);

pc_transfer(0x73);

pc_transfer(0x74);

pc_transfer(0x75);

pc_transfer(0x76);

}

else if (recieved_data == 0x60 )
{
man_control = 0;
pc_control = 1;


camera_cord = 0;
target_cord = 1;
target_cord_x = 1;
target_cord_y = 0;
mode = 2;
}

else if (recieved_data == 0x61 )
{
man_control = 0;
pc_control = 1;


camera_cord = 1;
target_cord = 0;
camera_cord_x = 1;
camera_cord_y = 0;
mode = 2;
}

else if (recieved_data == 0x40 )
{
man_control = 1;
pc_control = 0;
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

71



camera_cord = 0;
target_cord = 1;
target_cord_x = 1;
target_cord_y = 0;
mode = 3;

if (frst_chk == 1)
{
spi_transfer(0x42);
frst_chk = 0;
}

}

else if (recieved_data == 0x41 )
{
man_control = 1;
pc_control = 0;

camera_cord = 1;
target_cord = 0;
camera_cord_x = 1;
camera_cord_y = 0;
mode = 3;

}


else if (recieved_data == 0x42 )
{


PORTA |= (1<<GTR_DR);
mode = 1;

}

else if (recieved_data == 0x43 )
{

PORTA &= ~(1<<GTR_DR); //enable pwm operation
mode = 1;

}



}

else if (mode == 2)
{

if (camera_cord == 0 && target_cord ==1)
{
if (target_cord_x == 1 && target_cord_y == 0 )
{
angle_x = recieved_data;

req_angle_x = initial_x + (3*(angle_x - 0x7F));
References
2010

72


camera_cord = 0;
target_cord_x = 0;
target_cord_y = 1;
}

else if (target_cord_x == 0 && target_cord_y == 1 )
{
angle_y = recieved_data;

req_angle_y = initial_y + (4*(angle_y - 0x7F));
target_cord_x = 0;
target_cord_y = 0;
camera_cord = 0;
target_cord = 0;
mode = 1;
}
}

else if (camera_cord == 1 && target_cord == 0)
{
if (camera_cord_x == 1 && camera_cord_y == 0 )
{
cam_angle_x = recieved_data;


if (cam_angle_x == 0x7F)
{
PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_LEFT);
}

else if (cam_angle_x > 0x7F)
{
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
PORTC &= ~(1<<CAM_LEFT);
PORTC |= (1<<CAM_RIGHT);
}

else if (cam_angle_x < 0x7F)
{
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
PORTC &= ~(1<<CAM_RIGHT);
PORTC |= (1<<CAM_LEFT);
}

target_cord = 0;
camera_cord_x = 0;
camera_cord_y = 1;
}

else if (camera_cord_x == 0 && camera_cord_y == 1 )
{
cam_angle_y = recieved_data;

if (cam_angle_y == 0x7F)
{
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

73


}

else if (cam_angle_y > 0x7F)
{
PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_DOWN);
PORTC &= ~(1<<CAM_LEFT);
PORTC |= (1<<CAM_UP);
}

else if (cam_angle_y < 0x7F)
{
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_LEFT);
PORTC &= ~(1<<CAM_RIGHT);
PORTC |= (1<<CAM_DOWN);
}

camera_cord_x = 0;
camera_cord_y = 0;
camera_cord = 0;
target_cord = 0;
mode = 1;
}
}

}


else if (mode == 3)
{

if (camera_cord == 0 && target_cord ==1)
{
if (target_cord_x == 1 && target_cord_y == 0 )
{

if ( recieved_data == 0x7F )
{
man_speed_r = 0;
man_speed_l = 0;
}

else if ( recieved_data > 0x7F )
{
man_speed_r = (0x7F + ((recieved_data - 0x7F) / 0x1F)) ;
man_speed_l = 0;
}

else if ( recieved_data < 0x7F )
{
man_speed_l = (0x7F + (recieved_data / 0x1F)) ;
man_speed_r = 0;
}


camera_cord = 0;
target_cord_x = 0;
target_cord_y = 1;
}
References
2010

74



else if (target_cord_x == 0 && target_cord_y == 1 )
{

if ( recieved_data == 0x7F )
{
man_speed_u = 0;
man_speed_d = 0;
}

else if ( recieved_data > 0x7F )
{
man_speed_u = (0x4F + ((recieved_data - 0x7F) / 0x1F)) ;
man_speed_d = 0;
}

else if ( recieved_data < 0x7F )
{
man_speed_d = (0x4F + (recieved_data / 0x1F)) ;
man_speed_u = 0;
}

target_cord_x = 0;
target_cord_y = 0;
camera_cord = 0;
target_cord = 0;
mode = 1;
}
}

else if (camera_cord == 1 && target_cord ==0)
{
if (camera_cord_x == 1 && camera_cord_y == 0 )
{
if (recieved_data == 0x7F)
{
PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_LEFT);
}

else if (recieved_data > 0x7F)
{
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
PORTC &= ~(1<<CAM_LEFT);
PORTC |= (1<<CAM_RIGHT);

}
else if (recieved_data < 0x7F)
{

PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
PORTC &= ~(1<<CAM_RIGHT);
PORTC |= (1<<CAM_LEFT);

}

camera_cord_x = 0;
camera_cord_y = 1;
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

75


target_cord = 0;

}

else if (camera_cord_x == 0 && camera_cord_y == 1 )
{
if (recieved_data == 0x7F)
{
PORTC &= ~(1<<CAM_UP);
PORTC &= ~(1<<CAM_DOWN);
}

else if (recieved_data > 0x7F)
{

PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_LEFT);
PORTC &= ~(1<<CAM_DOWN);
PORTC |= (1<<CAM_UP);
}
else if (recieved_data < 0x7F)
{

PORTC &= ~(1<<CAM_RIGHT);
PORTC &= ~(1<<CAM_LEFT);
PORTC &= ~(1<<CAM_UP);
PORTC |= (1<<CAM_DOWN);

}
camera_cord_x = 0;
camera_cord_y = 0;
camera_cord = 0;
target_cord = 0;
mode = 1;

}
}
}
}



/////////////////////////////////////////////

void pc_transfer(char data)
{
while (!(UCSRA & (1<<UDRE)));
UDR = data;
}


////////////////////////////////////////////////////
void spi_function(char recieved_data)
{



if (smode == 0)
{

References
2010

76


if (recieved_data == 0x00)
{
char nodata = 0x00;
}
else if(recieved_data == 0x70)
{
smode = 1;
}
else if (recieved_data == 0x50)
{
pc_transfer(0x50);
smode = 2;
enter_rfid= 0;
}

}

else if (smode == 1)
{
if (recieved_data == 0x72)
{
rfid = 0x72;
smode=0;
}
else if (recieved_data == 0x73)
{
avr3 = 0x73;
smode=0;
}
else if (recieved_data == 0x74)
{
lcd = 0x74;
smode=0;
}

}

else if (smode == 2)
{
if (enter_rfid <= 5)
{
pc_transfer(recieved_data);
enter_rfid++;
}
if (enter_rfid > 5)
{
enter_rfid = 0;
smode=0;
}

}

}



///////////////////////////////////////////////////
void devices_ready(void)
{
spi_transfer(0x40);
Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

77


spi_transfer(0x31);
spi_transfer(0x40);
spi_transfer(0x35);
spi_transfer(0x40);
spi_transfer(0x37);
}


///////////////////////////////////////////////////
void spi_transfer(char data)
{
cli();
char no_data;

SPDR = data;
PORTB |= (1<<SPI_OUT);


while (!(SPSR & (1<<SPIF)));
no_data = SPDR;

PORTB &= ~(1<<SPI_OUT);
sei();
}
References
2010

78


ANNEX C
RFID Module Specifications:


Card Proximity 3-15 cm, 125 Khz for PP-5707 Hand free card about
3meters for PF-5
Type Surface mount, water proof
Operation mode Card only or card and keypad
Monitor inputs Door contact, Exit push button, case tamper
Operation temperature 0o~50oC
Humidity 20%~90% RH, Non condensation
Power supply 11 VDC~16 VDC

Transmission rate 4,800 bps, N.8.1 (optional for 300~19,200bps)
Keypad With brief 3 x 4 membrane keypad for system
programming and
Password entry
Interface RS-485 or TTL
Dimensions 120(L)x 83(W)x 30(H)mm
Weight 450g +5%

Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

79


ANNEX D
Communication Protocol:
Protocol Byte Value (Hex) Remarks
SERIAL DATA
Enter Command Mode 0x80
Exit Command Mode 0x81
System Reset 0x70 Sent by PC to AVR1 indicating a
system Reset
System Reset Response 0x71 Immediate response by AVR1 to PC,
notifying that it is starting all the
initializations.
RFID Ready 0x72 Sent by AVR4 to AVR2 upon System
Reset Command
Manual Controller Ready 0x73 Sent by AVR3 to AVR2 upon System
Reset Command
LCDs Ready 0x74 Sent by AVR2 to AVR1 upon System
Reset Command
Malfunction 0x77
Target Detected/Manual
controller
0x60
Target Centre X Data
Target Centre Y Data
Camera movement/Manual
controller
0x61
Camera -X Data
Camera -Y Data
RFID data 0x50 From AVR1 to PC
Serial number of tags Data From AVR1 to PC
SPI - Data
Enter Command Mode 0x80
Exit Command Mode 0x81
RFID data start 0x50
RFID data end 0x51
FROM AVR1 TO AVR2 (SPI-DATA)
System ready commands 0x40
Alphanumeric LCD command 0x41
Graphical LCD command 0x42
Graphical LCD exit 0x43
up 0x45
down 0x46
right 0x47
left 0x48
Tilt off 0x49
Pan off 0x4A
Avr1 ready 0x31
References
2010

80


Avr3 ready 0x33
Avr4 ready 0x34
Weapon ready 0x35
Avr3 offline 0x37

Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

81


ANNEX E
Pinouts of microcontrollers:
AVR1 Control Pins
Receive data from Computer.
Drive Motors (both AC and DC).
Send data back to Computer.
Receive Data from AVR2 regarding RFID etc.
Send Positions to AVR2, which in turn will display data on LCDs.

AC Motor Drives
PC7 Camera Pan Left.
PC6 Camera Pan Right.
PC5 Camera Tilt Up.
PC4 Camera Tilt Down.

DC Motor Drives
PC3 Gun Pan Direction
PC2 Gun Pan Break
PD4 Gun Pan PWM (OC1B)
PC1 Gun Tilt Direction
PC0 Gun Tilt Break
PD7 Gun Tilt PWM (OC2)
PA7 Gun Trigger Direction
PD6 Gun Trigger Break
PD5 Gun Trigger PWM (OC1A)

Limit Switches
PD2 Gun Pan Limit Switch Left (INT0)
PD3 Gun Pan Limit Switch Right (INT1)
PA4 Gun Tilt Limit Switch Left
PA5 Gun Tilt Limit Switch - Right
PB0 Gun Pan Limit Switch Center
PB1 Gun Tilt Limit Switch - Center

Feedback ADCs
PA0 ADC0 Gun Pan Feedback
PA1 ADC1 Gun Tilt Feedback
PA2 ADC2 Camera Pan Feedback
PA3 ADC3 Camera Tilt Feedback

Synchronous Communication between AVR1 and AVR2
PB2 INT2 Interrupt which AVR2 will give to AVR1, during Synchronous
Communication. Connected to PD7 of AVR2
PB3 To give an Interrupt to AVR2. Connected to INT2 (PB2) of AVR2
PB4 Slave Select of AVR1. Controlled by PD6 of AVR2.
PB5 MOSI Connected to MOSI of AVR2
PB6 MISO Connected to MISO of AVR2
References
2010

82


PB7 SCK Common Clock between AVR1 and AVR2.

Asynchronous Communication between AVR1 and Computer
PD0 RXD Received Data from Computer during Asynchronous Communication.
PD1 TXD Transmit Data to Computer during Asynchronous Communication.

AVR2 Control Pins
Receive data from AVR3 regarding RFID (using MAX485).
Forward Data to AVR1, which in turn will inform the Computer.
Receive Data from AVR1, to be displayed on LCD.
Display RFIDs and Motor Positions on LCDs.

Graphical and Alphanumeric LCD Data Pins
PC Port C is the Data Port.

Graphical and Alphanumeric LCD Control Pins
PA2 RS-Pin of Alphanumeric LCD
PA1 RW-Pin of Alphanumeric LCD
PA0 Enable (E) Pin of Alphanumeric LCD
PB1 RS-Pin of Graphical LCD
PA4 RW-Pin of Graphical LCD
PA3 Enable (E) Pin of Graphical LCD
PA7 CS1 Pin of Graphical LCD
PA6 CS2 Pin of Graphical LCD
PA5 RST Pin of Graphical LCD

Synchronous Communication between AVR1 and AVR2
PB2 INT2 Interrupt which AVR1 will give to AVR2, during Synchronous
Communication. Connected to PB3 of AVR1
PD7 To give an Interrupt to AVR1. Connected to INT2 (PB2) of AVR1
PB4 Slave Select of AVR2. This Pin is given a permanent HIGH or LOW, to
configure it as a Master.
PD6 Pin to Configure AVR1 as Slave using SS.
PB5 MOSI Connected to MOSI of AVR1
PB6 MISO Connected to MISO of AVR1
PB7 SCK Common Clock between AVR1 and AVR2.

Asynchronous Communication between AVR2 and AVR3
PD2 DE of MAX485
PD3 RE of MAX485
PD0 RXD Received Data from AVR3 during Asynchronous Communication via
MAX485. Connected to RO of MAX485
PD1 TXD Transmit Data to AVR3 during Asynchronous Communication via
MAX485. Connected to DI of MAX485


Report: Strategic Monitoring using RFID & Real-time Target Tracking
2010

83


AVR3 Control Pins
Receive data from Joy-Pad for Manual Control.
The Selected operation will be transmitted to AVR2 and then to AVR1 via Serial and
SPI.
The Start Button will interrupt the AVR3 and will enable the Manual Control.
Motors will be driven at some specific PWM, and if the Turbo Button is pressed
than they will be driven at some faster PWM. Pressing the Turbo button for the
Second time will disable the Turbo Mode.
By pressing the Analog Button, Control will be shifted to Joysticks for dynamic
control.
The left half of Joy-Pad is for AC (Camera) Control and right half is for DC (Gun)
Control.

Joy-Pad
Pins
MEGA16 Pins AVR3 Pins Function

01 04 PB3 Unassigned Button 2
02 05 PB4 Unassigned Button 1
03 02 PB1 AC Forward
04 06 PB5 AC Left
05 01 PB0 AC Backward
06 07 PB6 AC Right
07 18 PD4 Left Motor Vibrator
08 11 - Ground
09 19 PD5 Right Motor Vibrator
10 20 PD6 DC Motor Reset
11 39 PA1 AC Motor Reset
12 37 PA3 AC Motor POT-X
13 38 PA2 AC Motor POT-Y
14 36 PA4 DC Motor POT-X
15 35 PA5 DC Motor POT-Y
16 29 PC7 Select Button
17 34 PA6 Analog
18 28 PC6 Turbo
19 03 PB2 Start (INT 2) This Button is on Interrupt
20 27 PC5 DC Left
21 23 PC1 DC Backward
22 26 PC4 DC Right
23 22 PC0 DC Forward
24 25 PC3 Fire 2
25 21 PD7 Fire 1
26 10 - 5V VDCL




References
2010

84


AVR4 Control Pins
Receive data from RFID at 4800 Baud Rate.
Process the RFID Data, extract relevant information and transfer it to AVR2 via 485.

MEGA16
Pins
AVR4 Pins Function
02 PD0 RXD of AVR4, connected to RO of MAX485 and R1OUT of
MAX232, to receive any data from RFID or from AVR2.
03 PD1 TXD of AVR4, connected to DI of MAX485 and T1IN of
MAX232, to transfer any data to RFID or AVR2.
PB0(RE) High for transmission, Low for reception, Low for high
impedance.
PD7(DE) High for transmission, Low for reception, High for high
impedance.

You might also like