* @author Michael Gesundheit\r
* @version 1.0\r
*/\r
+@LATTICE("MGR<MASK,PREV<CMD,MASK<CMD,CMD<CCMD,CCMD<T,PREV*,MASK*")\r
+@METHODDEFAULT("THIS,THISLOC=THIS,GLOBALLOC=THIS")\r
public class RobotMain {\r
\r
+ @LOC("T")\r
private static boolean DEBUG1 = true;\r
+ @LOC("T")\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
- 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
+\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 byte LF_FRONT = 0x1;\r
- public static byte RT_FRONT = 0x2;\r
- public static byte RT_SIDE = 0x4;\r
- public static byte BK_SIDE = 0x8;\r
- public static byte LF_SIDE = 0x10;\r
- public static byte ALL_SONARS = 0x1f;\r
- public static byte LF_RT_FRONT = 0x3; // LF_FRONT | RT_FRONT;\r
- public static byte LS_LEFT = 0x1;\r
- public static byte LS_RIGHT = 0x2;\r
- public static byte LS_REAR = 0x4;\r
- public static byte LS_LEFT_RIGHT = 0x3;\r
- public static byte LS_LEFT_REAR = 0x5;\r
- public static byte LS_RIGHT_REAR = 0x6;\r
- public static byte LS_ALL = 0x7;\r
- private static int ALL_DATA = 0x1f;\r
-\r
- private static PWMManager pwmm;\r
- private static StrategyMgr strategyMgr;\r
-\r
- private static int onOffMode = ON_MODE;\r
- private static int manualAutonomusMode = AUTONOMUS_MODE;\r
- private static byte lineSensorsMask;\r
- private static byte sonarSensors;\r
- private static byte[] command;\r
- private static byte currentCommand;\r
- private static Object obj;\r
- private static Object obj1;\r
- private static byte privSonars;\r
- private static byte privLineSensors;\r
- private static byte currentSonars;\r
- private static byte currentLineSensors;\r
- public static String pwmSelection;\r
+ public static final byte LF_FRONT = 0x1;\r
+ public static final byte RT_FRONT = 0x2;\r
+ public static final byte RT_SIDE = 0x4;\r
+ public static final byte BK_SIDE = 0x8;\r
+ public static final byte LF_SIDE = 0x10;\r
+ public static final byte ALL_SONARS = 0x1f;\r
+ public static final byte LF_RT_FRONT = 0x3; // LF_FRONT | RT_FRONT;\r
+ public static final byte LS_LEFT = 0x1;\r
+ public static final byte LS_RIGHT = 0x2;\r
+ public static final byte LS_REAR = 0x4;\r
+ public static final byte LS_LEFT_RIGHT = 0x3;\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
+ public static final int ALL_DATA = 0x1f;\r
+\r
+ @LOC("MGR")\r
+ private PWMManager pwmm;\r
+ @LOC("MGR")\r
+ private StrategyMgr strategyMgr;\r
+\r
+ @LOC("MASK")\r
+ private int onOffMode = ON_MODE;\r
+ @LOC("MASK")\r
+ private int manualAutonomusMode = AUTONOMUS_MODE;\r
+ @LOC("MASK")\r
+ private byte lineSensorsMask;\r
+ @LOC("MASK")\r
+ private byte sonarSensors;\r
+ @LOC("CCMD")\r
+ private byte currentCommand;\r
+ @LOC("MASK")\r
+ private byte privSonars;\r
+ @LOC("PREV")\r
+ private byte privLineSensors;\r
+ @LOC("MASK")\r
+ private byte currentSonars;\r
+ @LOC("MASK")\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
- private static void processIOCommand() {\r
+ @LATTICE("THIS,THISLOC=THIS,GLOBALLOC=THIS")\r
+ private void processIOCommand() {\r
\r
- int data = 0;\r
- int opCode = 0;\r
+ // int data = 0;\r
+ // int opCode = 0;\r
// synchronized (obj1) {\r
- data = (int) (currentCommand & ALL_DATA);\r
- opCode = (int) (currentCommand & 0xe0); // ALL_COMMANDS);\r
+ @LOC("THIS,RobotMain.CMD") int data = (int) (currentCommand & ALL_DATA);\r
+ @LOC("THIS,RobotMain.CMD") int opCode = (int) (currentCommand & 0xe0); // ALL_COMMANDS);\r
// }\r
\r
if (DEBUG) {\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
- public static void main(String args[]) {\r
+ public static void main(@LOC("IN") String args[]) {\r
\r
TestSensorInput.init();\r
- boolean active = true;\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
/**\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
// Pass in the PWMManager for callbacks.\r
// sm = new IOManager(pwmm);\r
// ram = new RemoteApplicationManager(pwmm);\r
- strategyMgr = new StrategyMgr(pwmm);\r
+ @LOC("MC") MotorControl mc = new MotorControl(100, 100);\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
- int count = 0;\r
-\r
- while (active && count < 100000) {\r
- try {\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
+ start();\r
+\r
+ System.exit(0);\r
+ }\r
+\r
+ @LATTICE("THIS<IN,IN<T,THISLOC=THIS,GLOBALLOC=THIS")\r
+ public void start() {\r
+ @LOC("T") boolean active = true;\r
+\r
+ SSJAVA: while (active) {\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 (currentCommand == -1) {\r
+ break;\r
}\r
- count++;\r
+ System.out.println("currentCommand=" + currentCommand);\r
+ processIOCommand();\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