X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FBenchmarks%2FSSJava%2FJavaNatorInfer%2FRobotMain.java;h=f7e780ee349f272988df9cb1ee436969ceb770c9;hb=8642620b2e4b2c1c0e71d5612007a935abc42eb6;hp=a3d582a839b7861e1a61babb15312586959c9c8e;hpb=d45bb251bdc1196d7848094fa2ccd566b39e021c;p=IRC.git diff --git a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java index a3d582a8..f7e780ee 100644 --- a/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java +++ b/Robust/src/Benchmarks/SSJava/JavaNatorInfer/RobotMain.java @@ -32,14 +32,14 @@ public class RobotMain { 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; - private static PWMManager pwmm; + private PWMManager pwmm; - private static StrategyMgr strategyMgr; + private StrategyMgr strategyMgr; - private static int onOffMode = ON_MODE; + private int onOffMode = ON_MODE; - private static int manualAutonomusMode = AUTONOMUS_MODE; + private int manualAutonomusMode = AUTONOMUS_MODE; - private static byte lineSensorsMask; + private byte lineSensorsMask; - private static byte sonarSensors; + private byte sonarSensors; - private static byte currentCommand; + private byte currentCommand; - private static byte privSonars; + private byte privSonars; - private static byte privLineSensors; + private byte privLineSensors; - private static byte currentSonars; + private byte currentSonars; - 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. */ - 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,22 @@ public class RobotMain { /** * Runs the robot's main thread. */ - public static void main( String args[]) { TestSensorInput.init(); + RobotMain r = new RobotMain(); + r.doit(); + } + + + public void doit() { boolean active = true; /** - * RealTime management of the robot behaviour based on sensors and commands - * input. + * RealTime management of the robot behaviour based on sensors and commands input. */ /** - * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile - * library-based). + * Set the low level PWM interface type, e.g. "rtsj" or "native" (ajile library-based). */ pwmSelection = "rtsj"; @@ -273,38 +273,45 @@ public class RobotMain { strategyMgr = new StrategyMgr(mc); /* - * Sets initial values for the speed and agility parameters. Speed and - * agility are arbitrary scale factors for the overall speed and speed of - * turns, respectively. These work with PWM via the native ajile libraries, - * but do not work well with the RTSJ implementation due to limits on the - * granularity of timing for the PWM pulse (quantization). + * Sets initial values for the speed and agility parameters. Speed and agility are arbitrary + * scale factors for the overall speed and speed of turns, respectively. These work with PWM via + * the native ajile libraries, but do not work well with the RTSJ implementation due to limits + * on the granularity of timing for the PWM pulse (quantization). */ pwmm.setSpeedAgilityFactors(100, 100); /* - * Robot's initial state is "ON" by default. Set this parameter to "OFF" if - * the robot is to be started over the TCP/IP link. + * Robot's initial state is "ON" by default. Set this parameter to "OFF" if the robot is to be + * started over the TCP/IP link. */ // issueCommand("OFF"); SSJAVA: while (active) { - // 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(); + Command com = HWSimulator.getCommand(); + currentCommand = com.command; + sonarSensors = com.sonarSensors; + lineSensorsMask = com.lineSensorsMask; + manualAutonomusMode = com.manualAutonomusMode; + onOffMode = com.onOffMode; + if (currentCommand == -1) { break; } System.out.println("currentCommand=" + currentCommand); processIOCommand(); + // erase current settings + initialize(); } System.exit(0); } + public void initialize() { + privLineSensors = 0; + currentCommand = 0; + privSonars = 0; + currentSonars = 0; + pwmSelection = ""; + } + }