Ejemplo n.º 1
0
  /**
   * 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();
  }
Ejemplo n.º 2
0
  public static void main(String[] args) throws Exception {
    new RaceMain();

    // Race
    Settings.PILOT.setTravelSpeed(Settings.PILOT.getMaxTravelSpeed() * 0.70);
    Settings.PILOT.setRotateSpeed(Settings.PILOT.getMaxRotateSpeed() / 4);
    Motor.A.setSpeed(Motor.A.getMaxSpeed() / 5);
    new SensorHeadCalibrate();
    Settings.motorAAngle = Settings.SENSOR_RIGHT;
    Settings.atStart = false;

    new LightCalibrate();

    Behavior b1 = new RaceFollowWall(13);
    Behavior b2 = new Race();
    Behavior b4 = new ReadCodes();
    Behavior b3 = new RaceDrive();
    Behavior b5 = new SensorHeadPosition();
    Behavior b6 = new MotorAStall();
    Behavior[] bArray = {b1, b2, b4, b3, b5, b6};

    CustomArbitrator arbitrator = new CustomArbitrator(bArray);
    Thread t = new Thread(arbitrator);
    t.start();
  }
Ejemplo n.º 3
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);
    }
  }
Ejemplo n.º 4
0
 public static void main(String[] arguments) {
   Motor.A.setSpeed(200);
   Motor.B.setSpeed(200);
   Motor.A.forward();
   Motor.B.forward();
   final LightSensor sensor = new LightSensor(SensorPort.S1);
   final Object blocker = new Object();
   while (true) {
     if (sensor.readNormalizedValue() >= 512) {
       LCD.bitBlt(
           null,
           LCD.SCREEN_WIDTH,
           LCD.SCREEN_HEIGHT,
           0,
           0,
           0,
           0,
           LCD.SCREEN_WIDTH,
           LCD.SCREEN_HEIGHT,
           LCD.ROP_CLEAR);
     } else {
       LCD.bitBlt(
           null,
           LCD.SCREEN_WIDTH,
           LCD.SCREEN_HEIGHT,
           0,
           0,
           0,
           0,
           LCD.SCREEN_WIDTH,
           LCD.SCREEN_HEIGHT,
           LCD.ROP_SET);
     }
     synchronized (blocker) {
       try {
         blocker.wait(100);
       } catch (InterruptedException e) {
       }
     }
   }
 }
Ejemplo n.º 5
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);
  }
  // Decode msg method
  public void decodeMSG(Byte msg) throws IOException {
    // Motor Movement Functions
    //        int currentSpeedA = Motor.A.getSpeed();
    //        int currentSpeedB = Motor.B.getSpeed();

    if (msg == MOVE_FOWARD) {
      Motor.A.backward();
      Motor.B.backward();
    } else if (msg == MOVE_FOWARD_LEFT) {
      Motor.A.backward();
      Motor.B.setSpeed(motorSpeed / 2);
      Motor.B.backward();

    } else if (msg == MOVE_FOWARD_RIGHT) {
      Motor.A.setSpeed(motorSpeed / 2);
      Motor.A.backward();
      Motor.B.backward();

    } else if (msg == ROTATE_LEFT) {
      Motor.A.backward();
      Motor.B.forward();
    } else if (msg == ROTATE_RIGHT) {
      Motor.A.forward();
      Motor.B.backward();
    } else if (msg == MOVE_BACKWARD) {
      Motor.A.forward();
      Motor.B.forward();
    } else if (msg == STOP) {
      Motor.A.setSpeed(motorSpeed);
      Motor.B.setSpeed(motorSpeed);
      Motor.A.stop();
      Motor.B.stop();
    }

    // Motor set Speed Function
    if (msg == SET_MOTOR_SPD) {

      Byte rMsg = 40;

      rMsg = dis.readByte();

      int spd = 9 * rMsg;
      motorSpeed = spd;

      Motor.A.setSpeed(spd);
      Motor.B.setSpeed(spd);
    }

    if (msg == CUSTOM_MOVE) {
      int motorB = dis.read();
      int motorA = dis.read();
      Motor.A.setSpeed(motorA * 9);
      Motor.B.setSpeed(motorB * 9);
      Motor.A.backward();
      Motor.B.backward();
    }

    // Connection close msg
    if (msg == CLOSE_COMM) {
      closeBTConnection();
    }
  }