예제 #1
0
  /*
   * This method makes the robot turn 90 deg to the given direction
   */
  public void turnNXT(Direction direction) {
    if (direction == Direction.RIGHT) {
      Motor.A.rotate(237);

    } else if (direction == Direction.LEFT) {
      Motor.B.rotate(237);
    }
  }
예제 #2
0
  /**
   * Stops the robot when the ultrasonic sensor detects a certain distance.
   *
   * @param stopDistance as long as the current distance is less than this stop distance, the robot
   *     will keep moving. Once the current distance is larger than the stop distance, the function
   *     returns.
   * @return the current distance upon stopping.
   */
  private boolean stopBeforeEdge() {
    int currentDistance = 0;
    int lightLevelReading;
    int distanceToObject;
    boolean edgeIsSafe = false;

    do {
      lightLevelReading = lightSensorDown.readValue();

      Motor.A.rotate(centerToEdgeDistance, true);
      Motor.C.rotate(centerToEdgeDistance, true);
    } while ((lightLevelReading > BLACK_WHITE_THRESHOLD)
        && (Motor.A.isMoving() && Motor.C.isMoving()));

    pilot.stop();

    lightLevelReading = lightSensorDown.readValue();

    /*
    distanceToObject = ultrasonicSensor.getDistance();

    if(distanceToObject < 20)
    {
    	edgeIsSafe = true;
    	Motor.A.setSpeed(1000);
    	Motor.C.setSpeed(1000);
    	pilot.setRotateSpeed(1000);
    	pilot.travel(280);
    	Delay.msDelay(10000);
    	return(edgeIsSafe);
    }

    if(lightLevelReading < BLACK_WHITE_THRESHOLD)
    {
    	System.out.println("Unsafe edge");
    	edgeIsSafe = false;
    	return(edgeIsSafe);
    }
    else if (lightLevelReading > BLACK_WHITE_THRESHOLD)
    {
    	System.out.println("Safe edge");
    	edgeIsSafe = true;
    	safeEdgeCount++;
    	return(edgeIsSafe);
    }

    */

    return (edgeIsSafe);
  }
예제 #3
0
 private void randomTurn() {
   int rnd = (int) Math.round(Math.random() * (double) 4);
   Motor.A.rotate(turnValue[rnd]);
 }