Pada postingan kali ini benar2 tingkat tinggi levelnya karena sudah masuk ke robot line follower atau robot pengikut garis, sebenarnya sangat sederhana sekali prinsip kerjanya yaitu terdapat 8 buah led putih atau infrared yang mana masing-masing led / infrared tersebut terdapat satu penampung atau yang mengambil cahaya tersebut namanya photodioda, nah sensor photodioda lah yang akan memberikan arahan untuk robot dapat bergerak ke kanan, ke kiri, lurus atau mundur, robot ini tidak dilengkapi dengan PID control karena untuk pemahaman PID control ada pada halaman sendiri dan pada alat yang berbeda, Anda bisa menggabungkan kedua program tersebut jika menginginkan robot LF ini menggunakan PID control.
Jadi ada 8 led dan photodioda yang mana masing-masing mewakili satu kontrol arah, misal seperti gambar diatas, 3 led bagian kiri akan mengendalikan robot untuk belok ke kanan, begitu pula dengan led dan photodioda bagian kanan akan mengendalikan robot atau motor untuk belok ke kanan, berikut penjelasan gambar untuk skematik dan programnya.
a. Minimum System ATMega16
b. Sensor Photodioda dan LED
c. Motor Driver L293
d. Program Bascom AVR
$regfile = "m32def.dat"
$crystal = 11059200
Dirkiri1 Alias Portd.2
Dirkiri2 Alias Portd.3
Dirkanan1 Alias Portd.6
Dirkanan2 Alias Portd.7
Config Portd.3 = Output
Config Portd.2 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Portc.7 = Output
Tombol1 Alias Pinb.3
Tombol2 Alias Pinb.2
Tombol3 Alias Pinb.1
Tombol4 Alias Pinb.0
Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pinb.2 = Input
Config Pinb.3 = Input
Set Portb.0
Set Portb.1
Set Portb.2
Set Portb.3
Reset Portc.7
Config Timer1 = Pwm , Pwm = 8 , Prescale = 64 ,
Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Config Adc = Single , Prescaler = 8 , Reference = Avcc
Declare Sub Pwm(byval Kiri As Byte , Byval Kanan As
Byte)
Declare Sub Isibobot
Declare Sub Bacaadc
Declare Sub Kalibrasi
Declare Sub Ceksensor
Declare Sub Setting
Declare Sub Aturpid
Declare Sub Liatadc
Declare Sub Cekregister
Declare Sub Maju_dikit
Dim Sensor As Byte
Dim Pilihan As Byte
Dim Kecepatan As Byte
Dim Regkan As Byte
Dim Regkir As Byte
Dim Pwm_ka_max As Integer , Pwm_ki_max As Integer ,
Pwm_ka As Integer , Pwm_ki As Integer
Dim Kp As Byte , Kd As Byte , Ki As Byte , Sum_error
As Integer , Diff As Integer , Bobot As Integer , Bobot_lalu As Integer
Dim Kpeeprom As Eram Byte
Dim Kdeeprom As Eram Byte
Dim Kieeprom As Eram Byte
Dim Keceeprom As Eram Byte
Dim Prop As Integer , Deriv As Integer , Integ As
Integer , Integral As Single , X As Byte
Dim Vref0 As Word , Vref1 As Word , Vref2 As Word ,
Vref3 As Word , Vref4 As Word , Vref5 As Word , Vref6 As Word , Vref7 As Word
Dim Dataadc0 As Word , Dataadc1 As Word , Dataadc2 As
Word , Dataadc3 As Word , Dataadc4 As Word , Dataadc5 As Word , Dataadc6 As
Word , Dataadc7 As Word
Dim Eeprom0 As Eram Word , Eeprom1 As Eram Word ,
Eeprom2 As Eram Word , Eeprom3 As Eram Word , Eeprom4 As Eram Word , Eeprom5 As
Eram Word , Eeprom6 As Eram Word , Eeprom7 As Eram Word
Dim Href0 As Word , Href1 As Word , Href2 As Word ,
Href3 As Word , Href4 As Word , Href5 As Word , Href6 As Word , Href7 As Word
Dim Lref0 As Word , Lref1 As Word , Lref2 As Word ,
Lref3 As Word , Lref4 As Word , Lref5 As Word , Lref6 As Word , Lref7 As Word
Dim A As Byte
Sensor0 Alias Sensor.0
Sensor1 Alias Sensor.1
Sensor2 Alias Sensor.2
Sensor3 Alias Sensor.3
Sensor4 Alias Sensor.4
Sensor5 Alias Sensor.5
Sensor6 Alias Sensor.6
Sensor7 Alias Sensor.7
'=====================================================================
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4
= Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 ,
Db7 = Portc.5
Config Lcd = 16 * 2
Cursor Off
'Deflcdchar 0 , 32 , 10 , 21 , 17 , 17 , 17 , 10 , 4
'=====================================================================
Inisialisasi:
Vref0 =
Eeprom0
Vref1 =
Eeprom1
Vref2 =
Eeprom2
Vref3 =
Eeprom3
Vref4 =
Eeprom4
Vref5 =
Eeprom5
Vref6 =
Eeprom6
Vref7 =
Eeprom7
'========================
Atur:
Cls
Locate 1 , 1
Lcd "
ROBOMAN "
Locate 2 , 1
Lcd " set
start"
Do
If Tombol1 =
0 Then
Call Setting
End If
If Tombol4 =
0 Then
Set Portc.7
Cls
Goto Utama
End If
Waitms 50
Loop
'================================== mulai =======================
Utama:
Do
Call Bacaadc
Call Ceksensor
Cls
Locate 2 , 5
Lcd Bin(sensor)
Select Case Pilihan
Locate 1 , 1
Case 1 : Lcd
"DATAADC0= " ; Dataadc0
Case 2 : Lcd
"DATAADC1= " ; Dataadc1
Case 3 : Lcd
"DATAADC2= " ; Dataadc2
Case 4 : Lcd
"DATAADC3= " ; Dataadc3
Case 5 : Lcd
"DATAADC4= " ; Dataadc4
Case 6 : Lcd
"DATAADC5= " ; Dataadc5
Case 7 : Lcd
"DATAADC6= " ; Dataadc6
Case 8 : Lcd
"DATAADC7= " ; Dataadc7
End Select
Call Ceksensor
If Sensor =
&B10000000 Or Sensor = &B01000000 Or Sensor = &B00100000 Or Sensor
= &B11000000 Or Sensor = &B11100000 Or Sensor = &B11110000 Then
Dirkiri1 = 0 ‘robot belok kiri
Dirkiri2 = 1
Dirkanan1 = 1
Dirkanan2 = 0
Pwm1a = 200
Pwm1b = 0
Elseif Sensor
= &B00000001 Or Sensor = &B00000010 Or Sensor = &B00000100 Or
Sensor = &B00000011 Or Sensor = &B00000111 Or Sensor = &B00001111
Then
Dirkiri1 = 0 ‘robot belok kanan
Dirkiri2 = 1
Dirkanan1 = 1
Dirkanan2 = 0
Pwm1a = 0
Pwm1b = 200
Elseif Sensor
= &B00011000 Or Sensor = &B00111100 Or Sensor = &B00001000 Or
Sensor = &B00010000 Then
Dirkiri1 = 0
Dirkiri2 = 1 ‘robot jalan Lurus
Dirkanan1 = 1
Dirkanan2 = 0
Pwm1a = 200
Pwm1b = 200
Elseif Sensor
= &B00000000 Then
Dirkiri1 = 1
Dirkiri2 = 0 ‘robot jalan mundur
Dirkanan1 = 0
Dirkanan2 = 1
Pwm1a = 100
Pwm1b = 100
End If
Loop
'===========================================
Sub Bacaadc:
Start Adc
Dataadc0 =
Getadc(0)
Dataadc1 =
Getadc(1)
Dataadc2 =
Getadc(2)
Dataadc3 =
Getadc(3)
Dataadc4 =
Getadc(4)
Dataadc5 =
Getadc(5)
Dataadc6 =
Getadc(6)
Dataadc7 =
Getadc(7)
Stop Adc
End Sub
'============================================
Sub Kalibrasi
Cls
Lcd "proses kalibrasi"
Do
Call Bacaadc
If Dataadc0 < Href0 Then Lref0 = Dataadc0
If Dataadc1 < Href1 Then Lref1 = Dataadc1
If Dataadc2 < Href2 Then Lref2 = Dataadc2
If Dataadc3 < Href3 Then Lref3 = Dataadc3
If Dataadc4 < Href4 Then Lref4 = Dataadc4
If Dataadc5 < Href5 Then Lref5 = Dataadc5
If Dataadc6 < Href6 Then Lref6 = Dataadc6
If Dataadc7 < Href7 Then Lref7 = Dataadc7
If Dataadc0 > Lref0 Then Href0 = Dataadc0
If Dataadc1 > Lref1 Then Href1 = Dataadc1
If Dataadc2 > Lref2 Then Href2 = Dataadc2
If Dataadc3 > Lref3 Then Href3 = Dataadc3
If Dataadc4 > Lref4 Then Href4 = Dataadc4
If Dataadc5 > Lref5 Then Href5 = Dataadc5
If Dataadc6 > Lref6 Then Href6 = Dataadc6
If Dataadc7 > Lref7 Then Href7 = Dataadc7
Waitms 50
Loop Until Tombol1 = 0
Vref0 = Lref0 + Href0
Vref1 = Lref1 + Href1
Vref2 = Lref2 + Href2
Vref3 = Lref3 + Href3
Vref4 = Lref4 + Href4
Vref5 = Lref5 + Href5
Vref6 = Lref6 + Href6
Vref7 = Lref7 + Href7
Vref0 = Vref0 / 2
Vref1 = Vref1 / 2
Vref2 = Vref2 / 2
Vref3 = Vref3 / 2
Vref4 = Vref4 / 2
Vref5 = Vref5 / 2
Vref6 = Vref6 / 2
Vref7 = Vref7 / 2
Eeprom0 = Vref0
Eeprom1 = Vref1
Eeprom2 = Vref2
Eeprom3 = Vref3
Eeprom4 = Vref4
Eeprom5 = Vref5
Eeprom6 = Vref6
Eeprom7 = Vref7
Kalibrasi_x:
Cls
Lcd "kalibrasi sukses"
Wait 2
Do
Call Ceksensor
Cls
Lcd Bin(sensor)
Waitms 50
Loop Until Tombol1 = 0
Goto Setting
End Sub
Sub Ceksensor
Call Bacaadc
If Dataadc0
> 922 Then
Sensor.0 =
1
End If
If Dataadc0
< 922 Then
Sensor.0 =
0
End If
If Dataadc1
> 900 Then
Sensor.1 =
1
End If
If Dataadc1
< 900 Then
Sensor.1 =
0
End If
If Dataadc2
> 890 Then
Sensor.2 =
1
End If
If Dataadc2
< 890 Then
Sensor.2 =
0
End If
If Dataadc3
> 989 Then
Sensor.3 =
1
End If
If Dataadc3
< 989 Then
Sensor.3 =
0
End If
If Dataadc4
> 960 Then
Sensor.4 =
1
End If
If Dataadc4
< 960 Then
Sensor.4 =
0
End If
If Dataadc5
> 994 Then
Sensor.5 =
1
End If
If Dataadc5
< 994 Then
Sensor.5 =
0
End If
If Dataadc6
> 989 Then
Sensor.6 =
1
End If
If Dataadc6
< 989 Then
Sensor.6 =
0
End If
If Dataadc7
> 967 Then
Sensor.7 =
1
End If
If Dataadc7
< 967 Then
Sensor.7 =
0
End If
End Sub
'=======================================
Liatadc:
Do
Call Bacaadc
Call Ceksensor
Cls
Locate 2 , 5
Lcd Bin(sensor)
Select Case Pilihan
Locate 1 , 1
Case 1 : Lcd
"DATAADC0= " ; Dataadc0
Case 2 : Lcd
"DATAADC1= " ; Dataadc1
Case 3 : Lcd
"DATAADC2= " ; Dataadc2
Case 4 : Lcd
"DATAADC3= " ; Dataadc3
Case 5 : Lcd
"DATAADC4= " ; Dataadc4
Case 6 : Lcd
"DATAADC5= " ; Dataadc5
Case 7 : Lcd
"DATAADC6= " ; Dataadc6
Case 8 : Lcd
"DATAADC7= " ; Dataadc7
End Select
If Tombol3 = 0 Then
Waitms 200
Incr Pilihan
If Pilihan
> 8 Then Pilihan = 1
End If
If Tombol2 = 0 Then
Waitms 200
Decr Pilihan
If Pilihan
< 1 Then Pilihan = 8
End If
If Tombol1 = 0 Or Tombol4 = 0 Then Goto Setting
Waitms 100
Loop
'========================================
Setting:
Cls
Locate 1 , 1
Lcd "ADC SENSOR PID"
Do
Waitms 200
If Tombol1 =
0 Then
Waitms 200
Goto Liatadc
End If
If Tombol2 =
0 Then
Waitms 200
Call
Kalibrasi
End If
If Tombol4 =
0 Then
Waitms 200
Goto Atur
End If
Waitms 50
Loop
'================ selesai =====================
Tabel
5.2.2 Tabel Kalibrasi ADC Sensor
Port ADC
|
Nilai ADC pada Kertas Putih
|
Nilai ADC pada Kertas Hitam
|
Nilai tengah
|
ADC.0
|
822
|
1022
|
922
|
ADC.1
|
800
|
1000
|
900
|
ADC.2
|
780
|
1020
|
890
|
ADC.3
|
800
|
1020
|
989
|
ADC.4
|
810
|
1021
|
960
|
ADC.5
|
812
|
1024
|
994
|
ADC.6
|
811
|
1023
|
989
|
ADC.7
|
811
|
1012
|
967
|
Sehingga dari data table
diatas jika sensor mengenai medan berwarna hitam akan dihasilkan nilai 1 dan
jika mengenai medan putih akan dihasilkan nilai 0, karena terkena eksekusi
program yang di Bold berikut
If Dataadc0 > 922 Then
Sensor.0 = 1
End If
If Dataadc0
< 922 Then
Sensor.0 = 0
End If
5.2.5 Cara Penggunaan Robot
Cara
penggunaan robot line follower ini pertama pilih tampilan pada menu “Set”, maka
akan masuk ke menu kalibrasi, jika sensor sudah membaca dengan baik pada track,
langkah kedua yaitu menyimpan nilai kalibrasi tersebut dengan menekan tombol 2,
setelah itu kembali ke menu awal dengan menekan tombol 4, sehingga akan tampak
tampilan awal “set” dan “start”, pilihlah menu “start” yang menandakan robot
siap untuk dijalankan.
5.2.6 VIDEO HASILNYA
No comments:
Post a Comment