Browse Source

Voelspriet toegevoegd

jancoow 11 years ago
parent
commit
219f6cabb9
8 changed files with 88 additions and 47 deletions
  1. 31 9
      BoeBot.java
  2. 28 8
      Botsingdetectie.java
  3. 1 0
      FysiekeIndicator.java
  4. 1 1
      IrDetectie.java
  5. 1 1
      Lijnvolger.java
  6. 4 4
      Main.java
  7. 3 21
      Voelspriet.java
  8. 19 3
      VsDetectie.java

+ 31 - 9
BoeBot.java

@@ -10,26 +10,48 @@ public class BoeBot{
     motor = new MotorAansturing();
     botsingdetectie = new Botsingdetectie();
     fysiekeindicator = new FysiekeIndicator();
-    motor.setSnelheid(50);
+    motor.setSnelheid(100);
     motor.setRichting(true);
     motor.start();
 
     while(true){
-      if(botsingdetectie.detectEdge()){
-           fysiekeindicator.setLed1(false);
-           fysiekeindicator.setLed2(false);
-      }  else{
-           fysiekeindicator.setLed1(true);
-           fysiekeindicator.setLed2(true);
+        if(botsingdetectie.detectEdge()){
+          CPU.writePin(CPU.pin1,true);
           motor.noodStop();
           motor.setRichting(false);
           motor.start();
-          CPU.delay(3000);
+          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){
+           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();
        }
         CPU.delay(1000);
 

+ 28 - 8
Botsingdetectie.java

@@ -2,29 +2,49 @@ package boebot;
 public class Botsingdetectie{
   private IrDetectie irL;
   private IrDetectie irR;
+  private VsDetectie vsR;
+  private VsDetectie vsL;
   private boolean IrDetectL;
   private boolean IrDetectR;
+  private boolean VsDetectL;
+  private boolean VsDetectR;
 
   public Botsingdetectie(){
-       irL = new IrDetectie(8, 9);
-       irR = new IrDetectie(2, 0);
+      irL = new IrDetectie(8, 9);
+      irR = new IrDetectie(2, 0);
+      vsL = new VsDetectie(7);
+      vsR = new VsDetectie(5);
   }
 
   public boolean detectEdge(){
-
     IrDetectL = irL.detect();
     IrDetectR = irR.detect();
-    System.out.println(IrDetectL);
-    System.out.println(IrDetectR);
-    if(IrDetectL || IrDetectR){
+    if(!IrDetectL || !IrDetectR){
         return true;
-
     }else{
       return false;
 
     }
+  }
 
+  public int detectObject(){
+    VsDetectL = vsL.detect();
+    VsDetectR = vsR.detect();
 
-
+    if(VsDetectL && VsDetectR)
+    {
+      return 3;
+    }
+    else if(VsDetectL)
+    {
+      return 1;
+    }
+    else if(VsDetectR)
+    {
+      return 2;
+    }
+    else {
+      return 0;
+    }
   }
 }

+ 1 - 0
FysiekeIndicator.java

@@ -6,6 +6,7 @@ public class FysiekeIndicator{
    public FysiekeIndicator(){
       led1 = new Led(1);
       led2 = new Led(10);
+     // speaker = new Speaker(10);
    }
    public void setLed1(boolean state){
      led1.setState(state);

+ 1 - 1
IrDetectie.java

@@ -25,7 +25,7 @@ public class IrDetectie{
         irZender.stop();
         CPU.delay (20);
     }
-    CPU.writePin(pinSend, false);
+    CPU.writePin(pinSend, false);  
     return  !irDetect;
  }
 

+ 1 - 1
Lijnvolger.java

@@ -1,4 +1,4 @@
-package boebot;
+package boebot; 
 public class Lijnvolger{
  public Lijnvolger(){
 

+ 4 - 4
Main.java

@@ -1,11 +1,11 @@
+package boebot;
+import stamp.core.*;
  /*
  * @version 1.0 27-11-2014
  * @author Janco
  */
-package boebot;
-import stamp.core.*;
 public class Main{
   public static void main(){
-    BoeBot bot = new BoeBot();
+    BoeBot boebot = new BoeBot();
   }
-}
+}

+ 3 - 21
Voelspriet.java

@@ -1,24 +1,6 @@
 package boebot;
-import stamp.core.*;
+public class Voelspriet{
+ public Voelspriet(){
 
-public class VsDetectie{
-PWM vsZender;
-  boolean vsDetect;
-  private int pinRead;
-  private int pinSend;
-
- public VsDetectie(int pinS, int pinR){
-     vsZender = new PWM (CPU.pins[pinS], 1, 2);
-     vsZender.stop();
-     pinRead = pinR;
-     pinSend = pinS;
-
- }
- public void setPinRead(int pin){
-   pinRead = pin;
- }
- public boolean detect(){
-    vsDetect = CPU.readPin(CPU.pins[pinRead]);
-    return vsDetect;
  }
-}
+}

+ 19 - 3
VsDetectie.java

@@ -1,6 +1,22 @@
 package boebot;
-public class Voelspriet{
- public Voelspriet(){
+import stamp.core.*;
+public class VsDetectie{
+  boolean vsDetect;
+  private int pinRead;
 
+
+ public VsDetectie( int pinR){
+     pinRead = pinR;
+ }
+
+ public void setPinRead(int pin){
+   pinRead = pin;
  }
-}
+
+ public boolean detect(){
+    vsDetect = CPU.readPin(CPU.pins[pinRead]);
+    return !vsDetect;
+ }
+
+}
+