Anda di halaman 1dari 91

LATIHAN 1

11 MEMBERSHIP FUNCTION

Tanggal : 01 Maret 2017

Grafik Dari Membership Function

1. Gauss2mf
2. gaussmf

3. Gbellmf
4. Pimf

5. Gbellmf
6. Trimf

7. Dsigmf
8. Trapmf

9. Psigmf
10. Sigmf

11. Smf
Program Pada Scilab

x = [0:0.1:10]';
y1 = gauss2mf(x,[2 4 1 8]);
y2 = gauss2mf(x,[2 5 1 7]);
y3 = gauss2mf(x,[2 6 1 6]);
y4 = gauss2mf(x,[2 7 1 5]);
y5 = gauss2mf(x,[2 8 1 4]);
plot(x,[y1 y2 y3 y4 y5])
xtitle ("gauss2mf","x","y")
scf;

x = 0:0.1:10;
y = gaussmf(x,[2 5]);
plot(x,y)
xlabel('gaussmf, P=[2 5]')
xtitle ("gaussmf","x","y")
scf;

x = 0:0.1:10;
y = gbellmf(x,[2 4 6]);
plot(x,y)
xlabel('gbellmf, P=[2 4 6]')
xtitle ("gbellmf","x","y")
scf;

x = 0:0.1:10;
y = pimf(x,[1 4 5 10]);
plot(x,y)
xlabel('pimf, P = [1 4 5 10]')
xtitle ("pimf","x","y")
scf;

x = 0:0.1:10;
y = zmf(x,[3 7]);
plot(x,y)
xlabel('zmf, P = [3 7]')
xtitle ("gbellmf","x","y")
scf;

x = 0:0.1:10;
y = trimf(x,[3 6 8]);
plot(x,y)
xlabel('trimf, P = [3 6 8]')
xtitle ("trimf","x","y")
scf;
x = 0:0.1:10;
y = dsigmf(x,[5 2 5 7]);
plot(x,y)
xlabel('dsigmf, P = [5 2 5 7]')
xtitle ("dsigmf","x","y")
scf;

x = 0:0.1:10;
y = trapmf(x,[1 5 7 8]);
plot(x,y)
xlabel('trapmf, P = [1 5 7 8]')
xtitle ("trapmf","x","y")
scf;

x = 0:0.1:10;
y = psigmf(x,[2 3 -5 8]);
plot(x,y)
xlabel('psigmf, P = [2 3 -5 8]')
xtitle ("psigmf","x","y")
scf;

x = 0:0.1:10;
y = sigmf(x,[2 4]);
plot(x,y)
xlabel('sigmf, P = [2 4]')
xtitle ("sigmf","x","y")
scf;

x = 0:0.1:10;
y = smf(x,[1 8]);
plot(x,y)
xlabel('smf, P = [1 8]')
xtitle ("smf","x","y")
scf;

Deskripsi :

MEMBERSHIP FUNCTION merupakan suatu kurva yang menunjukkan pemetaan


titik-titik input data ke dalam nilai keanggotaannya (sering juga disebut dengan
derajat keanggotaan) yang memiliki interval antara 0 sampai 1. Salah satu cara yang
dapat digunakan untuk mendapatkan nilai keanggotaan adalah dengan melalui
pendekatan fungsi.
LATIHAN 2

MEMBERSHIP FUNCTION DENGAN CASE (VOLTAGE)

Tanggal : 8 Maret 2017

Grafik menggunakan Sigmf

Program Pada Scilab


style = -3;
x = [-60:0.1:120]';
y1 = sigmf(x,[0.5 20]);
y2 = sigmf(x,[0.5 40]);
y3 = sigmf(x,[0.5 60]);
plot2d(x,[y1 y2 y3], leg="low@medium@high");
xtitle("Voltage(sigmf)","Volt","Degree of Membership Function");
scf(4);

Deskripsi
Pada grafik ini menunjukan 3 kondisi, dimana kasus ini menjelaskan tentang kondisi
tegangan ( low, medium, dan high) yang ditunjukan pada grafik tersebut dalam bentuk
sigmf. Penggunaan "plot2d(x,[y1y2y3],leg=low@medium@high): berfungsi untuk
menampilkan keterangan grafik mengenai kondisi yang terdapat pada bagian bawah
grafik.
LATIHAN 3
MEMBERSHIP FUNCTION DENGAN CASE (SPEED)

Tanggal : 15 Maret 2017

Grafik menggunakan 11 Membership Function

1. Gaussian
2. Gaussian2

3. sigmf
4. Zmf

5. Smf
6. Pimf

7. Gbell
8. Triangular

9. Trapezoid
10. Difference Two Sigmoidal

11. Product Two Sigmoidal


Program pada Scilab

scf(1);
clf(1);
style = -3;
x=[-50:0.1:120]';
y1=gaussmf(x,[10 20]);
y2=gaussmf(x,[10 40]);
y3=gaussmf(x,[10 60]);
y4=gaussmf(x,[10 80]);
plot2d(x,[y1 y2 y3 y4], leg="slow@medium@fast@faster");
xtitle("Speed(Gaussian)","KM/Jam","Degree of Membership Function");
scf (2);

style = -3;
x = [-80:0.1:160]';
y1 = gauss2mf(x,[10 -30 9 80]);
y2 = gauss2mf(x,[10 -10 9 60]);
y3 = gauss2mf(x,[10 15 9 40]);
y4 = gauss2mf(x,[10 30 9 20]);
plot2d(x,[y1 y2 y3 y4], leg="slow@medium@fast@faster");
xtitle("Speed(Gaussian2)","KM/Jam","Degree of Membership Function");
scf(3);

style = -3;
x = [-60:0.1:120]';
y1 = sigmf(x,[0.5 20]);
y2 = sigmf(x,[0.5 40]);
y3 = sigmf(x,[0.5 60]);
y4 = sigmf(x,[0.5 80]);
plot2d(x,[y1 y2 y3 y4], leg="slow@medium@fast@faster");
xtitle("Speed(sigmf)","KM/Jam","Degree of Membership Function");
scf(4);

style = -3;
x = [0:0.1:120]';
y4 = zmf(x,[1 20]);
y5 = zmf(x,[1 40]);
y6 = zmf(x,[1 60]);
y7 = zmf(x,[1 80]);
plot2d(x,[y4 y5 y6 y7],leg="slow@medium@fast@faster");
xtitle("Speed(Zmf)","KM/Jam","Degree of Membership Function");
scf(5);

style = -3;
x=[0:0.1:120]';
y1=smf(x,[2 80]);
y2=smf(x,[2 60]);
y3=smf(x,[2 40]);
y4=smf(x,[2 20]);
plot2d(x,[y1 y2 y3 y4],leg="slow@medium@fast@faster");
xtitle("Speed(Smf)","KM/Jam","Degree of Membership Function");
scf(6);

style = -3;
x=[-50:0.1:120]';
y1=pimf(x,[1 5 6 20]);
y2=pimf(x,[2 5 6 40]);
y3=pimf(x,[3 5 6 60]);
y4=pimf(x,[4 5 6 80]);
plot2d(x,[y1 y2 y3 y4],leg="slow@medium@fast@faster");
xtitle("Speed(pimf)","KM/Jam","Degree of Membership Function");
scf(7);

style = -3;
x=[-100:0.1:200]';
y1=gbellmf(x,[80 30 80]);
y2=gbellmf(x,[80 45 60]);
y3=gbellmf(x,[80 70 40]);
y4=gbellmf(x,[80 90 20]);
plot2d(x,[y1 y2 y3 y4],leg="slow@medium@fast@faster");
xtitle("Speed(Gbell)","KM/Jam","Degree of Membership Function");
scf(8);

style = -3;
x=[-120:0.1:120]';
y1=trimf(x,[-30 30 80]);
y2=trimf(x,[-45 15 60]);
y3=trimf(x,[-70 -10 40]);
y4=trimf(x,[-90 -30 20])
plot2d(x,[y1 y2 y3 y4],leg="slow@medium@fast@faster");
xtitle("speed(Triangular)","KM/Jam","Degree of Membership Function");
scf(9);

style = -3;
x=[-200:0.1:200]';
y1=trapmf(x,[-150 -90 -30 20]);
y2=trapmf(x,[-130 -70 -10 40]);
y3=trapmf(x,[-105 -45 15 60]);
y4=trapmf(x,[-90 -30 30 80]);
plot2d(x,[y1 y2 y3 y4],leg="slow@medium@fast@faster");
xtitle("Speed(Trapezoid)","KM/Jam","Degree of Membership Function");
scf(10);

style = -3;
x=[-50:0.1:200]';
y1=dsigmf(x,[-30 -90 -30 20]);
y2=dsigmf(x,[-10 -70 -10 40]);
y3=dsigmf(x,[15 -45 15 60]);
y4=dsigmf(x,[30 -30 30 80]);
plot2d(x,[y1 y2 y3 y4],leg="slow@medium@fast@faster");
xtitle("Speed(Difference Two Sigmoidal)","KM/Jam","Degree of Membership Function");
scf(11);

style = -3;
x=[-100:0.1:100]';
y1=psigmf(x,[-0.100 -60 -70 80]);
y2=psigmf(x,[-0.110 -80 -80 70]);
y3=psigmf(x,[-0.120 -90 -90 60]);
plot2d(x,[y1 y2 y3],leg="slow@medium@fast@faster");
xtitle("Speed(Product Two Sigmoidal)","KM/Jam","Degree of Membership Function");

Deskripsi

Pada latihan ini membuat grafik menggunakan 11 bentuk dari Membership function,
dimana terdapat kasus tentang Speed atau kecepatan yang menempatkan dalam
beberapa kondisi yaitu, slow, medium, fast, dan faster.
LATIHAN 4
FUZZY LOGIC 1

Tanggal : 22 Maret 2017

X-cos dengan Gerbang Logika

Tabel kebenaran
Input Output
A B C D E F Y0 Y1 Y2 Y3 Y4 Y5
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 1
0 0 0 0 1 0 1 0 0 0 1 0
0 0 0 0 1 1 1 0 0 0 1 1
0 0 0 1 0 0 1 0 0 1 0 0
0 0 0 1 0 1 1 0 0 1 0 1
0 0 0 1 1 0 1 0 0 1 1 0
0 0 0 1 1 1 1 0 0 1 1 1
0 0 1 0 0 0 1 0 0 0 0 0
0 0 1 0 0 1 1 0 1 0 0 1
0 0 1 0 1 0 1 0 1 0 1 0
0 0 1 0 1 1 1 0 1 0 1 1
0 0 1 1 0 0 1 0 0 1 0 0
0 0 1 1 0 1 1 0 0 1 0 1
0 0 1 1 1 0 1 0 0 1 1 0
0 0 1 1 1 1 1 1 0 1 1 1
0 1 0 0 0 0 0 1 0 0 0 0
0 1 0 0 0 1 1 0 1 0 0 0
0 1 0 0 1 0 0 1 1 0 1 0
0 1 0 0 1 1 0 1 0 1 1 1
0 1 0 1 0 0 1 0 1 1 0 1
0 1 0 1 0 1 1 1 0 0 1 1
0 1 0 1 1 0 1 0 1 1 1 0
0 1 0 1 1 1 1 0 1 1 1 1
0 1 1 0 0 0 1 0 1 0 0 0
0 1 1 0 0 1 1 0 1 11 1 0
0 1 1 0 1 0 0 1 1 1 0 1
0 1 1 0 1 1 1 0 1 1 0 1
0 1 1 1 0 0 1 0 1 1 0 0
0 1 1 1 0 1 1 1 1 1 0 1
0 1 1 1 1 0 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 1
Grafik
Input : 0 1 1 0 0 1

Input : 0 1 1 0 11
Input : 0 1 1 1 0 0
Deskripsi

Pada X-cos ini menerapkan gerbang logika, dimana terdapat 6 input dan 6 output.
Dan berdasarkan beberapa grafik yang dihasilkan dengan tabel tersebut membuktikan
hasil yang sama pada keluarannya.

LATIHAN 5
FUZZY LOGIC
LATIHAN 6
FUZZY LOGIC (ALARM MOBIL)

Tanggal : 05 April 2017

X-cos
Kondisi : 1 0 1 0

Kondisi : 1 0 0 0
Kondisi : 0 1 1 0

Tabel kebenaran

Input Output
A B C D Y
0 0 0 0 0
0 0 0 1 0
0 0 1 0 0
0 0 1 1 0
0 1 0 0 0
0 1 0 1 0
0 1 1 0 1
0 1 1 1 0
1 0 0 0 0
1 0 0 1 0
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 0
1 1 1 0 1
1 1 1 1 1

Keterangan :
A : Oven B : Kompor Listrik
C : Tungku Pemanas D : Ventilasi

Y = +
+
+
+

Deskripsi
Dalam suatu ruangan terdapat oven, kompor listrik, dan tungku panas serta ventilasi
untuk mengeluarkan suhu panas dalam ruangan. Dalam gerbang logika ini alarm
digunakan sebagai tanda peringatan untuk suhu yang melewati batas normal pada
suhu.
LATIHAN 7
FUZZY LOGIC (ALARM MOBIL 1)

Tanggal : 12 April 2017

X-cos
Kondisi : 0 1 1
Kondisi : 1 1 1

Kondisi : 1 1 0
Tabel kebenaran
Input Output
X Y Z Bunyi Lampu Keadaan
0 0 0 0 0 0
0 0 1 0 0 0
0 1 0 0 0 0
0 1 1 0 1 1
1 0 0 0 0 0
1 0 1 0 0 0
1 1 0 1 0 1
1 1 1 1 1 1

Keterangan :
X : Kunci Kontak
Y : Pintu
Z : Jarak

Grafik
Pada saat kondisi 1 1 1, 0 1 1, dan 1 1 0
Deskripsi
Alarm akan bekerja jika kondisi nilai X dan Y bernilai 1 atau Y dan Z bernilai 1.
Disini dikondisikan bernilai satu jika kunci kontak tidak terpasang (X), pintu terbuka
(Y), dan jaraknya jauh (Z).

LATIHAN 9
FUZZY LOGIC (ALARM MOBIL 2)
Tanggal : 19 April 2017

X-cos

Tabel Kebenaran
Input Output
X Y Z Bunyi Lampu Keadaan
0 0 0 0 0 0
0 0 1 0 0 0
0 1 0 0 0 0
0 1 1 0 1 1
1 0 0 0 0 0
1 0 1 0 0 0
1 1 0 1 0 1
1 1 1 1 1 1

Keterangan :
X : Kunci Kontak
Y : Pintu
Z : Jarak

Deskripsi
Alarm akan bekerja jika kondisi nilai X dan Y bernilai 1 atau Y dan Z bernilai 1.
Disini dikondisikan bernilai satu jika kunci kontak tidak terpasang (X), pintu terbuka
(Y), dan jaraknya jauh (Z).

LATIHAN 17
MOBOT NN 2
Pengantar Makanan
Sebelum dijalankan

Setelah di jalankan
Kode Program
Deskripsi

Pada robot pengantar makanan ini bekerja berdasarkan titik lokasi yang diberikan,
yaitu mengantarkan semua makanan pada lokasi yang telah ditentukan kemudian
kembali pada saat makanannya telah terkirim di titik awal atau pusat.
LATIHAN 16

ROBOT VFF

Tanggal : 14 Juni 2017

Robot Pendeteksi Jejak


Sebelum di jalankan

Setelah di jalankan
Kode Program

Dim Mobot, Mobot1 As Byte Mobot number

Dim SensorValue (10), SensorValue1 (10) As Double ' Distance values returned from sensors

Dim SensorNr, SensorNr1 As Byte

Dim Outputs(44) As Double ' Outputs from neurons //BELOM

Dim Outputs1(44) As Double

Dim c1(4) As Integer ' Input layer connections

Dim c2(40) As Integer ' Hidden layer connections

Dim c11(4) As Integer ' Input layer connections

Dim c21(40) As Integer ' Hidden layer connections

' Weights

Dim
w5(),w6(),w7(),w8(),w9(),w10(),w11(),w12(),w13(),w14(),w15(),w16(),w17(),w18(),w19(),v5(),v6(),v7(),v8(),v9(
),v10(),v11(),v12(),v13(),v14(),v15(),v16(),v17(),v18(),v19() As Double

Dim
w20(),w21(),w22(),w23(),w24(),w25(),w26(),w27(),w28(),w29(),w30(),w31(),w32(),w33(),w34(),v20(),v21(),v22
(),v23(),v24(),v25(),v26(),v27(),v28(),v29(),v30(),v31(),v32(),v33(),v34() As Double

Dim
w35(),w36(),w37(),w38(),w39(),w40(),w41(),w42(),w43(),w44(),w45(),w46(),v35(),v36(),v37(),v38(),v39(),v40()
,v41(),v42(),v43(),v44(),v45(),v46() As Double

Dim mnInput(10), mnInput1(10) As Double ' Input array for forwarding sensor values to the
network //BELOM

Dim mnOutput(2), mnOutput1(2) As Double ' Output array for


returning values from the network

Sub Main

Dim X,Y, OldX, OldY,A,B, OldA, OldB As Double ' Mobot position

Dim S,S1 As Double ' Temporary


sensor value

Dim SideSensDiff,FrontSensDiff,SideSensDiff1,FrontSensDiff1 As Double' Difference between left and


right sensors

Dim Alpha, Brake,Alpha1, Brake1 As Double ' Steering and braking

Dim i, j, k, l As Integer

Dim Train, Train1 As Boolean ' True if we're going to


create a file with training values

Static Weights1,Weights11 As Integer ' Number of weights

Static Weights2,Weights21 As Integer ' Number of weights

' Initializing variables

Train = False
Train1 = False

Sensor = Array (4,5,6,7,8) ' Sensors that we activate

Mobot = 0 ' Mobot we're controlling

Mobot1 = 1

' Initializing network when not training

If Not Train Then

Weights1 = 4

Weights2 = 41

Weights11 = 4

Weights21 = 41

' Dimensioning weight arrays

ReDim w5(Weights1)

ReDim w6(Weights1)

ReDim w7(Weights1)

ReDim w8(Weights1)

ReDim w9(Weights1)

ReDim w10(Weights1)

ReDim w11(Weights1)

ReDim w12(Weights1)

ReDim w13(Weights1)

ReDim w14(Weights1)

ReDim w15(Weights1)

ReDim w16(Weights1)

ReDim w17(Weights1)

ReDim w18(Weights1)

ReDim w19(Weights1)

ReDim w20(Weights1)

ReDim w21(Weights1)

ReDim w22(Weights1)

ReDim w23(Weights1)

ReDim w24(Weights1)

ReDim w25(Weights1)

ReDim w26(Weights1)
ReDim w27(Weights1)

ReDim w28(Weights1)

ReDim w29(Weights1)

ReDim w30(Weights1)

ReDim w31(Weights1)

ReDim w32(Weights1)

ReDim w33(Weights1)

ReDim w34(Weights1)

ReDim w35(Weights1)

ReDim w36(Weights1)

ReDim w37(Weights1)

ReDim w38(Weights1)

ReDim w39(Weights1)

ReDim w40(Weights1)

ReDim w41(Weights1)

ReDim w42(Weights1)

ReDim w43(Weights1)

ReDim w44(Weights1)

ReDim w45(Weights2)

ReDim w46(Weights2)

ReDim v5(Weights11)

ReDim v6(Weights11)

ReDim v7(Weights11)

ReDim v8(Weights11)

ReDim v9(Weights11)

ReDim v10(Weights11)

ReDim v11(Weights11)

ReDim v12(Weights11)

ReDim v13(Weights11)

ReDim v14(Weights11)

ReDim v15(Weights11)
ReDim v16(Weights11)

ReDim v17(Weights11)

ReDim v18(Weights11)

ReDim v19(Weights11)

ReDim v20(Weights11)

ReDim v21(Weights11)

ReDim v22(Weights11)

ReDim v23(Weights11)

ReDim v24(Weights11)

ReDim v25(Weights11)

ReDim v26(Weights11)

ReDim v27(Weights11)

ReDim v28(Weights11)

ReDim v29(Weights11)

ReDim v30(Weights11)

ReDim v31(Weights11)

ReDim v32(Weights11)

ReDim v33(Weights11)

ReDim v34(Weights11)

ReDim v35(Weights11)

ReDim v36(Weights11)

ReDim v37(Weights11)

ReDim v38(Weights11)

ReDim v39(Weights11)

ReDim v40(Weights11)

ReDim v41(Weights11)

ReDim v42(Weights11)

ReDim v43(Weights11)

ReDim v44(Weights11)

ReDim v45(Weights21)

ReDim v46(Weights21)

' Opening connection file

Open ".\conn.txt" For Input As #20


For i = 0 To 3

Input #20, c1(i) Input layer

Next i

For i = 0 To 39

Input #20, c2(i) ' Hidden layer

Next i

Close #20

Open ".\conn.txt" For Input As #20

For k = 0 To 3

Input #20, c11(k) Input layer

Next k

For k = 0 To 39

Input #20, c21(k) ' Hidden layer

Next k

Close #20

' Opening weights file

Open ".\weights.txt" For Input As #21

For i = 0 To Weights1

Input #21,w5(i)

Next i

For i = 0 To Weights1

Input #21,w6(i)

Next i

For i = 0 To Weights1

Input #21,w7(i)

Next i

For i = 0 To Weights1

Input #21,w8(i)

Next i

For i = 0 To Weights1
Input #21,w9(i)

Next i

For i = 0 To Weights1

Input #21,w10(i)

Next i

For i = 0 To Weights1

Input #21,w11(i)

Next i

For i = 0 To Weights1

Input #21,w12(i)

Next i

For i = 0 To Weights1

Input #21,w13(i)

Next i

For i = 0 To Weights1

Input #21,w14(i)

Next i

For i = 0 To Weights1

Input #21,w15(i)

Next i

For i = 0 To Weights1

Input #21,w16(i)

Next i

For i = 0 To Weights1

Input #21,w17(i)

Next i

For i = 0 To Weights1

Input #21,w18(i)

Next i

For i = 0 To Weights1

Input #21,w19(i)

Next i

For i = 0 To Weights1
Input #21,w20(i)

Next i

For i = 0 To Weights1

Input #21,w21(i)

Next i

For i = 0 To Weights1

Input #21,w22(i)

Next i

For i = 0 To Weights1

Input #21,w23(i)

Next i

For i = 0 To Weights1

Input #21,w24(i)

Next i

For i = 0 To Weights1

Input #21,w25(i)

Next i

For i = 0 To Weights1

Input #21,w26(i)

Next i

For i = 0 To Weights1

Input #21,w27(i)

Next i

For i = 0 To Weights1

Input #21,w28(i)

Next i

For i = 0 To Weights1

Input #21,w29(i)

Next i

For i = 0 To Weights1

Input #21,w30(i)

Next i

For i = 0 To Weights1
Input #21,w31(i)

Next i

For i = 0 To Weights1

Input #21,w32(i)

Next i

For i = 0 To Weights1

Input #21,w33(i)

Next i

For i = 0 To Weights1

Input #21,w34(i)

Next i

For i = 0 To Weights1

Input #21,w35(i)

Next i

For i = 0 To Weights1

Input #21,w36(i)

Next i

For i = 0 To Weights1

Input #21,w37(i)

Next i

For i = 0 To Weights1

Input #21,w38(i)

Next i

For i = 0 To Weights1

Input #21,w39(i)

Next i

For i = 0 To Weights1

Input #21,w40(i)

Next i

For i = 0 To Weights1

Input #21,w41(i)

Next i

For i = 0 To Weights1
Input #21,w42(i)

Next i

For i = 0 To Weights1

Input #21,w43(i)

Next i

For i = 0 To Weights1

Input #21,w44(i)

Next i

For i = 0 To Weights2 - 1

Input #21,w45(i)

Next i

For i = 0 To Weights2 - 1

Input #21,w46(i)

Next i

Close #21

' Opening weights file

Open ".\weights.txt" For Input As #21

For k = 0 To Weights11

Input #21,v5(k)

Next k

For k = 0 To Weights11

Input #21,v6(k)

Next k

For k = 0 To Weights11

Input #21,v7(k)

Next k

For k = 0 To Weights11

Input #21,v8(k)

Next k

For k = 0 To Weights11

Input #21,v9(k)

Next k

For k = 0 To Weights11
Input #21,v10(k)

Next k

For k = 0 To Weights11

Input #21,v11(k)

Next k

For k = 0 To Weights11

Input #21,v12(k)

Next k

For k = 0 To Weights11

Input #21,v13(k)

Next k

For k = 0 To Weights11

Input #21,v14(k)

Next k

For k = 0 To Weights11

Input #21,v15(k)

Next k

For k = 0 To Weights11

Input #21,v16(k)

Next k

For k = 0 To Weights11

Input #21,v17(k)

Next k

For k = 0 To Weights11

Input #21,v18(k)

Next k

For k = 0 To Weights11

Input #21,v19(k)

Next k

For k = 0 To Weights11

Input #21,v20(k)

Next k

For k = 0 To Weights11
Input #21,v21(k)

Next k

For k = 0 To Weights11

Input #21,v22(k)

Next k

For k = 0 To Weights11

Input #21,v23(k)

Next k

For k = 0 To Weights11

Input #21,v24(k)

Next k

For k = 0 To Weights11

Input #21,v25(k)

Next k

For k = 0 To Weights11

Input #21,v26(k)

Next k

For k = 0 To Weights11

Input #21,v27(k)

Next k

For k = 0 To Weights11

Input #21,v28(k)

Next k

For k = 0 To Weights11

Input #21,v29(k)

Next k

For k = 0 To Weights11

Input #21,v30(k)

Next k

For k = 0 To Weights11

Input #21,v31(k)

Next k

For k = 0 To Weights11
Input #21,v32(k)

Next k

For k = 0 To Weights11

Input #21,v33(k)

Next k

For k = 0 To Weights11

Input #21,v34(k)

Next k

For k = 0 To Weights11

Input #21,v35(k)

Next k

For k = 0 To Weights11

Input #21,v36(k)

Next k

For k = 0 To Weights11

Input #21,v37(k)

Next k

For k = 0 To Weights11

Input #21,v38(k)

Next k

For k = 0 To Weights11

Input #21,v39(k)

Next k

For k = 0 To Weights11

Input #21,v40(k)

Next k

For k = 0 To Weights11

Input #21,v41(k)

Next k

For k = 0 To Weights11

Input #21,v42(k)

Next k

For k = 0 To Weights11
Input #21,v43(k)

Next k

For k = 0 To Weights11

Input #21,v44(k)

Next k

For k = 0 To Weights21 - 1

Input #21,v45(k)

Next k

For k = 0 To Weights21 - 1

Input #21,v46(k)

Next k

Close #21

End If

Randomize

SetMobotPosition (Mobot, 17, 16, 180)

SetMobotPosition (Mobot1, 21.4, 23.7, 180)

SetCellSize(0,0.1) 'Set cell size 10 cm x 10 cm

SetTimeStep(0.5) 'Set simulation time step of 0.1 seconds

' Opening file for training values

If Train And Train1 Then

Open "NNtrain.txt" For Output As #1

End If

' Just used when debugging

' Open "nndebug.txt" For Output As #10

' Used for checking if the mobot is stuck

OldX = GetMobotX(0) - 1

OldY = GetMobotY(0) - 1

OldA = GetMobotX(1) - 1

OldB = GetMobotY(1) - 1

Do '
Starting main loop

X=GetMobotX(Mobot) ' Present mobot coordinates (in meters)


Y=GetMobotY(Mobot)

A=GetMobotX(Mobot1) ' Present mobot coordinates (in meters)

B=GetMobotY(Mobot1)

' Reading sensors

For SensorNr = 0 To 3

SensorValue (SensorNr) = MeasureRange (Mobot, Sensor(SensorNr), 0)

S = SensorValue(SensorNr)

If Not Train Then

If S = -1 Then S = 0 ' Uses 0 instead of -1 when no obstacle in sight

mnInput(SensorNr) = S / 10 ' Scaling sensor values between 0 and 1 ...

'
..and writing to a debug file if used

'Print #10, Round(S / 10, 3); " ";

End If

Next SensorNr

For SensorNr1 = 0 To 3

SensorValue1 (SensorNr1) = MeasureRange (Mobot1, Sensor(SensorNr1), 0)

S1 = SensorValue1(SensorNr1)

If Not Train1 Then

If S1 = -1 Then S1 = 0 ' Uses 0 instead of -1 when no obstacle in sight

mnInput1(SensorNr1) = S1 / 10 ' Scaling sensor values between 0 and 1 ...

' ...
and writing to a debug file if used

'Print #10, Round(S1 / 10, 3); " ";

End If

Next SensorNr1

' A rudimentary steering algorithm that tries to stay in the middle of the "road",

' is used here when creating training values for the network

If Train And Train1 Then

' Calculating difference between left and right side sensors

SideSensDiff = SensorValue(3) - SensorValue(0)

Alpha = (SideSensDiff * 15)

SideSensDiff1 = SensorValue1(3) - SensorValue1(0)

Alpha1 = (SideSensDiff1 * 15)


' Calculating difference between left and right front sensors

FrontSensDiff = SensorValue(2) - SensorValue(1)

Alpha = Alpha + (FrontSensDiff * 7)

FrontSensDiff1 = SensorValue1(2) - SensorValue1(1)

Alpha1 = Alpha1 + (FrontSensDiff1 * 7)

' Braking when turning and if far from the middle

Brake = ((Abs(SideSensDiff) + Abs(FrontSensDiff)) / 90) + (Abs(Alpha) / 60)

Brake1 = ((Abs(SideSensDiff1) + Abs(FrontSensDiff1)) / 90) + (Abs(Alpha1) / 60)

' Don't brake too much though

If Brake > 0.6 Then Brake = 0.6

If Brake1 > 0.6 Then Brake1 = 0.6

' Applying steering and speed reduction

SetSteering(Mobot, 0.7 - Brake, Alpha)

SetSteering(Mobot1, 0.7 - Brake1, Alpha1)

' Writing training values

For i = 0 To 3

outSens = SensorValue(i)

If outsens = -1 Then outsens = 0.0000

Print #1, Round(outsens / 10, 5); " ";

Next i

' Scaling values between 0 and 1, Brake is already below 1

Print #1, " "; Round((Alpha + 180) / 360, 5); " "; Round(Brake, 5)

For k = 0 To 3

outSens1 = SensorValue1(k)

If outsens1 = -1 Then outsens1 = 0.0000

Print #1, Round(outsens1 / 10, 5); " ";

Next k

' Scaling values between 0 and 1, Brake is already below 1

Print #1, " "; Round((Alpha1 + 180) / 360, 5); " "; Round(Brake1, 5)

Else

' Activates the neural network

forward_pass(mnInput(),mnOutput())
forward_pass1(mnInput1(),mnOutput1())

' "Unscaling" the returned values

Alpha = (mnOutput(0) * 360) - 180

Brake = mnOutput(1)

Alpha1 = (mnOutput1(0) * 360) - 180 '//mn BELOM

Brake1 = mnOutput1(1)

' Debugging

'Print #10, Round(alpha,5); " "; Round(brake, 5)

SetSteering(Mobot, 1.2 - (1.3 * Brake / 0.7), Alpha)

SetSteering(Mobot1, 1.2 - (1.3 * Brake1 / 0.7), Alpha1)

End If

' Checking if stuck

stuckcheck = True

stuckcheck1 = True '//AMBIGU

If stuckcheck And stuckcheck1 Then

If OldX = X And OldY = Y Then

DoWhat = Rnd() ' Using a random value for choosing what to do

Select Case DoWhat

Case Is < 0.33

SetWheelSpeed(Mobot,-230,-230)

Case 0.33 To 0.66

SetWheelSpeed(Mobot, -137, 137)

Case Is > 0.66

SetWheelSpeed(Mobot, 100, -100)

End Select

End If

If OldA = A And OldB = B Then

DoWhat1 = Rnd() ' Using a random value for choosing what to do

Select Case DoWhat1

Case Is < 0.7

SetWheelSpeed(Mobot1,-0,10)

Case 0.7 To 0.9

SetWheelSpeed(Mobot1, 10, 0)
Case Is > 0.9

SetWheelSpeed(Mobot1, 10, 10)

End Select

End If

OldX = X

OldY = Y

OldA = A

OldB = B

End If

StepForward ' Dynamics simulation progresses one time step

Loop Until True=False ' Looping "forever"

If Train And Train1 Then

Close #1

End If

' debugging file

' Close #10

End Sub

' Calculating output sums from each neuron

Function Sum(connect, weight, cnt As Integer) As Double

Dim fnSum As Double

fnSum = weight(0)

Do

fnSum = fnSum + Outputs(connect(cnt-1)) * weight(cnt)

cnt = cnt - 1

Loop While (cnt > 0)

Sum = tanh (fnSum)

End Function

Function Sum1(connect1, weight1, cnt1 As Integer) As Double

Dim fnSum1 As Double

fnSum1 = weight1(0)

Do

fnSum1 = fnSum1 + Outputs1(connect1(cnt1-1)) * weight1(cnt1)

cnt1 = cnt1 - 1
Loop While (cnt1 > 0)

Sum = tanh1 (fnSum1)

End Function

' Found this in the help file for Visual Basic 5

Function tanh(X) As Double

tanh = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X)) 'BELOMMMMMMMMM

End Function

Function tanh1(A) As Double

tanh1 = (Exp(A) - Exp(-A)) / (Exp(A) + Exp(-A)) 'BELOMMMMMMMMM

End Function

' Backpropagating

Function forward_pass (fnInput, fnOutput) As Double

Dim i As Integer

For i=0 To 3

Outputs(i) = fnInput(i)

Next i

Outputs(4) = Sum(c1, w5, 4)

Outputs(5) = Sum(c1, w6, 4)

Outputs(6) = Sum(c1, w7, 4)

Outputs(7) = Sum(c1, w8, 4)

Outputs(8) = Sum(c1, w9, 4)

Outputs(9) = Sum(c1, w10, 4)

Outputs(10) = Sum(c1, w11, 4)

Outputs(11) = Sum(c1, w12, 4)

Outputs(12) = Sum(c1, w13, 4)

Outputs(13) = Sum(c1, w14, 4)

Outputs(14) = Sum(c1, w15, 4)

Outputs(15) = Sum(c1, w16, 4)

Outputs(16) = Sum(c1, w17, 4)

Outputs(17) = Sum(c1, w18, 4)

Outputs(18) = Sum(c1, w19, 4)

Outputs(19) = Sum(c1, w20, 4)

Outputs(20) = Sum(c1, w21, 4)


Outputs(21) = Sum(c1, w22, 4)

Outputs(22) = Sum(c1, w23, 4)

Outputs(23) = Sum(c1, w24, 4)

Outputs(24) = Sum(c1, w25, 4)

Outputs(25) = Sum(c1, w26, 4)

Outputs(26) = Sum(c1, w27, 4)

Outputs(27) = Sum(c1, w28, 4)

Outputs(28) = Sum(c1, w29, 4)

Outputs(29) = Sum(c1, w30, 4)

Outputs(30) = Sum(c1, w31, 4)

Outputs(31) = Sum(c1, w32, 4)

Outputs(32) = Sum(c1, w33, 4)

Outputs(33) = Sum(c1, w34, 4)

Outputs(34) = Sum(c1, w35, 4)

Outputs(35) = Sum(c1, w36, 4)

Outputs(36) = Sum(c1, w37, 4)

Outputs(37) = Sum(c1, w38, 4)

Outputs(38) = Sum(c1, w39, 4)

Outputs(39) = Sum(c1, w40, 4)

Outputs(40) = Sum(c1, w41, 4)

Outputs(41) = Sum(c1, w42, 4)

Outputs(42) = Sum(c1, w43, 4)

Outputs(43) = Sum(c1, w44, 4)

fnOutput(0) = Sum(c2, w45, 41)

fnOutput(1) = Sum(c2, w46, 41)

End Function

Function forward_pass1 (fnInput1, fnOutput1) As Double

Dim k As Integer

For k=0 To 3

Outputs1(k) = fnInput1(k)

Next k

Outputs1(4) = Sum1(c11, v5, 4)

Outputs1(5) = Sum1(c11, v6, 4)


Outputs1(6) = Sum1(c11, v7, 4)

Outputs1(7) = Sum1(c11, v8, 4)

Outputs1(8) = Sum1(c11, v9, 4)

Outputs1(9) = Sum1(c11, v10, 4)

Outputs1(10) = Sum1(c11, v11, 4)

Outputs1(11) = Sum1(c11, v12, 4)

Outputs1(12) = Sum1(c11, v13, 4)

Outputs1(13) = Sum1(c11, v14, 4)

Outputs1(14) = Sum1(c11, v15, 4)

Outputs1(15) = Sum1(c11, v16, 4)

Outputs1(16) = Sum1(c11, v17, 4)

Outputs1(17) = Sum1(c11, v18, 4)

Outputs1(18) = Sum1(c11, v19, 4)

Outputs1(19) = Sum1(c11, v20, 4)

Outputs1(20) = Sum1(c11, v21, 4)

Outputs1(21) = Sum1(c11, v22, 4)

Outputs1(22) = Sum1(c11, v23, 4)

Outputs1(23) = Sum1(c11, v24, 4)

Outputs1(24) = Sum1(c11, v25, 4)

Outputs1(25) = Sum1(c11, v26, 4)

Outputs1(26) = Sum1(c11, v27, 4)

Outputs1(27) = Sum1(c11, v28, 4)

Outputs1(28) = Sum1(c11, v29, 4)

Outputs1(29) = Sum1(c11, v30, 4)

Outputs1(30) = Sum1(c11, v31, 4)

Outputs1(31) = Sum1(c11, v32, 4)

Outputs1(32) = Sum1(c11, v33, 4)

Outputs1(33) = Sum1(c11, v34, 4)

Outputs1(34) = Sum1(c11, v35, 4)

Outputs1(35) = Sum1(c11, v36, 4)

Outputs1(36) = Sum1(c11, v37, 4)

Outputs1(37) = Sum1(c11, v38, 4)

Outputs1(38) = Sum1(c11, v39, 4)


Outputs1(39) = Sum1(c11, v40, 4)

Outputs1(40) = Sum1(c11, v41, 4)

Outputs1(41) = Sum1(c11, v42, 4)

Outputs1(42) = Sum1(c11, v43, 4)

Outputs1(43) = Sum1(c11, v44, 4)

fnOutput1(0) = Sum1(c21, v45, 41)

fnOutput1(1) = Sum1(c21, v46, 41)

End Function

Deskripsi

Robot ini merupakan robot pendeteksi jejak, dimana robot ini akan mengikuti jejak
yang tertinggal sebagai pentunjuk untuk menemukan sesuatu yang dicari. Robot ini
menggunakan konsep mobot NN.
LATIHAN 15

MOBOT (ROBOT PENDETEKSI RUANGAN)

Tanggal : 7 Juni 2017

Sebelum dijalankan

Setelah dijalankan
Kode Program

Dim Mobot,Mobot1,Mobot2,Mobot3 As Byte ' Mobot number


Dim SensorValue (10) As Double ' Distance values returned from sensors
Dim SensorNr As Byte
Dim Outputs(44) As Double ' Outputs from neurons
Dim c1(4) As Integer ' Input layer connections
Dim c2(40) As Integer ' Hidden layer connections
' Weights
Dim
w5(),w6(),w7(),w8(),w9(),w10(),w11(),w12(),w13(),w14(),w15(),w16(),w17(),w18(),
w19() As Double
Dim
w20(),w21(),w22(),w23(),w24(),w25(),w26(),w27(),w28(),w29(),w30(),w31(),w32(),
w33(),w34() As Double
Dim w35(),w36(),w37(),w38(),w39(),w40(),w41(),w42(),w43(),w44(),w45(),w46() As
Double
Dim mnInput(10) As Double ' Input array for forwarding sensor values to the network
Dim mnOutput(2) As Double ' Output array for returning values from the network
Sub Main
Dim X,Y, OldX, OldY As Double ' Mobot position
Dim S As Double ' Temporary sensor value
Dim SideSensDiff,FrontSensDiff As Double' Difference between left and right
sensors
Dim Alpha, Brake As Double ' Steering and braking
Dim i, j As Integer
Dim Train As Boolean ' True if we're going to create a file with training values
Static Weights1 As Integer ' Number of weights
Static Weights2 As Integer ' Number of weights
' Initializing variables
Train = False
Sensor = Array (4,5,6,7) ' Sensors that we activate
Mobot0 = 0
Sensor = Array (4,5,6,7)
Mobot1 = 1
Sensor = Array (4,5,6,7)
Mobot2 = 1
Sensor = Array (4,5,6,7)
Mobot3 = 1
' Initializing network when not training
If Not Train Then
Weights1 = 4
Weights2 = 41
' Dimensioning weight arrays
ReDim w5(Weights1)
ReDim w6(Weights1)
ReDim w7(Weights1)
ReDim w8(Weights1)
ReDim w9(Weights1)
ReDim w10(Weights1)
ReDim w11(Weights1)
ReDim w12(Weights1)
ReDim w13(Weights1)
ReDim w14(Weights1)
ReDim w15(Weights1)
ReDim w16(Weights1)
ReDim w17(Weights1)
ReDim w18(Weights1)
ReDim w19(Weights1)
ReDim w20(Weights1)
ReDim w21(Weights1)
ReDim w22(Weights1)
ReDim w23(Weights1)
ReDim w24(Weights1)
ReDim w25(Weights1)
ReDim w26(Weights1)
ReDim w27(Weights1)
ReDim w28(Weights1)
ReDim w29(Weights1)
ReDim w30(Weights1)
ReDim w31(Weights1)
ReDim w32(Weights1)
ReDim w33(Weights1)
ReDim w34(Weights1)
ReDim w35(Weights1)
ReDim w36(Weights1)
ReDim w37(Weights1)
ReDim w38(Weights1)
ReDim w39(Weights1)
ReDim w40(Weights1)
ReDim w41(Weights1)
ReDim w42(Weights1)
ReDim w43(Weights1)
ReDim w44(Weights1)
ReDim w45(Weights2)
ReDim w46(Weights2)
' Opening connection file
Open ".\conn.txt" For Input As #20
For i = 0 To 3
Input #20, c1(i) ' Input layer
Next i
For i = 0 To 39
Input #20, c2(i) ' Hidden layer
Next i
Close #20
' Opening weights file
Open ".\weights.txt" For Input As #21
For i = 0 To Weights1
Input #21,w5(i)
Next i
For i = 0 To Weights1
Input #21,w6(i)
Next i
For i = 0 To Weights1
Input #21,w7(i)
Next i
For i = 0 To Weights1
Input #21,w8(i)
Next i
For i = 0 To Weights1
Input #21,w9(i)
Next i
For i = 0 To Weights1
Input #21,w10(i)
Next i
For i = 0 To Weights1
Input #21,w11(i)
Next i
For i = 0 To Weights1
Input #21,w12(i)
Next i
For i = 0 To Weights1
Input #21,w13(i)
Next i
For i = 0 To Weights1
Input #21,w14(i)
Next i
For i = 0 To Weights1
Input #21,w15(i)
Next i
For i = 0 To Weights1
Input #21,w16(i)
Next i
For i = 0 To Weights1
Input #21,w17(i)
Next i
For i = 0 To Weights1
Input #21,w18(i)
Next i
For i = 0 To Weights1
Input #21,w19(i)
Next i
For i = 0 To Weights1
Input #21,w20(i)
Next i
For i = 0 To Weights1
Input #21,w21(i)
Next i
For i = 0 To Weights1
Input #21,w22(i)
Next i
For i = 0 To Weights1
Input #21,w23(i)
Next i
For i = 0 To Weights1
Input #21,w24(i)
Next i
For i = 0 To Weights1
Input #21,w25(i)
Next i
For i = 0 To Weights1
Input #21,w26(i)
Next i
For i = 0 To Weights1
Input #21,w27(i)
Next i
For i = 0 To Weights1
Input #21,w28(i)
Next i
For i = 0 To Weights1
Input #21,w29(i)
Next i
For i = 0 To Weights1
Input #21,w30(i)
Next i
For i = 0 To Weights1
Input #21,w31(i)
Next i
For i = 0 To Weights1
Input #21,w32(i)
Next i
For i = 0 To Weights1
Input #21,w33(i)
Next i
For i = 0 To Weights1
Input #21,w34(i)
Next i
For i = 0 To Weights1
Input #21,w35(i)
Next i
For i = 0 To Weights1
Input #21,w36(i)
Next i
For i = 0 To Weights1
Input #21,w37(i)
Next i
For i = 0 To Weights1
Input #21,w38(i)
Next i
For i = 0 To Weights1
Input #21,w39(i)
Next i
For i = 0 To Weights1
Input #21,w40(i)
Next i
For i = 0 To Weights1
Input #21,w41(i)
Next i
For i = 0 To Weights1
Input #21,w42(i)
Next i
For i = 0 To Weights1
Input #21,w43(i)
Next i
For i = 0 To Weights1
Input #21,w44(i)
Next i
For i = 0 To Weights2 - 1
Input #21,w45(i)
Next i
For i = 0 To Weights2 - 1
Input #21,w46(i)
Next i
Close #21
End If
Randomize
'SetMobotPosition (Mobot0, 15, 15.55, 180)
'SetMobotPosition (Mobot1, 6.0342, 6.1649, 180)
'SetMobotPosition (Mobot2, 35, 35.55, 180)
'SetMobotPosition (Mobot3, 45, 45.55, 180)
SetCellSize(0,0.1) 'Set cell size 10 cm x 10 cm
SetTimeStep(0.1) 'Set simulation time step of 0.1 seconds
' Opening file for training values
If Train Then
Open "NNtrain.txt" For Output As #1
End If
' Just used when debugging
' Open "nndebug.txt" For Output As #10
' Used for checking if the mobot is stuck
OldX = GetMobotX(0) - 1
OldY = GetMobotY(0) - 1
Do '
Starting main loop

X=GetMobotX(Mobot) ' Present mobot coordinates (in meters)


Y=GetMobotY(Mobot)
' Reading sensors
For SensorNr = 0 To 3
SensorValue (SensorNr) = MeasureRange (Mobot,
Sensor(SensorNr), 0)
S = SensorValue(SensorNr)
If Not Train Then
If S = -1 Then S = 0 ' Uses 0 instead of -1 when
no obstacle in sight

mnInput(SensorNr) = S / 10 ' Scaling sensor values


between 0 and 1 ...and writing to a debug file if used
'Print #10, Round(S / 10, 3); " ";
End If
Next SensorNr
' A rudimentary steering algorithm that tries to stay in the middle of the
"road",
' is used here when creating training values for the network
If Train Then
' Calculating difference between left and right side sensors
SideSensDiff = SensorValue(3) - SensorValue(0)
Alpha = (SideSensDiff * 15)
' Calculating difference between left and right front sensors
FrontSensDiff = SensorValue(2) - SensorValue(1)
Alpha = Alpha + (FrontSensDiff * 7)
' Braking when turning and if far from the middle
Brake = ((Abs(SideSensDiff) + Abs(FrontSensDiff)) / 90) +
(Abs(Alpha) / 60)
' Don't brake too much though
If Brake > 0.6 Then Brake = 0.6
' Applying steering and speed reduction
SetSteering(Mobot0, 0.7 - Brake, Alpha)
SetSteering(Mobot1, 0.7 - Brake, Alpha)
SetSteering(Mobot2, 0.7 - Brake, Alpha)
SetSteering(Mobot3, 0.7 - Brake, Alpha)
' Writing training values
For i = 0 To 3
outSens = SensorValue(i)
If outsens = -1 Then outsens = 0.0000
Print #1, Round(outsens / 10, 5); " ";
Next i
' Scaling values between 0 and 1, Brake is already below 1
Print #1, " "; Round((Alpha + 180) / 360, 5); " "; Round(Brake, 5)
Else
' Activates the neural network
forward_pass(mnInput(),mnOutput())
' "Unscaling" the returned values
Alpha = (mnOutput(0) * 360) - 180
Brake = mnOutput(1)
' Debugging
'Print #10, Round(alpha,5); " "; Round(brake, 5)
SetSteering(Mobot0, 1.2 - (1.3 * Brake / 0.7), Alpha)
SetSteering(Mobot1, 1.2 - (1.3 * Brake / 0.7), Alpha)
SetSteering(Mobot2, 1.2 - (1.3 * Brake / 0.7), Alpha)
SetSteering(Mobot3, 1.2 - (1.3 * Brake / 0.7), Alpha)
End If
' Checking if stuck
stuckcheck = True
If stuckcheck Then
If OldX = X And OldY = Y Then
DoWhat = Rnd()
' Using a random value for choosing what to do
Select Case DoWhat
Case Is < 0.33
SetWheelSpeed(Mobot0,-230,-230)
SetWheelSpeed(Mobot1,-230,-230)
SetWheelSpeed(Mobot2,-230,-230)
SetWheelSpeed(Mobot3,-230,-230)
Case 0.33 To 0.66
SetWheelSpeed(Mobot0, -137, 137)
SetWheelSpeed(Mobot1, -137, 137)
SetWheelSpeed(Mobot2, -137, 137)
SetWheelSpeed(Mobot3, -137, 137)
Case Is > 0.66
SetWheelSpeed(Mobot0, 100, -100)
SetWheelSpeed(Mobot1, 100, -100)
SetWheelSpeed(Mobot2, 100, -100)
SetWheelSpeed(Mobot3, 100, -100)
End Select

End If
OldX = X
OldY = Y
End If
StepForward ' Dynamics simulation progresses one time step
Loop Until True=False ' Looping "forever"
If Train Then
Close #1
End If
' debugging file
' Close #10

End Sub
' Calculating output sums from each neuron
Function Sum(connect, weight, cnt As Integer) As Double
Dim fnSum As Double
fnSum = weight(0)
Do
fnSum = fnSum + Outputs(connect(cnt-1)) * weight(cnt)
cnt = cnt - 1
Loop While (cnt > 0)
Sum = tanh (fnSum)
End Function
' Found this in the help file for Visual Basic 5
Function tanh(X) As Double
tanh = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))
End Function
' Backpropagating
Function forward_pass (fnInput, fnOutput) As Double
Dim i As Integer
For i=0 To 3
Outputs(i) = fnInput(i)
Next i
Outputs(4) = Sum(c1, w5, 4)
Outputs(5) = Sum(c1, w6, 4)
Outputs(6) = Sum(c1, w7, 4)
Outputs(7) = Sum(c1, w8, 4)
Outputs(8) = Sum(c1, w9, 4)
Outputs(9) = Sum(c1, w10, 4)
Outputs(10) = Sum(c1, w11, 4)
Outputs(11) = Sum(c1, w12, 4)
Outputs(12) = Sum(c1, w13, 4)
Outputs(13) = Sum(c1, w14, 4)
Outputs(14) = Sum(c1, w15, 4)
Outputs(15) = Sum(c1, w16, 4)
Outputs(16) = Sum(c1, w17, 4)
Outputs(17) = Sum(c1, w18, 4)
Outputs(18) = Sum(c1, w19, 4)
Outputs(19) = Sum(c1, w20, 4)
Outputs(20) = Sum(c1, w21, 4)
Outputs(21) = Sum(c1, w22, 4)
Outputs(22) = Sum(c1, w23, 4)
Outputs(23) = Sum(c1, w24, 4)
Outputs(24) = Sum(c1, w25, 4)
Outputs(25) = Sum(c1, w26, 4)
Outputs(26) = Sum(c1, w27, 4)
Outputs(27) = Sum(c1, w28, 4)
Outputs(28) = Sum(c1, w29, 4)
Outputs(29) = Sum(c1, w30, 4)
Outputs(30) = Sum(c1, w31, 4)
Outputs(31) = Sum(c1, w32, 4)
Outputs(32) = Sum(c1, w33, 4)
Outputs(33) = Sum(c1, w34, 4)
Outputs(34) = Sum(c1, w35, 4)
Outputs(35) = Sum(c1, w36, 4)
Outputs(36) = Sum(c1, w37, 4)
Outputs(37) = Sum(c1, w38, 4)
Outputs(38) = Sum(c1, w39, 4)
Outputs(39) = Sum(c1, w40, 4)
Outputs(40) = Sum(c1, w41, 4)
Outputs(41) = Sum(c1, w42, 4)
Outputs(42) = Sum(c1, w43, 4)
Outputs(43) = Sum(c1, w44, 4)
fnOutput(0) = Sum(c2, w45, 41)
fnOutput(1) = Sum(c2, w46, 41)
End Function

Deskripsi

Robot deteksi untuk ruangan ini menggunakan jenis mobot NN, dimana robot ini akan
mendeteksi keadaan suatu ruangan dengan cara mengelilingi ruangan tersebut apakah
dalam kondisi normal atau tidak.
LATIHAN 11
10 GAMBAR + BACKGROUND

Tanggal : 10 Mei 2017


10 Gambar
1. Spongebob
5. Garry

2. Patrick
6. Parl

3. Plankton
7. Mrs. Park

4. Mr. Crab
8. Raja Neptunus
9. Oren 10. Kum

3 Background

1. Blue 2. Red

3. Green

Deskripsi

Pada 10 gambar dan 3 background tersebut merupakan gambar yang dibentuk dengan
format JPEG (200 x 200) sebagai bahan untuk latihan selanjutnya dengan
menggunakan Neuroph.
LATIHAN 12
FACE RECOGNITION USING NEURAL NETWORK

Tanggal : 17 Mei 2017

Choose image to recognise

Layer
Grafik

Test result

Input: 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1406; 0.1406; 0.1406;
0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406; 0.1406;
0.1406; 0.1406; 0.1406; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1406; 0.1406; 0.1367; 0.1367; 0.1406; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367;
0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; 0.1367; Output: 0.1179; 0.0741;
0.1435; 0.0468; 0.1336; Desired output: 0; 0; 0; 0; 0; Error: 0.1179; 0.0741; 0.1435; 0.0468; 0.1336;

Total Mean Square Error: 0.06782836726842559

Deskripsi

Sistem pengenalan wajah terdiri dari dua bagian: hardware dan software. Sistem ini
digunakan untuk pengguna pengenalan otomatis atau konfirmasi password. Untuk
input digunakan baik gambar digital maupun video frame dari video yang sama. Akan
tetapi disini menggunakan gambar animasi dan baground sebagai media latihan ini.
LATIHAN 14
PERCEPTRON

Tanggal : 31 Mei 2017

Multilayer
Sebelum Set In

Setelah Set In
Single layer

Sebelum Set In

Setelah Set In
Tabel Kebenaran

Grafik

Multi Layer

Single Layer
Test Result

Multi Layer

Single Layer

Deskripsi

Single layer perceptron terdiri dari satu lapisan input dan output. Fungsi aktivasi yang
digunakan adalah hard limiting yaitu unit output akan bernilai 1, sedangkan Multi
layer perceptron dapat digunakan untukoperasi logik termasuk yang kompleks seperti
XOR dan merupakan jaringan syaraf tiruan feed-forward yang terdiri dari sejumlah
neuron yang dihubungkan oleh bobot-bobot penghubung. Neuron-neurontersebut
disusun dalam lapisan- lapisan yang terdiri dari satu lapisan input (inputlayer), satu
atau lebih lapisan tersembunyi (hidden layer), dan satu lapisan output(output layer).
LATIHAN 13
PERCEPTRON (ALARM)

Tanggal : 24 Mei 2017

Gerbang logika Alarm

Tabel kebenaran

Input Output
X Y Z Y0 Y1 Y2
0 0 0 0 0 0
0 0 1 1 1 1
0 1 0 1 1 1
0 1 1 1 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 0 0
1 1 1 1 1 1

Keterangan :
X : Kunci Kontak Y0 : Bunyi
Y : Pintu Y1 : Lampu
Y2 : Keadaan
Z : Jarak
Tabel Data Sheet Alarm

Layer (Multi Layer)

Pada saat Set In


Grafik

Result Test

Deskripsi

Pada latihan ini menerapkan program Neuroph sebagai penampil grafik bagaimana
cara kerja alarm ini. Alarm ini tidak akan bekerja apabila semua kondisinya tidak aktif
atau bernilai 0 atau bernilai 1 0 1 atau 1 1 0. Alarm ini berfungsi sebagai tanda
peringatan untuk keamanan pada kendaraan beroda.
LATIHAN 10
SHUTTLE LANDING CONTROL USING NEURAL NETWORKS

Tanggal : 3 Mei 2017

Layer (Multi Layer)

Data sheet
Grafik

Result test

Deskripsi

Pada latihan ini pengenalan tentang software Neuroph, dengan menggunakan contoh
dari salah satu kasus. Dimana pada kasus ini menunjukan control manual pada
kendaraan.
LATIHAN 5

FUZZY LOGIC (ROBOT PENARI)

Tanggal : 29 Maret 2017

Grafik Input
Grafik Output

Grafik 3 Dimensi
Data Kebenaran

R1: IF {sensor suara IS hening } AND {sensor gyro IS 60 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS slow} {keseimbangan IS tidak seimbang} {lokasi IS dekat zona} weigth=1.0

R2: IF {sensor suara IS hening } AND {sensor gyro IS 60 derajat} AND {sensor warna IS redup} THEN
{gerakan IS slow} {keseimbangan IS tidak seimbang} {lokasi IS zona aman} weigth=1.0

R3: IF {sensor suara IS hening } AND {sensor gyro IS 60 derajat} AND {sensor warna IS terang} THEN
{gerakan IS slow} {keseimbangan IS tidak seimbang} {lokasi IS keluar zona} weigth=1.0

R4: IF {sensor suara IS hening } AND {sensor gyro IS 90 derajat} AND {sensor warna IS terang} THEN
{gerakan IS slow} {keseimbangan IS seimbang} {lokasi IS keluar zona} weigth=1.0

R5: IF {sensor suara IS hening } AND {sensor gyro IS 90 derajat} AND {sensor warna IS redup} THEN
{gerakan IS slow} {keseimbangan IS seimbang} {lokasi IS zona aman} weigth=1.0

R6: IF {sensor suara IS hening } AND {sensor gyro IS 90 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS slow} {keseimbangan IS seimbang} {lokasi IS dekat zona} weigth=1.0

R7: IF {sensor suara IS hening } AND {sensor gyro IS 90 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS slow} {keseimbangan IS seimbang} {lokasi IS dekat zona} weigth=1.0

R8: IF {sensor suara IS hening } AND {sensor gyro IS 90 derajat} AND {sensor warna IS redup} THEN
{gerakan IS slow} {keseimbangan IS seimbang} {lokasi IS zona aman} weigth=1.0

R9: IF {sensor suara IS hening } AND {sensor gyro IS 90 derajat} AND {sensor warna IS terang} THEN
{gerakan IS slow} {keseimbangan IS seimbang} {lokasi IS keluar zona} weigth=1.0

R10: IF {sensor suara IS hening } AND {sensor gyro IS 120 derajat} AND {sensor warna IS terang} THEN
{gerakan IS slow} {keseimbangan IS jatuh} {lokasi IS keluar zona} weigth=1.0

R11: IF {sensor suara IS hening } AND {sensor gyro IS 120 derajat} AND {sensor warna IS redup} THEN
{gerakan IS slow} {keseimbangan IS jatuh} {lokasi IS zona aman} weigth=1.0

R12: IF {sensor suara IS hening } AND {sensor gyro IS 120 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS slow} {keseimbangan IS jatuh} {lokasi IS dekat zona} weigth=1.0

R13: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS dekat zona} weigth=1.0

R14: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS redup} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS zona aman} weigth=1.0

R15: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS redup} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS zona aman} weigth=1.0

R16: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS terang} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS keluar zona} weigth=1.0

R17: IF {sensor suara IS alunan} AND {sensor gyro IS 90 derajat} AND {sensor warna IS terang} THEN
{gerakan IS medium } {keseimbangan IS seimbang} {lokasi IS keluar zona} weigth=1.0
R18: IF {sensor suara IS alunan} AND {sensor gyro IS 90 derajat} AND {sensor warna IS redup} THEN
{gerakan IS medium } {keseimbangan IS seimbang} {lokasi IS zona aman} weigth=1.0

R19: IF {sensor suara IS alunan} AND {sensor gyro IS 90 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS medium } {keseimbangan IS seimbang} {lokasi IS dekat zona} weigth=1.0

R20: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS dekat zona} weigth=1.0

R21: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS redup} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS zona aman} weigth=1.0

R22: IF {sensor suara IS alunan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS terang} THEN
{gerakan IS medium } {keseimbangan IS jatuh} {lokasi IS keluar zona} weigth=1.0

R23: IF {sensor suara IS tepukan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS terang} THEN
{gerakan IS fast} {keseimbangan IS jatuh} {lokasi IS keluar zona} weigth=1.0

R24: IF {sensor suara IS tepukan} AND {sensor gyro IS 90 derajat} AND {sensor warna IS terang} THEN
{gerakan IS fast} {keseimbangan IS seimbang} {lokasi IS keluar zona} weigth=1.0

R25: IF {sensor suara IS tepukan} AND {sensor gyro IS 90 derajat} AND {sensor warna IS redup} THEN
{gerakan IS fast} {keseimbangan IS seimbang} {lokasi IS zona aman} weigth=1.0

R26: IF {sensor suara IS tepukan} AND {sensor gyro IS 90 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS fast} {keseimbangan IS seimbang} {lokasi IS dekat zona} weigth=1.0

R27: IF {sensor suara IS tepukan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS gelap} THEN
{gerakan IS fast} {keseimbangan IS jatuh} {lokasi IS dekat zona} weigth=1.0

R28: IF {sensor suara IS tepukan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS redup} THEN
{gerakan IS fast} {keseimbangan IS jatuh} {lokasi IS zona aman} weigth=1.0

R29: IF {sensor suara IS tepukan} AND {sensor gyro IS 120 derajat} AND {sensor warna IS terang} THEN
{gerakan IS fast} {keseimbangan IS jatuh} {lokasi IS keluar zona} weigth=1.0

Deskripsi

Pada latihan ini terdapat kasus tentang robot menari, robot ini akan bergerak jika
mendengarkan lagu tertentu. Untuk pengolahan sinyal suara dari electronic condenser
digunakan filter. Motor servo sebagai penggerak pada kepala tangan, dan kaki robot
dan sensor warna sebagai deteksi batas area robot penari.