Example #1
0
  public EV3Bot() {
    this.botMessage = "Lejos!";
    this.xPosition = 0;
    this.yPosition = 2;
    this.waitTime = 4000;
    this.turnWaitTime = 500;

    distanceSensor = new EV3UltrasonicSensor(LocalEV3.get().getPort("S1"));
    ultrasonicSamples = new float[distanceSensor.sampleSize()];
    distanceSensor.enable();
    setupPilot();
  }
Example #2
0
  public SensorHandler() {
    distanceSensor = new EV3UltrasonicSensor(SensorPort.S1);
    colorSensor = new EV3ColorSensor(SensorPort.S4);

    distanceProvider = distanceSensor.getDistanceMode();
    colorProvider = colorSensor.getRGBMode();
  }
Example #3
0
 public void driveRoom() {
   displayMessage("DriveRoom!");
   distanceSensor.fetchSample(ultrasonicSamples, 0);
   if (ultrasonicSamples[0] < 5) {
     botPilot.travel(950.4);
     Delay.msDelay(turnWaitTime);
     botPilot.rotate(90);
     Delay.msDelay(turnWaitTime);
     botPilot.travel(3550.1);
     Delay.msDelay(turnWaitTime);
     botPilot.rotate(-90);
     Delay.msDelay(turnWaitTime);
     botPilot.travel(6000.2);
     Delay.msDelay(turnWaitTime);
     botPilot.rotate(90);
     Delay.msDelay(turnWaitTime);
     botPilot.travel(4410.4);
   } else {
     botPilot.travel(4410.4);
     Delay.msDelay(turnWaitTime);
     botPilot.rotate(-90);
     Delay.msDelay(turnWaitTime);
     botPilot.travel(6000.2);
     Delay.msDelay(turnWaitTime);
     botPilot.rotate(90);
     Delay.msDelay(turnWaitTime);
     botPilot.travel(3550.1);
     Delay.msDelay(turnWaitTime);
     botPilot.rotate(-90);
     Delay.msDelay(turnWaitTime);
     botPilot.travel(950.4);
   }
 }
Example #4
0
  private void elevatorCollision() {
    LCD.clear();
    LCD.drawString("Collision: " + collision, 0, 4);
    Delay.msDelay(3000);
    float[] dist = new float[sonicSensor.getDistanceMode().sampleSize()];
    sonicSensor.getDistanceMode().fetchSample(dist, 0);

    if ((dist[0] - DISTANCE_TO_WALL) > 0.005) {
      drive.turnRight(5, false);
    } else {
      drive.turnLeft(5, false);
    }
    if (collision == "Wall") {
      drive.stop();
    } else if (collision == "Left Wall") {
      drive.turnRight(5, false);
    } else if (collision == "Right Wall") {
      drive.moveDistance(drive.maxSpeed(), -2);
      drive.turnLeft(20, false);
    }
  }