@LOC("T")\r
private static boolean DEBUG = true;\r
\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
- private static final int AUTONOMUS_MODE = 2;\r
- private static final int ON_OFF = 128;// 0x80\r
- private static final int MANUAL_AUTONOMUS = 32; // 0x20\r
+ public static final int OFF_MODE = 1;\r
+ public static final int ON_MODE = 2;\r
+ public static final int MANUAL_MODE = 1;\r
+ public static final int AUTONOMUS_MODE = 2;\r
+ public static final int ON_OFF = 128;// 0x80\r
+ public static final int MANUAL_AUTONOMUS = 32; // 0x20\r
public static final int LINE_SENSORS = 64; // 0x40\r
- private static final int SONAR_SENSORS = 96; // 0x60\r
+ public static final int SONAR_SENSORS = 96; // 0x60\r
public static final int ALL_COMMANDS = 0xe0;\r
\r
public static final byte LF_FRONT = 0x1;\r
public static final byte LS_LEFT_REAR = 0x5;\r
public static final byte LS_RIGHT_REAR = 0x6;\r
public static final byte LS_ALL = 0x7;\r
- private static final int ALL_DATA = 0x1f;\r
+ public static final int ALL_DATA = 0x1f;\r
\r
@LOC("MGR")\r
- private static PWMManager pwmm;\r
+ private PWMManager pwmm;\r
@LOC("MGR")\r
- private static StrategyMgr strategyMgr;\r
+ private StrategyMgr strategyMgr;\r
\r
@LOC("MASK")\r
- private static int onOffMode = ON_MODE;\r
+ private int onOffMode = ON_MODE;\r
@LOC("MASK")\r
- private static int manualAutonomusMode = AUTONOMUS_MODE;\r
+ private int manualAutonomusMode = AUTONOMUS_MODE;\r
@LOC("MASK")\r
- private static byte lineSensorsMask;\r
+ private byte lineSensorsMask;\r
@LOC("MASK")\r
- private static byte sonarSensors;\r
+ private byte sonarSensors;\r
@LOC("CCMD")\r
- private static byte currentCommand;\r
+ private byte currentCommand;\r
@LOC("MASK")\r
- private static byte privSonars;\r
+ private byte privSonars;\r
@LOC("PREV")\r
- private static byte privLineSensors;\r
+ private byte privLineSensors;\r
@LOC("MASK")\r
- private static byte currentSonars;\r
+ private byte currentSonars;\r
@LOC("MASK")\r
- public static String pwmSelection;\r
+ public String pwmSelection;\r
\r
/**\r
* Constructor for the class for the robot main thread.\r
}\r
\r
/**\r
- * Processes sonar sensor input. This method is called each time new sonar\r
- * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
- * and Manual Override.\r
+ * Processes sonar sensor input. This method is called each time new sonar sensor data arrives,\r
+ * and each time that a mode switch occurs between ON/OFF and Manual Override.\r
*/\r
- static void processSonars() {\r
+ void processSonars() {\r
strategyMgr.processSonars(sonarSensors);\r
}\r
\r
/**\r
- * Processes line sensor input. This method is called each time new line\r
- * sensor data arrives, and each time that a mode switch occurs between ON/OFF\r
- * and Manual Override.\r
+ * Processes line sensor input. This method is called each time new line sensor data arrives, and\r
+ * each time that a mode switch occurs between ON/OFF and Manual Override.\r
*/\r
- static void processLineSensors() {\r
+ void processLineSensors() {\r
strategyMgr.processLineSensors(lineSensorsMask);\r
resume();\r
}\r
/**\r
* Resumes motors as per the last sonar command.\r
*/\r
- public static void resume() {\r
+ void resume() {\r
processSonars();\r
}\r
\r
/**\r
- * Extracts sonar sensor data from the adjunct sensor controller and from line\r
- * sensor data from the JStamp line sensor pins.\r
+ * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from\r
+ * the JStamp line sensor pins.\r
*/\r
@LATTICE("THIS,THISLOC=THIS,GLOBALLOC=THIS")\r
- private static void processIOCommand() {\r
+ private void processIOCommand() {\r
\r
// int data = 0;\r
// int opCode = 0;\r
lineSensorsMask = (byte) (data & LS_ALL);\r
\r
/*\r
- * Line sensors with '0' data means the robot moved off the edge line, and\r
- * there is nothing to do.\r
+ * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to\r
+ * do.\r
*/\r
if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) {\r
privLineSensors = (byte) (data & LS_ALL);\r
}\r
currentSonars = (byte) (data & ALL_SONARS);\r
/*\r
- * No need to synchronized on this variable assignment since all referring\r
- * code is on the same logical thread\r
+ * No need to synchronized on this variable assignment since all referring code is on the same\r
+ * logical thread\r
*/\r
sonarSensors = (byte) currentSonars;\r
if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) {\r
}\r
break;\r
default:\r
+ strategyMgr.stop();\r
System.out.println("processIOCommand: Default: opCode = " + Integer.toString((int) opCode)\r
+ " data = " + Integer.toString((int) data));\r
}\r
/**\r
* Saves the current IOManager command byte locally.\r
*/\r
- static public void setIOManagerCommand(byte[] cmd) {\r
+ public void setIOManagerCommand(byte[] cmd) {\r
// synchronized (obj1) {\r
currentCommand = cmd[0];\r
// }\r
}\r
\r
/**\r
- * Sets debug messaging state: true - Activate debug messages false -\r
- * deactivate debug messages\r
+ * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages\r
*/\r
static public void setDebug(boolean debug) {\r
DEBUG = debug;\r
/**\r
* Runs the robot's main thread.\r
*/\r
- @LATTICE("THIS<C,THIS<MC,MC<IN,C<IN,IN<T,C*,THISLOC=THIS,GLOBALLOC=THIS")\r
public static void main(@LOC("IN") String args[]) {\r
\r
TestSensorInput.init();\r
+ RobotMain r = new RobotMain();\r
+ r.doit();\r
+ }\r
+\r
+ @LATTICE("THIS<C,THIS<MC,MC<IN,C<IN,IN<T,C*,THISLOC=THIS,GLOBALLOC=THIS")\r
+ public void doit() {\r
@LOC("T") boolean active = true;\r
/**\r
- * RealTime management of the robot behaviour based on sensors and commands\r
- * input.\r
+ * RealTime management of the robot behaviour based on sensors and commands input.\r
*/\r
\r
/**\r
- * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile\r
- * library-based).\r
+ * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based).\r
*/\r
pwmSelection = "rtsj";\r
\r
strategyMgr = new StrategyMgr(mc);\r
\r
/*\r
- * Sets initial values for the speed and agility parameters. Speed and\r
- * agility are arbitrary scale factors for the overall speed and speed of\r
- * turns, respectively. These work with PWM via the native ajile libraries,\r
- * but do not work well with the RTSJ implementation due to limits on the\r
- * granularity of timing for the PWM pulse (quantization).\r
+ * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary\r
+ * scale factors for the overall speed and speed of turns, respectively. These work with PWM via\r
+ * the native ajile libraries, but do not work well with the RTSJ implementation due to limits\r
+ * on the granularity of timing for the PWM pulse (quantization).\r
*/\r
pwmm.setSpeedAgilityFactors(100, 100);\r
\r
/*\r
- * Robot's initial state is "ON" by default. Set this parameter to "OFF" if\r
- * the robot is to be started over the TCP/IP link.\r
+ * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be\r
+ * started over the TCP/IP link.\r
*/\r
// issueCommand("OFF");\r
\r
- @LOC("C") int count = 0;\r
SSJAVA: while (active) {\r
\r
- if (count > 100000) {\r
- break;\r
- }\r
+ @LOC("IN") Command com = HWSimulator.getCommand();\r
+ currentCommand = com.command;\r
+ sonarSensors = com.sonarSensors;\r
+ lineSensorsMask = com.lineSensorsMask;\r
+ manualAutonomusMode = com.manualAutonomusMode;\r
+ onOffMode = com.onOffMode;\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
- count++;\r
+ // erase current settings\r
+ initialize();\r
}\r
System.exit(0);\r
}\r
\r
+ public void initialize() {\r
+ privLineSensors = 0;\r
+ currentCommand = 0;\r
+ privSonars = 0;\r
+ currentSonars = 0;\r
+ pwmSelection = "";\r
+ }\r
+\r
}\r