jancoow 11 年 前
コミット
08c78c61cf

+ 308 - 308
Aansturing.java

@@ -1,308 +1,308 @@
-package boebot;
-public class Aansturing
-{
-   private int rotation;
-   private int x;
-   private int y;
-   private int maxx;
-   private int maxy;
-   private int ex;
-   private int ey;
-   public String coordinaten;
-   public Aansturing()
-   {
-       maxx = 0;
-       maxy = 0;
-       rotation = 0;
-       x = 0;
-       y = 0;
-       ex = 0;
-       ey = 0;
-   }
-   public void turnleft()
-   {
-       rotation = rotation - 90;
-       if (rotation < 0)
-       {
-           rotation = 270;
-       }
-   }
-   public void turnright()
-   {
-       rotation = rotation + 90;
-       if (rotation > 270)
-       {
-           rotation = 0;
-       }
-   }
-   public void keren()
-   {
-       rotation = rotation + 180;
-       if (rotation == 360)
-       {
-           rotation = 0;
-       }
-       if(rotation == 450)
-       {
-           rotation = 90;
-       }
-   }
-   public void vooruit()
-   {
-       if (rotation == 0 && y < maxy)
-       {
-           y ++;
-       }
-       if (rotation == 90 && x < maxx)
-       {
-           x ++;
-       }
-       if (rotation == 180 && y > 0)
-       {
-           y --;
-       }
-       if (rotation == 270 && x > 0)
-       {
-           x --;
-       }
-   }
-   public String geefCoordinaten()
-   {
-       coordinaten = "(" + x + "," + y + ")";
-       return coordinaten;
-   }
-   public String gaNaarPunt(int eindx, int eindy)
-   {
-       if(eindx <= maxx && eindy <= maxy && eindx >= 0 && eindy >= 0)
-       {
-           ex = eindx;
-           ey = eindy;
-       }
-       while(ex != x)
-       {
-           if(x < ex)
-           {
-               if(rotation == 90)
-               {
-                   vooruit();
-                   System.out.println("vooruit");
-               }
-               else
-               {
-                   turnleft();
-                   System.out.println("turnleft");
-               }
-           }
-           else
-           {
-               if(x > ex)
-               {
-                   if(rotation == 270)
-                   {
-                       vooruit();
-                       System.out.println("vooruit");
-                   }
-                   else
-                   {
-                       turnleft();
-                       System.out.println("turnleft");
-                   }
-               }
-           }
-       }
-       while(ey != y)
-       {
-           if(y < ey)
-           {
-               if(rotation == 0)
-               {
-                   vooruit();
-                   System.out.println("vooruit");
-               }
-               else
-               {
-                   turnright();
-                   System.out.println("turnright");
-               }
-           }
-           else
-           {
-               if(y > ey)
-               {
-                   if(rotation == 180)
-                   {
-                       vooruit();
-                       System.out.println("vooruit");
-                   }
-                   else
-                   {
-                       turnright();
-                       System.out.println("turnright");
-                   }
-               }
-           }
-       }
-       return "bestemming bereikt " + geefCoordinaten();
-   }
-   
-   public char[] berekenRoute(int eindx, int eindy, int beginx, int beginy, int rotatie, int maxxInput, int maxyInput)
-   {
-	   maxx = maxxInput;
-	   maxy = maxyInput;
-
-       char[] route = new char[40];
-       int teller = 0;
-       int links = 0;
-       x = beginx;
-       y = beginy;
-       rotation = rotatie;
-       if(eindx <= maxx && eindy <= maxy && eindx >= 0 && eindy >= 0)
-       {
-           ex = eindx;
-           ey = eindy;
-       }else{
-           return route;
-        }
-        if(beginx <= maxx && beginy <= maxy && beginx >= 0 && beginy >= 0)
-       {
-           x = beginx;
-           y = beginy;
-       }else{
-           return route;
-        }
-       while(ex != x)
-       {
-           if(x < ex)
-           {
-               if(rotation == 90)
-               {
-                   vooruit();
-                   route[teller] = 'v';
-                   teller ++;
-               }
-               if(rotation == 0)
-               {
-                   turnright();
-                   vooruit();
-                   route[teller] = 'r';
-                   teller ++;
-               }
-               if(rotation == 270)
-               {
-                   keren();
-                   vooruit();
-                   route[teller] = 'a';
-                   teller ++;
-               }
-               if(rotation == 180)
-               {
-                   turnleft();
-                   vooruit();
-                   route[teller] = 'l';
-                   teller ++;
-               }
-           }
-           else
-           {
-               if(x > ex)
-               {
-                   if(rotation == 270)
-               {
-                   vooruit();
-                   route[teller] = 'v';
-                   teller ++;
-               }
-               if(rotation == 0)
-               {
-                   turnright();
-                   vooruit();
-                   route[teller] = 'l';
-                   teller ++;
-               }
-               if(rotation == 90)
-               {
-                   keren();
-                   vooruit();
-                   route[teller] = 'a';
-                   teller ++;
-               }
-               if(rotation == 180)
-               {
-                   turnleft();
-                   vooruit();
-                   route[teller] = 'r';
-                   teller ++;
-               }
-               }
-           }
-       }
-       while(ey != y)
-       {
-           if(y < ey)
-           {
-               if(rotation == 0)
-               {
-                   vooruit();
-                   route[teller] = 'v';
-                   teller ++;
-               }
-               if(rotation == 270)
-               {
-                   turnright();
-                   vooruit();
-                   route[teller] = 'r';
-                   teller ++;
-               }
-               if(rotation == 180)
-               {
-                   keren();
-                   vooruit();
-                   route[teller] = 'a';
-                   teller ++;
-               }
-               if(rotation == 90)
-               {
-                   turnleft();
-                   vooruit();
-                   route[teller] = 'l';
-                   teller ++;
-               }
-           }
-           else
-           {
-               if(y > ey)
-               {
-                   if(rotation == 180)
-               {
-                   vooruit();
-                   route[teller] = 'v';
-                   teller ++;
-               }
-               if(rotation == 90)
-               {
-                   turnright();
-                   vooruit();
-                   route[teller] = 'r';
-                   teller ++;
-               }
-               if(rotation == 0)
-               {
-                   keren();
-                   vooruit();
-                   route[teller] = 'a';
-                   teller ++;
-               }
-               if(rotation == 270)
-               {
-                   turnleft();
-                   vooruit();
-                   route[teller] = 'l';
-                   teller ++;
-               }
-               }
-           }
-       }
-       System.out.println("bestemming bereikt " + geefCoordinaten());
-       return route;
-   }
-}
+package boebot;
+public class Aansturing
+{
+   private int rotation;
+   private int x;
+   private int y;
+   private int maxx;
+   private int maxy;
+   private int ex;
+   private int ey;
+   public String coordinaten;
+   public Aansturing()
+   {
+       maxx = 0;
+       maxy = 0;
+       rotation = 0;
+       x = 0;
+       y = 0;
+       ex = 0;
+       ey = 0;
+   }
+   public void turnleft()
+   {
+       rotation = rotation - 90;
+       if (rotation < 0)
+       {
+           rotation = 270;
+       }
+   }
+   public void turnright()
+   {
+       rotation = rotation + 90;
+       if (rotation > 270)
+       {
+           rotation = 0;
+       }
+   }
+   public void keren()
+   {
+       rotation = rotation + 180;
+       if (rotation == 360)
+       {
+           rotation = 0;
+       }
+       if(rotation == 450)
+       {
+           rotation = 90;
+       }
+   }
+   public void vooruit()
+   {
+       if (rotation == 0 && y < maxy)
+       {
+           y ++;
+       }
+       if (rotation == 90 && x < maxx)
+       {
+           x ++;
+       }
+       if (rotation == 180 && y > 0)
+       {
+           y --;
+       }
+       if (rotation == 270 && x > 0)
+       {
+           x --;
+       }
+   }
+   public String geefCoordinaten()
+   {
+       coordinaten = "(" + x + "," + y + ")";
+       return coordinaten;
+   }
+   public String gaNaarPunt(int eindx, int eindy)
+   {
+       if(eindx <= maxx && eindy <= maxy && eindx >= 0 && eindy >= 0)
+       {
+           ex = eindx;
+           ey = eindy;
+       }
+       while(ex != x)
+       {
+           if(x < ex)
+           {
+               if(rotation == 90)
+               {
+                   vooruit();
+                   System.out.println("vooruit");
+               }
+               else
+               {
+                   turnleft();
+                   System.out.println("turnleft");
+               }
+           }
+           else
+           {
+               if(x > ex)
+               {
+                   if(rotation == 270)
+                   {
+                       vooruit();
+                       System.out.println("vooruit");
+                   }
+                   else
+                   {
+                       turnleft();
+                       System.out.println("turnleft");
+                   }
+               }
+           }
+       }
+       while(ey != y)
+       {
+           if(y < ey)
+           {
+               if(rotation == 0)
+               {
+                   vooruit();
+                   System.out.println("vooruit");
+               }
+               else
+               {
+                   turnright();
+                   System.out.println("turnright");
+               }
+           }
+           else
+           {
+               if(y > ey)
+               {
+                   if(rotation == 180)
+                   {
+                       vooruit();
+                       System.out.println("vooruit");
+                   }
+                   else
+                   {
+                       turnright();
+                       System.out.println("turnright");
+                   }
+               }
+           }
+       }
+       return "bestemming bereikt " + geefCoordinaten();
+   }
+
+   public char[] berekenRoute(int eindx, int eindy, int beginx, int beginy, int rotatie, int maxxInput, int maxyInput)
+   {
+           maxx = maxxInput;
+           maxy = maxyInput;
+
+       char[] route = new char[40];
+       int teller = 0;
+       int links = 0;
+       x = beginx;
+       y = beginy;
+       rotation = rotatie;
+       if(eindx <= maxx && eindy <= maxy && eindx >= 0 && eindy >= 0)
+       {
+           ex = eindx;
+           ey = eindy;
+       }else{
+           return route;
+        }
+        if(beginx <= maxx && beginy <= maxy && beginx >= 0 && beginy >= 0)
+       {
+           x = beginx;
+           y = beginy;
+       }else{
+           return route;
+        }
+       while(ex != x)
+       {
+           if(x < ex)
+           {
+               if(rotation == 90)
+               {
+                   vooruit();
+                   route[teller] = 'v';
+                   teller ++;
+               }
+               if(rotation == 0)
+               {
+                   turnright();
+                   vooruit();
+                   route[teller] = 'r';
+                   teller ++;
+               }
+               if(rotation == 270)
+               {
+                   keren();
+                   vooruit();
+                   route[teller] = 'a';
+                   teller ++;
+               }
+               if(rotation == 180)
+               {
+                   turnleft();
+                   vooruit();
+                   route[teller] = 'l';
+                   teller ++;
+               }
+           }
+           else
+           {
+               if(x > ex)
+               {
+                   if(rotation == 270)
+               {
+                   vooruit();
+                   route[teller] = 'v';
+                   teller ++;
+               }
+               if(rotation == 0)
+               {
+                   turnright();
+                   vooruit();
+                   route[teller] = 'l';
+                   teller ++;
+               }
+               if(rotation == 90)
+               {
+                   keren();
+                   vooruit();
+                   route[teller] = 'a';
+                   teller ++;
+               }
+               if(rotation == 180)
+               {
+                   turnleft();
+                   vooruit();
+                   route[teller] = 'r';
+                   teller ++;
+               }
+               }
+           }
+       }
+       while(ey != y)
+       {
+           if(y < ey)
+           {
+               if(rotation == 0)
+               {
+                   vooruit();
+                   route[teller] = 'v';
+                   teller ++;
+               }
+               if(rotation == 270)
+               {
+                   turnright();
+                   vooruit();
+                   route[teller] = 'r';
+                   teller ++;
+               }
+               if(rotation == 180)
+               {
+                   keren();
+                   vooruit();
+                   route[teller] = 'a';
+                   teller ++;
+               }
+               if(rotation == 90)
+               {
+                   turnleft();
+                   vooruit();
+                   route[teller] = 'l';
+                   teller ++;
+               }
+           }
+           else
+           {
+               if(y > ey)
+               {
+                   if(rotation == 180)
+               {
+                   vooruit();
+                   route[teller] = 'v';
+                   teller ++;
+               }
+               if(rotation == 90)
+               {
+                   turnright();
+                   vooruit();
+                   route[teller] = 'r';
+                   teller ++;
+               }
+               if(rotation == 0)
+               {
+                   keren();
+                   vooruit();
+                   route[teller] = 'a';
+                   teller ++;
+               }
+               if(rotation == 270)
+               {
+                   turnleft();
+                   vooruit();
+                   route[teller] = 'l';
+                   teller ++;
+               }
+               }
+           }
+       }
+       System.out.println("bestemming bereikt " + geefCoordinaten());
+       return route;
+   }
+}

+ 125 - 0
Afstandsbediening.java

@@ -0,0 +1,125 @@
+package boebot;
+import stamp.core.*;
+public class Afstandsbediening
+{
+int[] databits = new int[12];
+MotorAansturing motor;
+boolean status = false;
+int pin;
+int lastspeed;
+public Afstandsbediening(MotorAansturing motor, int pin)
+{
+    this.pin = pin;
+    this.motor = motor;
+    motor.setSnelheid(50);
+    motor.setRichting(true);
+
+
+}
+
+     public int detect()
+  {
+    int startPuls = CPU.pulseIn(2000, CPU.pins[pin], false);
+    if(startPuls < 200)
+    {
+      return -1;
+    }
+
+    for(int i=0; i<12; i++)
+    {
+      databits[i] = CPU.pulseIn(300, CPU.pins[pin], false);
+    }
+
+    int resultaat = 0;
+    for(int i=0; i<7; i++)
+    {
+      if(databits[i] < 0)
+      {
+        return -1;
+      }
+
+      if(databits[i] > 100)
+      {
+        resultaat |= 1<<i;
+      }
+    }
+    return resultaat;
+  }
+
+  public void verwerkSignaal(int getal)
+  {
+  if(getal != -1){
+       switch(getal)
+        {
+          case 0:
+                 motor.setSnelheidL(30);
+                 motor.setSnelheidR(0);
+                 motor.setRichting(true);
+                 motor.rijden();
+                 break;
+          case 1:
+                  motor.setSnelheid(motor.getDriveSnelheid());
+                  motor.setRichting(true);
+                  motor.rijden();
+                  break;
+          case 2:
+                  motor.setSnelheidL(0);
+                  motor.setSnelheidR(30);
+                  motor.setRichting(true);
+                  motor.rijden();
+                  break;
+          case 3:
+                  motor.noodStop();
+                  motor.turn(270);
+                  break;
+
+          case 4:
+                  motor.noodStop();
+                  break;
+          case 5:
+                  motor.noodStop();
+                  motor.turn(90);
+                  break;
+          case 6:
+                  motor.setSnelheidL(30);
+                  motor.setSnelheidR(0);
+                  motor.setRichting(false);
+                  motor.rijden();
+                  break;
+          case 7:
+                  motor.setSnelheid(motor.getDriveSnelheid());
+                  motor.setRichting(false);
+                  motor.rijden();
+                  break;
+          case 8:
+                  motor.setSnelheidL(0);
+                  motor.setSnelheidR(30);
+                  motor.setRichting(false);
+                  motor.rijden();
+                  break;
+          case 88:
+                  motor.setSnelheid(motor.getDriveSnelheid() + 10);
+                  motor.rijden();
+                  break;
+          case 89:
+                  motor.setSnelheid(motor.getDriveSnelheid() - 10);
+                  motor.rijden();
+                  break;
+
+          default:
+                 break;
+
+        }
+     }
+  }
+
+  public boolean getStatus()
+  {
+    return status;
+  }
+
+  public void setStatus(boolean status)
+  {
+    this.status = status;
+  }
+  }

+ 166 - 165
Bluetooth.java

@@ -1,165 +1,166 @@
-package boebot;
-import stamp.core.*;
-public class Bluetooth
-{
-  final static int SERIAL_RX_PIN  = CPU.pin2;
-  final static int SERIAL_TX_PIN  = CPU.pin0;
-
-  static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
-  static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN,Uart.dontInvert, Uart.speed9600, Uart.stop1);
-
-  char tempChar;
-  char[] route = new char[40];
-  char romoteControl = ' ';
-
-  public int checkBt()
-  {
-    if (rxUart.byteAvailable())
-    {
-      tempChar = (char)rxUart.receiveByte();
-
-      if (tempChar == '?')
-      {
-        int i = 0;
-        clearRoute();
-
-        while (true)
-        {
-          if (rxUart.byteAvailable())
-          {
-            tempChar = (char)rxUart.receiveByte();
-
-            if(tempChar == '?')
-            {
-              return 2;
-            }
-
-            route[i] = tempChar;
-            i ++;
-          }
-
-        }
-
-                }
-        }
-        else if (tempChar == '!')
-        {
-                        int i = 0;
-                        clearRoute();
-
-                        while (true)
-                        {
-                          if (rxUart.byteAvailable())
-                          {
-                                        tempChar = (char)rxUart.receiveByte();
-
-                                        if(tempChar == '!')
-                                        {
-                                          route[i] = tempChar;
-                                          return 3;
-                                        }
-
-                                        route[i] = tempChar;
-                                        i ++;
-                          }
-                        }
-        }else if ((tempChar == 'a') || (tempChar =='v') || (tempChar == 'l') || (tempChar == 'r') || (tempChar == 's'))
-      {
-        romoteControl = tempChar;
-        return 1;
-      }
-
-       return 0;
-  }
-
-  public char[] getRoute()
-  {
-    return route;
-  }
-
-  public int[] getCoordinates()
-  {
-    String[] dataString = new String[40];
-    int[] dataInt = new int[7];
-    String coordinate = "";
-    int StringArrayCount = 0;
-    int intArrayCount = 0;
-
-    for (int i = 0; route.length > i; i ++)
-    {
-
-      if (route[i] != ',' && route[i] != '!')
-      {
-        coordinate += new String(new char[]{route[i]});
-      }
-
-      if (route[i] == ',')
-      {
-
-        dataString[StringArrayCount] = coordinate;
-        coordinate = "";
-        StringArrayCount ++;
-      }
-
-      if (route[i] == '!')
-      {
-          i = route.length;
-                  StringArrayCount = 0;
-      }
-    }
-
-    for (int i = 0; dataString.length > i; i ++)
-    {
-        if (dataString[i] != null)
-        {
-
-            dataInt[intArrayCount] = Integer.parseInt(dataString[i]);
-            intArrayCount ++;
-        }
-
-        if (dataString[i] == null)
-        {
-                        intArrayCount = 0;
-                        return dataInt;
-        }
-    }
-    return dataInt;
-  }
-
-  public int getRemoteControl()
-  {
-    int value = 4;
-
-    switch (romoteControl)
-    {
-      case 'v':
-        value = 1;
-        break;
-      case 'a':
-        value = 7;
-        break;
-      case 's':
-        value = 4;
-        break;
-      case 'r':
-        value = 5;
-        break;
-      case 'l':
-        value = 3;
-        break;
-      default:
-        value = 4;
-        break;
-    }
-
-    return value;
-  }
-
-  public void clearRoute()
-  {
-    for(int i = 0; i < 40; i++)
-    {
-      route[i] = ' ';
-    }
-  }
-}
+package boebot;
+import stamp.core.*;
+public class Bluetooth
+{
+  final static int SERIAL_RX_PIN  = CPU.pin2;
+  final static int SERIAL_TX_PIN  = CPU.pin0;
+
+  static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
+  static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN,Uart.dontInvert, Uart.speed9600, Uart.stop1);
+
+  char tempChar;
+  char[] route = new char[40];
+  public char romoteControl = ' ';
+  int speed;
+
+  public int checkBt(){
+        if (rxUart.byteAvailable()){
+                tempChar = (char)rxUart.receiveByte();
+                if (tempChar == '?'){
+                        int i = 0;
+                        clearRoute();
+                        while (true){
+                                if (rxUart.byteAvailable()){
+                                        tempChar = (char)rxUart.receiveByte();
+                                        if(tempChar == '?'){
+                                                return 2;
+                                        }
+                                        route[i] = tempChar;
+                                        i ++;
+                                }
+                        }
+                }else if (tempChar == '!'){
+                        int i = 0;
+                        clearRoute();
+                        while (true){
+                                if (rxUart.byteAvailable()){
+                                        tempChar = (char)rxUart.receiveByte();
+                                        if(tempChar == '!'){
+                                                route[i] = tempChar;
+                                                return 3;
+                                        }
+                                        route[i] = tempChar;
+                                        i ++;
+                                }
+                        }
+        }else if ((tempChar == 'a') || (tempChar =='v') || (tempChar == 'l') || (tempChar == 'r') || (tempChar == 's')){
+                        romoteControl = tempChar;
+                        return 1;
+        }else if ((tempChar == 'p') || (tempChar == 'h')){
+          romoteControl = tempChar;
+            return 5;
+
+        } else if (tempChar == 'f'){
+                       while (true){
+                                if (rxUart.byteAvailable()){
+                                      speed = Integer.parseInt(new String(new char[]{(char)rxUart.receiveByte()}));
+                                      return 4;
+                                }
+                }           }
+      }
+      return 0;
+}
+
+  public char[] getRoute()
+  {
+    return route;
+  }
+  public int getSpeed(){
+    if(speed >= 0 && speed <= 9){
+      return (((speed + 1) * 10));
+    }
+    return 0;
+  }
+  public void sendChar(char c){
+   txUart.sendByte(c);
+  }
+
+  public int[] getCoordinates()
+  {
+    String[] dataString = new String[40];
+    int[] dataInt = new int[7];
+    String coordinate = "";
+    int StringArrayCount = 0;
+    int intArrayCount = 0;
+
+    for (int i = 0; route.length > i; i ++)
+    {
+
+      if (route[i] != ',' && route[i] != '!')
+      {
+        coordinate += new String(new char[]{route[i]});
+      }
+
+      if (route[i] == ',')
+      {
+
+        dataString[StringArrayCount] = coordinate;
+        coordinate = "";
+        StringArrayCount ++;
+      }
+
+      if (route[i] == '!')
+      {
+          i = route.length;
+                  StringArrayCount = 0;
+      }
+    }
+
+    for (int i = 0; dataString.length > i; i ++)
+    {
+        if (dataString[i] != null)
+        {
+
+            dataInt[intArrayCount] = Integer.parseInt(dataString[i]);
+            intArrayCount ++;
+        }
+
+        if (dataString[i] == null)
+        {
+                        intArrayCount = 0;
+                        return dataInt;
+        }
+    }
+    return dataInt;
+  }
+
+  public char getChar(){
+   return romoteControl;
+  }
+  public int getRemoteControl()
+  {
+    int value = 4;
+
+    switch (romoteControl)
+    {
+      case 'v':
+        value = 1;
+        break;
+      case 'a':
+        value = 7;
+        break;
+      case 's':
+        value = 4;
+        break;
+      case 'r':
+        value = 5;
+        break;
+      case 'l':
+        value = 3;
+        break;
+      default:
+        value = 4;
+        break;
+    }
+
+    return value;
+  }
+
+  public void clearRoute()
+  {
+    for(int i = 0; i < 40; i++)
+    {
+      route[i] = ' ';
+    }
+  }
+}

+ 97 - 107
BoeBot.java

@@ -11,109 +11,97 @@ public class BoeBot{
         Afstandsbediening afstandsbedieningir;
 
         boolean routeAfgerond;
-
+        boolean routeplannerPauze;
         char[] route;
-		int[] coordinates;
         static int currentCase = 4;
         static int currentStep = 0;
 
         public BoeBot(){
                 motor = new MotorAansturing();
-                afstandsbedieningir = new Afstandsbediening(motor);
-                //botsingdetectie = new Botsingdetectie();
-                aansturing = new Aansturing(4,4);
+                afstandsbedieningir = new Afstandsbediening(motor, 11);
+                botsingdetectie = new Botsingdetectie();
+                aansturing = new Aansturing();
                 lijnvolger = new Lijnvolger();
                 bluetooth = new Bluetooth();
 
                 motor.setSnelheid(100);
                 motor.setRichting(true);
                 routeAfgerond = false;
+                routeplannerPauze = true;
+                int[] coordinates;
+
 
-                System.out.println("de huidige stappen:" );
-                //variabele om functies in en uit te schakelen.
-                boolean afstandsbediening = true;
-                boolean obstakelDetectie = false;
-                boolean routeplanner = true;
-                boolean sparcours = false;
                 int btcode = 0;
                 while(true){
-                        btcode = bluetooth.checkBt();
-						if(btcode == 3){
-							System.out.println("Coördinaten ontvangen!");
-							coordinates = bluetooth.getCoordinates();
-							aansturing.berekenRoute(coordinats[0], coordinats[1], coordinats[2], coordinats[3], coordinats[4], coordinats[5], coordinats[6]);
-							routeAfgerond = true;
-							currentStep = 0;
+
+                        btcode = bluetooth.checkBt();
+
+                        if(btcode == 3){
+                                System.out.println("Coördinaten ontvangen!");
+                                coordinates = bluetooth.getCoordinates();
+                                for(int i = 0; i <coordinates.length; i++){
+                                 System.out.println(coordinates[i]);
+                                }
+                                route = aansturing.berekenRoute(coordinates[0], coordinates[1], coordinates[2], coordinates[3], coordinates[4], coordinates[5], coordinates[6]);
+                                routeAfgerond = true;
+                                currentStep = 0;
+                                for(int i = 0; i < route.length; i++){
+                                  System.out.println(route[i]);
+                                  if(route[i] == ' '){ break;}
+                                }
                         }else if(btcode == 2){
-						  System.out.println("Route ontvangen!");
-                          route = bluetooth.getRoute();
-                          routeAfgerond = true;
-                          currentStep = 0;
-                          System.out.println(route[3]);
+                            System.out.println("Route ontvangen!");
+                            route = bluetooth.getRoute();
+                            routeAfgerond = true;
+                            currentStep = 0;
+                            for(int i = 0; i < route.length; i++){
+                                  System.out.println(route[i]);
+                                  if(route[i] == ' '){ break;}
+                                }
                         }else if(btcode == 1){
-                          afstandsbedieningir.verwerkSignaal(bluetooth.getAfstandsbediening());
-                        }
-                        if(obstakelDetectie){
-                                obstakelDetectie();
-                        }
-                        if(afstandsbediening){
+                          afstandsbedieningir.verwerkSignaal(bluetooth.getRemoteControl());
+                        }else if(btcode == 4){
+                          System.out.println("Snelheid: " + bluetooth.getSpeed());
+                          motor.setSnelheid(bluetooth.getSpeed());
+
+                        }else if(btcode == 5){
+                            if(bluetooth.getChar() == 'p'){
+                                 routeplannerPauze = false;
+                                  motor.noodStop();
+                            }else if(bluetooth.getChar() == 'h'){
+                                  System.out.println("test");
+                                  routeplannerPauze = true;
+                                 if(!routeAfgerond){
+                                  routeAfgerond = true;
+                                  currentStep = 0;
+                                  currentCase  = 0;
+                                }
+
+                            }
                         }
-                        if(routeplanner){
+                        afstandsbedieningir.verwerkSignaal(afstandsbedieningir.detect());
+                        obstakelDetectie();
+                        if(routeplannerPauze){
                           if(routeAfgerond){
-                               routeAfgerond = routeplanner();
+                                 routeAfgerond = routeplanner();
                           }
-                        }
-                        if(sparcours){
-
                         }
                         CPU.delay(100);
                 }
         }
         public void obstakelDetectie(){
-                if(botsingdetectie.detectEdge()){
-                        CPU.writePin(CPU.pin1,true);
-                        motor.noodStop();
-                        motor.setRichting(false);
-                        motor.start();
-                        CPU.delay(2000);
-                        motor.noodStop();
-                        motor.turn(180);
-                        motor.setRichting(true);
-                        motor.start();
-                }else if(botsingdetectie.detectObject() == 1){
-                        motor.noodStop();
-                        motor.setRichting(false);
-                        motor.start();
-                        CPU.delay(2000);
-                        motor.noodStop();
-                        motor.turn(90);
-                        motor.setRichting(true);
-                        motor.start();
-                }else if(botsingdetectie.detectObject() == 2){
+                if(botsingdetectie.detectObject() == 1 || botsingdetectie.detectObject() == 2 || botsingdetectie.detectObject() == 3 ){
+                        System.out.println("obstakel gedetecteerd! ");
                         motor.noodStop();
                         motor.setRichting(false);
                         motor.start();
-                        CPU.delay(2000);
                         motor.noodStop();
-                        motor.turn(270);
-                        motor.setRichting(true);
-                        motor.start();
-                }else if(botsingdetectie.detectObject() == 3){
-                        motor.noodStop();
-                        motor.setRichting(false);
-                        motor.start();
-                        CPU.delay(2000);
-                        motor.noodStop();
-                        motor.turn(180);
-                        motor.setRichting(true);
-                        motor.start();
-                }
+                        routeplannerPauze = false;
+                        bluetooth.sendChar('b');
+               }
         }
 
         public boolean routeplanner(){
-               if(currentStep == 0){
-                        verwerkAansturing(route[currentStep]);
-                }
                 int getalLijnvolger = lijnvolger.readSensor();
                 switch(getalLijnvolger){
                         case 0:
@@ -125,33 +113,37 @@ public class BoeBot{
                                 }
                                 break;
                         case 1:
-                                if(currentCase != 1){
-                            motor.setSnelheidL(10);
-                            motor.setSnelheidR(100);
-                            motor.setRichting(true);
-                            motor.rijden();
-                            currentCase = 1;
+                            if(currentCase != 1){
+                              motor.setSnelheidL(10);
+                              motor.setSnelheidR(100);
+                              motor.setRichting(true);
+                              motor.rijden();
+                              currentCase = 1;
                             }
                             break;
                         case 2:
                                 if(currentCase != 2){
-                                        motor.setSnelheidL(100);
-                                        motor.setSnelheidR(10);
-                                        motor.setRichting(true);
-                                        motor.rijden();
-                                        currentCase = 2;
+                                    motor.setSnelheidL(100);
+                                    motor.setSnelheidR(10);
+                                    motor.setRichting(true);
+                                    motor.rijden();
+                                    currentCase = 2;
                                 }
                                 break;
                         case 4:
                                 if(currentCase != 4){
                                         if(route[currentStep] != ' '){
+
                                                 verwerkAansturing(route[currentStep]);
+                                                currentStep++;
+                                                 bluetooth.sendChar('k');
                                                 System.out.println(route[currentStep-1]);
                                                 CPU.delay(1000);
                                                 motor.rijden();
                                         }else{
                                                 motor.noodStop();
                                                 System.out.println("klaar");
+                                                bluetooth.sendChar('f');
                                                 return false;
                                         }
                                         currentCase = 4;
@@ -166,8 +158,9 @@ public class BoeBot{
                                 CPU.delay(1000);
                                 motor.setRichting(false);
                                 motor.rijden();
-                                CPU.delay(3000);
+                                CPU.delay(1000);
                                 motor.noodStop();
+                                 bluetooth.sendChar('g');
                                 return false;
                                // route = ontwijkBoebot(int xx, int xy, int x, int y, int rotation)
                               }
@@ -181,38 +174,35 @@ public class BoeBot{
                 switch(opdracht){
                 case 'v':
                        motor.rijden();
-                       CPU.delay(200);
+                       CPU.delay(100);
                        break;
                 case 'a':
                         CPU.delay(1200);
-            motor.noodStop();
-
-            CPU.delay(200);
-            motor.turn(180);
-            break;
+                        motor.noodStop();
+                      CPU.delay(200);
+                      motor.turn(180);
+                      break;
                 case 'r':
                       motor.setSnelheid(100);
                       motor.setRichting(true);
                       motor.rijden();
-                        CPU.delay(1200);
-            motor.noodStop();
-
-            CPU.delay(200);
-            motor.turn(90);
-            break;
+                      CPU.delay(1200);
+                      motor.noodStop();
+                      CPU.delay(200);
+                      motor.turn(90);
+                      break;
                 case 'l':
                     motor.setSnelheid(100);
-                      motor.setRichting(true);
-                      motor.rijden();
-                        CPU.delay(1200);
-            motor.noodStop();
-            CPU.delay(200);
-            motor.turn(270);
-            break;
-                default:
-            motor.noodStop();
-            break;
+                    motor.setRichting(true);
+                    motor.rijden();
+                    CPU.delay(1200);
+                    motor.noodStop();
+                    CPU.delay(200);
+                    motor.turn(270);
+                    break;
+               default:
+                   motor.noodStop();
+                   break;
                 }
-                currentStep++;
         }
-}
+}

+ 1 - 1
Botsingdetectie.java

@@ -45,4 +45,4 @@ public class Botsingdetectie{
       return 0;
     }
   }
-}
+}

+ 1 - 1
Lijnvolger.java

@@ -41,4 +41,4 @@ public class Lijnvolger
            }
       return waarde;
      }
-}
+}

+ 7 - 2
MotorAansturing.java

@@ -4,6 +4,7 @@ import stamp.core.*;
 public class MotorAansturing{
  private int snelheidL;
  private int snelheidR;
+ private int driveSnelheid;
  private boolean richting;
  private PWM motorL, motorR;
 
@@ -18,6 +19,7 @@ public class MotorAansturing{
     snelheidR = snelheid;
  }
   public void setSnelheid(int snelheid){
+    driveSnelheid = snelheid;
     setSnelheidR(snelheid);
     setSnelheidL(snelheid);
  }
@@ -27,9 +29,12 @@ public class MotorAansturing{
   public int getSnelheid(){
     return snelheidL;
  }
+ public int getDriveSnelheid(){
+  return driveSnelheid;
+ }
 
  public void start(){
-    int maxSnelheid = snelheidL;   
+    int maxSnelheid = snelheidL;
     for (int i=0; i<=maxSnelheid; i = i + 10)  {
              setSnelheid(i);
              rijden();
@@ -85,4 +90,4 @@ public class MotorAansturing{
      motorR.update(173, 2304);
 }
 
-}
+}

+ 0 - 1
VsDetectie.java

@@ -19,4 +19,3 @@ public class VsDetectie{
  }
 
 }
-

+ 36 - 0
gui/customComponents/Filedata.java

@@ -0,0 +1,36 @@
+package customComponents;
+
+import java.util.ArrayList;
+
+public class Filedata {
+	private ArrayList<ArrayList<Integer>> cordinates;
+	private ArrayList<Character> steps;
+	private int rows, columns;
+	public Filedata(){;
+	}
+	public ArrayList<ArrayList<Integer>> getCordinates() {
+		return cordinates;
+	}
+	public void setCordinates(ArrayList<ArrayList<Integer>> cordinates) {
+		this.cordinates = cordinates;
+	}
+	public ArrayList<Character> getSteps() {
+		return steps;
+	}
+	public void setSteps(ArrayList<Character> steps) {
+		this.steps = steps;
+	}
+	public int getRows() {
+		return rows;
+	}
+	public void setRows(int rows) {
+		this.rows = rows;
+	}
+	public int getColumns() {
+		return columns;
+	}
+	public void setColumns(int columns) {
+		this.columns = columns;
+	}
+	
+}

+ 27 - 14
gui/customComponents/Filehandling.java

@@ -19,7 +19,7 @@ public class Filehandling {
 		
 	}
     //route uitlezen uit een file en de file controleren
-	public ArrayList<ArrayList<Integer>> readRouteFile(String aFileName){
+	public Filedata readRouteFile(String aFileName){
 		Path path = Paths.get(aFileName);
 		try {
 			List<String> routebestand = Files.readAllLines(path, ENCODING);
@@ -29,21 +29,28 @@ public class Filehandling {
 			}else{
 				String[] sizesplitarray = routebestand.get(1).split(",");
 				String[] corsplitarray = routebestand.get(2).split(";");
+				String[] stepsplitarray = routebestand.get(3).split(",");
 				
 				ArrayList<ArrayList<Integer>> corarray = new ArrayList<ArrayList<Integer>>();
-				corarray.add(new ArrayList<Integer>());
-				corarray.get(0).add(Integer.parseInt(sizesplitarray[0]));
-				corarray.get(0).add(Integer.parseInt(sizesplitarray[1]));
+				ArrayList<Character> steps = new ArrayList<Character>();
 				
-				int teller = 1;
+				Filedata file = new Filedata();
+				file.setColumns(Integer.parseInt(sizesplitarray[1]));
+				file.setRows(Integer.parseInt(sizesplitarray[0]));
+
 				for(String cor:corsplitarray){
 					String[] temparray = cor.split(",");
-					corarray.add(teller, new ArrayList<Integer>());
-					corarray.get(teller).add(0, Integer.parseInt(temparray[0]));
-					corarray.get(teller).add(1, Integer.parseInt(temparray[1]));
-					teller++;
+					corarray.add(new ArrayList<Integer>());
+					corarray.get(corarray.size()-1).add(0, Integer.parseInt(temparray[0]));
+					corarray.get(corarray.size()-1).add(1, Integer.parseInt(temparray[1]));
+				}
+				for(String step:stepsplitarray){
+					steps.add(step.toCharArray()[0]);
 				}
-				return corarray;
+				file.setCordinates(corarray);
+				file.setSteps(steps);
+				System.out.println(file.getCordinates());
+				return file;
 			}
 		} catch (IOException e) {
 			JOptionPane.showMessageDialog(null, "Route niet geldig!", "Alert: " + "Fout", JOptionPane.INFORMATION_MESSAGE);
@@ -53,7 +60,7 @@ public class Filehandling {
 	}
 
 	//route file schrijven 
-	public void writeRouteFile(int maxx, int maxy, ArrayList<ArrayList<Integer>> route, String aFileName){
+	public void writeRouteFile(int maxx, int maxy, ArrayList<ArrayList<Integer>> route, ArrayList<Character> steps, String aFileName){
 	    Path path = Paths.get(aFileName);
 	    List<String> file = new ArrayList<String>();
 	    
@@ -62,10 +69,16 @@ public class Filehandling {
 	    	routestring += cor.get(0) + "," + cor.get(1) + ";" ;
 	    }
 	    
+	    String stepstring = "";
+	    for(Character c:steps){
+	    	stepstring += c +",";
+	    }
+	    
 	    file.add("broboticsrouteplanner");
-	    file.add(maxx+","+maxy);
-	    System.out.println(maxx);
-	    file.add(routestring + ";");
+	    file.add(maxx+","+maxy);	
+	    file.add(routestring);
+	    file.add(stepstring);
+	    
 	    try {
 			Files.write(path, file, ENCODING);
 		} catch (IOException e) {

+ 11 - 9
gui/customComponents/Kruispunt.java

@@ -22,13 +22,14 @@ public class Kruispunt extends JLabel
     public Kruispunt() 
     {
      kruispunt = null;
+     this.repaint();
     }
     public void setBoebot(int rotation)
     {
         if(rotation == 90)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/boebot.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/boebot.png"));
         }catch (IOException e){
             
         }
@@ -36,7 +37,7 @@ public class Kruispunt extends JLabel
         if(rotation == 0)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/boven boebot.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/boven boebot.png"));
         }catch (IOException e){
             
         }
@@ -44,7 +45,7 @@ public class Kruispunt extends JLabel
         if(rotation == 180)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/onder boebot.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/onder boebot.png"));
         }catch (IOException e){
             
         }
@@ -52,7 +53,7 @@ public class Kruispunt extends JLabel
         if(rotation == 270)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/links boebot.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/links boebot.png"));
         }catch (IOException e){
             
         }
@@ -64,7 +65,7 @@ public class Kruispunt extends JLabel
           if(rotation == 90)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/gatrechts.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/gatrechts.png"));
         }catch (IOException e){
             
         }
@@ -72,7 +73,7 @@ public class Kruispunt extends JLabel
         if(rotation == 0)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/gatboven.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/gatboven.png"));
         }catch (IOException e){
             
         }
@@ -80,7 +81,7 @@ public class Kruispunt extends JLabel
         if(rotation == 180)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/gatonder.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/gatonder.png"));
         }catch (IOException e){
             
         }
@@ -88,7 +89,7 @@ public class Kruispunt extends JLabel
         if(rotation == 270)
         {
         try{
-            kruispunt = ImageIO.read(new File("pictures/gatlinks.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/gatlinks.png"));
         }catch (IOException e){
             
         }
@@ -97,8 +98,9 @@ public class Kruispunt extends JLabel
     }
     public void setFinish()
     {
+    	
         try{
-            kruispunt = ImageIO.read(new File("pictures/finish.png"));
+            kruispunt = ImageIO.read(new File("src/pictures/finish.png"));
         }catch (IOException e){
             
         }

+ 16 - 5
gui/customComponents/MapLabel.java

@@ -11,29 +11,36 @@ public class MapLabel extends JLabel{
 	
 	int x1, y1;
 	public int xcoord, ycoord;
-	private boolean isSelected;
+	private int selected;
 	
 	public MapLabel(int x1, int y1, int xcoord, int ycoord){
 		this.x1 = x1;
 		this.y1 = y1;
 		this.xcoord = xcoord;
 		this.ycoord = ycoord;
+		selected = 0;
 		isSelected(false);
 		setBounds(x1 - 3,y1 - 3, 6, 6);
 		setOpaque(true);
+		setCursor(new Cursor(Cursor.HAND_CURSOR));
 	}
 	
 	public void isSelected(boolean selected){
 		if(selected){
+			this.selected++;
+		}else{
+			if(this.selected != 0){
+				this.selected--;
+			}
+		}
+		if(isSelected()){
 			setBackground(new Color(255,0,0));
 			setBorder(BorderFactory.createLineBorder(new Color(255,0,0), 1, true));
-			setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+
 		}else{
 			setBackground(new Color(100, 100, 100));
 			setBorder(BorderFactory.createLineBorder(new Color(80,80,80), 1, true));
-			setCursor(new Cursor(Cursor.HAND_CURSOR));
 		}
-		this.isSelected = selected;
 	}
 	/*public void paintComponent(Graphics g){
 		super.paintComponent(g);
@@ -51,7 +58,11 @@ public class MapLabel extends JLabel{
 		setY1(y);
 	}
 	public boolean isSelected() {
-		return isSelected;
+		if(selected > 0){
+			return true;
+		}else{
+			return false;
+		}
 	}
 
 	public int getX1() {

+ 10 - 5
gui/menubar/Menu_edit.java

@@ -1,17 +1,22 @@
 package menubar;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
 
 public class Menu_edit extends JMenu {
+	public JMenuItem ongedaan;
+	
 	public Menu_edit(){
+		ongedaan = new JMenuItem("Stap ongedaan maken");
+		ongedaan.setAccelerator(KeyStroke.getKeyStroke(
+		          KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
 		setText("Bewerken");
-		addSeparator();
-		add(new JMenuItem("Stap ongedaan maken"));
+		add(ongedaan);
 		add(new JMenuItem("Opnieuw"));
 		addSeparator();
-		add(new JMenuItem("Knippen"));
-		add(new JMenuItem("Kopieren"));
-		add(new JMenuItem("Plakken"));	
 	}
 }

+ 3 - 3
gui/panels/Iconbar.java

@@ -12,8 +12,8 @@ public class Iconbar extends JPanel {
 	public JButton irremote;
 	public JLabel currentroute;
 	public JLabel currentGridSize;
-	private JLabel messages;
-	Timer timer;
+	static private JLabel messages;
+	static Timer timer;
 	
 	public Iconbar(){
 		currentGridSize = new JLabel();
@@ -29,7 +29,7 @@ public class Iconbar extends JPanel {
 		this.add(currentGridSize);
 		this.add(messages);
 	}
-	public void setMessage(String message, int time){
+	public static void setMessage(String message, int time){
 		messages.setText(message);
 		if (time != 0){
 			timer.schedule(new TimerTask() {

+ 31 - 13
gui/panels/MainMenu.java

@@ -19,6 +19,7 @@ import javax.swing.text.NumberFormatter;
 import menubar.Menubar;
 import windows.Remote;
 import customComponents.ComWriter;
+import customComponents.Filedata;
 import customComponents.Filehandling;
 
 
@@ -58,11 +59,16 @@ public class MainMenu extends JPanel{
     			while(true){
     				try {
 						c = (char) bluetooth.getInput().read();
+						System.out.println(c);
 						if(c == 'b'){
-							iconbar.setMessage("Botsing gedetecteerd!", 2000);
+							iconbar.setMessage("Botsing gedetecteerd!", 3000);
+							routeSplitpane.gat();
 						}else if(c == 'g'){
-							iconbar.setMessage("Gat gedetecteerd!", 2000);
-						}else if(c == 'k');
+							iconbar.setMessage("Gat gedetecteerd!", 3000);
+							routeSplitpane.gat();
+						}else if(c == 'k'){
+							routeSplitpane.kruispunt();
+						};
 					} catch (IOException e) {
 						e.printStackTrace();
 					}
@@ -79,7 +85,7 @@ public class MainMenu extends JPanel{
 	}
     
     //methode om een route in te laden of om een nieuwe route aan te maken.
-	public void setCurrentRouteFile(String route, ArrayList<ArrayList<Integer>> tempcorarray ){
+	public void setCurrentRouteFile(String route, Filedata filedata ){
 		int c;
 		if(startup){
 			c = 0;
@@ -88,14 +94,13 @@ public class MainMenu extends JPanel{
 			c = JOptionPane.showConfirmDialog(null, "Weet u zeker dat u de huidige route wilt afsluiten?", "Alert: " + "Weet u het zeker?", JOptionPane.YES_NO_OPTION);  
 		}
     	if (c == JOptionPane.YES_OPTION) {
-	        	if(tempcorarray != null){	
+	        	if(filedata != null){	
 	        		// route openen via bestand
-	        		int maxx = tempcorarray.get(0).get(0);
-	        		int maxy = tempcorarray.get(0).get(1);
+	        		int maxx = filedata.getColumns();
+	        		int maxy = filedata.getRows();
 
 		    		iconbar.currentGridSize.setText( maxx + " x " + maxy);
-		        	tempcorarray.remove(0);	
-		        	routeSplitpane.setFieldSize(maxx, maxy, tempcorarray);
+		        	routeSplitpane.setFieldSize(maxx, maxy, filedata.getCordinates(), filedata.getSteps());
 		        	currentRouteFile = route;
 		    		iconbar.currentroute.setText(currentRouteFile);
 		        	menubar.menu_file.opslaan.setEnabled(true);
@@ -104,7 +109,7 @@ public class MainMenu extends JPanel{
 	  	  		  // Geen route ingeladen, nieuwe route openen
 	  	  		int[] tempsize = sizePopup();
 	  	  		if(tempsize != null){
-			  	 	routeSplitpane.setFieldSize(tempsize[0], tempsize[1], new ArrayList<ArrayList<Integer>>());
+			  	 	routeSplitpane.setFieldSize(tempsize[0], tempsize[1], new ArrayList<ArrayList<Integer>>(), new ArrayList<Character>());
 		    		iconbar.currentGridSize.setText(tempsize[0] + " x " + tempsize[1]);
 		        	currentRouteFile = "new";
 		    		iconbar.currentroute.setText("Nieuw bestand");
@@ -160,7 +165,7 @@ public class MainMenu extends JPanel{
 		menubar.menu_file.opslaan.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
-				file.writeRouteFile(routeSplitpane.getColumns(), routeSplitpane.getRows(), routeSplitpane.leftpanel.coordinaten, currentRouteFile);				
+				file.writeRouteFile(routeSplitpane.getColumns(), routeSplitpane.getRows(), routeSplitpane.leftpanel.coordinaten, routeSplitpane.leftpanel.steps, currentRouteFile);				
 			}
 		});
 		menubar.menu_file.opslaanals.addActionListener(new ActionListener() {
@@ -170,7 +175,7 @@ public class MainMenu extends JPanel{
 			      c.setFileFilter(new FileNameExtensionFilter("Route bestanden", "rt"));
 			      int rVal = c.showOpenDialog(MainMenu.this);
 			      if (rVal == JFileChooser.APPROVE_OPTION) {
-			    	  file.writeRouteFile(routeSplitpane.getColumns(), routeSplitpane.getRows(), routeSplitpane.leftpanel.coordinaten, c.getSelectedFile().getAbsolutePath());
+			    	  file.writeRouteFile(routeSplitpane.getColumns(), routeSplitpane.getRows(), routeSplitpane.leftpanel.coordinaten, routeSplitpane.leftpanel.steps, c.getSelectedFile().getAbsolutePath());
 			    	  setCurrentRouteFile(c.getSelectedFile().getAbsolutePath(), file.readRouteFile(c.getSelectedFile().getAbsolutePath()));
 			      }		
 			}
@@ -181,6 +186,14 @@ public class MainMenu extends JPanel{
 				setCurrentRouteFile("Nieuwe route", null);
 			}
 		});
+		menubar.menu_edit.ongedaan.addActionListener(new ActionListener() {
+			
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				routeSplitpane.leftpanel.stepBackwards();
+			}
+		});
+		
 		
 		iconbar.irremote.addActionListener(new ActionListener() {
 			@Override
@@ -203,13 +216,18 @@ public class MainMenu extends JPanel{
 		routeSplitpane.upload.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
+				routeSplitpane.rightpanel.clear();
+				routeSplitpane.setCurrentstep(0);
 				bluetooth.sendRoute(routeSplitpane.leftpanel.steps);
+				int length = routeSplitpane.leftpanel.coordinaten.size()-1;
+				routeSplitpane.rightpanel.setFinish(routeSplitpane.leftpanel.coordinaten.get(length).get(1), routeSplitpane.leftpanel.coordinaten.get(length).get(0));
+				routeSplitpane.rightpanel.setBoebot(routeSplitpane.leftpanel.coordinaten.get(0).get(1), routeSplitpane.leftpanel.coordinaten.get(0).get(0), 0);
 			}
 		});
 		routeSplitpane.automatisch.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
-				routeSplitpane.automatischBerekenen(iconbar);
+				routeSplitpane.automatischBerekenen();
 			}
 		});
     }

+ 37 - 8
gui/panels/RouteSplitpane.java

@@ -21,7 +21,8 @@ public class RouteSplitpane extends JPanel {
 	private int rows, columns;
 	JButton pauze, hervatten, clear, upload, automatisch;
 	JPanel menubar;
-	   
+	int currentstep = 0;   
+	
 	public RouteSplitpane(){	
 		//Linker paneel van de splitPane
 		leftpanel = new RouteSplitpanePlanner();
@@ -46,14 +47,22 @@ public class RouteSplitpane extends JPanel {
 	   	menubar.setLayout(new GridLayout(1,4));
 		
 	   	menubar.add(automatisch = new JButton("Automatische route"));
+	   	automatisch.addActionListener(new ActionListener() {
+			
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				leftpanel.setAutomatisch(true);
+			}
+		});
 		menubar.add(upload = new JButton("Upload"));
 	   	menubar.add(clear = new JButton("Clear"));
 	   	clear.addActionListener(new ActionListener() {
 			
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
-				rightpanel.refresh();
-				leftpanel.clear();				
+				rightpanel.clear();
+				leftpanel.clear();
+				currentstep = 0;
 			}
 		});
 	   	menubar.add(pauze = new JButton("Pauze"));
@@ -62,15 +71,32 @@ public class RouteSplitpane extends JPanel {
 		this.add(split, BorderLayout.CENTER);
 		this.add(menubar, BorderLayout.SOUTH);
 	}
-	public void setFieldSize(int y, int x, ArrayList<ArrayList<Integer>> cor){
+	public void setFieldSize(int y, int x, ArrayList<ArrayList<Integer>> cor, ArrayList<Character> steps){
 		rightpanel.setGridsize(x, y);
-    	leftpanel.drawField(x, y, cor);
+    	leftpanel.drawField(x, y, cor, steps);
     	setRows(y);
     	setColumns(x);
 	}
-	public void automatischBerekenen(Iconbar iconbar){
-		iconbar.setMessage("Zet eerste coordinaat", 0);
-		
+	public void automatischBerekenen(){
+		//Iconbar.setMessage("Zet eerste coordinaat", 0);
+	}
+	public void kruispunt(){
+			
+		try{
+			int x =leftpanel.coordinaten.get(currentstep).get(1);
+			int y = leftpanel.coordinaten.get(currentstep).get(0);
+			int o = leftpanel.coordinaten.get(currentstep).get(2);
+			rightpanel.setBoebot(x, y, o);
+			currentstep++;
+		}catch(IndexOutOfBoundsException e){
+			currentstep = 0;
+		}
+	}
+	public void gat(){
+		int x =leftpanel.coordinaten.get(currentstep).get(0);
+		int y = leftpanel.coordinaten.get(currentstep).get(1);
+		int o = leftpanel.coordinaten.get(currentstep).get(2);
+		rightpanel.setGat(x, y, o);
 	}
 	public int getRows() {
 		return rows;
@@ -84,5 +110,8 @@ public class RouteSplitpane extends JPanel {
 	public void setColumns(int columns) {
 		this.columns = columns;
 	}	
+	public void setCurrentstep(int step){
+		this.currentstep = step;
+	}
 	
 }

+ 15 - 14
gui/panels/RouteSplitpaneDisplay.java

@@ -28,22 +28,15 @@ public class RouteSplitpaneDisplay extends JPanel
    private int ex;
    private int ey;
    private JPanel content;
-   JButton pauze, hervatten;
-   JPanel menubar;
    
    public RouteSplitpaneDisplay()
    {
        content = new JPanel(new GridLayout(1,1));
-       menubar = new JPanel();
+      
        map = new ArrayList<ArrayList<Kruispunt>>();
       
-     menubar.setLayout(new GridLayout(1,4));
-  menubar.add(pauze = new JButton("Pauze"));
-  menubar.add(hervatten = new JButton("Hervatten"));
-  
        this.setLayout(new BorderLayout());
        this.add(content, BorderLayout.CENTER);
-       this.add(menubar, BorderLayout.SOUTH);
    }
    public void vorigeStapBoebot()
    {
@@ -79,21 +72,29 @@ public class RouteSplitpaneDisplay extends JPanel
            {
                map.get(row).add(new Kruispunt());
                Kruispunt kruispunt = map.get(row).get(col);
-               if(row == (y - ey -1) && col == ex)
+               if(row == (ey - 1 ) && col == ex)
                {
                    kruispunt.setFinish();
                }
-               if(row == (y - oy - 1) && col == ox)
+               if(row == (oy - 1) && col == ox)
                {
                    kruispunt.setBoebot(orotation);
                }
-               if(row == (y - xy -1) && col == xx)
+               if(row == (xy -1) && col == xx)
                {
                    kruispunt.setGat(xrotation);
                }
                content.add(kruispunt);
            }
        }
+       this.add(content);
+       this.revalidate();
+       this.repaint();
+   }
+   public void clear(){
+	   ox = oy = xx = xy = ex = ey = -1;
+	   System.out.println("test");
+	   refresh();
    }
    public void setGridsize(int x, int y){
     this.x = x;
@@ -102,19 +103,19 @@ public class RouteSplitpaneDisplay extends JPanel
    }
    public void setBoebot(int x,  int y, int o){
     ox = x;
-    oy = y;
+    oy = y+1;
     orotation = o;
     refresh();
    }
    public void setGat(int x, int y, int o){
 	   xx = x;
-	   xy = y;
+	   xy = y + 1;
 	   xrotation = o;
 	   refresh();
    }
    public void setFinish(int x, int y){
 	   ex= x;
-	   ey = y;
+	   ey = y + 1;
 	   refresh();
    }
 }

+ 416 - 40
gui/panels/RouteSplitpanePlanner.java

@@ -21,9 +21,14 @@ public class RouteSplitpanePlanner extends JPanel{
 	ArrayList<ArrayList<Integer>> coordinaten;
 	private ArrayList<ArrayList<MapLabel>> lines = new ArrayList<ArrayList<MapLabel>>();
 	ArrayList<Character> steps = new ArrayList<Character>();
+	ArrayList<ArrayList<Integer>> automatischcor = new ArrayList<ArrayList<Integer>>();
 	private boolean automatisch;
 	private int orientation;
 	
+	private int x, y, ex, ey;
+	
+	
+	
 	public RouteSplitpanePlanner(){
 		setLayout(new FlowLayout());
 		coordinaten = new ArrayList<ArrayList<Integer>>();
@@ -31,9 +36,12 @@ public class RouteSplitpanePlanner extends JPanel{
 		orientation = 0;
 	}
 
-	public void drawField(int c, int r, ArrayList<ArrayList<Integer>> cor){
+	public void drawField(int c, int r, ArrayList<ArrayList<Integer>> cor, ArrayList<Character> stappen){
 		clear();
+		labels.clear();
+		this.removeAll();
 		coordinaten = cor;
+		this.steps = stappen;
 		this.rows = r + 1;
 		this.columns = c + 1;
 	    for(int h = 0; h < rows -1; h++){
@@ -42,7 +50,7 @@ public class RouteSplitpanePlanner extends JPanel{
 	    		labels.get(h).add(new MapLabel(0 ,0, h, v));
 	    	}
 	    }
-	    
+
 	    
 		for(ArrayList<MapLabel> row : labels){
 			for(final MapLabel label : row){
@@ -50,37 +58,7 @@ public class RouteSplitpanePlanner extends JPanel{
 				label.addMouseListener(new MouseAdapter() {
 					@Override
 					public void mouseClicked(MouseEvent e) {
-						if(automatisch){
-							
-						}else{
-							if(!label.isSelected() && e.getButton() == e.BUTTON1){
-								if(coordinaten.size() == 0){
-									label.isSelected(true);
-									coordinaten.add(new ArrayList<Integer>());
-									coordinaten.get(coordinaten.size()-1).add(label.getXcoord());
-									coordinaten.get(coordinaten.size()-1).add(label.getYcoord());
-								}else if(checkInRange(label.getXcoord(), label.getYcoord())){
-									label.isSelected(true);
-									coordinaten.add(new ArrayList<Integer>());
-									coordinaten.get(coordinaten.size()-1).add(label.getXcoord());
-									coordinaten.get(coordinaten.size()-1).add(label.getYcoord());
-									
-									lines.add(new ArrayList<MapLabel>());
-									lines.get(lines.size()-1).add(labels.get(coordinaten.get(coordinaten.size()-2).get(0)).get(coordinaten.get(coordinaten.size()-2).get(1)));
-									lines.get(lines.size()-1).add(label);
-									repaint();
-								}
-							}else if(label.isSelected() && e.getButton() == e.BUTTON3){
-								if(coordinaten.size() > 1){
-									if(label.getXcoord() == coordinaten.get(coordinaten.size()-1).get(0) && label.getYcoord() == coordinaten.get(coordinaten.size()-1).get(1) ){
-										lines.remove(lines.size() -1);
-										coordinaten.remove(coordinaten.size() -1);
-										label.isSelected(false);	
-										repaint();
-									}
-								}
-							}
-						}
+						labelClick(label, e.getButton());
 					}
 				});
 			}
@@ -96,9 +74,68 @@ public class RouteSplitpanePlanner extends JPanel{
 			}
 			first = false;
 		}
+	    revalidate();
 		repaint();
 	}
 	
+	public void labelClick(MapLabel label, int e){
+		if(automatisch){
+			if(automatischcor.size() == 0 ){
+				Iconbar.setMessage("Geef 2e coordinaat", 0);
+				automatischcor.add(new ArrayList<Integer>());
+				automatischcor.get(0).add(rows-label.xcoord-1);
+				automatischcor.get(0).add(label.ycoord);
+			}else{
+				Iconbar.setMessage("Route gegenereerd!", 2000);
+				label.isSelected(true);
+				System.out.println(								automatischcor.get(0).get(0));
+				System.out.println(								automatischcor.get(0).get(1));
+				System.out.println(label.xcoord);
+				System.out.println(label.ycoord);
+				berekenRoute(label.ycoord, rows-label.xcoord-1, automatischcor.get(0).get(1), automatischcor.get(0).get(0), 0);
+				System.out.println(coordinaten);
+				System.out.println(steps);
+				drawField(columns-1, rows-1, new ArrayList<ArrayList<Integer>>(coordinaten), new ArrayList<Character>(steps));
+				
+			}
+		}else{
+			if(e == 0x01){
+				if(coordinaten.size() == 0){
+					label.isSelected(true);
+					coordinaten.add(new ArrayList<Integer>());
+					coordinaten.get(coordinaten.size()-1).add(label.getXcoord());
+					coordinaten.get(coordinaten.size()-1).add(label.getYcoord());
+					 coordinaten.get(coordinaten.size()-1).add(0);
+				}else if(checkInRange(label.getXcoord(), label.getYcoord())){
+					label.isSelected(true);
+					coordinaten.add(new ArrayList<Integer>());
+					coordinaten.get(coordinaten.size()-1).add(label.getXcoord());
+					coordinaten.get(coordinaten.size()-1).add(label.getYcoord());
+					
+					lines.add(new ArrayList<MapLabel>());
+					lines.get(lines.size()-1).add(labels.get(coordinaten.get(coordinaten.size()-2).get(0)).get(coordinaten.get(coordinaten.size()-2).get(1)));
+					lines.get(lines.size()-1).add(label);
+					setStep();
+					repaint();
+				}
+			}else if(label.isSelected() && e == 0x03){
+				if(coordinaten.size() > 1){
+					if(label.getXcoord() == coordinaten.get(coordinaten.size()-1).get(0) && label.getYcoord() == coordinaten.get(coordinaten.size()-1).get(1) ){
+						lines.remove(lines.size() -1);
+						coordinaten.remove(coordinaten.size() -1);
+						label.isSelected(false);
+						orientation = coordinaten.get(coordinaten.size()-1).get(2);
+						steps.remove(steps.size() -1);
+						repaint();
+					}
+				}
+			}
+		}
+	}
+	public void stepBackwards(){
+		MapLabel label =labels.get(coordinaten.get(coordinaten.size()-1).get(0)).get(coordinaten.get(coordinaten.size()-1).get(1)); 
+		labelClick(label, 0x03);
+	}
 	
 	public void paintComponent(Graphics g){
 		super.paintComponent(g);
@@ -138,10 +175,13 @@ public class RouteSplitpanePlanner extends JPanel{
 				label.isSelected(false);
 			}
 		}
+		automatisch = false;
 		lines.clear();
 		coordinaten.clear();
 		steps.clear();
 		orientation = 0;
+		automatischcor.clear();
+		ex = ey = x = y = 0;
 		repaint();
 	}
 	
@@ -151,27 +191,188 @@ public class RouteSplitpanePlanner extends JPanel{
 
 		if(currenty == y ){
 			if(currentx + 1 == x){
-				setStep("down");
 				return true;
 			}else if(currentx - 1 == x){
-				setStep("up");
 				return true;
 			}
 		}else if(currentx == x){
 			if(currenty + 1 == y){
-				setStep("right");
 				return true;
 			}else if(currenty - 1 == y){
-				setStep("left");
 				return true;
 			}
 		}
 		return false;
 	}
 
-	public void setStep(String orient){
-		
+	public void setStep(){
+		int last = coordinaten.size() -1;
+		int x1 = coordinaten.get(last-1).get(1);
+		int y1 = rows - coordinaten.get(last-1).get(0) -1;
+		int x2 = coordinaten.get(last).get(1);
+		int y2 = rows  - coordinaten.get(last).get(0) - 1;
+
+        if(x1 < x2)
+        {
+            if(orientation == 90)
+            {
+                steps.add('v');
+            }
+            if(orientation == 0)
+            {
+                turnright();
+                steps.add('r');
+            }
+            if(orientation == 270)
+            {
+                keren();
+                steps.add('a');
+            }
+            if(orientation == 180)
+            {
+                turnleft();
+                steps.add('l');
+            }
+        }
+        else
+        {
+            if(x1 > x2)
+            {
+                if(orientation == 270)
+                {
+                	steps.add('v');
+                }
+                if(orientation == 0)
+                {
+                    turnleft();
+                    steps.add('l');
+                }
+                if(orientation == 90)
+                {
+                    keren();
+                    steps.add('k');
+                }
+                if(orientation == 180)
+                {
+                    turnright();
+                    steps.add('r');
+                }
+            }
+        }
+        
+        if(y1 < y2)
+        {
+            if(orientation == 0)
+            {
+                steps.add('v');
+            }
+            if(orientation == 270)
+            {
+                turnright();
+
+                steps.add('r');
+            }
+            if(orientation == 180)
+            {
+
+                steps.add('a');
+            }
+            if(orientation == 90)
+            {
+                turnleft();
+
+                steps.add('l');
+            }
+        }
+        else
+        {
+            if(y1 > y2)
+            {
+                if(orientation == 180)
+                {
+                    steps.add('v');
+                }
+                if(orientation == 90)
+                {
+                    turnright();
+
+                    steps.add('r');
+                }
+                if(orientation == 0)
+                {
+                    keren();
+
+                    steps.add('a');
+                }
+                if(orientation == 270)
+                {
+                    turnleft();
+
+                    steps.add('l');
+                }
+            }
+        }
+        coordinaten.get(coordinaten.size()-1).add(orientation);
+		System.out.println(steps);
 	}
+	
+	 public void turnleft()
+	    {
+	        orientation = orientation - 90;
+	        if (orientation < 0)
+	        {
+	            orientation = 270;
+	        }
+	    }
+
+	    public void turnright()
+	    {
+	        orientation = orientation + 90;
+	        if (orientation > 270)
+	        {
+	            orientation = 0;
+	        }
+	    }
+
+	    public void keren()
+	    {
+	        orientation = orientation + 180;
+	        if (orientation == 360)
+	        {
+	            orientation = 0;
+	        }
+	        if(orientation == 450)
+	        {
+	            orientation = 90;
+	        }
+	    }
+	    public void vooruit()
+	    {
+	        if (orientation == 0 && y < rows)
+	        {
+	            y ++;
+	        }
+	        if (orientation == 90 && x < columns)
+	        {
+	            x ++;
+	        }
+	        if (orientation == 180 && y > 0)
+	        {
+	            y --;
+	        }
+	        if (orientation == 270 && x > 0)
+	        {
+	            x --;
+	        }
+	        coordinaten.add(new ArrayList<Integer>());
+	        coordinaten.get(coordinaten.size()-1).add(rows-y-1);
+	        coordinaten.get(coordinaten.size()-1).add(x);
+	        coordinaten.get(coordinaten.size()-1).add(orientation);
+	    }
+	public int getOrientation() {
+			return orientation;
+		}
+
 	public void setOrientation(int o){
         orientation += o;
         if (orientation == 360)
@@ -188,10 +389,185 @@ public class RouteSplitpanePlanner extends JPanel{
 	}
 
 	public void setAutomatisch(boolean automatisch) {
+		boolean labelselected = false;
+		for(ArrayList<MapLabel> row:labels){
+			for(MapLabel label1:row){
+				if(label1.isSelected()){
+					labelselected = true;
+				}
+			}
+		}
+		if(labelselected){
+			Iconbar.setMessage("Zet tweede coordinaat", 0);
+			automatischcor.add(new ArrayList<Integer>());
+			automatischcor.get(0).add(coordinaten.get(coordinaten.size()-1).get(0));
+			automatischcor.get(0).add(coordinaten.get(coordinaten.size()-1).get(1));
+			System.out.println(automatischcor.get(0).get(0));
+			System.out.println(automatischcor.get(0).get(1));
+		}
+		else{
+			Iconbar.setMessage("Zet eerste coordinaat", 0);
+		}
 		this.automatisch = automatisch;
 		
 	}
 	
-	
+   public void berekenRoute(int eindx, int eindy, int beginx, int beginy, int rotatie)
+    {
+	   coordinaten.add(new ArrayList<Integer>());
+       coordinaten.get(coordinaten.size()-1).add(rows-beginy-1);
+       coordinaten.get(coordinaten.size()-1).add(beginx);
+       coordinaten.get(coordinaten.size()-1).add(rotatie);
+        char[] route = new char[40];
+        int teller = 0;
+        orientation = rotatie;
+        int lengte = 0;
+        if(eindx <= columns && eindy <= rows && eindx >= 0 && eindy >= 0)
+        {
+            ex = eindx;
+            ey = eindy;
+        }else{
+            
+        }
+        if(beginx <= columns && beginy <= rows && beginx >= 0 && beginy >= 0)
+        {
+            x = beginx;
+            y = beginy;
+        }else{
+          
+        }
+        while(ex != x)
+        {
+            if(x < ex)
+            {
+                if(orientation == 90)
+                {
+                    vooruit();
+                    steps.add('v');
+                    teller ++;
+                }
+                if(orientation == 0)
+                {
+                    turnright();
+                    vooruit();
+                    steps.add('r');
+                    teller ++;
+                }
+                if(orientation == 270)
+                {
+                    keren();
+                    vooruit();
+                    steps.add('k');
+                    teller ++;
+                }
+                if(orientation == 180)
+                {
+                    turnleft();
+                    vooruit();
+                    steps.add('l');
+                    teller ++;
+                }
+            }
+            else
+            {
+                if(x > ex)
+                {
+                    if(orientation == 270)
+                    {
+                        vooruit();
+                        steps.add('v');
+                        teller ++;
+                    }
+                    if(orientation == 0)
+                    {
+                        turnleft();
+                        vooruit();
+                        steps.add('l');
+                        teller ++;
+                    }
+                    if(orientation == 90)
+                    {
+                        keren();
+                        vooruit();
+                        steps.add('k');
+                        teller ++;
+                    }
+                    if(orientation == 180)
+                    {
+                        turnright();
+                        vooruit();
+                        steps.add('r');
+                        teller ++;
+                    }
+                }
+            }
+        }
+        while(ey != y)
+        {
+            if(y < ey)
+            {
+                if(orientation == 0)
+                {
+                    vooruit();
+                    steps.add('v');
+                    teller ++;
+                }
+                if(orientation == 270)
+                {
+                    turnright();
+                    vooruit();
+                    steps.add('r');
+                    teller ++;
+                }
+                if(orientation == 180)
+                {
+                    keren();
+                    vooruit();
+                    steps.add('k');
+                    teller ++;
+                }
+                if(orientation == 90)
+                {
+                    turnleft();
+                    vooruit();
+                    steps.add('l');
+                    teller ++;
+                }
+            }
+            else
+            {
+                if(y > ey)
+                {
+                    if(orientation == 180)
+                    {
+                        vooruit();
+                        steps.add('v');
+                        teller ++;
+                    }
+                    if(orientation == 90)
+                    {
+                        turnright();
+                        vooruit();
+                        steps.add('r');
+                        teller ++;
+                    }
+                    if(orientation == 0)
+                    {
+                        keren();
+                        vooruit();
+                        steps.add('k');
+                        teller ++;
+                    }
+                    if(orientation == 270)
+                    {
+                        turnleft();
+                        vooruit();
+                        steps.add('l');
+                        teller ++;
+                    }
+                }
+            }
+        }
+    }
 
 }