ON
Submitted by:DASHMEET KAUR(10413202810) NAMRATA (12513202810) ARNAV MENDIRATTA (13013202810) DAMANJEET SINGH MAAN (15213202810)
Guru Tegh Bahadur Institute of Technology G-8 Area, Rajouri Garden Affiliated to Guru Gobind Singh Indraprastha University, Dwarka New Delhi Batch 2010 2014
DECLARATION
We hereby declare that all work presented in the dissertation entitled AIR GESTURE CONTROLLED ROVER in the partial fulfilment of requirement for the award of the degree of Bachelor of Technology in Electronics and Communication, Guru Tegh Bahadur Institute of Technology, affiliated to Guru Gobind singh Indraprasth University is an authentic record of our own work carried out under the guidance of our mentor, Mr. Mukesh Sahu and Mr. Kalyan Singh.
Date:
NAMRATA (12513202810)
CERTIFICATE
This is to certify that the report entitled AIR GESTURE CONTROLLED ROVER submitted by Dashmeet Kaur (10413202810), Namrata (12513202810), Arnav Mendiratta (13013202810), Damanjeet Singh Maan (15213202810) in the partial fulfilment of the requirement for the award of the degree of Bachelor of Technology in Electronics and Communications, Guru Tegh Bahadur Institute of Technology, is the record of students own work carried out by them under my supervision.The matter embodied in this report is original and has not been submitted for the award of any degree.
Date:
ACKNOWLEDGEMENT
It is a pleasure to acknowledge many people who knowingly and unwittingly helped us to complete our report. First of all we thank God for all the blessings, which carried us through all these days. We are particularly indebted to our college, Guru Tegh Bahadur Institute of Technology which inculcated in us, utmost respect for human values and groomed us in the field of software Technology to take on the challenges of competitive world.We would like to express our regards to our Mentors, Mr.Mukesh Sahu and Mr.Kalyan Singh for their constant encouragement and support. We would also like to express our immense gratitude towards them for providing the invaluable knowledge, time & guidance during the completion of this report.
Mr.Mukesh Sahu
Mr.Kalyan Singh
3
3 3 3 5 7 7 8 11 13 15 18 20 20 20 20 20
2. About HARDWARE
2.1 MSPEXP430G2 2.1.1 Features 2.1.2 MSP430 Architecture 2.1.3 Pin Description and Terminal Functions 2.1.4MSP430 Universal Synchronous Asynchronous Receive/Transmit (USART) Communication Interface 2.2 L293D Motor Control H-Bridge IC 2.3 MAX232 Serial Communication IC 2.4 USB to Serial Convertor 2.5 Serial Port 2.6 Webcam
22
22 23 24 24 27 32 34 37 38 40
3. Source Code
3.1 For MATLAB 3.2 For IAR Embedded Workbench
41
41 44
4. Conclusion 5. References
48 49
LIST OF FIGURES
Fig 1: MATLAB Welcome Screen Fig 2: MATLAB Tool Box Showing current directory where files are being saved Fig 3: MATLAB Help Fig 4: MATLAB Command Window Fig 5: Types of Images: (a) A Binary Image (b) A Grayscale Image (c) A Color Image Fig 6: Process Overview Fig 7: A test program in MATLAB Fig 8(a): Sample Image for detection Fig 8(b): Green Color detected in sample image Filteration Fig 9: A sample image for Filteration Fig 9(a): Output of sample image when the program is executed Fig 9(b): Filtered image Fig 9(c): Filtered image Fig 10: Snapshot of MATLAB window showing Camera Specifications Fig 11: GUIDE Quick Start Box Fig 12: Explanation of layout of the GUI Template Fig 13: Using Push Button in GUI Fig 14: The program for Push Buttons created in GUI Fig 15: TI MSP430G2 Launchpad Fig 16: TI MSP430G2x53 Architecture Block Diagram Fig 17: Pin Summary for 20 pin MSP430 Devices Fig 18(a): Connecting UART Fig 18(b): UART Bits Fig 19: The concept of H-Bridge Fig 20: A complete Schematic for L293D IC Fig 21: MAX232 Driver/Receiver Fig 22: MAX232(A) DIP Package Fig 23: DB9 Male Connector Fig 24: RS232 Connections Fig 25: Screenshot of Device Manager showing Serial Port detected at COM1 Fig 26: Screenshot of GUI in working project Fig 27: Air Gesture Controlled Rover 3 4 4 5 6 7 8 9 10 10 11 12 12 13 16 16 17 17 22 24 24 28 28 32 33 34 35 38 39 39 45 48
Page
ABSTRACT
This project consists of a PC, a microcontroller that collects the data from the PC through MATLAB and control the robot to move in different directions. The robot is fully controlled by the PC and the commands from the PC are received by the microcontroller using UART peripheral of microcontroller. Image processing is generated using MATLAB (MATLAB R2010a version is used). For image processing, the webcam captures the image and the image is viewed over the screen. The information from image is manipulated; the data is transmitted from PC to microcontroller through serial interfacing. The robot's hardware is a simple drive using two 200RPM DC gear motors mounted on a metal chassis with a front castor wheel. On the back motors, plastic wheels are mounted. The motor to drive the circuit uses L293D IC which has H bridge circuit to move the robot.
Page
Page
Fig 2: MATLAB Tool Box Showing current directory where files are being saved
Workspace: It displays the list of the variables defined by you in the current session of MATLAB. The Menu bar and Toolbar: The toolbar has buttons for common operations like cut, copy, paste, undo, redo. The most important button here is the HELP button. It opens the MATLAB help window which has looks somewhat like this:
Page
User can get the details of any MATLAB command/function here and many demos of some commonly used applications. Locate the four tabs: Contents, Index, Search Results and Demos on the left. User will then get the complete details of the function like its use, syntax, as well as few examples on how to use it.
Fig 5(a)
Fig 5(b)
Fig 5(c) Fig 5: Types of Images: (a) A Binary Image (b) A Grayscale Image (c) A Color Image
Representation of an Image in MATLAB An image in MATLAB is stored as a 2D matrix (of size mxmxn) where each element of the matrix represents the intensity of light/color of that particular pixel. Hence, for a binary image, the value of each element of the matrix is either 0 or 1 and for a grayscale image each value lies between 0 and 255. A color image is stored as an mxnx3 matrix where each element is the RGB value of that particular pixel (hence its a 3D matrix). It can be considered as three 2D matrices for red, green and blue intensities.
Page
Once detected, the program replaces the picture of the band with a centroid. This enables to treat it as a point sourced object. Now, the MATLAB program will detect the movement of this centroid for a subsequent number of frames. This number of frames to be captured can be changed according to the processor speed and camera quality (We have used 10 frames per trigger).
Page
Page
Here we have saved the m-file by the name test.m. Now as you type >>test in MATLAB command window, all the above commands will execute.
Fig 8(a): Sample Image for detection So, you first read the image and then call the function by typing in the command window >> I=imread('shapes.bmp'); >>[img, n]=green(I); >>n n= 28753 >>imshow(img);
Page Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Fig 8(b): Green Color detected in sample image As you can see, this is a binary image with white pixels at those coordinates which were green in input image. Consider the following picture, which is processed using Matlab commands given as follows:
Page
So, we use the same function with the main conditional statement changed as: functionbw=red(im) [m,n,t]=size(im); bw=zeros(m,n); for i=1:m for j=1:n
10
1.1.7 Removing Noise The binary image obtained above has quite a lot of noise. There is a need to smoothen the edges, remove the tiny dots scattered here and there so that at last you have some countable number of objects to work upon. There are several functions available in MATLAB to remove noise in an Image. Some of them are (bw is the above binary image): bwconncomp(BW): This returns the connected components CC found in BW. The binary image BW can have any dimension. CC is a structure with four fields. bwconncomp uses a default connectivity of 8 for two dimensions and 26 for three dimensions CC = bwconncomp(BW,conn) specifies the desired connectivity for the connected components. conn can have 4, 8, 6,18 or 26 value.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
11
imfill(): Remove holes from the image Holes are background pixels surrounded by foreground (image) pixels. >>bw=imfill(bw,'holes'); >>imshow(bw);
Fig 9 (c): Filtered Image Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
12
The use of making a binary file: In most of problem statements of robotics based on image processing, we are required to find the centroid, area, and no. of objects of a particular colour. MATLAB has in-built functions for these tasks which operate on binary images only. Hence we create binary images corresponding to different colours. For example, in the problem statement Brooklyn Builder of Techkriti10, the image from the top (overhead camera) looks somewhat like (again its an ideal image; the real one will be far different and full of noise) 1.1.8 Working in Real Time Getting Hardware information Till now we have been working on images already saved on our computer. But in actual practice, we need to work in real time, i.e., we need to take images continuously from the current environment using a webcam and then process them. Hence, the Image Acquisition toolbox of MATLAB provides support in this regard. To start with working in real time, you must have a functional USB webcam connected to your PC and its driver installed. MATLAB has built-in adaptors for accessing these devices. An adaptor is a software that MATLAB uses to communicate with an image acquisition device. You can check if the support is available for your camera in MATLAB by typing the following: >>imaqhwinfo % stands for image acquisition hardware info >>cam=imaqhwinfo; >>cam.InstalledAdaptors
Fig 10: Snapshot of MATLAB window showing Camera Specifications Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
13
Most probably you would have 'winvideo' installed and use that. If it is not available, use whichever adapter is shown by imaqhwinfo If you are using a laptop, you may also have a webcam in it. So note down the DeviceName shown as above. If it is not the USB webcam, then probably DeviceID = 2 should work. Hence, type >>dev_info = imaqhwinfo('winvideo',2) *Note:From now onwards, I will refer Adapter by winvideo and DeviceID by 1. You must check yourself what is available on your system and change the commands described further accordingly. Note down the supported formats by your camera as >>dev_info = imaqhwinfo('winvideo',1); >>dev_info.SupportedFormats
Page
14
There are 5 supported formats in my camera. The numbers (160x120, 176x144.) denote the size of the image to be captured by the camera. Previewing video One can preview the video captured by the camera by defining an object (say by the name vid) and associate it with the device. >>vid=videoinput('winvideo',1, 'YUY2_160x120') or >>vid=videoinput('winvideo',1, 'RGB24_160x120') % depends on availability It should give information somewhat like this
Page
15
From the GUIDE Quick Start dialog box, one can perform the following tasks: Create a new GUI from one of the GUIDE templatesprebuilt GUIs that you can modify for your own purposes. Open an existing GUI.
The Layout Editor When you open a GUI in GUIDE, it is displayed in the Layout Editor, which is the control panel for all of the GUIDE tools. The following figure shows the Layout Editor with a blank GUI template.
Fig 12: Explanation of layout of the GUI Template Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
16
User can lay out their GUI by dragging components, such as panels, push buttons, pop-up menus, or axes, from the component palette, at the left side of the Layout Editor, into the layout area. For example, if user drag three push buttons into the layout area, it might look like this. The illustration also shows how the GUIDE tool palette looks when user set a preference to show component names, as described above. User can also use the Layout Editor (along with the Toolbar Editor and Icon Editor) to create menus and toolbars, create and modify tool icons, and set basic properties of the GUI components.
Fig 14: The program for Push Buttons created in GUI Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
17
Good Idea To Set: User's device will work without setting these but user can set these to make their life easy later. Tag:The tag is like giving the serial port object a nickname.If have a few different serial ports open this a good way to keep track of them.Example, serialPort is configured to talk with a garmin GPS. set(serialPort, 'tag', 'GarminGPS') TimeOut: If user try to read data from the serial port and there is no data in the buffer matlab will keep trying to read for "Timeout" seconds (default 10 sec): get(serialPort, 'Timeout') ans = 10
Page
This might really slow down the code. There are ways around this, but if there is no data there user probably don't want to sit there for 10 seconds, so consider making it smaller. On the other hand, it does
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
18
Closing Serial Port Objects Concepts When user is done with a serial port object it doesn't go away. Also, closing it, deleting it from memory and clearing it from the workspace are three separate actions. Example Code For technical reasons user have to use this syntax to properly get rid of it: delete(serialPort_new) clearserialPort_new
Page
19
Page
20
Page
21
Page
22
Page
23
Page
24
I/O NA
DESCRIPTION
A0 CA0 3
P1.1/ TA0.0/ UCA0RXD/
I/O
I/O
USCI_A0 SPI mode: slave data out/master in ADC10 analog input A1(1) Comparator_A+, CA1 input I/O
General-purpose digital I/O pin Timer0_A, capture: CCI1A input, compare: Out1 output
USCI_A0 UART mode: transmit data output USCI_A0 SPI mode: slave data in/master out ADC10 analog input A2(1) Comparator_A+, CA2 input
General-purpose digital I/O pin
I/O
ADC10, conversion clock output(1) ADC10 analog input A3(1) ADC10 negative reference voltage (1) Comparator_A+, CA3 input Comparator_A+, output
General-purpose digital I/O pin
I/O
SMCLK signal output USCI_B0 slave transmit enable USCI_A0 clock input/output ADC10 analog input A4(1) ADC10 positive reference voltage(1) Comparator_A+, CA4 input JTAG test clock, input terminal for device programming and test
P1.5/
Page
25
P2.0/
TA1.0
P2.1/ I/O
TA1.1
10
P2.2/ I/O
TA1.1 11
P2.3/ I/O
TA1.0
12 13
P2.4/
TA1.2
P2.5/
I/O
TA1.2
I/O
14
P1.6/
Page
Timer0_A, compare: Out1 output ADC10 analog input A6(1) Comparator_A+, CA6 input USCI_B0 SPI mode: slave out master in USCI_B0 I2C mode: SCL I2C clock JTAG test data input or test clock input during
26
15
P1.7/
I/O
ADC10 analog input A7(1) Comparator_A+, CA7 input Comparator_A+, output USCI_B0 SPI mode: slave in master out USCI_B0 I2C mode: SDA I2C data JTAG test data output terminal or test data input during programming
16
RST/
Reset
NMI/ SBWTDIO I 17
TEST/
Nonmaskable interrupt input Spy-Bi-Wire test data input/output during programming and test
Selects test mode for JTAG pins on Port 1.
SBWTCK 18
XOUT/
P2.7 19
XIN/
I/O
P2.6/ TA0.1 20
DVSS
I/O
NA
2.1.4MSP430 Universal Synchronous Asynchronous Receive/Transmit(USART) Communication Interface The universal synchronous/asynchronous receive/transmit communicationinterface of the MSP430 family can operate in two different modes: synchronousand asynchronous.MSP430 has Universal Serial Communication Interface (USCI) Module also for serial communication. Depending on derivative of the MSP430 we can either use USCI or USART and enable one of the modes of operation such as UART, SPI, I2C, etc. Using UART UART is simple to connect and it uses 2 lines: TX (Transmit) and RX (Receive). No clock isrequired because its asynchronous. RS232 is a common connection between PC and devices, and it can be easily converted to RS232 using a level converter. Another popular solution is to connect the UART of the MSP430 to a USB to UART converter when interfaced to another module that uses UART, you will need to cross connect the lines.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
27
Fig18(b):UART Bits UART sends bit serially, one bit after the other, as opposed to parallel. However user dont usually send individual bits because of the fact that they convey little information by themselves. Rather, the UART uses a buffer that is one byte (8 bits) long to which information is written. On a deeper level, the module sends more than just the byte a user places in the buffer. UART typically sends a start bit, seven or eight data bits, an even/odd/no parity bit, an address bit (address-bit mode), and one or two stop bits. The extra bits depend on the configuration of the UART module, but the most common configuration is 8 data bits, one stop bit and no parity. Extra bits that are sent are ultimately discarded and not stored at the destination buffer. The result of the parity check is however available. Figure 18(b) shows the bit arrangement in the MSP430s UART Module. Configuring the UART Before user can use the UART successfully to send data, both the host computer and the UART Module must be configured. Because the communication is asynchronous, if the two are not configured correctly then errors will occur because the interpretation of the timing of the bits will be off. To better explain how to configure the UART module, the following code is used as an example.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
28
Page
29
Page
30
Page
31
AIR GESTURE CONTROLLED ROVER (AGCRov) 2.2 L293D Motor Control H-Bridge IC
The first thing comes to mind when making a robot is making the robot move on the ground. And there are always two options in front of the designer whether to use a DC motor or a stepper motor. When it comes to speed, weight, size, cost... DC motors are always preferred over stepper motors. There are many things which user can do with your DC motor when interfaced with a microcontroller. For example user can control the speed of motor, user can control the direction of rotation, user can also do encoding of the rotation made by DC motor i.e. keeping track of how many turns are made by their motors etc. So one can see DC motors are no less than a stepper motor. Usually H-bridge is preferred way of interfacing a DC motor. These days many IC manufacturers have H-bridge motor drivers available in the market like L293D is most used H-Bridge driver IC. H-bridge can also be made with the help of transistors and MOSFETs etc. rather of being cheap, they only increase the size of the design board, which is sometimes not required so using a small 16 pin IC is preferred for this purpose. The name "H-Bridge" is derived from the actual shape of the switching circuit which control the motion of the motor. It is also known as "Full Bridge". Basically there are four switching elements in the Hbridge as shown in the figure below.
In figure above there are four switching elements named as "High side left", "High side right", "Low side right", "Low side left". When these switches are turned on in pairs motor changes its direction accor15dingly. Like, if we switch on High side left and Low side right then motor rotate in forward directio16n, as current flows from Power supply through the motor coil goes to ground via switch low side right.17 Similarly, when we switch on low side left and high side right, the current flows in opposite direction and motor rotates in backward direction.
Page
32
Page
33
The MAX232 from Maxim was the first IC which in one package contains the necessary drivers (two) and receivers (also two), to adapt the RS-232 signal voltage levels to TTL logic. It became popular, because it just needs one voltage (+5V) and generates the necessary RS-232 voltage levels (approx. 10V and +10V) internally. This greatly simplified the design of circuitry. Circuitry designers no longer need to design and build a power supply with three voltages (e.g. -12V, +5V, and +12V), but could just provide one +5V power supply, e.g. with the help of a simple 78x05 voltage regulator. The MAX232 has a successor, the MAX232A. The ICs are almost identical, however, the MAX232A is much more often used (and easier to get) than the original MAX232, and the MAX232A only needs external capacitors 1/10th thecapacity of what the original MAX232 needs. MAX232(A) is just a driver/receiver. It does not generate the necessary RS-232 sequence of marks and spaces with the right timing, it does not decode the RS-232 signal, it does not provide a serial/parallel conversion. All it does is to convert signal voltage levels. Generating serial data with the right timing and decoding serial data has to be done by additional circuitry, e.g. by a 16550 UART or one of these small micro controllers.
Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
Page
34
Pin Description Table for MAX232(A) DIP Package Pin Layout PIN Name Purpose 1 2 3 4 5 6 7 8 C1+ V+ C1C2+ C2V+ connector for capacitor C1 output of voltage pump - connector for capacitor C1 + connector for capacitor C2 - connector for capacitor C2 output of voltage pump / inverter Signal Voltage Capacitor Value MAX232 Capacitor Value MAX232A 100nF 100nF to VCC 100nF 100nF 100nF 100nF to GND
capacitor should stand at 1F least 16V +10V, capacitor should stand at least 16V 1F to VCC
capacitor should stand at 1F least 16V capacitor should stand at 1F least 16V capacitor should stand at 1F least 16V -10V, capacitor should stand at least 16V RS-232 RS-232 1F to GND
Page
R2in
Receiver 2 input
35
V+(2) is also connected to VCC via a capacitor (C3). V-(6) is connected to GND via a capacitor (C4). And GND(15) and VCC(16) are also connected by a capacitor (C5), as close as possible to the pins. A Typical Application The MAX232(A) has two receivers (converts from RS-232 to TTL voltage levels) and two drivers (converts from TTL logic to RS-232 voltage levels). This means only two of the RS-232 signals can be converted in each direction. Typically a pair of a driver/receiver of the MAX232 is used for
TX and RX MAX232 to RS232 DB9 Connection as a DCE MAX232 Pin No. MAX232 Pin Name Signal Voltage DB9 Pin 7 8 9 10 11 12 13 14 15 T2out R2in R2out T2in T1in R1out R1in T1out GND RTS CTS CTS RTS TX RX TX RX GND RS-232 8 RS-232 7 TTL TTL TTL TTL n/a n/a n/a n/a
RS-232 3 RS-232 2 0 5
Page
36
In addition one can directly wire DTR (DB9 pin 4) to DSR (DB9 pin 6) without going through any circuitry. This gives automatic (brain dead) DSR acknowledgment of an incoming DTR signal. Sometimes pin 6 of the MAX232 is hard wired to DCD (DB9 pin 1). This is not recommended. Pin 6 is the raw output of the voltage pump and inverter for the -10V voltage. Drawing currents from the pin leads to a rapid breakdown of the voltage, and as a consequence to a breakdown of the output voltage of the two RS-232 drivers. It is better to use software which doesn't care about DCD, but does hardwarehandshaking via CTS/RTS only. The circuitry is completed by connecting five capacitors to the IC as it follows. The MAX232 needs 1.0F capacitors, the MAX232A needs 0.1F capacitors. MAX232 clones show similar differences. It is recommended to consult the corresponding data sheet. At least 16V capacitor types should be used. The first pin is always where the plus pole of the capacitor should be connected to. 2.4 USB <-> RS-232 Converter With the rise of mobile phones so called data cables for these phones have also become popular. These are cables to connect the mobile phone to a serial interface of a computer. The interesting thing is that modern mobile phones work with 3.3V logic, and older phones with 5V logic on their data buses. So these data cables must and do convert the phone logic voltage levels to and from RS232 voltage levels. No-name data cables have become rather cheap (as opposite to original phone-brand data cables). The cheap cables with their voltage converters can be used as an alternative to home-made MAX232-based circuitry. The advantage is that the cables occupy much less space (the converter is usually inside the RS232 plug). Such a cable also saves the effort to solder a circuitry board. Another advantage, which can also be a disadvantage of such a data cable is that they usually take their power from the RS232 connector. This saves an external power supply, but can also cause problems, because the RS232 interface is not designed to power some logic and the DTE might not provide enough power. Another disadvantage is that many of these cables just support RX and TX (one receiver, one driver), and not two drivers/receivers as the MAX232. So there is no hardware handshake possible. Finally, when using such a cable it should be made sure that they convert to the desired voltage (3.3V or 5V). USB to Serial interface cables often have two components: a USB transceiver that outputs serial data; and a voltage shifter to produce standards-compliant RS-232 voltages. It is often possible to throw away (ignore, desolder, cut-out) the USB part of these cables, connect an external 5V power source (or abuse the RS-232 interface) to replace the power coming from the USB bus and to just use the RS-232 levelshifter. All this is probably as much work as using a MAX232A, although you get one RS-232 connector for free. On considering a USB cable, it is also worthwhile to consider using USB directly, instead of RS-232. Many USB transceiver chips can be integrated directly into circuits, eliminating the need for voltageshifting components. Parts such as the FTDI FT232BM even have an input allowing designers to select 5V or 3.3V output levels. Most of these USB transceiver chips are available as surface-mount components only. But some vendors offer DIP-sized preassembled modules, often at competitive prices, and often with free or cheap drivers or driver developmentenvironments.
Page
37
Page
38
*Note: The Tx and Rx shown in above figure (pins 11 and 12 of MAX232) are the Tx and Rx of microcontroller. For example, PD0 and PD1 in Atmega16. For controlling the robot via serial port, the microcontroller is connected to the motor driver ICs which control the right and left motors. After processing the image, and deciding the motion of the robot, some predefined codewords (lets say A=Left, B=Right, C=Forward, D=Backward, E=Pick object, etc.) are sent to microcontroller through the serial port. First you must check from the Device Manager of your system (My Computer->System Properties>Device Manager->Ports) that what the name is given to the serial port of your computer (or the virtual serial port of USB to Serial Converter). Lets say it is COM1.
Fig 25: Screenshot of Device Manager showing Serial Port detected at COM1
Page
39
Page
40
Page
% --- Executes just before Minortest1 is made visible. function Minortest1_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure
41
% Choose default command line output for Minortest1 handles.output = hObject; axes(handles.axes1); imshow('blank.jpg'); axes(handles.axes2); imshow('blank.jpg'); set(handles.edit1,'String',''); handles.t=0; handles.vid=videoinput('winvideo',1,'YUY2_1280x720'); set(handles.vid,'ReturnedcolorSpace','rgb'); set(handles.vid,'FramesPerTrigger',1); set(handles.vid,'TriggerRepeat',inf); triggerconfig(handles.vid,'manual'); % Update handles structure guidata(hObject, handles); % UIWAIT makes Minortest1 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Minortest1_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in Start. functionStart_Callback(hObject, eventdata, handles) % hObject handle to Start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) start(handles.vid); for i=1:20 trigger(handles.vid); handles.im=getdata(handles.vid,1); axes(handles.axes1); imshow(handles.im); end guidata(hObject, handles); % --- Executes on button press in Trigger. functionTrigger_Callback(hObject, eventdata, handles) % hObject handle to Trigger (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [x y k]=impixel(handles.im);
Page
42
Page
43
function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc&&isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
Page
44
3.2 FOR IAR EMBEDDED WORKBENCH #include "msp430g2553.h" #define UART_TXD 0x02 #define UART_RXD 0x04 // Hardware-related definitions // TXD on P1.1 (Timer0_A.OUT0) // RXD on P1.2 (Timer0_A.CCI1A)
#define UART_TBIT_DIV_2 (1000000 / (9600 * 2)) // Conditions for 9600 Baud SW UART, SMCLK = 1MHz #define UART_TBIT (1000000 / 9600) // Globals for full-duplex UART communication unsignedinttxData; // UART internal variable for TX unsigned char rxBuffer; // Received UART character voidTimerA_UART_tx(unsigned char byte); voidTimerA_UART_print(char *string); void main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL = 0x00; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; P1OUT = 0x00; // Stop watchdog timer // Set DCOCLK to 1MHz // Function prototypes
Page
45
// Wait for incoming character // Enter low poser mode // Transmit the received data
if (rxBuffer=='F' || rxBuffer=='f') P2OUT = 0x0A; else if (rxBuffer=='B' || rxBuffer=='b') P2OUT = 0x06; else if (rxBuffer=='L' || rxBuffer=='l') P2OUT = 0x01; else if (rxBuffer=='R' || rxBuffer=='r') P2OUT = 0x08; else P2OUT = 0x00; } } voidTimerA_UART_tx(unsigned char byte) { while (TACCTL0 & CCIE); TA0CCR0 = TAR; TA0CCR0 += UART_TBIT; TA0CCTL0 = OUTMOD0 + CCIE; // Outputs one byte using the Timer_A UART // Ensure last char got TX'd // Current state of TA counter // One bit time till first bit // Set TXD on EQU0, Int
Page Dashmeet Kaur, Namrata, Arnav Mendiratta, Damanjeet Singh Maan
46
voidTimerA_UART_print(char *string) { while (*string) TimerA_UART_tx(*string++); } #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A0_ISR(void) { static unsigned char txBitCnt = 10; TA0CCR0 += UART_TBIT; if (txBitCnt == 0) { TA0CCTL0 &= ~CCIE; txBitCnt = 10; } else { if (txData& 0x01) TA0CCTL0 &= ~OUTMOD2; else TA0CCTL0 |= OUTMOD2; } txData>>= 1; txBitCnt--; }
// Add Offset to CCRx // All bits TXed? // All bits TXed, disable interrupt // Re-load bit counter
#pragma vector = TIMER0_A1_VECTOR __interrupt void Timer_A1_ISR(void) { static unsigned char rxBitCnt = 8;
Page
47
case TA0IV_TACCR1: TA0CCR1 += UART_TBIT; if (TA0CCTL1 & CAP) { TA0CCTL1 &= ~CAP; TA0CCR1 += UART_TBIT_DIV_2; } else { rxData>>= 1; if (TA0CCTL1 & SCCI) rxData |= 0x80; rxBitCnt--; if (rxBitCnt == 0) { rxBuffer = rxData; rxBitCnt = 8; TA0CCTL1 |= CAP; _BIC_SR(LPM0_EXIT); } } break; }}
// TACCR1 CCIFG - UART RX // Add Offset to CCRx // Capture mode = start bit edge // Switch capture to compare mode // Point CCRx to middle of D0
// All bits RXed? // Store in global variable // Re-load bit counter // Switch compare to capture mode // wake up from low power mode.
Page
48
4.CONCLUSION
The integration of Embedded system with Image Processing using MATLAB has been performed. AGCRov uses two modules Hardware on MSP430 and Software on MATLAB which is integrated via UART. The Rover accepts the control signals issued by the user. The user uses number of fingers to move the rover in particular direction. These control signals are accepted over serial communication by the MSP430 MCU which then directs the DC motors to move in the appropriate direction. The motors are driven by L293D IC for maximum efficiency.
Page
49
5.REFERENCES
1. www.e2e.ti.com 2. www.mathworks.com 3. www.msp430.com 4. www.embeddedrelated .com 5. http://www.instructables.com/id/MATLAB-to-PIC-serial-interface/ 6. http://www.magna-power.com/applications/interfacing-matlab-through-rs232 7. http://mbed.org/cookbook/Interfacing-with-Matlab
Page
50