public class RobotMain {\r
\r
private static boolean DEBUG1 = true;\r
- private static boolean DEBUG = false;\r
+ private static boolean DEBUG = true;\r
private static final int OFF_MODE = 1;\r
private static final int ON_MODE = 2;\r
private static final int MANUAL_MODE = 1;\r
// }\r
\r
if (DEBUG) {\r
- // System.out.println("processIOCommand: Getting in opCode = "\r
- // + Integer.toHexString((int) opCode) + " data = " +\r
- // Integer.toHexString((int) data));\r
+ System.out.println("processIOCommand: Default: opCode = " + Integer.toString((int) opCode)\r
+ + " data = " + Integer.toString((int) data));\r
}\r
switch ((int) opCode) {\r
case ON_OFF:\r
*/\r
public static void main(String args[]) {\r
\r
+ TestSensorInput.init();\r
boolean active = true;\r
/**\r
* RealTime management of the robot behaviour based on sensors and commands\r
\r
int count = 0;\r
\r
- while (active && count < 10000) {\r
+ while (active && count < 100000) {\r
try {\r
- if (DEBUG) {\r
- System.out.println("Main: Waiting for remote commands");\r
- }\r
+ // if (DEBUG) {\r
+ // System.out.println("Main: Waiting for remote commands");\r
+ // }\r
// try {\r
// obj.wait();\r
// } catch (IllegalMonitorStateException ie) {\r
// System.out.println("IllegalMonitorStateException caught in main loop");\r
// }\r
currentCommand = TestSensorInput.getCommand();\r
+ if (currentCommand == -1) {\r
+ break;\r
+ }\r
+ System.out.println("currentCommand="+currentCommand);\r
processIOCommand();\r
// Nothing to do\r
} catch (Exception e) {\r
// private boolean DEBUGL = false;\r
\r
// private boolean DEBUG = true;\r
- private boolean DEBUG = false;\r
+ private boolean DEBUG = true;\r
\r
/**\r
* Constructor - Invoke communication to remote application thread\r
this.pwmControl = pwmManager.getPWMControl();\r
rand = new Random();\r
}\r
- \r
- \r
\r
void processSonars(byte sonarSensors) {\r
\r
} catch (InterruptedException ie) {\r
}\r
}\r
-\r
- // TODO\r
- // lineSensorsMask = sm.getLineSensorsState();\r
-\r
+ lineSensorsMask = TestSensorInput.getCommand();\r
}// while loop\r
}\r
\r
public class TestSensorInput {
- FileInputStream inputFile;
+ private static FileInputStream inputFile;
- public void init() {
+ public static void init() {
inputFile = new FileInputStream("input.dat");
}
public static byte getCommand() {
- // return Byte.parseInt(inputFile.readLine());
- return 0;
+ String in = inputFile.readLine();
+ if (in == null) {
+ return (byte) -1;
+ }
+ return (byte) Integer.parseInt(in);
}
}