/** The main method of the application */ public static void main(String[] args) { Calibration calib = new Calibration(); Definitions defs = Definitions .getInstance(); // Definitions.initInstance(Definitions.MASTER);//TODO change here Definitions.pilot.setSpeed(300); ; AI ai = null; try { ai = new AI(); } catch (Exception e) { Console.println("-------------------"); Console.println("ERROR in Ai"); Console.println(e.getMessage()); Console.println("-------------------"); Button.waitForPress(); return; } Console.println("start ai"); ai.start(); }
/** Runs the ai... */ public void run() { Communicator comm = null; try { comm = Communicator.getInstance(this); } catch (Exception e) { Console.println("-------------------"); Console.println("ERROR in Comm"); Console.println("-------------------"); Button.waitForPress(); return; } while (grid.isWorkToDo()) { PathElement p = null; if (motion.isObjLoaded()) { p = grid.getAWayBackHome(robo); } else if ((p = grid.getAWayToNextKnownUnCommon(robo)) == null) { if ((p = grid.getAWayToNextUnknown(robo)) == null) { /* does not work.. if ((p = grid.getAWayToNextKnownCommon(robo)) == null) { try { sleep(500); } catch (InterruptedException e) { // can't sleep, so do a busy waiting } continue; // try again }*/ } } Console.println("here3"); // TODO do { orient(p); // ask other if (!askOther(p)) continue; // try later again // if its not for me, i won't go there. (see grid.getway...) if (grid.getJunction(p).getType() == Junction.MASTER_OBJ || grid.getJunction(p).getType() == Junction.SLAVE_OBJ) { // load motion.goToNextJunction(true); grid.setJunction(new Junction(robo.getMyActualPosition(), Junction.EMPTY), true); } else { // unloading loaded object if (motion.isObjLoaded() && grid.getJunction(grid.getNextProjectedPosition(robo)).getType() == Junction.HOME_BASE) { motion.goToNextJunction(false); // orient to south Position orientation = grid.getNextProjectedPosition(robo); Position unloadPos = new Position(robo.getHomeBase().getX(), robo.getHomeBase().getY() - 1); // unload the object orient(unloadPos); motion.unload(); // orient back orient(orientation); // regular move } else motion.goToNextJunction(false); } } while ((p = p.getNextElt()) != null); } Console.println(" - FIN - "); Sound.playTone(400, 1000); Button.waitForPress(); }