Kaynağa Gözat

Nu wel de goede bestanden geupload

jancoow 11 yıl önce
ebeveyn
işleme
7f9957d6a6
9 değiştirilmiş dosya ile 112 ekleme ve 7 silme
  1. 35 1
      BoeBot.java
  2. 23 0
      Botsingdetectie.java
  3. 13 2
      FysiekeIndicator.java
  4. 28 1
      IrDetectie.java
  5. 9 2
      Led.java
  6. 1 0
      Lijnvolger.java
  7. 1 0
      Main.java
  8. BIN
      Main.jpf
  9. 2 1
      Voelspriet.java

+ 35 - 1
BoeBot.java

@@ -1,5 +1,39 @@
+package boebot;
+import stamp.core.*;
+
 public class BoeBot{
- public BoeBot(){
+  MotorAansturing motor;
+  Botsingdetectie botsingdetectie;
+  FysiekeIndicator fysiekeindicator;
+
+  public BoeBot(){
+    motor = new MotorAansturing();
+    botsingdetectie = new Botsingdetectie();
+    fysiekeindicator = new FysiekeIndicator();
+    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);
+          motor.noodStop();
+          motor.setRichting(false);
+          motor.start();
+          CPU.delay(3000);
+          motor.noodStop();
+          motor.turn(180);
+          motor.setRichting(true);
+          motor.start();
 
+       }
+        CPU.delay(1000);
+
+    }
  }
+
 }

+ 23 - 0
Botsingdetectie.java

@@ -1,5 +1,28 @@
+package boebot;
 public class Botsingdetectie{
+  private IrDetectie irL;
+  private IrDetectie irR;
+  private boolean IrDetectL;
+  private boolean IrDetectR;
+
   public Botsingdetectie(){
+       irL = new IrDetectie(8, 9);
+       irR = new IrDetectie(2, 0);
+  }
+
+  public boolean detectEdge(){
+
+    IrDetectL = irL.detect();
+    IrDetectR = irR.detect();
+    if(IrDetectL || IrDetectR){
+        return true;
+
+    }else{
+      return false;
+
+    }
+
+
 
   }
 }

+ 13 - 2
FysiekeIndicator.java

@@ -1,5 +1,16 @@
+package boebot;
 public class FysiekeIndicator{
- public FysiekeIndicator(){
+  private Led led1;
+  private Led led2;
 
- }
+   public FysiekeIndicator(){
+      led1 = new Led(1);
+      led2 = new Led(10);
+   }
+   public void setLed1(boolean state){
+     led1.setState(state);
+   }
+   public void setLed2(boolean state){
+     led1.setState(state);
+   }
 }

+ 28 - 1
IrDetectie.java

@@ -1,5 +1,32 @@
+package boebot;
+import stamp.core.*;
+
 public class IrDetectie{
- public IrDetectie(){
+  PWM irZender;
+  boolean irDetect;
+  private int pinRead;
+  private int pinSend;
+
+ public IrDetectie(int pinS, int pinR){
+     irZender = new PWM (CPU.pins[pinS], 1, 2);
+     irZender.stop();
+     pinRead = pinR;
+     pinSend = pinS;
 
  }
+ public void setPinRead(int pin){
+   pinRead = pin;
+ }
+ public boolean detect(){
+    for(int i = 0; i < 20; i++){
+        irZender.start();
+        CPU.delay(5);
+        irDetect = CPU.readPin(CPU.pins[pinRead]);
+        irZender.stop();
+        CPU.delay (20);
+    }
+    CPU.writePin(pinSend, false);
+    return  !irDetect;
+ }
+
 }

+ 9 - 2
Led.java

@@ -1,5 +1,12 @@
-public class Voelspriet(
- public Voelspriet(){
+package boebot;
+import stamp.core.*;
 
+public class Led{
+ private int pinNumber;
+ public Led(int pin){
+   pinNumber = pin;
+ }
+ public void setState(boolean state){
+    CPU.writePin(CPU.pins[pinNumber], state);
  }
 }

+ 1 - 0
Lijnvolger.java

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

+ 1 - 0
Main.java

@@ -2,6 +2,7 @@
  * @version 1.0 27-11-2014
  * @author Janco
  */
+package boebot;
 import stamp.core.*;
 public class Main{
   public static void main(){

BIN
Main.jpf


+ 2 - 1
Voelspriet.java

@@ -1,4 +1,5 @@
-public class Voelspriet(
+package boebot;
+public class Voelspriet{
  public Voelspriet(){
 
  }