/* Dexter Travis Bradley University 2001/2002 Senior Project Botdock http://pioneer1.bradley.edu http://cegt201.bradley.edu/projects/proj2002/botdock/ */ import java.lang.*; import java.util.*; public class embeddedinterface { public static float x; public static float y; public static float heading; public static void startbot() { JSaphira.paiRobotStartup(1); JSaphira.paiSetMoveVelocity(50); new BatteryDetector();//begin battery detection thread. ServiceClient.sendtoall("Robot Started"); } public static void shutdownbot() { BatteryDetector.stop(); JSaphira.paiRobotShutdown(); ServiceClient.sendtoall("Robot Shutdown"); } public static void move(String command) { try { StringTokenizer input = new StringTokenizer(command," ",false); //delimit line with space do not return delimiters String element1 = input.nextToken(); String element2 = input.nextToken(); ServiceClient.sendtoall(element1); ServiceClient.sendtoall(element2); if(element1.equals("r"))//rotate { Float Fparam = new Float (element2); float floatparam = Fparam.floatValue(); JSaphira.paiRotateRobot(floatparam); } else if(element1.equals("m"))//move; { Float Fparam = new Float (element2); int intparam = Fparam.intValue(); JSaphira.paiMoveRobot(intparam); } else if(element1.equals("v"))//rotate; { Float Fparam = new Float(element2); int intparam = Fparam.intValue(); JSaphira.paiSetMoveVelocity(intparam); } else if(element1.equals("b")) { Float bvoltFloat = new Float(getbatvolts()); ServiceClient.sendtoall(bvoltFloat.toString()); } else if(element1.equals("s")) { Integer snumber = new Integer(element2); int sint = snumber.intValue(); float sonarfloat = getsonar(sint); ServiceClient.sendtoall("sonar # " +sint+ "has a value of " +sonarfloat); } else if(element1.equals("stop")) { JSaphira.paiStopRobot(); } else { log.log("-invalid command recieved: " +command); } } catch (Exception e) { log.log("E problem while sending command to robot"); } } public static float getbatvolts() { float batvolts = JSaphira.paiBatteryVoltage(); return(batvolts); } public static float getx() { return(JSaphira.paiRobotX()); } public static float gety() { return(JSaphira.paiRobotY()); } public static float gethead() { return(JSaphira.paiRobotHeading()); } public static int getsonar(int sonar) { return(JSaphira.paiSonarRange(sonar)); } //end of class botinterface }