// method runs when robot is in a dead end and has to back up and go around public static void turnAround(boolean r, MapSystem ms, Movement mv) { mv.turn(ms); // 180 degree turn movRow(); // move forward // check for empty adjacent space boolean[] scanResults = new boolean[3]; scanResults = mapObj.scanAll(); // Move to said empty space if (scanResults[0] && !scanResults[2]) { // Obstacle on the Left mv.turn(scanResults[0], ms); // turn right movRow(); } else { // Obstacle on the Right mv.turn(!scanResults[2], ms); // turn left movRow(); mv.turn(!scanResults[2], ms); movRow(); // move forward 2 cells, scanning as we go // if an obstacle is still on the same axis as the first // class it as a different obstacle // move forward a cell // scan again - recursive // move back to the correct column // if at a 'limit cell', turn left instead of right } }
// Method to move around an obstacle - runs when obstacle is in front public static void movAround(boolean r, MapSystem ms, Movement mv) { mv.turn(r, ms); // true = right turn; false = left turn movRow(); // scan and move forward if necessary mv.turn(!r, ms); // invert the boolean to turn the other way // move forward twice to pass the obstacle movRow(); ++loop2; movRow(); ++loop2; mv.turn(!r, ms); // turn to face original column boolean extend = mapObj.scanAhead(); // flag to check object is passed while (extend) { mv.turn(r, ms); // turn to move along the axis movObj.nextCell(mapObj); ++loop2; mv.turn(!r, ms); // face the original column if (!mapObj.scanAhead()) { // if an obstacle is not found anymore extend = false; // break the while loop } else { } } movRow(); // move into the original column mv.turn(r, ms); // face the correct way to continue the patrol }
// Method to shift columns (X Axis) public static void movCol(boolean b) { movObj.turn(b, mapObj); // rotate 90 degrees - true = right; false = left movRow(); // move forward a cell movObj.turn(b, mapObj); // rotate 90 degrees - true = right; false = left }