/**
   * Main Entry Point. Creates the behaviors and starts the Arbitrator.
   *
   * @param args
   */
  public static void main(String[] args) {
    // Wall sensing behavior
    Behavior b1 = new WallBehavior(SensorPort.S3);
    // Move forward behavior
    Behavior b2 = new ForwardBehavior();
    // Left Light sensor sensing behavior
    Behavior b3 = new LeftLightBehavior(SensorPort.S2, SensorPort.S1);
    // Right Light sensor sensing behavior
    Behavior b4 = new RightLightBehavior(SensorPort.S2, SensorPort.S1);
    // Both Light sensors sensing behavior
    Behavior b5 = new BothLightsBehavior(SensorPort.S2, SensorPort.S1);
    // Win Behavior
    Behavior b6 = new WinBehavior(SensorPort.S2, SensorPort.S1);

    // Put the behaviors into the array based on priority
    Behavior[] behaviorArray = {b2, b1, b3, b4, b5, b6};

    // Create the arbitrator
    Arbitrator arby = new Arbitrator(behaviorArray);

    // Set the motor speeds
    Motor.A.setSpeed(800);
    Motor.C.setSpeed(800);

    // Start
    arby.start();
  }
Esempio n. 2
0
  /** Run. */
  public void run() {
    Motor.A.setSpeed(90);
    Motor.C.setSpeed(90);

    while (true) {
      moveForward();

      waitForReading();
      Motor.A.backward();
      Motor.C.backward();
      Delay.msDelay(1000);
      rotation(TURN_90_DEGREES, TURN_LEFT);
    }
  }
Esempio n. 3
0
  private int waitForReading() {
    int lightLevelReading;
    int distanceToObject;

    do {
      try {
        Thread.sleep(100);
      } catch (InterruptedException ex) {
      }

      lightLevelReading = lightSensorDown.readValue();
    } while (lightLevelReading > BLACK_WHITE_THRESHOLD);

    distanceToObject = ultrasonicSensor.getDistance();

    if (distanceToObject < 20) {
      Motor.A.setSpeed(1000);
      Motor.C.setSpeed(1000);
      pilot.travel(300);
      Delay.msDelay(10000);
    }

    return (lightLevelReading);
  }