/** * 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); }