public static void main(String... args) throws InterruptedException { init(); long lastVictimTime = 0; while (true) { RawColor color = colors.getSensorColor(robot.colorSensor); if ((color == colors.silver || color == colors.green) && System.currentTimeMillis() - lastVictimTime > 2500) { synchronized (robot.pilot) { robot.pilot.stop(); robot.showVictimFound(); lastVictimTime = System.currentTimeMillis(); robot.pilot.travel(5); findline(); } } else if (color == colors.white || color == colors.black) { synchronized (robot.pilot) { int[] sensors = robot.lineSensor.getSensors(); if (sensors != null) { int leftspeed = calcLeftSpeed(sensors); int rightspeed = calcRightSpeed(sensors); robot.pilot.setLeftSpeed(leftspeed); robot.pilot.setRightSpeed(rightspeed); } } } Thread.sleep(50); } }
public static boolean linefound() { if (colors.getSensorColor(robot.colorSensor) != colors.white) { return true; } else { /* * byte[] sensors = robot.lineSensor.getSensors(); * if(sensors != null) * { * return sensors[0] < 50 || sensors[3] < 50 || sensors[4] < 50 || sensors[7] < 50; * } * else */ return false; } }