/*
  * This method makes the robot drive FRONT or BACK depending on the direction it is given.
  */
 public void drive(Direction direction) {
   if (direction == Direction.FRONT) {
     Motor.A.forward();
     Motor.B.forward();
   } else if (direction == Direction.BACK) {
     Motor.A.backward();
     Motor.B.backward();
   }
 }
Esempio n. 2
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) {
       }
     }
   }
 }
  // 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();
    }
  }