// Method scans input and maps it; if obstacle is in front, left and right, // backpedal. If there is a space adjacent but an obstacle at the front, // turns to move around the obstacle using the available space. public static void movRow() { double nextCell = mapObj.basicProb(); // work out probability // output to RConsole through BlueTooth // btObj.stringToRCon("Object Probability in next Cell: %2f" + nextCell); // mapObj.printMap(columns, numOfRowCells); // sonar scan around of the robot boolean[] scanResults = new boolean[3]; scanResults = mapObj.scanAll(); mapObj.updateMap(scanResults); // btObj.stringToRCon("Scan Results: " + scanResults[0] + ", " + scanResults[1] + ", " + // scanResults[2]); // mapObj.printMap(columns, numOfRowCells); if (scanResults[1]) { // if there's an obstacle in front // if there's an obstacle to the left & right. i.e. a dead end if (scanResults[0] && scanResults[2]) { turnAround(scanResults[2], mapObj, movObj); // move backwards } else { // call movAround() method to navigate around the obstacle movAround(scanResults[1], mapObj, movObj); } } else { movObj.nextCell(mapObj); // move forward a cell } }
// 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 } }