You are on page 1of 45

Saa

CERTIFICATE

Certified that the contents and form of project entitledDead Eyesubmitted by Dillshad,Saad Ali and Wasif Ali have been found satisfactory for the requirement of the degree.

Advisor: Mr. Kamran Zaidi

Co-Advisor: Dr. Muhammad Murtaza Khan

DEDICATION

In the name of Allah, the Most Gracious, the Most Merciful

DEAD EYE is dedicated to the lives of the policemen, army personnel, guards and even the civilians that either sacrificed their lives for our safety, or became a target of terrorists attacks.

ACKNOWLEDGEMENTS

We are extremely thankful to our Advisor and Co-Advisor, Mr. Kamran Zaidi and Dr. Muhammad Murtaza who lead us in the right directions from the beginning to complete this project. They were always there to help and guide us in any possible manner.

A few other staff members who helped us were Mr. Abdul Afram, Mr. Osman Hassan and Mr. Tawakkal Hussain Balouch (R.A CS Lab), we are thankful to you as well.

Abstract

DEAD EYE is an automated gun project in which a real gun movement can be controlled from a distance and fired. There is a camera mounted as a scope of the gun. The video is used as a feedback to control the movement of the gun. Based on the image anyone sitting on the computer can decide whether or not to shoot and where exactly to shoot without even holding the gun. Moreover the gun can also auto-target objects using image processing. This is achieved by the RF link between the gun movement control unit and a computer. This idea if properly implemented for security purposes can help save lives of guards, army personnel and policemen.

Contents
ABSTRACT TABLE OF CONTENTS INTRODUCTION 1.1- BLOCK DIAGRAM LITERATURE REVIEW 1.2- THE SOFTWARE 2.12.2 2.3 2.4 2.5 2.7OPEN-CV OPEN-CV
VS.

5 6 9 9 11 11 11 MATLAB 12 12 13 16 20 22 27 27 29 35 39
PART)

SERIAL COMMUNICATION WIRELESS COMMUNICATION MICROCONTROLLERS MOTOR CONTROLLER

2.6- DC MOTORS

METHODOLOGY 3.1- SOFTWARE 3.2- THE ELECTRONICS 3.3- THE MECHANICS RESULTS 4.1- CAMERA INPUT (PC 4.2- TO GENERATE 4.3- RF LINK 4.4- MICRO CONTROLLER PART: 4.5- MOTOR MOVEMENTS: 4.6- OBJECT TRACKING:

38 CAMERA 38 39 39 40 40

CODE FROM FEEDBACK

List of Figures
(FIGURE 1.1-BASIC BLOCK DIAGRAM) (FIGURE 2.1, OPEN-CV STRUCTURE) (FIGURE 2.2- RF TRANSMITTER) (FIGURE 2.3- RF RECEIVER) (FIGURE 2.4-POWER WINDOW MOTOR) 8 11 13 14 20

(FIGURE 2.5- DC GEARED MOTOR) (FIGURE 2.6- BASIC SERVO-SYSTEM) (FIGURE 2.7-H-BRIDGE) (FIGURE 2.8-H-BRIDGE OPERATION) (TABLE 2.1- H-BRIDGE TRUTH TABLE) (FIGURE 3.1- CAMERA VIEW (FIGURE 3.2- CAMERA VIEW
MOUSE TRACKING) OBJECT TRACKING)

21 23 25 25 26 28 28 28 30 31 32 33 33 34 35 36 37 39 41 43

(FIGURE 3.3-FINAL SCHEMATIC) (FIGURE 3.4- SERIAL COMMUNICATION) (FIGURE 3.5-SYSTEM DIAGRAM) (FIGURE 3.6- FINAL H-BRIDGE) (FIGURE 3.7- OPTICAL ENCODER) (FIGURE 3.8- ENCODER PCB) (FIGURE 3.9-1 MECHANICAL PROTOTYPE)
ST

(FIGURE 3.0- MECHANICAL BASE) (FIGURE 3.10- MECHANICAL TOP) (FIGURE 3.11- IMPLEMENTED MECHANICAL ASSEMBLY) (FIGURE 4.1- RF OSCILLOSCOPE RESULT) (FIGURE 5.1- SERVOSYSTEM MATHEMATICS) (FIGURE 5.1- SERVOSYSTEM MATHEMATICS CONTD..)

CHAPTER 1 INTRODUCTION

Our country is suffering from intense security issues these days. Every time we switch on our television we hear some bomb blast, target killing or an intruder in a facility. We as Pakistanis are always liable to think for the betterment of our nation. We are not supposed to waste off our studies in some foreign company but whatever we gain, we have to contribute in our nations prosperity. This place is our identity and we respect it. So the FYP was a chance to just show the intent that we can help save lives even in current conditions. We all can think and even implement small ideas that maybe life saving. And what are engineers for? They are the ones to make life and surroundings easier, simpler and safe. The thought behind this project was just a try to give a sense of security and safety to the men who ensure our safety. Obviously no one can cheat death, but the feel can make a lot happy, peaceful at their jobs and hardworking as well. And how would that happen? Its that the project aims to make people able to use guns without putting their own life in danger.

1.1- BLOCK DIAGRAM


I would use this simple block diagram to illustrate my concept:

(Figure 1.1-Basic Block Diagram) This actually means that we dont carry a gun while holding it, rather we would be monitoring the gun movement on our computer and a click would be translated into a real trigger press at the same time. This would actually be helpful in a lot of occasions that I would mention further. This could give guards or army men a lot of time to react to any critical situation while they wont be at personal risk at the first attack. And most probably, they could deactivate the threat the first time it attempts to react violently.

This is an inspired version of some movie clips and other projects, but the aim was to make a cheap product from Pakistan that is beneficial for our law enforcing agencies once it reaches its implementation stage. DEAD EYE consists of a software part and a gun mount. The software could be for a laptop or a PC depending on the conditions for its intended use. The gun mount (mechanical part) would have a wireless camera to it that provides the feedback. The user on the computer end would be monitoring via this camera and make decisions based on it. There would be some auto functionalities included that could be object detection, object tracking, sentry gun etc. These could be extended to targeting and then wireless controls over the internet so that global access can be provided. The DEAD EYE could be helpful in various occasions. Army personnel can use these instead of initial trooping in any fight scenario. The snipers can use this at some distance as an aid to their mission. And the best of its application is the life saving of guards at security check points. If a thread is determined, shooting decisions can be made from a safe distance if the area is in threat of a suicide attack.

CHAPTER 2 LITERATURE REVIEW


1.2- THE SOFTWARE
One of the tasks in project development was creating a user interface to enable the user to view the live video feedback from onboard wireless camera and easily control the movement of the gun using the mouse or object tracking. The interface will also enable the user to access difference features of the Dead Eye like video recording, object detection, auto targeting etc. Also the interface would enable the user to choose different settings like which serial port (COM1, COM2etc.) is being used as an interface to the hardware etc. For the development of user interface there were several options available like Visual Basic, C++, and MATLAB etc. Also for image processing part MATLAB or OpenCV could be used. Data communication can be done through USB, parallel port or serial port. We are using OpenCV and C++ as a basis for the PC interface development. OpenCV can be used with any C based languages. For data communication we are using serial port.

2.1- OPEN-CV

OpenCV is an open source computer vision library. The library is written in C And C++ and runs under Linux, Windows and Mac OS X. OpenCV provides computational efficiency and with a strong focus on real time applications. OpenCV is written in optimized C and can take advantage of multicore processors. OpenCV is broadly structured into four main components, which are shown in Figure below the CV component contains the basic image processing and higher-level computer vision algorithms; ML is the machine learning library, which includes many statistical classifiers and clustering tools. HighGUI contains I/O routines and functions for storing and loading video and images, and CXCore contains the basic data structures and content.

(Figure 2.1, Open-CV Structure)

We will be using some features of OpenCV HighGUI Toolkit and some of MSDN library in the creation of user interface and to detect mouse movement.

2.2 - OPEN-CV VS. MATLAB


The reason of choosing OpenCV over MATLAB is that OpenCV is a library designed for this purpose while MATLAB provides a general purpose programming environment. OpenCV is a dedicated library for image processing application. Therefore the functions are optimized and can run on different platforms. OpenCV application can be easily integrated to other applications. Matlab on the other hand is a generic high level environment initially created for vector type operations and that has evolved to a powerful simulation and data exploration tool. MATLAB is used not only for image processing but also for signal

processing, neural networks, wavelet transforms, differential equations, statistics, etc. MATLAB is a good option for illumination design, image processing algorithm development, spectral analysis, and data exploration. But when is time to take the development to a realtime environment where the code may be integrated with other application OpenCV is a better option.

2.3 - SERIAL COMMUNICATION


Dead Eye uses UART (serial port) for communication with the hardware. The serial port takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits into complete bytes. Each UART contains a shift register which is the fundamental method of conversion between serial and parallel forms. Serial transmission of digital information (bits) through a single wire or other medium is much more cost effective than parallel transmission through multiple wires. Also serial data can be easily transmitted wirelessly. transmission and hence parallel port. Serial data can be transmitted either through USB or serial port. As we require very little data-rate (as will be explained later) so this makes serial port the best option. It is also the easiest to implement. This rules out any need of parallel data

2.4 - WIRELESS COMMUNICATION


The concept behind wireless communication for DEAD EYE is basically the necessity for the project as well. There has to be some wireless medium for exchanging data and control signals between the computer and the moving part i.e the gun. Wireless communication can be via: Radio frequency communication, Microwave communication, for example long-range line-of-sight via highly directional antennas, or short-range communication, or Infrared (IR) short-range communication, for example from remote controls or via Infrared Data Association (IrDA). Applications may involve point-to-point communication, point-to-multipoint

communication, broadcasting, cellular networks and other wireless networks. The ideal choice for DEAD EYE was to be made based on the requirements of the project that were.

Medium Range (distance) Can be interfaced with a Microcontroller ISM band Abundant Market Availability Cost Effective Easy Implementation

2.4.1- RadioFrequency Keeping in view these key points, we chose the Radio Frequency medium for communication. This was bought from SPARKFUN Electronics. They are off the shelf products so in case of a failure, we can always buy them again and are cheap as well. The best feature of the RF-434 module and our main reason to choose it was its protocol, i.e. UART for serial data. This way our task became simpler as this module was just simply removing the serial data cable for communication to a wireless link and that too without adding any complications. The RF-434 module has the following details for its Transmitter and Receiver respectively: 2.4.1.1 - RF Link transmitter - 434MHz (WRL-08946)

(Figure 2.2- RF Transmitter)

This is a 434MHz Radio Frequency transmitter. It works with the RF Links at 434MHz at either baud rate. Only one 434MHz transmitter will work within the same locality so that could ensure us safety. This wireless data is the easiest to use and the lowest cost RF link available in the market. These components are used to transmit position data, temperature data, and even current program register values wirelessly to the receiver. These modules have up to 500 ft range in open space. The transmitter operates from 2-12V. The higher the Voltage, the greater the range - see range test data in the documents section. These modules are used extensively and have been very impressive with their ease of use and direct interface to a Microcontroller. The theory of operation is very simple. What the transmitter 'sees' on its data pin is what the receiver outputs on its data pin. If you can configure the UART module on a Microcontroller, you have an instant wireless data connection. This is an ASK transmitter module with an output of up to 8mW depending on power supply voltage. The transmitter is based on SAW resonator and accepts digital inputs and makes building RF enabled products very easy. Features: 434 MHz Transmitter Operation 500 Ft. Range - Dependent on Transmitter Power Supply 2400 or 4800bps transfer rate Operating Voltage 2-12 Volts Low cost Extremely small and light weight Supported Antennae: 30-35cm of wire

2.4.1.2- RF Link 2400bps receiver - 434MHz (WRL-08949)

(Figure 2.3- RF Receiver)

This is used as a receiver only for 434 MHz with UART protocol. The following receiver type is good for data rates up to 2400bps and works only with the 434MHz transmitter. Multiple 434MHz receivers can listen to one 434MHz transmitter. This wireless data receiver on RF-434 is the easiest to use along with lowest cost, size and effectiveness. People have used these components to transmit position data, temperature data, and even current program register values wirelessly to the receiver. These modules have up to 500 ft range in open space. The receiver is operated at 5V. The receiver can be directly interfaced with any Microcontroller with its serial input pin. This could be well explained to layman that the RF module can replace the serial wire with the transmitter at the transmitting end and the receiver at the place of collection of data. Thus a wireless link can be created with extreme simplicity of just placing the module. Data rates are limited to 2400bps for this particular receiver. This receiver has a sensitivity of 3uV. It operates from 4.5 to 5.5 volts-DC and has digital output. Therefore it is recommended to use a regulator for its input so that there are safety precautions for the circuitry. The typical sensitivity is -103dbm and the typical current consumption is 3.5mA for 5V operation voltage. Features: 434 MHz Receiver Operation 500 Ft. Range - Dependent on Transmitter Power Supply 2400 bps transfer rate Low cost Extremely small and light weight

Operating Voltage 4.5-5.5 Volts (typically 5V) Supported Antennae: 30-35cm of wire

2.5 -

MICROCONTROLLERS
This is the module of our project in which we have to receive serial data from PC via

an RF Module and generate PWM for motor movements and synchronize them with the mouse movements at PC end. This task is easily achievable by the AVR we chose i.e. ATMEGA16 A microcontroller is a specialized form of microprocessor that is designed to be selfsufficient and cost-effective, where a microprocessor is typically designed to be general purpose (the kind used in a PC). Microcontrollers are frequently found in automobiles, office machines, toys, and appliances. Basic features of a Microcontroller we needed for the completion of DEAD EYE are: Interrupts Timers (for PWM) Serial Input (Asynchronous) I/O Ports

ProcessorsArchitecture 2.5.1- RISC Reduced Instruction Set Computers Fundamental set of instructions More control for users to design their own operations

2.5.2-CISC Reduced Instruction Set Computers Large amount of instructions each carrying different permutation of same operation Functionality of instruction dependant on processor design

Easily available controllers in market are; 1)PIC 2)8051 3) AVR 2.5.3- History Invention wise, 8051 is the forefather (date of birth = 1985) followed by PICs and AVRs. 2.5.4- Difference in Architecture 8051 - 8 bit micro based on CISC architecture (Complex Instruction Set Computer) PIC - 8 bit micro based on RISC architecture ( Reduced Instruction Set Computer) AVR - 8 bit micro based on RISC architecture ( Reduced Instruction Set Computer)

2.5.5- Machine cycles 8051 has 250 instructions which take 1 to 4 machine cycles to executive PIC has nearly 40 instructions which are mostly 4 cycles instructions AVR has 140 instructions which are mostly 1 cycle based 2.5.6- Speed Factor 8051 1 machine cycle in 8051 divides the clock freq. by PIC 1 machine cycle in PIC divides the clock freq by 4 AVR 1 M.C in AVRs divides the clock freq by 1 for e.g. if we use 12 MHz Xtal in all the 3 micros then the speed of execution will be as follows: 8051 = 12 MHz /12 = 1 MHz i.e. = 1 million instructions per second PIC = 12 MHz/4 = 3 MHz i.e. = 3 million instructions per second AVR = 12Mhz/1 = 12 MHz i.e. = 12 Million instructions per second So we can clearly see the that AVR executes more number of instructions per given time and can be considered as the fastest among the 3. 8051 consumes more power than the other two and PIC consumes the least power. Both PIC and AVR are RISC based but their instruction Sets are entirely different.

2.5.7- Programmings Percpective From Programmings (i.e. writing a code) perspective: 8051s are suitable for simpler and less demanding applications, next comes PICs and last comes AVRs.8051 has very powerful instruction set, it has commands which do more complex calculations, it also has got strong arithmetic logic unit which makes computation simple. Whereas PICs and AVRs have simple single instructions and the programmer has to tell (dictate) each and every step to achieve the final outcome.

2.5.8- Examples Normal AVRs do not have Multiplication instruction. 8051 Assembly we can simple use the instruction: MUL A, Bbut in AVR you have to write some 20 lines of code to multiply two registers or values. Similarly division also: in 8051 we have DIV A, B but in AVR again you have to write some 20 lines of code. There is no ADD instruction in AVRs, in 8051 we can Compliment a port bit or a bit variable by using CPL instruction but in AVR we don't have this instruction. In 8051 we can easily access the individual port bits but in AVRs we don't have this freedom. 2.5.9- Cost 8051 is still in use because of its simplicity and popularity and lowest cost.AVRs and PICS are costly and come with many on chip peripherals like: hardware SPI, ADC, I2C, USART, Analog comparator, internal RC oscillator, in-system programmability etc. 2.5.10- Selection of Controller From the above given facts and most importantly our previous experience, we have seen that AVR is more reliable than 8051. So AVR being a modern day controller too was our obvious choice. It is challenging yet a good learning experience. 2.5.11- Low Power CMOS 8-bit AVR

By executing powerful instructions in a single clock cycle, the ATmega16 achieves throughputs approaching 1 MIPS per MHz allowing the system designed to optimize power consumption versus processing speed. Features include: 16 Kbytes of In-System Programmable Flash with Read-While-Write capabilities 512 Bytes EEPROM 1 Kbyte SRAM 32 general-purpose I/O lines 32 general-purpose working registers JTAG interface for Boundary-scan On-chip Debugging support and programming Three flexible Timer/Counters with compare modes Internal and external interrupts A serial programmable USART Byte-oriented Two-wire serial interface An 8-channel 10-bit ADC A programmable Watchdog Timer with Internal Oscillator An SPI serial port

2.6-DC MOTORS
A direct current (DC) motor is a fairly simple electric motor that uses electricity and a magnetic field to produce torque, which turns the motor. At its most simple, a DC motor requires two magnets of opposite polarity and an electric coil, which acts as an electromagnet. The repellent and attractive electromagnetic forces of the magnets provide the torque that causes the DC motor to turn. Magnets are polarized with a positive and a negative side. The attraction between opposite poles and the repulsion of similar poles can easily be felt, even with relatively weak

magnets. A DC motor uses these properties to convert electricity into motion. As the magnets within the DC motor attract and repel one another, the motor turns. A DC motor requires at least one electromagnet. This electromagnet switches the current flow as the motor turns, changing its polarity to keep the motor running. The other magnet or magnets can either be permanent magnets or other electromagnets. Often, the electromagnet is located in the centre of the motor and turns within the permanent magnets, but this arrangement is not necessary. DC motors are used for a variety of purposes, including electric razors, electric car windows, and remote control cars. The simple design and reliability of a DC motor makes it a good choice for many different uses, as well as a fascinating way to study the effects of magnetic fields. Our initial purchase was the following DC Motor: 2.6.1- The Power Window DC Motor These are readily available in the market and have high power handling capabilities.

(Figure 2.4-Power Window Motor) Power Window MotorSpecifications Left and Right versions available Draws 2 amps 80 RPM output Output: 12 tooth 13/16" dia. gear Overall Size: 7 1/2"x 1 1/2"x4"

This wasnt sufficient for our purpose, reason being that it apparently had power handling capabilities but on the same time consumed alot of energy. Moreover, its response at certain frequencies was not good and it also sounded worst at times.

2.6.2- Pittman Geared DC Motor This was a pretty good choice of ours at the middle of our project timeline. These motors are highly powerfull and had more power handling capabilities than the previous choice, more over they consumed very little current and also had a 24VDC ratings. This gave us more room for PWM variations. The gearing of the motor was origional that was good for reliability and its RPM was just as we wanted. There was a rear shaft attached with the ungeared part which was necessary for the encoder to be fitted in.

(Figure 2.5- DC Geared Motor) DC Brush Gearmotor 1.37" Diameter 144.0:1 ratio 500 oz-in Maximum Continuous Torque 3033 oz-in Peak Torque (Note: Peak torque is provided for the purpose of performance calculations only. Operation near, or at, a stalled condition will result in motor and/or gearhead damage). 43 rpm No load speed Torque Constant (Kt) = 5.17 oz-in / amp Voltage Constant (Ke) = 3.82 v/krpm Resistance (R) = 2.96 ohms Inductance = 2.51 mH Rated voltage: 24 volts Encoder: None Length: 4.32" The gearhead will be damaged when operating at the Peak Torque Unit supplied with ball bearing output shaft

2.7- MOTOR CONTROLLER


A motor controller is a device or group of devices that serves to govern in some predetermined manner the performance of an electric motor. A motor controller might include a manual or automatic means for starting and stopping the motor, selecting forward or reverse rotation, selecting and regulating the speed, regulating or limiting the torque, and protecting against overloads and faults. Every electric motor has to have some sort of controller. The motor controller will have differing features and complexity depending on the task that the motor will be performing. The simplest case is a switch to connect a motor to a power source, such as in small appliances or power tools. The switch may be manually operated or may be a relay or contactor connected to some form of a sensor to automatically start and stop the motor. The switch may have several positions to select different connections of the motor. This may allow reduced-voltage starting of the motor, reversing control or selection of multiple speeds. Overload and overcurrent protection may be omitted in very small motor controllers, which rely on the supplying circuit to have overcurrent protection. Small motors may have built-in overload devices to automatically open the circuit on overload. Larger motors have a protective overload relay or temperature sensing relay included in the controller and fuses or circuit breakers for overcurrent protection. An automatic motor controller may also include limit switches or other devices to protect the driven machinery. 2.7.1- Relevant circuit to motor control, The H-Bridge An H bridge is an electronic circuit which enables a voltage to be applied across a load in either direction. These circuits are often used in robotics and other applications to allow DC motors to run forwards and backwards. H bridges are available as integrated circuits, or can be built from discrete components. The name, H-bridge. Sometimes called a "full bridge" the H-bridge is so named because it has four switching elements at the "corners" of the H and the motor forms the cross bar. The basic bridge is shown in the figure to the right. The key fact to note is that there are, in theory, four switching elements within the bridge. These four elements are often called, high side left, high side right, low side right, and low side left (when traversing in clockwise order) as shown below:

(Figure 2.7-H-Bridge) An H bridge is built with four switches (solid-state or mechanical). When the switches S1 and S4 (according to the first figure) are closed (and S2 and S3 are open) a positive voltage will be applied across the motor. By opening S1 and S4 switches and closing S2 and S3 switches, this voltage is reversed, allowing reverse operation of the motor. Using the nomenclature above, the switches S1 and S2 should never be closed at the same time, as this would cause a short circuit on the input voltage source. The same applies to the switches S3 and S4. This condition is known as shoot-through. 2.7.2- Operation

(Figure 2.8-H-Bridge Operation) The two basic states of an H bridge The H-bridge arrangement is generally used to reverse the polarity of the motor, but can also be used to 'brake' the motor, where the motor comes to a sudden stop, as the motor's terminals are shorted, or to let the motor 'free run' to a stop, as the motor is effectively disconnected from the circuit. The following table summarises operation, with S1-S4 corresponding to the diagram above.

S1 1 0 0 0 1

S2 0 1 0 1 0

S3 0 1 0 0 1

S4 1 0 0 1 0

Result Motor moves right Motor moves left Motor free runs Motor brakes Motor brakes

(Table 2.1- H-Bridge Truth Table)

CHAPTER 3

METHODOLOGY
The aim was to accomplish the task using easy and has simple maintenance procedures in case failures are faced. It always is the simplicity that is reached in designing. The designing was indeed tough in the beginning but the advisor/co-advisor was always there to help us.

3.1- SOFTWARE
3.1.1- OpenCV As explained previously the user interface of the Dead Eye uses OpenCV. A camera is mounted on gun so that when gun moves camera moves with it. The user interface consists of a Camera Window that displays live video feedback from camera along with cross hair as shown in the figure.

(Figure 3.1- Camera View mouse tracking)

That camera is aligned so that the centre of crosshair is where the gun is targeting. In the software part each frame is accessed from the camera one at a time. Then using some OpenCV functions a crosshair is drawn at the centre of that window by calculating the dimensions and width of that window. After that there are two modes in the software part. Mouse tracking and objecting 3.1.1.1 - Mouse Tracking After generation of crosshair mouse listener function checks for any mouse movement/click. If any movement or click is detected a mouse call back function is called. This function stores the coordinates of mouse and any click/key pressed at that location and compares them with mouse position in previous frame thus giving us the magnitude of mouse movement. These coordinates are stored in variables and sent through serial port over to the RF transmitter. In case of no mouse movement some data in still transmitted indicating no movement. The data consists of 3 bytes. One indicating X coordinate, one Y coordinate and one indicating any click or key presses. After that the next frame is loaded into memory and process carries on for each frame in a loop. That serial data is received by microcontroller and PWM and encoder signals are generated for each motor accordingly hence moving the gun and camera. 3.1.1.2 - Object Tracking In this mode a crosshair is generated in a similar way. The whole frame is stored in memory in RGB format. The software then divides the whole frame into several 5x5 pixel areas and applies a filer which detects red pixels. If the concentration of red pixels crosses a threshold it marks it as red area and draws a tiny circle around it indicated a detected area. Similarly whole frame is scanned for red pixels. A red object is going to have several red pixel areas as indicated by circles in the figure. Then the centroid of red areas is calculated and X and Y coordinate of that centroid is compared with current crosshair position and sent through serial port, the same way mouse coordinates are sent in mouse tracking mode. The same process is carried out in each frame of the video sending coordinates of the target by

taking feedback from the camera, enabling the gun to autotrack the object in real time.

(Figure 3.2- Camera View object tracking)

3.2- THE ELECTRONICS


Here is an overall schematic of our project, each part is then further explained. This is our actual final implementation and the necessity of DEAD EYE as well.

(Figure 3.3-Final Schematic) 3.2.1- RF Linkage In the initial stages, we were unable to transmit through this module, the reason was mainly that these modules dont come with a proper data sheet and circuit diagrams. Then we had a hit and trial method and finally we were able to transmit serial data wirelessly.

1. The first way was to just use it as the circuit diagrams shown and the pin names suggested. We used a USB-RS-232 converter and tried the circuit and then the signal received was in mill-volts as compared to a 5v transmitted signal. This was certainly no acceptable. 2. The next way was to use a PCs Serial Port and then the same configuration but the results were the same even on a 12V Transmitted Signal that is from a PCs Serial Port. 3. At first in the forums etc. It was mentioned that this module is excellent without an antenna at small ranges and also where there are no hindrances, but we then tried it out with a laptop and a USB-RS232 converter along an antenna and the results were better, we were getting a 1V signal but not as we wanted. The antenna for 433Mhz was of 17Cm in length. 4. The next experiment was indeed refreshing for us and that gave us excellent results i.e around 3.8V Received Signal as compared to a 5V transmitted. Now this was done by a rather simpler approach, i.e an antenna mapped to the module, the serial port from a PC and then an MAX-233 before the Transmitter.

The issue with this configuration was glitches, unreliability, noise increments as the temperature rose and a reset was also required timely. 5. The next was the use of 2 ICs that were a bit expensive as well with the previous configuration. The HT 12E Encoder ICs are series of CMOS LSIs for Remote Control system applications. They are capable of Encoding 12 bit of information which consists of N address bits and 12-N data bits. Each address/data input is externally trinary programmable if bonded out. The HT 12D ICs are series of CMOS LSIs for remote control system applications. This ICs are paired with each other. For proper operation a pair of encoder/decoder with the same number of address and data format should be selected. The Decoder receive the serial address and data from its corresponding decoder, transmitted by a carrier using an RF transmission medium and gives output to the output pins after processing the data. Compatible with RF Modules 433 MHz. 3.2.2- Serial Communication Block As explained in the PC part, the computer sends 3 bytes of data in every frame of video through serial port over an RF link. The microcontroller receives those 3 bytes of data.One byte represents mouse movement in X axis, one for Y axis and one represents clicks/keys pressed. The magnitude of number is directly proportional to movement of mouse in respective axis. For example if the mouse moved 10 pixels in X direction and 2 pixel in Y direction. It will transmit 10,2,0 to the microcontroller. The actual data received it at a rate of 3 Xframratsecond Here is the schematic of the Serial Port along with a MAX233 implemented physically on our final board.

(Figure 3.4- Serial Communication) 3.2.3- Microcontroller The PID Controller was implemented by the microcontroller in DEAD EYE. The block diagram can make things easier to understand that is as follows:

(Figure 3.5-System Diagram) Its easy to get the basic idea of this part that how is the microcontroller acting. Actually the PC sends data via RF link and then the microcontroller generates the desired

PWM and sends it to the H-Bridge which in turn powers the motors. Now the best part is that the encoders send pulses back to the microcontroller as feedback and then the actual motion of the motor is sensed and then again the microcontroller pulses the H-Bridge and in this way an accurate control system is established. 3.2.4- H-Bridge An H-bridge has been well explained in the previous chapters, but there is something new to the one we implemented finally, the limit switches. Now these were needed as we have to limit the motion of our gun to as far as a naked eyes vision can see. If a switch doest short the ends, the respective side of the H-Bridge would not find a groud and hence limiting its motion to that side. The limit switches were fixed physically at locations so that the mechanical structure isnt affected in case of false PWM Generation. Therefore the normally closed switches and the final H-Bridge is shown below

(Figure 3.6- Final H-Bridge) 3.2.5- Optical Encoders (Feedback from motors) A digital optical encoder is a device that converts motion into a sequence of digital pulses. By counting a single bit or by decoding a set of bits, the pulses can be converted to relative or absolute position measurements. Encoders have both linear and rotary configurations, but the most common type is rotary. Rotary encoders are manufactured in two basic forms: the absolute encoder where a unique digital word corresponds to each rotational position of the shaft, and the incremental encoder, which produces digital pulses as the shaft rotates, allowing measurement of relative position of shaft. Most rotary encoders are composed of a glass or plastic code disk with a photographically deposited radial pattern organized in tracks. As radial lines in each track interrupt the beam between a photo-emitterdetector pair, digital pulses are produced. The most popular type of encoder is the optical encoder, which consists of a rotating disk, a light source, and a photo-detector (light sensor). The disk, which is mounted on the rotating shaft, has coded patterns of opaque and transparent sectors. As the disk rotates, these patterns interrupt the light emitted onto the photodetector, generating a digital or pulse signal output. A similar disk was mounted on the rear axle of each motor. Its shown in the figure below and similar to the approach we used in our structure.

(Figure 3.7- Optical Encoder)

We designed the encoder ourselves using a (commonly known as) U Shape Infrared Sensor in series with a resistor and a Pull-UP resistor. Below is its PCB Layout :

(Figure 3.8- Encoder PCB)

3.3- THE MECHANICS THE 1st Protype:


As mentioned in the previous chapter, we were using power window DC motors and therefore we made a simple and light mechanical assembly for the project. The material used was ACRYLIC and that was as it had DIY capabilities. It had a low height base and a strong Y-Axis as well. But due to the change in motor selections, the whole mechanical structure had to be revised.

(Figure 3.9-1st Mechanical Prototype)

THE FINAL STRUCTURE:


There was a lot to be done as the time lines were getting tougher and tougher but we had to cope with it. As soon as the motors were bought and tested thoroughly, we realized that a strong and long lasting mechanical structure shall be designed that has the capabilities to work further and beyond this project as well. Therefore we shifted to metal and there was Iron, Steel, Aluminium, Cast Iron, Plastics and all sorts of nuts and bolts used for the completion.

3.3.1- The Base This design was indeed a challenge in itself but it worked pretty well. The base has the ability to rotate 360 degrees clockwise and counter clockwise. It can be limited to design it for any specific application. Therefore we limited it to 180 degrees as that is what a human eye is capable of.This was designed using simple mechanics and the structure could be repaired as well (if anything goes wrong). That means that it was thought before for errors.

The first step was to create a base sheet .3 inch wide of iron in dimensions of 20inch by 20inch. There were wheels below and handles on it for easy carriage of the structure while working on it. This was chosen so that weldings could be done on it later. Then the motor holding plate along with the rotating pulley was made out of cast iron. After this the appropriate height was given to the plate and then wheels to be equal in height to the pulley were lifted using Steel Bars and all this is illustrated by the picture below:

(Figure 3.9- Mechanical Base) 3.3.1- The Top Part The next step became to feel critical as there was further less time remaining. Then we first made an aluminium sheet of 19 inch in diameter. Then a steel plate of 3feet by 1 feet was taken. 1 feet on each side was bended at right angles and then it was cut in between for weight reduction. Its illustrated well in the picture. Then the tops ends of the bended plate were fitted with ball bearings and then an iron bar was fitted in it for rotation.

(Figure 3.10- Mechanical Top)

Finally the motor and the gun was mounted and the structure was complete. This was done well in time.

(Figure 3.11- Implemented Mechanical Assembly)

CHAPTER 4 RESULTS

MILESTONES:
Our targets were to:

1. Get the correct input from camera to computer 2. To perform Differential method on the frames to generate encrypted code for the gun to move. 3. The code has to be received by the controller via RF LINK. 4. To generate PWM so that we can synchronize the mouse movement and the gun movement. 5. The PWM generated has to be delivered to Gun Assembly through H-BRIDGE. 6. To make an Assembly that can hold the gun and to place motors to achieve best possible results for the prototype. 7. Image processing/object tracking.

ACHIEVED MILESTONES:

4.1- CAMERA INPUT (PC PART)


As explained previously the user interface of the Dead Eye uses OpenCV. A wireless camera is mounted on gun so that when gun moves camera moves with it. The user interface consists of a Camera Window that displays live video feedback from camera along with cross hair as shown in the figure. We were able to achieve this GUI and this milestone

4.2- TO GENERATE CODE FROM FEEDBACK CAMERA


That camera is aligned so that the centre of crosshair is where the gun is targeting. In the software part each frame is accessed from the camera one at a time. Then OpenCV shows a crosshair at the centre of that window by calculating the dimensions and width of that

window. After that a mouse listener function checks for any mouse movement/click. If any movement or click is detected a mouse call back function is called. This function stores the coordinates of mouse and any click/key pressed at that location and compares them with mouse position in previous frame thus giving us the magnitude of mouse movement. These coordinates are stored in variables and sent through serial port over to the RF transmitter. In case of no mouse movement some data in still transmitted indicating no movement. The data consists of 3 bytes. One indicating X coordinate, one Y coordinate and one indicating any click or key presses. After that the next frame is loaded into memory and process carries on for each frame in a loop. That serial data is received by microcontroller and PWM signals are generated for each motor accordingly hence moving the gun and camera. We were able to correctly execute this and achieve this milestone

4.3- RF LINK
These were the best possible results achieved from our RF Linkage out of all experiments we performed.

(Figure 4.1- RF Oscilloscope Result)

4.4- MICRO CONTROLLER PART:


3 bytes of data was received by the controller from the RF Receiver. First 8 bit data is for the gun movement in X-AXIS. For that a PWM has to be generated, we used its internal registers and its predefined functionalities to do so, it was simple we had to place the input in its OCR register , which has its function to generate PWM corresponding to any 8 bit value placed in it. Then the Prescalar operations were performed to achieve PWM of our desired specifications. Same was done for the Y-AXIS.

Then the feedback from the encoders was incorporated and an accurate PID controller was implemented. This incread our accuracy and response time as well.

4.5- MOTOR MOVEMENTS


To give pulses to the motor and their widths defining the amount rotations i.e. the distance covered. This could not be achieved without H BRIDGE to control the movements in both directions. There are two motors one for X-AXIS and the other for Y-AXIS. We were able to complete the movement of our mechanical assembly correctly synchronized with the mouse movements. This was further tuned by the use of encoders for feedback. The slits were counted and that told us of the actual motion of the motors and the desired motion and errors, delay and inaccuracy was decreased to a great extent.

4.6- OBJECT TRACKING


Successful object tracking was achieved by using image processing techniques implemented at computer end using OpenCV. The gun is able to auto track and target any red object in real time.

CHAPTER 5 DISCUSSIONS
5.1- MATHEMATICAL MODELLING: THE SERVOMECHANISM
A servomechanism, or servo, is an automatic device that uses error-sensing negative feedback to correct the performance of a mechanism. The term correctly applies only to systems where the feedback or error-correction signals help control mechanical position or other parameters. For example, an automotive power window control is not a servomechanism, as there is no automatic feedback that controls positionthe operator does this by observation. By contrast the car's cruise control uses closed loop feedback, which classifies it as a servomechanism. It is illustrated in the figure below:

(Figure 5.1- Servosystem Mathematics) H-Bridge: It is the power amplifier used to power the DC motors. As we have used two identical servo systems, their control is implemented separately. Transfer Function of the H-Bridge is given as: Ts=KaTas+1 Where, Ka is the voltage gain of the amplifier & (Tas+ 1) is the log due to low pass filters of all sorts in the Voltage Amplifier DC-Servo Motors:

Its transfer function is as follows: Ts=1Ke(Tes+1)(Tms+1) Where, Te= Electrical Time Constant of the motor Tm= Mechanical Time Constant of the motor Generally Tm is greater than the given Ke if the voltage is kept constant. From the datasheet of our motors used: Te=0.85 Tm=9.3 Ke=3.82

Encoder: A counter is required to monitor the output of the encoder. The encoder-counter is modelled as an integrator: Ts=KencS Where Kenc is the resolution of the encoder. Let us now calculate it: Number of Slits=24 Total Rotation= 360 Degrees Gearing Ratio= 144.0 : 1 So ResolutionKenc=36024*144= 0.1041 Degrees = 6.084 Minutes

Controller: Transfer function of the PID Controller is as follows: Ts=Kp+Kis+Kds

Now

putting

all

these

into

the

basic

form:

(Figure 5.1- Servosystem Mathematics Contd..)

TRANSFER FUNCTION OF OUR SERVO-SYSTEM:


Now we calculate our transfer function using the simple feedback formula that comes out to be: Ts=ss+1Tas+1Tes+1TmTaTeTmKess+1Tas+1Tes+1Tm+KaKenc(Kp+Kis+Kds)

Chapter 6 CONCLUSION

By the grace of Allah, we successfully completed our project by the help of our supervisors, faculty members and lab assistants. Our batch was very helpful and supportive during the whole project and was there to help us in all possible ways. As mentioned in the previous chapters, all the milestones were achieved successfully and the gun movements were synchronised with mouse movements and object movement in object tracking mode. The RF link was well established at low baud rates but that was once the most challenging part of our project. The gun moves excellent in both the axis of rotation and can be a good replace of human eyes monitoring at security points. The accuracy was well above expectations of a little more than 6 Minutes. Open CV was a very good choice over MATLAB reason being its designed for Faster and real time applications It is designed for imaging and computer vision It offers much greater performance and frame rates for video streaming

The AVR being the modern controller showed up excellent performance and it was indeed easier to program as we were hands on with C++ programming already. Encoders for feedback from the motors were the backbone of our implementation of the Proportional controller. That was the point where we reduced our errors and then finally achieved excellent results. The ideology of DEAD EYE was for the betterment of law enforcing agencies of Pakistan. The results shown and explained shoe that these can be mounted on military vehicles, security check points, guarding areas and intense security places where earlier there were guards risking their lives. Improving this system can make it so important for our defence organisations that it can be useful in navy ships and even helicopters. We want our nation to progress as other countries are advancing technologically. South Koreans and Americans have already implemented such ideas and have aided a lot to their soldiers by the use of autonomous armoury.

Such systems are quite necessary for the implementation of any autonomous project. We were successful in proving the proof of concept and also proving a platform and idea for future engineers to work on.

Chapter 7 RECOMMENDATIONS

We would like to add up some advice for the future engineers to just keep these in mind so that they do not face the problems we did. In this way, they may work faster and maybe are implement something much better than we did. That is the way technology evolves and new products are created: 1. Students should be aided to get high quality equipment for their projects and not the low quality, unreliable and untested components from the market. At least there should be a system to help students in their purchase and also feedback on various vendors. 2. There can be a system in this campus to aid students to import components under the university import and custom policies so that students can save a lot of their money. 3. An in campus mechanical workshop should be formed for the aid of students to save time and last moment modifications. 4. The modules bought by the students are not up to the exact specifications that are mentioned in forums and on the websites of the suppliers and producers. There should be availability of high end sensors and modules and if possible military grade products so that students can achieve what they desire and have worked hard for.

You might also like