• Tidak ada hasil yang ditemukan

BAB 5. KESIMPULAN DAN SARAN

5.2. Saran

Saran berikut dapat dijadikan acuan untuk penelitian lebih lanjut.

1. Algoritma robot dapat diperbaiki sehingga semua ruang dapat dijelajahi di mana pun posisi awal dan letak titik api.

2. Struktur robot dapat diperkecil sehingga tidak terlalu menyulitkan pergerakan robot.

http://www.robot‐electronics.co.uk/htm/tpa81tech.htm 

http://sales.hamamatsu.com/en/products/electron‐tube‐division/detectors/flame‐

sensors‐uvtron/part‐c10807.php 

http://kontesrobot.dinus.ac.id/main/getfile/45995a092943974008d195461202fe0c 

http://www.atmel.com/Images/doc2467.pdf 

Lampiran A

Struktur Mikrokontroler ATMEGA128

ATMEGA128 memiliki memory 128 kilobyte, dilengkapi dengan flash

memory, EEPROM (Electrically Erasable Programmable Read Only Memory), timer, clock, modul ADC (Analog to Digital Converter), communication interface

seperti I2C, serial port, dan parallel port, serta modul input output sebanyak 53 pin yang terbagi ke dalam 7 blok. Pemrograman menggunakan bahasa assembler atau menggunakan bahasa tingkat tinggi seperti bahasa C.

Spesifikasi mikrokontroler ATMEGA128 adalah sebagai berikut : 1. Arsitektur RISC (Reduced Instruction Set Computing)

a. 32 x 8 bit register

b. Kemampuan eksekusi instruksi sampai 16 MIPS (Million Instruction

Per Second) pada frekuensi kerja 16 MHz

2. Memory

a. 128 kilobyte flash memory program b. 4 kilobyte EEPROM

c. 4 kilobyte SRAM

d. Siklus baca-tulis flash/EEPROM : 10.000/100.000 3. In-System Programming

4. Fitur Pheriperal a. 2 Timer 8 bit b. 2 Timer 16 bit c. 6 kanal PWM d. 8 kanal ADC 10 bit e. Analog Comparator

f. 2 kanal komunikasi serial USART g. RC oscillator internal terkalibrasi h. Sumber interupsi eksternal dan internal

1 : Kaki yang digunakan untuk mengaktifkan mode pemrogramman secara serial dengan memberikan tegangan 0V selama power-on

reset.

2-9 : Kaki-kaki ini sebagai PORTE, digunakan sebagai input/output. Kaki 2 dan 3 juga digunakan untuk komunikasi serial.

10-17: Kaki-kaki ini sebagai PORTB, digunakan sebagai input/output. 18-19: Kaki-kaki ini sebagai PORTG, digunakan sebagai input/output. 20 : Kaki input untuk me-reset pengontrol mikro secara manual dengan

memberikan tegangan 0V selama waktu tertentu. 21,52 : Input catu daya positif dari sumber tegangan. 22,53 : Input catu daya negatif dari sumber tegangan.

23,24 : Kaki-kaki ini digunakan sebagai input/output oscillator.

25-32: Kaki-kaki ini sebagai PORTD, digunakan sebagai input/output. Kaki 27 dan 28 juga digunakan untuk komunikasi serial.

33,34 : Kaki-kaki ini sebagai PORTG, digunakan sebagai input/output. 35-42: Kaki-kaki ini sebagai PORTC, digunakan sebagai input/output. 43 : Kaki ini sebagai PORTG, digunakan sebagai input/output. 44-51: Kaki-kaki ini sebagai PORTA, digunakan sebagai input/output. 54-61: Kaki-kaki ini sebagai PORTF, digunakan sebagai input/output. 62 : Kaki ini digunakan sebagai referensi analog untuk ADC. 63 : Input catu daya negatif dari sumber tegangan.

Gambar A.1 Konfigurasi Kaki ATMEGA128

Struktur pengontrol mikro ATMEGA128 digambarkan dalam diagram blok pada Gambar 2.10. ATMEGA128 disusun dari beberapa bagian seperti

central processing unit, input/output, analog to digital converter, analog comparator, SPI (Serial Peripheral Interface), TWI (Two-Wired Interface),

rangkaian pewaktu (timer), rangkaian clocking, kontrol interupsi, EEPROM dan USART (Universal Synchronous and Asynchronous serial Receiver and

Lampiran B

Struktur ROBOTIS CM-510

Gambar B.1 Struktur CM-510

CM-510 adalah unit pengontrol dari kit ROBOTIS BIOLOID Premium berbasis ATMEGA2561. Unit ini memiliki dua memori terpisah untuk servo

control dan logic control yang terintegrasi dengan software ROBOPLUS. Adapun

komponen-komponen CM-510 adalah :

PC Link (Kabel Serial) : Menghubungkan CM-510 dengan PC melalui port serial. Digunakan untuk komunikasi atau download program.

Communication Device Connection : Untuk komunikasi dengan pheriperal lain secara serial.

Battery Jack : Konektor baterai

Power Jack : Konektor adaptor tegangan

Power LED : Penanda kondisi On/Off dari unit CM-510

Peripheral Devices Connection : Menghubungkan sensor-sensor lain dalam set BIOLOID.

Mode Display LED : LED penanda mode operasi terpilih Status Display LED : Menandakan status CM-510

TxD : Menyala ketika CM-510 mengirim data keluar . RxD : Menyala ketika CM-510 menerima data dari luar.

AUX : Dapat dikontrol melalui program yang dibuat pengguna. [ MODE MANAGE ]

Menandakan pengaturan servo sedang berlangsung.

Digunakan untuk mengetes atau mengatur operasi CM-510 dan AX-12 menggunakan ROBOPLUS Manager.

Otomatis tereksekusi ketika CM-510 dan ROBOPLUS Manager terhubung melalui PC-Link.

[ MODE PROGRAM ]

Menandakan pengaturan gerakan (motion) sedang berlangsung. Digunakan ketika pergerakan diatur dengan ROBOPLUS Motion. Otomatis terekseksi ketika CM-510 dan ROBOPLUS Motion terhubung.

[ MODE PLAY ]

Menandakan pengaturan algoritma sedang berlangsung. Digunakan untuk download program dari ROBOPLUS Task.

Tombol Start harus ditekan ketika LED berkedip untuk menjalankan program.

Spesifikasi Lainnya : Berat : 51.3g

Mikrokontroler : ATMega2561 Tegangan Kerja

o Batas Tegangan : 6.5V ~ 15V

o Tegangan yang Dianjurkan : 11.1V (LiPo 3 sel) Konsumsi Arus

o Saat diam : 50mA

o Arus Maksimum I/O Eksternal : 0.9A

o Total Arus Maksimum : 10A (Batas Sekring)

Suhu Kerja : -5Ԩ~70Ԩ

Alat I/O Internal

o Tombol : 5 (Reset 1, Port 5)

o Mic (untuk deteksi suara) : 1

o Sensor Suhu : 1

C.1.Pemrograman ATMEGA128

Pemrograman ATMEGA128 mencakup logic control serta pemrograman fungsi sensor-sensor yang digunakan. Pemrograman sensor-sensor yang membutuhkan protokol khusus dipisahkan pada suatu library tersendiri dalam bentuk header. Pemrograman sepenuhnya menggunakan software

CodeVisionAVR 2.03.4 Standard Edition.

#include <mega128.h> #include <delay.h> #include <stdio.h>

// Alphanumeric LCD Module functions #asm

.equ __lcd_port=0x15 ;PORTC #endasm

#include <lcd.h>

// I2C Bus functions #asm

.equ __i2c_port=0x12 ;PORTD .equ __sda_bit=1 .equ __scl_bit=0 #endasm #include <i2c.h> #include "srf01.h" #include "tpa.h" #include "main.h" #define ldr_white 300 //---GLOBAL VARIABLES---//

unsigned int range_data[9];

unsigned int start, retry, ldr, ruang, ruang_count, juring, api, bio_stat, home, putih, cal, out_home, i, j;

unsigned int blk_kiri, blk_kanan; unsigned char lcd_text[32], pixel[8];

//---//

void main(void) {

// ESC Input Port Definition PORTA = 0x00;

DDRA = 0x02;

// Config Button Pull-Up PORTD = 0x80; DDRD = 0x00; // USART0 Initialization UCSR0A=0x00; UCSR0B=0x18; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x47; // USART1 Initialization UCSR1A=0x00; UCSR1B=0x18; UCSR1C=0x06; UBRR1H=0x00; UBRR1L=0x0B;

// I2C Bus initialization i2c_init(); // Alphanumeric LCD initialization lcd_init(16); // ADC initialization ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0x84; //---CALIBRATE SENSORS---// //cal_sensor(); //---// //---INITIAL START---// robot_init(); //---// //---COMMAND LIST---// /* 1 --> Start 2 --> Retry 3 --> Lurus 4 --> Mepet Kiri 5 --> Mepet Kanan 6 --> Belok Kanan

//---// //---MAIN PROGRAM---// while (1)

{

//---SOUND ACT & RETRY---// while (start!=1) { readSensor(); start = sound_act(); } if (start==1) { sendBioloid(1,0); bio_stat = 1; blk_kiri = 0; blk_kanan = 0; } //---// //---START MOVEMENT---// while (start==1) {

//---DETEKSI GARIS PUTIH---// while (home==1)

{

//Deteksi Lingkar Home

if (ldr<ldr_white) putih = 1; if ( (ldr>ldr_white)&&(putih==1) ) { home = 0; ruang = 0; putih = 0; } readSensor(); moving(); } while (ruang==0) {

//Deteksi Garis Ruangan

if (ldr<ldr_white) putih = 1; if ( (ldr>ldr_white)&&(putih==1) )

{ ruang_count--; ruang = 1; putih = 0; } readSensor(); moving(); } //---//

//---CEK API DI RUANGAN---// while (ruang==1) { readSensor(); forceForward(); sendBioloid(0,0); bio_stat = 0; delay_ms(1500); readSensor(); if (api==1) { sendBioloid(1,0); bio_stat = 1; ruang = 2; } else if (api==0) { sendBioloid(11,0); bio_stat = 11; ruang = 3; } } //---// //---ADA API DI RUANGAN---// while (ruang==2) { while(juring==0) { if (ldr<ldr_white) { sendBioloid(0,0); bio_stat = 0; tpa_servo_scan(); api = 0; juring = 1; } else

{ delay_ms(1000); sendBioloid(11,0); bio_stat = 11; out_home = 1; ruang = 4; juring = 0; } } //---// //---TAK ADA API DI RUANGAN---// while (ruang==3) { goOut(); } while (ruang==4) {

//Deteksi Garis Ruangan if (ldr<ldr_white) { putih = 1; readSensor(); moving(); } if ( (ldr>ldr_white)&&(putih==1) ) { ruang_count--; ruang = 0; putih = 0; } readSensor(); moving(); } //---// } } //---// }

Pemrograman sensor SRF01 dipisahkan dalam header srf01.h sebagai berikut : #ifndef RXB8 #define RXB8 1 #endif #ifndef TXB8 #define TXB8 0 #endif #ifndef UPE #define UPE 2 #endif #ifndef DOR #define DOR 3 #endif #ifndef FE #define FE 4 #endif #ifndef UDRE #define UDRE 5 #endif #ifndef RXC #define RXC 7 #endif

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

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

unsigned char rx_buf[8];

extern unsigned int i, j, range_data[9]; extern unsigned char lcd_text[32];

#define b_kiri range_data[1] #define kiri range_data[2] #define f_kiri range_data[3] #define f_kanan range_data[4]

{

while (( UCSR0A & DATA_REGISTER_EMPTY)==0); UDR0 = data;

}

// Terima Data Serial

void serialRX(unsigned char nByte) {

unsigned char x;

for(x=0 ; x<nByte ; x++) {

while ((UCSR0A & RX_COMPLETE)==0); rx_buf[x] = UDR0;

} }

// Mengosongkan buffer array receiver void clearRXBuf(void)

{

char junk;

while ((UCSR0A & RX_COMPLETE)==0); junk = UDR0;

while ((UCSR0A & RX_COMPLETE)==0); junk = UDR0; } // Melaukan ‘Break’ void sendBrk(void) { UCSR0B = 0x00; DDRE = 0x02; PORTE.1 = 1; PORTE.1 = 0; delay_ms(1); PORTE.1 = 1; UCSR0B = 0x18; }

// Pengukuran dengan hasil dalam satuan cm ke seluruh address void startRangeAll() { sendBrk(); serialTX(0x00); serialTX(0x51); }

// Membaca hasil pengukuran

unsigned int getRange(unsigned char address) {

unsigned int data;

sendBrk(); serialTX(address); serialTX(0x5E);

clearRXBuf(); serialRX(2);

data = (rx_buf[0] << 8) + rx_buf[1]; return(data);

}

// Routine pengukuran dan pembacaan hasil void rangingAll()

{

startRangeAll(); delay_ms(70); }

// Mengganti address salah satu sensor SRF01

void setAddress(unsigned char curAddress, unsigned char newAddress) { sendBrk(); serialTX(curAddress); serialTX(0xA0); delay_ms(70); sendBrk(); serialTX(curAddress); serialTX(0xAA); delay_ms(70); sendBrk(); serialTX(curAddress); serialTX(0xA5); delay_ms(70); sendBrk(); serialTX(curAddress); serialTX(newAddress);

serialTX(0);

serialTX(baudRate); delay_ms(70); }

// Menampilkan hasil pengukuran kedelapan SRF01 void lcd_srf01()

{

extern unsigned int range_data[9]; extern unsigned char lcd_text[32]; lcd_clear(); lcd_gotoxy(0,0); sprintf(lcd_text,"%3d %3d %3d %3d\n%3d %3d %3d %3d",b_kiri,kiri,f_kiri, f_kanan,kanan,b_kanan,blakang,bawah); lcd_puts(lcd_text); delay_ms(50); } // Kalibrasi SRF01 void cal_srf01() { rangingAll(); for (i=1;i<=8;i++) { range_data[i] = getRange(i); } lcd_srf01(); }

Pemrograman sensor TPA81 dipisahkan dalam header tpa.h sebagai berikut :

extern unsigned int i, j;

extern unsigned char lcd_text[32], pixel[8];

#define kipas PORTA.1

// Membaca data dari register tertentu TPA81 unsigned int tpa_read(unsigned char reg) {

unsigned int data; delay_ms(40);

i2c_start(); i2c_write(0xD0); i2c_write(reg); i2c_start(); i2c_write(0xD1); data=i2c_read(0); i2c_stop(); return(data); }

// Memberi perintah ke command register TPA81

void tpa_write(unsigned char reg, unsigned char value) { i2c_start(); i2c_write(0xD0); i2c_write(reg); i2c_write(value); i2c_stop(); delay_ms(10); }

// Membaca nilai tiap pixel thermal array void tpa_data() { for (j=2;j<=9;j++) { pixel[j-2] = tpa_read(j); } }

// Menjalankan motor brushless void motor_start() { unsigned int i, j; kipas = 1; for(j=0;j<=20;j++) { kipas = 1; delay_us(500); kipas = 0; delay_us(19500); } for(i=0;i<=100;i++) { kipas = 1; delay_us(1500); kipas = 0;

kipas = 0; delay_us(18200); }

}

// Menggerakkan servo ke seluruh arah sembari memutar kipas void tpa_servo_all()

{

unsigned int loop; loop = 3; while(loop--) { tpa_write(0,16); motor_start(); } }

// Mencari titik api, lalu menjalankan motor bila titik api sudah ditemukan void tpa_servo_scan()

{

unsigned int place, blow;

blow = 0; for(i=14;i<=20;i++) { tpa_write(0,i); tpa_data(); for(j=0;j<=7;j++) { if (pixel[j]>50) { blow = 1; place = i; j = 8; i = 26; } } }

if (blow!=1) { for(i=20;i>=14;i--) { tpa_write(0,i); tpa_data(); for(j=0;j<=7;j++) { if (pixel[j]>50) { place = i; blow = 1; j = 8; i = 6; } } } } if (blow==1) { tpa_write(0,place); motor_start(); } else { tpa_servo_all(); } }

// Menampilkan hasil pembacaan seluruh pixel ke LCD void lcd_tpa() { sprintf(lcd_text,"%3d %3d %3d %3d %3d %3d %3d %3d",pixel[0],pixel[1], pixel[2],pixel[3],pixel[4],pixel[5],pixel[6],pixel[7]); lcd_clear(); lcd_gotoxy(0,0); lcd_puts(lcd_text); delay_ms(50); } // Kalibrasi TPA81 void cal_tpa81() { tpa_data(); lcd_tpa();

extern unsigned int start, retry, ldr, ruang, ruang_count, juring, api, bio_stat, home, putih, cal, out_home, i, j;

extern unsigned int blk_kiri, blk_kanan; extern unsigned char lcd_text[32], pixel[8]; #define ADC_VREF_TYPE 0x40

#define uvtron PINA.0 #define emergency PIND.7

// Pembacaan nilai ADC

unsigned int read_adc(unsigned char adc_input) {

ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);

// Delay needed for the stabilization of the ADC input voltage delay_us(10);

// Start the AD conversion ADCSRA|=0x40;

// Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0);

ADCSRA|=0x10; return ADCW; }

// Kirim data ke USART1

void serialTX1(unsigned char data) {

while (( UCSR1A & DATA_REGISTER_EMPTY)==0); UDR1 = data;

}

// Kirim data ke CM-510

void sendBioloid(unsigned char lsb, unsigned char msb) { serialTX1(0xFF); serialTX1(0x55); serialTX1(lsb); serialTX1(~lsb); serialTX1(msb); serialTX1(~msb); }

// Menampilkan data tertentu ke LCD void lcd_main()

{ lcd_clear(); lcd_gotoxy(0,0); if (home!=2) {

sprintf(lcd_text,"Bio: %2d LDR: %3d\nRoom: %d Api: %d",bio_stat,ldr,ruang,api);

lcd_puts(lcd_text); }

if (home==2) {

sprintf(lcd_text," SI ITEM MANIS \n PULANG KE RUMAH"); lcd_puts(lcd_text); } } void lcd_cal() { lcd_clear(); lcd_gotoxy(0,0); if (home!=2) {

sprintf(lcd_text,"Bio: %2d LDR: %3d\nCal: %3d Api: %d",bio_stat,ldr,cal,api); lcd_puts(lcd_text); } if (home==2) {

sprintf(lcd_text," SI ITEM MANIS \n PULANG KE RUMAH"); lcd_puts(lcd_text); } } void readSensor() { //---SRF01 READINGS---// rangingAll(); for (i=1;i<=8;i++) { range_data[i] = getRange(i); } //---//

void forceForward() {

//Belum Rata Kiri

if ( ((kiri<12)&&(kiri>9))||(((kiri>30)&&(b_kiri>30))&&(kiri<35)) ) { sendBioloid(8,0); bio_stat = 8; }

//Belum Rata Kanan else if ( ((kanan<12)&&(kanan>9))||(((kanan>30)&&(b_kanan>30))&&(kanan<35)) ) { sendBioloid(9,0); bio_stat = 9; } //Sudah Rata else { //Lurus sendBioloid(3,0); bio_stat = 3; } } void moving() {

extern unsigned int blk_kiri, blk_kanan;

//---MOVING CONDITIONS---//

//Depan Jauh

if ( (f_kiri>15)||(f_kanan>15) )

{ //Belum Rata Kiri

if (((kiri<12)&&(kiri>9))||(((kiri>30)&&(b_kiri>30))&&(kiri<35))) { sendBioloid(8,0); bio_stat = 8; }

//Belum Rata Kanan else if (((kanan<12)&&(kanan>9))||(((kanan>30)&&(b_kanan>30))&&(kanan<35))) { sendBioloid(9,0); bio_stat = 9; } //Sudah Rata else {

if ( (b_kiri>40)&&(kiri>40)&&(blakang>72) ) { sendBioloid(7,0); bio_stat = 7; blk_kiri = 1; blk_kanan = 0; }

//Kanan Jauh, Belok Kanan

else if ( (b_kanan>40)&&(kanan>40)&&(blakang>72) ) { sendBioloid(6,0); bio_stat = 6; blk_kiri = 0; blk_kanan = 1; } //Lurus

else { sendBioloid(3,0); bio_stat = 3; } //Uneven Floor

if ( (bawah>16)&&(bawah<25) ) {

//Belum Rata Kiri

if (((kiri<12)&&(kiri>9))||(((kiri>30)&&(b_kiri>30))&&(kiri<35))) { sendBioloid(8,0); bio_stat = 8; }

//Belum Rata Kanan

else if (((kanan<12)&&(kanan>9))||(((kanan>30)&&(b_kanan>30))&&(kanan<35))) { sendBioloid(9,0); bio_stat = 9; }

//Sudah Rata

else { sendBioloid(10,0); bio_stat = 10; } } } } //Depan Dekat else if ( ((f_kiri<15)&&(f_kanan<15)) ) {

//Belum Rata Kiri

if ( ((kiri<12)&&(kiri>9))||(((kiri>30)&&(b_kiri>30))&&(kiri<35)) ) { sendBioloid(8,0); bio_stat = 8; }

//Belum Rata Kanan else if ( ((kanan<12)&&(kanan>9))||(((kanan>30)&&(b_kanan>30))&&(kanan<35)) ) { sendBioloid(9,0); bio_stat = 9; } //Sudah Rata else {

//Kiri>Kanan, Belok Kiri

if( (b_kiri>b_kanan)&&(kiri>kanan) ) { sendBioloid(7,0); bio_stat = 7; blk_kiri = 0; blk_kanan = 0; }

//Kiri<Kanan, Belok Kanan

else if( (b_kiri<b_kanan)&&(kiri<kanan) ) { sendBioloid(6,0); bio_stat = 6; blk_kanan = 0; blk_kiri = 0; }

//Lurus

else { sendBioloid(3,0); bio_stat = 3; } }

}

//---// }

readSensor(); forceForward(); }

//Tadi Kiri, Kiri Jauh, Belok Kiri

if ( (((b_kiri>40)&&(kiri>40))&&(blk_kiri==1)) ) { sendBioloid(7,0); bio_stat = 7; blk_kiri = 1; blk_kanan = 0; ruang = 0; }

//Tadi Kiri, Kiri Deket, Belok Kanan

else if ( (((b_kiri<20)&&(kiri<20))&&(blk_kiri==1)) ) { sendBioloid(6,0); bio_stat = 6; blk_kiri = 0; blk_kanan = 1; ruang = 0; }

//Tadi Kanan, Kanan Jauh, Belok Kanan

else if ( (((b_kanan>40)&&(kanan>40))&&(blk_kanan==1)) )

{ sendBioloid(6,0); bio_stat = 6; blk_kiri = 0; blk_kanan = 1; ruang = 0; } //Tadi Kanan, Kanan Deket, Belok Kiri

else if ( (((b_kanan<20)&&(kanan<20))&&(blk_kanan==1)) )

{ sendBioloid(7,0); bio_stat = 7; blk_kiri = 1; blk_kanan = 0; ruang = 0; } } // Start Awal void robot_init() { tpa_write(0,16); lcd_clear(); lcd_gotoxy(1,0);

lcd_putsf("SI ITEM MANIS\nPERGI DARI RUMAH");

setBaudRate(0x65); UBRR0L=0x11; start = 0; retry = 0; ruang = 5; ruang_count = 4; juring = 0; home = 1; blk_kiri = 0; blk_kanan = 0; delay_ms(100); for (i=0;i<20;i++)

{

rangingAll(); }

}

// Home Dari Mana void setHome() {

//Belum Rata Kiri readSensor(); if ( ~((b_kiri<16)&&(kiri<16)) ) { readSensor(); sendBioloid(8,0); bio_stat = 8; } else { readSensor(); cal = ((b_kiri+kiri)/2)+((f_kiri+f_kanan)/2)+((kanan+b_kanan/2))+blakang; if (cal>210) { ruang=0; home = 1; }

else { ruang=0; home = 2; } }

}

// Kalibrasi Sensor-sensor void cal_sensor()

{

unsigned int cal_count, stat;

setBaudRate(0x65); UBRR0L=0x11; cal_count=0; while(1) { if (cal_count==0) { readSensor(); cal = ((b_kiri+kiri)/2)+((f_kiri+f_kanan)/2)+(kanan+b_kanan/2)+blakang; lcd_cal(); } else if (cal_count==1) {

} if (emergency==0) stat = 1; if ( (emergency==1)&&(stat==1) ) { stat = 0; cal_count++; if (cal_count>2) cal_count=0; } } } C.2.Pemrograman CM-510

Pemrograman CM-510 mencakup servo control serta penerimaan instruksi dari ATMEGA128 beserta eksekusi instruksi yang diminta dalam proses navigasi. Pemrograman menggunaan program yang sudah terintegrasi dengan unit ini, yaitu software ROBOPLUS, sebagai berikut :

Lampiran D

Datasheet Sensor-sensor

SRF01 Ultrasonic range finder

Technical Documentation

Overview

The SRF01 is a single transducer ultrasonic rangefinder in a very small footprint PCB. Connection is to a single pin Serial interface. The serial interface is a standard TTL level UART format of 1 start, 1 stop and no parity bits, and may be connected directly to many controllers, such as the Basic Stamps or the PICAXE. Baud rate at power-up is always 9600, there is a command to change this to 19200 or 38400 baud if preferred. Up to 16 SRF01's may be connected together on a single bus. Like all our rangefinders, the SRF01 can measure in Cm or Inches. Power Requirements

The SRF01 accepts any voltage between 3.3v and 12v, however the recommended maximum is 5.5v. Internally, it operates at 3.3v and there is a low dropout

regulator already on the SRF01 to provide this. The serial I/O pin operates at 3.3v and also 5v tolerant, so you can connect it directly to 3.3v or 5v signals. Operating current during ranging is 25mA, 11mA in standby (waiting for a command) and around 55uA in sleep mode (shutdown).

Single Pin Serial Communication

Serial data is 1 start, 1 stop and no parity bits. Serial data is a TTL level signal - It is NOT RS232. Do not connect the SRF01 to an RS232 port - you will destroy

"break" is just a low level for 12 bit times or longer. 1.5mS or more will be fine. It is used to synchronize transfers on the 1-wire serial bus. The default shipped address can be changed by the user to any of 16 addresses 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 or 16, and therefore up to 16 sonar's can be used. Note - this range is different to the SRF02 which has addresses 0-15. The reason is that for specific commands only all SRF01's regardless of their programmed address, will respond to address 0. This makes it easy to start all SRF01s ranging at the same time.

Baud Rate

The serial baud rate on the SRF01 always starts at 9600 on power up. It can be changed to 19200 or 38400 if you wish. It will revert to 9600 at the next power up. To change the baud rate, just send a "break" followed by the general call address of zero (not the module address), then command 0x64 for 19200 or command 0x65 for 38400. You can only send the command to address zero to change all SRF01's at the same time.

Connections

The connections to the SRF01 are shown below. If you're using multiple SRF01's, you can connect them all up to the same serial port on your controller. Just make sure all the SRF01's are programmed to different addresses. There is a weak pull-up resistor (47k) to 3.3v on the module, to pull the Tx line pull-up to a logic high level when none of the SRF01's are transmitting. Our 3-way JST connectors are

Commands

To send a command to the SRF01, you need to send a "break" followed by two bytes. The first is the SRF01's address 1 to 16, (0x01 to 0x10) and then the actual command itself - see below. There are two commands to initiate a ranging (80 to 81) giving results in inches and centimeters. These two commands don't Transmit the result back to your controller. You should wait 70mS and then use command 94 to get the result of the ranging.

Another set of two commands (83 to 84) do the same, but also transmits the result of the ranging back to your controller as soon as it is available. Together, these four commands (80,81,84 & 84) are called "Real" because they perform a complete ranging. There is another set of four commands (86, 87, 89 & 90) called "Fake". They are the same as the "Real" commands except that they do not send the 8-cycle ultrasonic burst out. These are used where the burst has been transmitted by another sonar. It is up to you to synchronize the commands to the two sonar's. There is a command (92) to transmit a burst without doing the ranging.

Command 93 is used to get the firmware revision of the SRF01. Command 94 gets returns two bytes (high byte first) from the most recent ranging. Put them together to make a 16-bit result. Command 95 gets the status byte. Bit 0 is the "Lock" bit. it is low (0) after power up, after the "Unlock" command is executed and after the module exits sleep mode. It goes high after 6 rangings have been completed with at least 30cm of free space in front of the sonar. See Advanced Mode for more details. Command 96 is used to place the SRF01 in a low power sleep mode. See Sleep Mode for more details. Commands 98 & 99 are used to enable/disable Advanced Mode.

Command 

Decimal  Hex 

Address 0 

Access  Action 

80  0x50  Yes  Real Ranging Mode ‐ Result in inches   81  0x51  Yes  Real Ranging Mode ‐ Result in centimeters 

           

83  0x53  No 

Real Ranging Mode ‐ Result in inches,  automatically Tx range back to controller as  soon as ranging is complete. 

84  0x54  No 

Real Ranging Mode ‐ Result in centimeters,  automatically Tx range back to controller as  soon as ranging is complete. 

           

89  0x59  No 

Fake Ranging Mode ‐ Result in inches,  automatically Tx range back to controller as  soon as ranging is complete. 

90  0x5A  No 

Fake Ranging Mode ‐ Result in centimeters,  automatically Tx range back to controller as  soon as ranging is complete. 

           

92  0x5C  Yes  Transmit an 8 cycle 40khz burst ‐ no ranging  takes place 

93  0x5D  No  Get software version ‐ sends a single byte  back to the controller 

94  0x5E  No  Get Range, returns two bytes (high byte  first) from the most recent ranging. 

95  0x5F  No 

Get Status, returns a single byte. Bit 0  indicates "Transducer locked", Bit 1  indicates "Advanced Mode" 

96  0x60  Yes  Sleep, shuts down the SRF01 so that it uses  very low power (55uA). 

97  0x61  Yes 

Unlock. Causes the SRF01 to release and re‐ acquire its "Transducer lock". Used by our  factory test routines. 

98  0x62  Yes 

Set Advanced Mode (Factory default) ‐  When locked, SRF01 will range down to  zero. 

99  0x63  Yes  Clear Advanced Mode ‐ SRF01 will range  down to approx. 12cm/5in, 

100  0x64  Yes  Changes the baud rate to 19200  101  0x65  Yes  Changes the baud rate to 38400 

           

160  0xA0  No  1st in sequence to change I2C address  165  0xA5  No  3rd in sequence to change I2C address  170  0xAA  No  2nd in sequence to change I2C address 

None of the commands which return data can use address 0. That would mean SRF01's trying to transmit data at the same time, and is prevented.

Most commands which do not return data are allowed to use address 0. Exceptions are address change commands.

The advantage of allowing address 0 access is that by sending a ranging command such as 0x51 (81 decimal), all SRF01s will start ranging at the same time. After 70mS, you can then get the results from each SRF01 at its own address.

LED

The Led gives a brief flash during the "ping" whilst ranging. If the transducer has not locked, the Led is on with a brief flash off. If the transducer is locked, the Led

Dokumen terkait