• Tidak ada hasil yang ditemukan

Pengujian pada lintasan berbentuk L tanpa halangan benda

BAB IV. HASIL DAN PEMBAHASAN

METODOLOGI PENELITIAN

4. Modul Algoritma Penentuan Posisi Bola Mata

4.3 Pengujian Percobaan Sistem Secara Keseluruhan

4.3.2 Pengujian pada lintasan berbentuk L tanpa halangan benda

Untuk mngetahui tingkat keberhasilan sistem maka diperlukan pengujian pada sebuah lapangan uji coba yakni berbentuk L dengan spesifikasi sesuai dengan gambar 4.19. Pada pengujian lapangan berbentuk L dengan tanpa halangan, dilakukan percobaan sebanyak 5 kali percobaan. Dari 5 kali percobaan tersebut memiliki

variasi waktu tempuh yang berbeda-beda dan dilakukan pada intensitas cahaya sebesar 110,5 lumen.

Gambar 4.17 Desain lapangan berbentuk L

Tabel 4.18 Tabel percobaan pada lapangan berbentuk L tanpa halangan

No Percobaan ke - Waktu Keterangan

1 1 28 second Berhasil

2 2 25 second Berhasil

3 3 24 second Berhasil

4 4 25 second Berhasil

5 5 23 second Berhasil

Rata - rata 25 second 100 %

Pada percobaan diatas dapat dilihat bahwa sistem berjalan dengan baik karena tidak ada kegagalan dalam percobaan . Rata –rata waktu yang diperlukan untuk melintasi lapangan uji coba tersebut adalah 25 second. Prosentase keberhasilan robot dalam bernavigasi pada lintasan tersebut yakni

 % keberhasilan = 5/5 * 100 %  80 % F I N I S H 1 m 1 m START

 Rata –rata waktu tempuh = (28 + 25 +24 +25 +23) / 4  25 4.3.3 Pengujian pada lintasan berbentuk L dengan halangan balok

Gambar 4.18 Desain lapangan berbentuk L dengan halangan balok

Pada pengujian lapangan berbentuk L dengan halangan, dilakukan percobaan sebanyak 5 kali percobaan. Untuk percobaan dengan halangan ini menggunakan 3 buah halangan berbentuk balok. Penempatan posisi halangan balok dapat dilihat pada gambar 4.20. Pada percobaan ketiga mengalami kegagalan hal ini dikarenakan sulitnya penyesuaian pergerakan mata dengan robot yang sering kali membentur halangan maupun dinding.

Tabel 4.19 Tabel percobaan pada lapangan berbentuk L dengan halangan

No Percobaan ke - Waktu Keterangan

1 1 29 second Berhasil 2 2 28 second Berhasil 3 3 -- Gagal 4 4 31 second Berhasil 5 5 29 second Berhasil F I N I S H 1 m 1 m START

Rata - rata 29,25 second 80 %

. Dari table diatas dapat disimpulkan bahwa dengan percobaan lapangan berbentuk L dengan halangan 3 buah balok robot dapat menempuh dengan rata-rata waktu sebesar 29,25 second. Dan prosentase ketercapaian finish sebesar 80%. Untuk pengujian dengan halangan dan tanpa halangan tidak terpaut waktu yang besar karena sistem transmisi wireless berjalan dengan baik dan cepat.

BAB 5. PENUTUP

5.1 Kesimpulan

Dari hasil penelitian yang telah dilakukan, maka dapat diambil kesimpulan sebagai berikut :

1. Secara keseluruhan system dapat berjalan dengan baik sesuai algoritma yang dirancang.

2. Komunikasi secara wireless menggunakan modul TLP 433.92A dan RLP 433.92-LC berjalan dengan baik dengan maksimum range jarak pembacaan yakni 100 meter tanpa halangan dan 25 meter dengan halangan tembok . 3. Kombinasi antara deteksi tepi canny dengan Hough Transform terbukti dapat

mendeteksi bola mata dengan optimal (lihat tabel 4.13 – 4.15).

4. Delay waktu kerja system membutuhkan waktu rata-rata sebesar 1 detik (lihat tabel 4.17)

5. Pada uji lapangan berbentuk L robot dapat menempuhnya dengan rata-rata waktu tempuh sebesar 25 second sedangkan pada lapangan berbentuk L dengan halangan rata-rata waktu tempuh sebesar 29,25 second.

6. Sistem ini dapat berjalan optimal pada batas range intensitas pencahayaan 10 – 150 lumen.

5.2 Saran

1. Sistem ini mempunyai kelemahan pada pengaruh cahaya luar yang masuk, dikarenakan dapat merubah warna yang dedeteksi pada kamera webcam, karena system tidak akan bekerja jika kondisi pencahayaan yang sangat gelap. 2. Untuk kedepan diharapkan ada pengembangan agar sistem ini tidak lagi

menggunakan helm.

3. Kualitas kamera webcam sangat menentukan hasil dari Image yang diperoleh, sehingga deteksi tepi yang diperoleh untuk diproses scanning bola mata bisa lebih smooth.

4. Penambahan GUI pada software image processing agar lebih memudahkan pengguna (user friendly) dan lebih menarik.

DAFTAR PUSTAKA

[1] Sankar, Amita. 2001. Pattern Recognition From Classical to Modern. Singapura: World Scientific Peblishing.

[2] Ahmad, Usman. 2005. Pengolahan Citra Digital dan Teknik Pemrogramannya. Yogyakarta : Graha Ilmu.

[3] Gunawan, Budi. 2003. Deteksi Isyarat Tangan Oleh Komputer Dengan Digital Image Processing. ISSN : 1979 - 6870

[4] R.L.Hsu and M.A.Mottaleb. Face Detection in Color Image, Appear In IEEE Tans. PAMI, Vol. 24, no.5, pp.696-706, may 2002.

[5] Puspita,Eru. Syamsiar, Trendy. Nur,Budi. 2006. Sistem Identifikasi Scan Iris Mata Menggunakan Metode JST Propagansi Balik Untuk Aplikai . Surabaya: PENS ITS.

[6] Murni, Aniati., Diktat Kuliah : Pengolahan Citra Digital, Universitas Indonesia, Jakarta, 2004.

[7] Mulyono, Dwi. 2011. Pembuatan Mobile Robot Gripper Sebagai Pemindah Barang Otomatis Menggunakan Metode Fuzzy Logic. Jember: Universitas Jember

[8]http://www.nashruddin.com/Real_Time_Eye_Tracking_and_Blink_Detection#tem

plate-creation : diakses pada tanggal 20 November 2011 : pada pukul 16.35 WIB.

LAMPIRAN

1. Program Deteksi Bola Mata pada Microoft Visual C++

// skripsi.cpp : Defines the entry point for the console application. #include "stdafx.h" #include <tchar.h> #include "cv.h" #include "highgui.h" #include "cxcore.h" #include <iostream> #include <stdlib.h> #include <windows.h> #include <stdio.h> #include <string.h> #include <time.h>

void serial(int data); HANDLE hSerial;

#define FRAME_WIDTH 300 #define FRAME_HEIGHT 300

#define TPL_WIDTH 16

#define TPL_HEIGHT 16

#define WIN_WIDTH TPL_WIDTH * 2 #define WIN_HEIGHT TPL_HEIGHT * 2 #define TM_THRESHOLD 0.4

#define STAGE_INIT 1

#define STAGE_TRACKING 2

#define POINT_TL(r) cvPoint(r.x, r.y)

#define POINT_BR(r) cvPoint(r.x + r.width, r.y + r.height) #define POINTS(r) POINT_TL(r), POINT_BR(r)

#define PORTNUM 1 #define BAUDRATE 9600

#define DRAW_RECTS(f, d, rw, ro) \ do { \ cvRectangle(f, POINTS(rw), CV_RGB(255, 0, 0), 1, 8, 0); \ cvRectangle(f, POINTS(ro), CV_RGB(0, 255, 0), 1, 8, 0); \

cvRectangle(d, POINTS(rw), cvScalarAll(255), 1, 8, 0); \

cvRectangle(d, POINTS(ro), cvScalarAll(255), 1, 8, 0); \

} while(0)

#define DRAW_TEXT(f, t, d, use_bg) \

if (d) \ { \ CvSize _size; \

cvGetTextSize(t, &font, &_size, NULL); \

if (use_bg)

\ {

\

cvRectangle(f, cvPoint(0, f->height), \ cvPoint(_size.width + 5, \ f->height - _size.height * 2), \ CV_RGB(255, 100, 0), CV_FILLED, 8, 0); \ } \

cvPutText(f, t, cvPoint(2, f->height - _size.height / 2), \

&font, CV_RGB(255,255,0)); \ d--; \ } CvCapture* capture;

IplImage* frame, * gray, * prev, * diff, * tpl, *croppedka,

*crop ,*croppedki, *img, *eyes ,*origImg,*outImg,*ori;

IplImage* edges; IplImage* img_a; CvMemStorage* storage; IplConvKernel* kernel; CvFont font; CvPoint (pt1); CvPoint (pt2); CvPoint (pt3); CvPoint (pt4);

char* wnd_name = "video capture";

char* wnd_eye = "face&eye detection"; char* wnd_debug = "treshold&morpholigi"; char* wnd_nama = "grayscale";

char* wnd_prev = "prev"; char* wnd_cropka = "croppedka"; char* wnd_cropki = "croppedki"; char* crop_eye = "crop_eye"; char* wnd_crp = "crop"; char* wnd_crp1 = "crop";

int get_connected_components(IplImage* img, IplImage* prev, CvRect window, CvSeq** comp);

bool keepAspectRatio; int i,scale; int heighthsv,widthhsv,stephsv,channelshsv; int heighthsv1,widthhsv1,stephsv1,channelshsv1; int x,y,widtho,heighto,stepo,channelso; uchar *datahsv,*datahsv1,*dataho ;

int text_delay, stage = STAGE_INIT;

CvSeq* comp = 0;

CvRect window, eye;

char* kata = "Robot Eye Navigation by Redo"; char* kata1 = "Teknik Elektro Univ.Jember"; int newWidth, newHeight;

void detectEyes(IplImage *eyes);

IplImage* resizeImage(const IplImage *origImg, int newWidth,int

newHeight, bool keepAspectRatio);

void delay_frames(int nframes); void init();

void exit_nicely(char* msg);

int key, nc, found;

int ka0,ka1,ki0,ki1; int min,max; float* p; CvHaarClassifierCascade *cascade_f; CvHaarClassifierCascade *cascade_e; int maxLowThreshold = 255; int lowSliderPosition =11;

// Slider for the high threshold value of our edge detection

int maxHighThreshold = 255; int highSliderPosition = 100; int maxSliderPosition=50; int minSliderPosition=20; int SliderPosition=23; int sliderposisi=18;

int a,b, tengah, hasil;

void onLowThresholdSlide(int theSliderValue) {

lowSliderPosition = theSliderValue; }

// Callback function to adjust the high threshold on slider movement

void onHighThresholdSlide(int theSliderValue) {

highSliderPosition = theSliderValue; }

void tepi(IplImage *gray,double thelowThreshold, double theHighThreshold,double theAperture){

cvCanny( gray, edges, thelowThreshold, theHighThreshold,

theAperture); }

void onMinSlide(int theSliderValue) {

SliderPosition = theSliderValue; }

void onMaxSlide(int theSliderValue) {

sliderposisi = theSliderValue; }

void kirim(char data){

int n=12;

char szBuff1[100]={data}; DWORD dwByteswrote = 0;

printf("||=> Data Serial Tx: %d

||\r\n",data);

if(!WriteFile(hSerial, szBuff1, n, &dwByteswrote, NULL)) {

printf("||=> Status serial : error writing data

||\r\n"); }

return ; }

int main(int argc, char** argv) {

hSerial = CreateFile(L"COM2", GENERIC_WRITE, 0, 0,

OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hSerial == INVALID_HANDLE_VALUE) {

if (GetLastError() == ERROR_FILE_NOT_FOUND) printf("COM port not found!\n");

printf("Unknow error! - 1\n"); } DCB dcbSerialParams = {0}; dcbSerialParams.DCBlength = sizeof(dcbSerialParams); if (!GetCommState(hSerial, &dcbSerialParams)) printf("Unknow error! - 2\n"); dcbSerialParams.BaudRate = CBR_9600; dcbSerialParams.ByteSize = 8; dcbSerialParams.StopBits = ONESTOPBIT; dcbSerialParams.Parity = NOPARITY;

if(!SetCommState(hSerial, &dcbSerialParams)) printf("Unknow error! - 3\n"); COMMTIMEOUTS timeouts = {0}; timeouts.ReadIntervalTimeout = 50; timeouts.ReadTotalTimeoutConstant = 50; timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.WriteTotalTimeoutConstant = 50; timeouts.WriteTotalTimeoutMultiplier = 10; if(!SetCommTimeouts(hSerial, &timeouts)) printf("Timeout(s) error - 4\n"); init();

//============declarasi fungsi detect face &eye==================

CvCapture *capture;

//load image

capture = cvCaptureFromCAM( 0 );

cvNamedWindow("Processed WebCam", CV_WINDOW_AUTOSIZE);

cvCreateTrackbar("Low Threshold",wnd_name, &lowSliderPosition, maxLowThreshold, onLowThresholdSlide);

// Create the high threshold slider

cvCreateTrackbar("High Threshold", wnd_name,

&highSliderPosition, maxHighThreshold, onHighThresholdSlide); cvCreateTrackbar("min",wnd_name,&SliderPosition,

minSliderPosition, onMinSlide);

cvCreateTrackbar("max", wnd_name,&sliderposisi,

maxSliderPosition, onMaxSlide); while (key != 'a')

{

frame = cvQueryFrame(capture); if (!frame)

exit_nicely("cannot query frame!"); frame->origin = 0;

//---buat garis x,y---

pt1.x = (frame->width)/2; pt1.y = 0; pt2.x =(frame->width)/2; pt2.y = frame->height; pt3.x = 0; pt3.y = (frame->height)/2; pt4.x = (frame->width); pt4.y = (frame->height)/2; cvLine(frame,pt1,pt2,CV_RGB(255,255,0),1,4,0); cvLine(frame,pt3,pt4,CV_RGB(255,255,0),1,4,0); cvFlip(frame,NULL,-1);

//===========tampil tulisan---

CvSize _size;

\

cvGetTextSize(kata, &font, &_size, NULL); cvGetTextSize(kata1, &font, &_size, NULL);

cvPutText(frame, kata, cvPoint(2, frame->height-12 -

_size.height / 2), \

&font, CV_RGB(255,0,0));

cvPutText(frame, kata1, cvPoint(2, frame->height -

_size.height / 2), \

&font, CV_RGB(0,255,0));

//---grayscale n edge detection---

ori= (IplImage*)cvClone(frame); if (stage == STAGE_INIT)

window = cvRect(0, 0, ori->width, frame->height);

cvCvtColor(ori, gray, CV_RGB2GRAY);

cvSmooth( gray, gray, CV_GAUSSIAN, 11, 11 ); // smooth

it, otherwise a lot of false circles may be detected

cvThreshold(gray,gray,lowSliderPosition,highSliderPosition,CV_ THRESH_BINARY);

edges = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1); tepi(gray,lowSliderPosition, highSliderPosition,3); cvShowImage(wnd_nama,gray); widtho = edges->width; heighto= edges->height; stepo = edges->widthStep; channelso = edges->nChannels; // cvDilate(gray,gray,0,10);

CvSeq* circles = cvHoughCircles(edges, storage,

CV_HOUGH_GRADIENT,0.5, edges->height,SliderPosition,sliderposisi);

int i;

for( i = 0; i < circles->total; i++ ) {

cvCircle( frame, cvPoint(cvRound(p[0]),cvRound(p[1])), 8, CV_RGB(0,0,255), -1, 8, 0 ); cvCircle( frame, cvPoint(cvRound(p[0]),cvRound(p[1])),cvRound(p[2]),CV_RGB(255,255,25 5),1,8,0); //} }

printf("||=======Desain Navigasi Robot Menggunakan

Mata=========== ||\r\n");

printf("|| ***Dengan Metode MORPHOLOGY by Reda Anggra D*** ||\r\n");

printf("|| ||\r\n");

printf("|| <===DATA NILAI POSISI PIXEL===> ||\r\n");

printf("|| ||\r\n");

printf("||=> posisi x:%d posisi y:%d

||\r\n\n",(int)p[0],(int)p[1]);

printf("||=> hasil:%d ||\r\n\n",hasil);

printf("|| ||\r\n");

//---kalibrasi posisi bola

mata---if (key == 's'){ tengah = p[0]; goto a; } a: hasil = tengah - p[0]; if (hasil > 20 )

{printf("\r MATA KIRI \n"); kirim(100);

}

else if (hasil < -20 ){ printf("\r MATA KANAN \n"); kirim(50);

}

else if (hasil> -20 && hasil <20) {printf("\r TENGAH \n");

kirim(90);}

printf("||======================================================== ||\r\n");

cvShowImage("Processed WebCam", edges); cvShowImage(wnd_name, frame);

int f;

for (f=0;f<10;f++){ printf("\n");

} key = cvWaitKey(15); } cvReleaseImage(&edges); exit_nicely(NULL); } int

get_connected_components(IplImage* img, IplImage* prev, CvRect

window, CvSeq** comp) {

IplImage* _diff;

cvZero(diff);

/* apply search window to images */

cvSetImageROI(img, window); cvSetImageROI(prev, window); cvSetImageROI(diff, window);

/* motion analysis */

cvSub(img, prev, diff, NULL);

cvThreshold(diff, diff, 0,255 , CV_THRESH_BINARY_INV);

/* reset search window */

cvResetImageROI(img); cvResetImageROI(prev); cvResetImageROI(diff);

_diff = (IplImage*)cvClone(diff);

/* get connected components */

int nc = cvFindContours(_diff, storage, comp,

sizeof(CvContour),CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); cvClearMemStorage(storage); //cvReleaseImage(&_diff); return nc; } void delay_frames(int nframes) { int i;

for (i = 0; i < nframes; i++) {

frame = cvQueryFrame(capture); if (!frame)

exit_nicely("cannot query frame"); cvShowImage(wnd_name, frame);

if (diff)

cvWaitKey(30); } } void init() { char* msg[] = { "Bismillahirrohmanirrohim", "Reda Anggra Distira", "071910201079",

"Fakultas Teknik UJ", "Press 'q' to quit...", "Enjoy it,,,," };

int delay, i;

capture = cvCaptureFromCAM(0); if (!capture)

exit_nicely("Cannot initialize camera!");

cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, FRAME_WIDTH); cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT); frame = cvQueryFrame(capture); cvFlip(frame,NULL,-1); if (!frame)

exit_nicely("cannot query frame!");

cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.4, 0.4, 0, 1, 8); cvNamedWindow(wnd_name, 1);

for (delay = 30, i = 0; i < 6; i++, delay = 30) while (delay)

{

frame = cvQueryFrame(capture); if (!frame)

exit_nicely("cannot query frame!"); DRAW_TEXT(frame, msg[i], delay, 0);

cvShowImage(wnd_name, frame); cvWaitKey(30);

}

storage = cvCreateMemStorage(0); if (!storage)

exit_nicely("cannot allocate memory storage!");

kernel = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_CROSS, NULL); gray = cvCreateImage(cvGetSize(frame), 8, 1); prev = cvCreateImage(cvGetSize(frame), 8, 1); diff = cvCreateImage(cvGetSize(frame), 8, 1); croppedka = cvCreateImage(cvGetSize(frame), 8, 1); croppedki = cvCreateImage(cvGetSize(frame), 8, 1);

eyes = cvCreateImage(cvGetSize(frame), 8, 1);

tpl = cvCreateImage(cvSize(TPL_WIDTH, TPL_HEIGHT), 8, 1);

if (!kernel || !gray || !prev || !diff || !tpl || !croppedka || !croppedki || !eyes) exit_nicely("system error."); gray->origin = frame->origin; prev->origin = frame->origin; diff->origin = frame->origin; croppedka->origin = frame->origin; croppedki->origin = frame->origin; eyes->origin = frame->origin; cvNamedWindow(wnd_debug, 1); }

IplImage* cropImage(const IplImage *img, const CvRect region) {

IplImage *imageCropped; CvSize size;

if (img->width <= 0 || img->height <= 0

|| region.width <= 0 || region.height <= 0) {

//cerr << "ERROR in cropImage(): invalid dimensions." << endl;

exit(1); }

if (img->depth != IPL_DEPTH_8U) {

//cerr << "ERROR in cropImage(): image depth is not 8." << endl;

exit(1); }

// Set the desired region of interest.

cvSetImageROI((IplImage*)img, region);

// Copy region of interest into a new iplImage and return it.

size.width = region.width; size.height = region.height;

imageCropped = cvCreateImage(size, IPL_DEPTH_8U,

img->nChannels);

cvCopy(img, imageCropped); // Copy just the region.

return imageCropped; }

IplImage* resizeImage(const IplImage *origImg, int newWidth,int

newHeight, bool keepAspectRatio) {

//IplImage resizeImage(const IplImage *origImg, int newWidth,int newHeight, bool keepAspectRatio)

IplImage *outImg = 0; int origWidth;

if (origImg) {

origWidth = origImg->width; origHeight = origImg->height; }

if (newWidth <= 0 || newHeight <= 0 || origImg == 0 || origWidth <= 0 || origHeight <= 0) {

//cerr << "ERROR: Bad desired image size of " << newWidth

// << "x" << newHeight << " in resizeImage().\n";

exit(1); }

if (keepAspectRatio) {

// Resize the image without changing its aspect ratio, // by cropping off the edges and enlarging the middle section.

CvRect r;

// input aspect ratio

float origAspect = (origWidth / (float)origHeight);

// output aspect ratio

float newAspect = (newWidth / (float)newHeight);

// crop width to be origHeight * newAspect

if (origAspect > newAspect) {

int tw = (origHeight * newWidth) / newHeight; r = cvRect((origWidth - tw)/2, 0, tw, origHeight); }

else { // crop height to be origWidth / newAspect

int th = (origWidth * newHeight) / newWidth;

r = cvRect(0, (origHeight - th)/2, origWidth, th); }

IplImage *croppedImg = cropImage(origImg, r);

// Call this function again, with the new aspect ratio image.

// Will do a scaled image resize with the correct aspect ratio.

outImg = resizeImage(croppedImg, newWidth, newHeight, false);

cvReleaseImage( &croppedImg );

} else {

// Scale the image to the new dimensions, // even if the aspect ratio will be changed.

outImg = cvCreateImage(cvSize(newWidth,

newHeight),origImg->depth, origImg->nChannels);

if (newWidth > >width && newHeight > origImg->height) {

// Make the image larger

cvResetImageROI((IplImage*)origImg);

// CV_INTER_LINEAR: good at enlarging. // CV_INTER_CUBIC: good at enlarging.

cvResize(origImg, outImg, CV_INTER_LINEAR); }

else {

// Make the image smaller

cvResetImageROI((IplImage*)origImg);

// CV_INTER_AREA: good at shrinking (decimation) only.

cvResize(origImg, outImg, CV_INTER_AREA); }

}

return outImg; }

void detectEyes(IplImage *eyes) {

int i;

//detect faces

CvSeq *faces = cvHaarDetectObjects( eyes, cascade_f, storage, 1.1, 3, 0, cvSize( 40, 40 ) );

// return if not found

if (faces->total == 0) return;

// draw a rectangle

CvRect *r = (CvRect*)cvGetSeqElem(faces, 0); cvRectangle(eyes,

cvPoint(r->x, r->y),

cvPoint(r->x + r->width, r->y + r->height), CV_RGB(255, 0, 0), 1, 8, 0);

// reset buffer for the next object detection

cvClearMemStorage(storage);

// Set the Region of Interest: estimate the eyes' position

cvSetImageROI(eyes, cvRect>x + >width/3), r->y + (r->height/5), (r->width),( r->height/3)));

// detect eyes

CvSeq* eyes1 = cvHaarDetectObjects( eyes, cascade_e, storage,

1.15, 3, 0, cvSize(15, 15));

// draw a rectangle for each eye found

// for( i = 0; i < (eyes1 ? eyes1->total : 0); i++ ) {

if (eyes1 ?eyes1->total:0 ) {

r = (CvRect*)cvGetSeqElem( eyes1,0 );

//if (r->x > r->width/2){

cvRectangle(eyes,

cvPoint(>x + >width, >y + r->height), CV_RGB(0, 255, 0), 1, 8, 0); IplImage* crop ; CvSize size; } cvResetImageROI(eyes); }

void serial(int data){

char szBuff[12] = {data};

char array[100];

int len = strlen(array); int i, pos;

int delay=100;

for (pos = 0; pos<100; pos++) { for (i = 0; i < 12; i++)

szBuff[i + 1] = array[(pos + i) % 100];

DWORD dwBytesWrite = 0;

if (!WriteFile(hSerial, szBuff,12, &dwBytesWrite, NULL)) printf("Error writing to device - 5\n");

Sleep(delay); } CloseHandle(hSerial); } void exit_nicely(char* msg) { cvDestroyAllWindows(); if (capture) cvReleaseCapture(&capture); if (gray) cvReleaseImage(&gray); if (prev) cvReleaseImage(&prev); if (diff) cvReleaseImage(&diff); if (croppedka) cvReleaseImage(&croppedka); if (croppedki)

cvReleaseImage(&croppedki); if (tpl) cvReleaseImage(&tpl); if (storage) cvReleaseMemStorage(&storage); if (msg != NULL) { fprintf(stderr, msg); fprintf(stderr, "\n"); exit(1); } exit(0); }

2. Program Mikrokontroller pada sisi Transmitter

#include <mega8535.h> #include <delay.h> #include <stdio.h> char buf[22];

// Alphanumeric LCD Module functions #asm

.equ __lcd_port=0x18 ;PORTB #endasm #include <lcd.h> #define RXB8 1 #define TXB8 0 #define UPE 2 #define OVR 3 #define FE 4 #define UDRE 5 #define RXC 7

#define FRAMING_ERROR (1<<FE) #define PARITY_ERROR (1<<UPE) #define DATA_OVERRUN (1<<OVR)

#define DATA_REGISTER_EMPTY (1<<UDRE) #define RX_COMPLETE (1<<RXC)

// USART Receiver buffer #define RX_BUFFER_SIZE 8 char rx_buffer[RX_BUFFER_SIZE]; int receiv;

#if RX_BUFFER_SIZE<256

unsigned char rx_wr_index,rx_rd_index,rx_counter; #else

unsigned int rx_wr_index,rx_rd_index,rx_counter; #endif

bit rx_buffer_overflow;

// USART Receiver interrupt service routine interrupt [USART_RXC] void usart_rx_isr(void) {

char status,data; status=UCSRA; data=UDR;

if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) {

rx_buffer[rx_wr_index]=data; receiv= rx_buffer[0];

if ((++rx_wr_index == RX_BUFFER_SIZE)) rx_wr_index=0; if (++rx_counter == RX_BUFFER_SIZE) { rx_counter=0; rx_buffer_overflow=1; }; }; } #ifndef _DEBUG_TERMINAL_IO_

// Get a character from the USART Receiver buffer #define _ALTERNATE_GETCHAR_ #pragma used+ char getchar(void) { char data; while (rx_counter==0); data=rx_buffer[rx_rd_index];

if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0; #asm("cli") --rx_counter; #asm("sei") return data; } #pragma used- #endif

// Declare your global variables here void main(void) { PORTA=0x0f; DDRA=0xff; PORTB=0x00; DDRB=0x00; PORTC=0xff; DDRC=0xFF;

PORTD=0xF0; DDRD=0xFF;

// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x00;

TCNT0=0x00; OCR0=0x00;

// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off

// Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected ASSR=0x00;

TCCR2=0x00; TCNT2=0x00; OCR2=0x00;

// External Interrupt(s) initialization // INT0: Off

// INT1: Off // INT2: Off MCUCR=0x00; MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00;

// USART initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On

// USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 9600 UCSRA=0x00;

UCSRB=0x98; UCSRC=0x86; UBRRH=0x00; UBRRL=0x47;

// Analog Comparator initialization // Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80;

SFIOR=0x00;

// LCD module initialization lcd_init(16);

// Global enable interrupts #asm("sei") while (1) { #asm("cli"); lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("ComSer : AKSI"); lcd_gotoxy(0,1); sprintf(buf,"rx:%d",receiv); lcd_puts(buf); delay_ms(10); #asm("sei"); if(receiv== 90) { PORTD = 0b01110000; PORTC.5=0; delay_ms(500); //delay_ms(5000); lcd_gotoxy(9,1); lcd_putsf("MAJU"); } else if(receiv == 100) { PORTD = 0b10110000; PORTC.5=0; delay_ms(500); lcd_gotoxy(9,1); lcd_putsf("B.KIRI");

} else if(receiv== 50) { PORTD = 0b11010000; PORTC.5=0; delay_ms(500); lcd_gotoxy(9,1); lcd_putsf("B.KANAN"); } else if(receiv== 80) { PORTD = 0b11100000; PORTC.5=0; delay_ms(500); lcd_gotoxy(9,1); lcd_putsf("B.KANAN"); } }; }

3. Program pada mikrokontroller Robot (Sisis Penerima)

#include <mega8535.h> #include <delay.h> #include <stdio.h> int x,lpwm,rpwm;

// Alphanumeric LCD Module functions #asm

.equ __lcd_port=0x1B ;PORTA #endasm

#include <lcd.h> char lcd_buffer[33]; // switch

#define sw_ok PINB.0 #define sw_cancel PINB.1 #define sw_up PINB.2 #define sw_down PINB.3

// Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) {

x++;

if (x>867){x=0;} else {

else {PORTC.0=0;} if (x<rpwm){PORTC.1=1;} else {PORTC.1=0;} } } void belok_kanan(){ lpwm= 80; rpwm= 70;} void berhenti(){ lpwm= 70; rpwm= 70;} void belok_kiri(){ lpwm= 70; rpwm= 60;} void maju(){ lpwm= 100; rpwm= 40;} void main(void) { PORTA=0x00; DDRA=0x00; PORTB=0x0f; DDRB=0x00; PORTC=0x00; DDRC=0xff; PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 12000,000 kHz // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x01;

TCNT0=0x00; OCR0=0x00;

// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off

// Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected ASSR=0x00;

TCCR2=0x00; TCNT2=0x00; OCR2=0x00;

// External Interrupt(s) initialization // INT0: Off

// INT1: Off // INT2: Off MCUCR=0x00; MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01;

// Analog Comparator initialization // Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80;

SFIOR=0x00;

// LCD module initialization lcd_init(16);

// Global enable interrupts #asm("sei") //showMenu(); while (1) { lcd_clear(); lcd_gotoxy(0,0);

lcd_gotoxy(0,1); lcd_putsf(" Aksi:");

if (PIND.0==0 && PIND.1==1 &&PIND.2==1 &&PIND.3==1 ){ maju(); lcd_gotoxy(9,1); lcd_putsf("maju"); delay_ms(50); } else if (PIND.0==1 && PIND.1==0 &&PIND.2==1 &&PIND.3==1){ belok_kiri();lcd_gotoxy(9,1);lcd_putsf("b.kiri"); delay_ms(50); }

else if (PIND.0==1 && PIND.1==1 &&PIND.2==0 &&PIND.3==1){ belok_kanan(); lcd_gotoxy(9,1);lcd_putsf("b.kanan");delay_ms(50); }

else if (PIND.0==1 && PIND.1==1 &&PIND.2==1

&&PIND.3==0){berhenti();lcd_gotoxy(9,1);lcd_putsf("stop");delay_ms(50);} };

4. Skema Rangkaian Driver TLP 433 dan RLP 433 MHz

Dokumen terkait