X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FBenchmarks%2FSSJava%2FJavaNator%2FRobotMain.java;h=6838ef52228c4c98e308320c73b85f7786feb616;hb=937867fd8d958d7ce7dadc3e4aab8ff03084eb51;hp=51d9dd45fe0b2a78cff6db70f20d429ba293e926;hpb=3b010fe8985ad3bbf5c2796620d5684013c770fb;p=IRC.git diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java b/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java index 51d9dd45..6838ef52 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java +++ b/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java @@ -32,14 +32,14 @@ public class RobotMain { @LOC("T") private static boolean DEBUG = true; - private static final int OFF_MODE = 1; - private static final int ON_MODE = 2; - private static final int MANUAL_MODE = 1; - private static final int AUTONOMUS_MODE = 2; - private static final int ON_OFF = 128;// 0x80 - private static final int MANUAL_AUTONOMUS = 32; // 0x20 + public static final int OFF_MODE = 1; + public static final int ON_MODE = 2; + public static final int MANUAL_MODE = 1; + public static final int AUTONOMUS_MODE = 2; + public static final int ON_OFF = 128;// 0x80 + public static final int MANUAL_AUTONOMUS = 32; // 0x20 public static final int LINE_SENSORS = 64; // 0x40 - private static final int SONAR_SENSORS = 96; // 0x60 + public static final int SONAR_SENSORS = 96; // 0x60 public static final int ALL_COMMANDS = 0xe0; public static final byte LF_FRONT = 0x1; @@ -56,31 +56,31 @@ public class RobotMain { public static final byte LS_LEFT_REAR = 0x5; public static final byte LS_RIGHT_REAR = 0x6; public static final byte LS_ALL = 0x7; - private static final int ALL_DATA = 0x1f; + public static final int ALL_DATA = 0x1f; @LOC("MGR") - private static PWMManager pwmm; + private PWMManager pwmm; @LOC("MGR") - private static StrategyMgr strategyMgr; + private StrategyMgr strategyMgr; @LOC("MASK") - private static int onOffMode = ON_MODE; + private int onOffMode = ON_MODE; @LOC("MASK") - private static int manualAutonomusMode = AUTONOMUS_MODE; + private int manualAutonomusMode = AUTONOMUS_MODE; @LOC("MASK") - private static byte lineSensorsMask; + private byte lineSensorsMask; @LOC("MASK") - private static byte sonarSensors; + private byte sonarSensors; @LOC("CCMD") - private static byte currentCommand; + private byte currentCommand; @LOC("MASK") - private static byte privSonars; + private byte privSonars; @LOC("PREV") - private static byte privLineSensors; + private byte privLineSensors; @LOC("MASK") - private static byte currentSonars; + private byte currentSonars; @LOC("MASK") - public static String pwmSelection; + public String pwmSelection; /** * Constructor for the class for the robot main thread. @@ -89,20 +89,18 @@ public class RobotMain { } /** - * Processes sonar sensor input. This method is called each time new sonar - * sensor data arrives, and each time that a mode switch occurs between ON/OFF - * and Manual Override. + * Processes sonar sensor input. This method is called each time new sonar sensor data arrives, + * and each time that a mode switch occurs between ON/OFF and Manual Override. */ - static void processSonars() { + void processSonars() { strategyMgr.processSonars(sonarSensors); } /** - * Processes line sensor input. This method is called each time new line - * sensor data arrives, and each time that a mode switch occurs between ON/OFF - * and Manual Override. + * Processes line sensor input. This method is called each time new line sensor data arrives, and + * each time that a mode switch occurs between ON/OFF and Manual Override. */ - static void processLineSensors() { + void processLineSensors() { strategyMgr.processLineSensors(lineSensorsMask); resume(); } @@ -110,16 +108,16 @@ public class RobotMain { /** * Resumes motors as per the last sonar command. */ - public static void resume() { + void resume() { processSonars(); } /** - * Extracts sonar sensor data from the adjunct sensor controller and from line - * sensor data from the JStamp line sensor pins. + * Extracts sonar sensor data from the adjunct sensor controller and from line sensor data from + * the JStamp line sensor pins. */ @LATTICE("THIS,THISLOC=THIS,GLOBALLOC=THIS") - private static void processIOCommand() { + private void processIOCommand() { // int data = 0; // int opCode = 0; @@ -170,8 +168,8 @@ public class RobotMain { lineSensorsMask = (byte) (data & LS_ALL); /* - * Line sensors with '0' data means the robot moved off the edge line, and - * there is nothing to do. + * Line sensors with '0' data means the robot moved off the edge line, and there is nothing to + * do. */ if (((data & LS_ALL) == 0) || ((data & LS_ALL) == privLineSensors)) { privLineSensors = (byte) (data & LS_ALL); @@ -190,8 +188,8 @@ public class RobotMain { } currentSonars = (byte) (data & ALL_SONARS); /* - * No need to synchronized on this variable assignment since all referring - * code is on the same logical thread + * No need to synchronized on this variable assignment since all referring code is on the same + * logical thread */ sonarSensors = (byte) currentSonars; if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) { @@ -222,7 +220,7 @@ public class RobotMain { /** * Saves the current IOManager command byte locally. */ - static public void setIOManagerCommand(byte[] cmd) { + public void setIOManagerCommand(byte[] cmd) { // synchronized (obj1) { currentCommand = cmd[0]; // } @@ -236,8 +234,7 @@ public class RobotMain { } /** - * Sets debug messaging state: true - Activate debug messages false - - * deactivate debug messages + * Sets debug messaging state: true - Activate debug messages false - deactivate debug messages */ static public void setDebug(boolean debug) { DEBUG = debug; @@ -246,19 +243,21 @@ public class RobotMain { /** * Runs the robot's main thread. */ - @LATTICE("THIS 100000) { - break; - } + @LOC("IN") Command com = HWSimulator.getCommand(); + currentCommand = com.command; + sonarSensors = com.sonarSensors; + lineSensorsMask = com.lineSensorsMask; + manualAutonomusMode = com.manualAutonomusMode; + onOffMode = com.onOffMode; - // if (DEBUG) { - // System.out.println("Main: Waiting for remote commands"); - // } - // try { - // obj.wait(); - // } catch (IllegalMonitorStateException ie) { - // System.out.println("IllegalMonitorStateException caught in main loop"); - // } - currentCommand = TestSensorInput.getCommand(); if (currentCommand == -1) { break; } System.out.println("currentCommand=" + currentCommand); processIOCommand(); - count++; + // erase current settings + initialize(); } - System.exit(0); + } + + public void initialize() { + privLineSensors = 0; + currentCommand = 0; + privSonars = 0; + currentSonars = 0; + pwmSelection = ""; } }