From: yeom Date: Fri, 30 Sep 2011 23:13:25 +0000 (+0000) Subject: start new benchmark JavaNator. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=32cf2d8dd391fb74ec587e50bf6298200252c88b;p=IRC.git start new benchmark JavaNator. --- diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/MotorController.java b/Robust/src/Benchmarks/SSJava/JavaNator/MotorController.java new file mode 100644 index 00000000..31603843 --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/MotorController.java @@ -0,0 +1,4 @@ + +public class MotorController { + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/PWMControl.java b/Robust/src/Benchmarks/SSJava/JavaNator/PWMControl.java new file mode 100644 index 00000000..05a1c56a --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/PWMControl.java @@ -0,0 +1,192 @@ +/* + * PWMControl.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +/** + * This class is the super class of all motor control classes. The class + * represent a generic interface to such class. In our case the motor controller + * require for 0 speed 1.5 ms out of 10-20ms cycle and a change between 1 to 2 + * seconds for max reverse and forward speed. These values: 1, 1.5, 2 and 20 ms + * are thus this class specific + * + * @author Michael Gesundheit + * @version 1.0 + */ + +public abstract class PWMControl { + + PWMManager pwmManager; + boolean DEBUG = false; + // boolean DEBUG = true; + static final byte PULSE_HIGH = 1; + static final byte PULSE_LOW = 0; + int highMask; + int m1HighMask; + int m2HighMask; + int lowMask; + int myOwnBit; + int myBitPos; + int m1BitPos; + int m2BitPos; + int speedFactor; + int agilityFactor; + boolean updateTime; + int pulseWidth; + Object obj; + + int motorLeftUpTime = 150; + int motorRightUpTime = 150; + boolean manualMode = false; + + PWMControl(PWMManager pwmMan, int motor1bit, int motor2bit) { + pwmManager = pwmMan; // This is papa + m1BitPos = 0x1 << motor1bit; + m2BitPos = 0x1 << motor2bit; + m1HighMask = 0x1 << motor1bit; + m2HighMask = 0x1 << motor2bit; + lowMask = 0x0; + obj = new Object(); + } + + public void setManualMode() { + if (DEBUG) + System.out.println("PWMContolr: setManualMode... "); +// synchronized (obj) { + if (manualMode == false) { + manualMode = true; + } +// } + } + + public void setAutomatedMode() { + if (DEBUG) + System.out.println("PWMControl: setAutomatedMode... "); +// synchronized (obj) { + if (manualMode == true) { + System.out.println("PWMControl: wake me up... "); + manualMode = false; + // obj.notify(); + System.out.println("PWMControl: wake me up...... tried!!!"); + } +// } + } + + /** + * OutPut value to motor control line + */ + public void outToPortMLeft(byte value) { + /* + * System.out.println("PWMControl " + Integer.toString(myOwnBit) + + * //" bit position = 0x" + Integer.toHexString(myOwnBit) + + * " output value = 0x" + Integer.toHexString(value)); + */ + if (value == PULSE_HIGH) { + pwmManager.writeToPort(m1BitPos, m1HighMask); + } else { + pwmManager.writeToPort(m1BitPos, lowMask); + } + } + + public void outToPortMRight(byte value) { + /* + * System.out.println("PWMControl " + Integer.toString(myOwnBit) + + * //" bit position = 0x" + Integer.toHexString(myOwnBit) + + * " output value = 0x" + Integer.toHexString(value)); + */ + if (value == PULSE_HIGH) { + pwmManager.writeToPort(m2BitPos, m2HighMask); + } else { + pwmManager.writeToPort(m2BitPos, lowMask); + } + } + + /** + * setSpeedSpin - Set speed for the spin case motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedSpinLeft(int timePosition) { + } + + /** + * setSpeedSpinRight - Set speed for the spin case right motor. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedSpinRight(int timePosition) { + } + + /** + * setSpeedTurnM1 - set speed considering agility factor for motor 1 + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedTurnLeft(int timePosition) { + } + + /** + * setSpeedTurnM1 - set speed considering agility factor for motor 2 + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedTurnRight(int timePosition) { + } + + /** + * setSpeedLeft - speed control for motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedLeft(int timePosition) { + } + + /** + * setSpeedRight - speed control for motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedRight(int timePosition) { + } + + public void setSpeedAgilityFactors(int speed, int agility) { +// synchronized (this) { + speedFactor = speed; + agilityFactor = agility; +// } + } + + public void setUrgentReverse() { + } + + public void setUrgentStraight() { + } + + /** + * Control debug messageing. true - Activate debug messages false - deactivate + * debug messages + */ + public void setDebug(boolean debug) { + DEBUG = debug; + } +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java b/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java new file mode 100644 index 00000000..95dcad5a --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/PWMManager.java @@ -0,0 +1,211 @@ +/* + * PWMManager.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +/** + * PWMManager - Interface between robot strategy code and the various motors + * PWMControl classes. Agility is a number between 0 to 100 and represent the + * precentage of max speed to be applied to the turn side wheel. On left turn + * the left wheel will receive less speed as % of "speed" value represented by + * agility. + * + * @author Michael Gesundheit + * @version 1.0 + */ + +public class PWMManager { + + private int GPIO_A_OER = 0x09002000; + private int GPIO_A_OUT = GPIO_A_OER + 4; + private int GPIO_E_OER = 0x09002400; + private int GPIO_E_OUT = 0x09002404; + private byte MOTOR_PORTID_6 = 6; // Bit 2 (...3,2,1,0) + private byte MOTOR_PORTID_7 = 7; // Bit 3 (...3,2,1,0) + private int currentRegMask; + private boolean DEBUG = false; + private int currentSpeedL; + private int currentSpeedR; + private int currentSpeed; + private PWMControl pwmControl; + private PWMNative pwmNative; + private PWMRtsj pwmRtsj; + private RCBridge rcb; + private int speedFactor; + private int agilityFactor; + private int zeroSpeed = 45; + + /** + * Constractor + */ + public PWMManager(String pwmSelection) { + /* + * Instantiate PWM Makers one for each motor. motorPortId is 1 to 8 and is + * corresponding to 8 bits in a byte. + */ + if (pwmSelection.equals("rtsj")) + pwmControl = new PWMRtsj(this, MOTOR_PORTID_6, MOTOR_PORTID_7); + else { + System.out.println("Selection PWMNative is activated"); + pwmControl = new PWMNative(this, MOTOR_PORTID_6, MOTOR_PORTID_7); + System.out.println("Selection PWMNative is activated.... Return"); + } + + // rcb = new RCBridge(this); + rcb = new RCBridge(); + + /* Enable input bits 0,1 Enable output for the rest */ + // rawJEM.set(GPIO_E_OER, 0x00C0); + } + + public void setManualMode() { + if (DEBUG) + System.out.println("PWMManager: setManualMode...."); + pwmControl.setManualMode(); + rcb.setManualMode(); + } + + public void setAutomatedMode() { + if (DEBUG) + System.out.println("PWMManager: setAutomatedMode...."); + pwmControl.setAutomatedMode(); + rcb.setAutomatedMode(); + } + + public PWMControl getPWMControl() { + if (DEBUG) + System.out.println("PWMManager: getPWMControl...."); + return pwmControl; + } + + public synchronized void writeToPort(int myBit, int myValue) { + currentRegMask &= ~myBit; // e.g. 0x11110111 + currentRegMask |= myValue; + /* + * // if (DEBUG){ // System.out.println("PWMM: writeToPort: myBit = 0x" + + * Integer.toHexString(myBit) + // " ~myBit = 0x" + + * Integer.toHexString(~myBit) + " myValue = 0x" + // + * Integer.toHexString(myValue) + " currentRegMask = 0x" + // + * Integer.toHexString(currentRegMask)); //} + */ + // rawJEM.set(GPIO_E_OUT, currentRegMask); + } + + /* + * public void stop(){ if(DEBUG) System.out.println("PWMManager: stop...."); + * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedRight(zeroSpeed); } + * + * public void search(){ if(DEBUG) + * System.out.println("PWMManager: search...."); pwmControl.setSpeedLeft(70); + * pwmControl.setSpeedRight(50); } + * + * public void straight(){ if(DEBUG) + * System.out.println("PWMManager: strait...."); pwmControl.setSpeedLeft(100); + * pwmControl.setSpeedRight(100); } + * + * public void spinRight(){ if(DEBUG) + * System.out.println("PWMManager: spinRight...."); + * pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); } + * + * public void spinLeft(){ if(DEBUG) + * System.out.println("PWMManager: spinLeft...."); + * pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); } + * + * public void spin180(){ int mod = (rand.nextInt() % 2); + * + * if(DEBUG) System.out.println("PWMManager: spin180...."); if(mod == 1){ + * pwmControl.setSpeedSpinLeft(0); pwmControl.setSpeedSpinRight(100); }else{ + * pwmControl.setSpeedSpinLeft(100); pwmControl.setSpeedSpinRight(0); } } + * + * public void right(){ if(DEBUG) System.out.println("PWMManager: right...."); + * pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedRight(zeroSpeed); } + * + * public void left(){ if(DEBUG) System.out.println("PWMManager: left...."); + * pwmControl.setSpeedLeft(zeroSpeed); pwmControl.setSpeedTurnRight(100); } + * + * public void bearRight(){ if(DEBUG) + * System.out.println("PWMManager: bearRight...."); + * pwmControl.setSpeedTurnLeft(100); pwmControl.setSpeedTurnRight(60); } + * + * public void bearLeft(){ if(DEBUG) + * System.out.println("PWMManager: bearLeft...."); + * pwmControl.setSpeedTurnLeft(60); pwmControl.setSpeedTurnRight(100); } + * + * public void back(){ if(DEBUG) System.out.println("PWMManager: back...."); + * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(0); } + * + * public void backBearLeft(){ if(DEBUG) + * System.out.println("PWMManager: backBearLeft...."); + * pwmControl.setSpeedLeft(30); pwmControl.setSpeedRight(0); } + * + * public void backBearRight(){ if(DEBUG) + * System.out.println("PWMManager: backBearRight...."); + * pwmControl.setSpeedLeft(0); pwmControl.setSpeedRight(30); } + */ + public void resume() { + if (DEBUG) + System.out.println("PWMManager: Reasume..........."); + } + + /** + * setSpeedFactor - set speed factor value + * + * @param speed + * factor + */ + public synchronized void setSpeedFactor(int speedFactor) { + if (DEBUG) + System.out.println("PWMManager: setSpeedFactor...."); + this.speedFactor = speedFactor; + pwmControl.setSpeedAgilityFactors(speedFactor, agilityFactor); + } + + /** + * setAgilityFactor + * + * @param agility + * factor + */ + public synchronized void setAgilityFactor(int agilityFactor) { + if (DEBUG) + System.out.println("PWMManager: setAgilityFactor...."); + this.agilityFactor = agilityFactor; + pwmControl.setSpeedAgilityFactors(speedFactor, agilityFactor); + } + + /** + * setSpeedAgilityFactors - set both speed and agility + * + * @param speed + * @param agility + */ + public synchronized void setSpeedAgilityFactors(int speed, int agility) { + if (DEBUG) + System.out.println("PWMManager: setSpeedAgilityFactors...."); + speedFactor = speed; + agilityFactor = agility; + pwmControl.setSpeedAgilityFactors(speedFactor, agilityFactor); + } + + /** + * Control debug messaging. true - Activate debug messages false - deactivate + * debug messages + */ + public void setDebug(boolean debug) { + DEBUG = debug; + } +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/PWMNative.java b/Robust/src/Benchmarks/SSJava/JavaNator/PWMNative.java new file mode 100644 index 00000000..4bc2be52 --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/PWMNative.java @@ -0,0 +1,377 @@ +/* + * PWMNative.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +//public class PWMNative extends PWMControl implements Runnable, InterruptEventListener { +public class PWMNative extends PWMControl { + + private int PULSE_INTERVAL = 2000; + private int NATIVE_OFFSET = 100; + private Object obj; + private Object tc0Obj; + private Object tc1Obj; + private int pulseUpTime; + + // private TimerCounter tc0; + // private TimerCounter tc1; + // private TimerCounter[] tcSet = new TimerCounter[2]; + + PWMNative(PWMManager pwmMan, int motor1bit, int motor2bit) { + super(pwmMan, motor1bit, motor2bit); + + System.out.println("PWMNative constructor.....Start"); + obj = new Object(); + tc0Obj = new Object(); + tc1Obj = new Object(); + + // TimerCounter.setPrescalerClockSource(TimerCounter.INTERNAL_PERIPHERAL_CLOCK); + // TimerCounter.setPrescalerReloadRegisterValue(375); + // TimerCounter.setPrescalerEnabled(true); + + // tc0 = tcSet[0] = new TimerCounter(0); + // tc0.setMode_IO_Line_A(TimerCounter.TIMER_0_OUTPUT); + // // bring TIMER_0_OUTPUT_DIVIDE_BY_2 out via IO_Line_B + // tc0.setMode_IO_Line_B(TimerCounter.TIMER_0_OUTPUT_DIVIDE_BY_2); + // // In JemBuilder, go to Pin Setup 2 and allocate Port E bit 6 to + // // be Timer IO_Line_B. + // + // // Connect signal lead of servo (usually the white one) to IOE6 on + // // JStamp + // tc0.set_IO_Line_A_Polarity(TimerCounter.POLARITY_ACTIVE_STATE_HIGH); + // tc0.set_IO_Line_B_Polarity(TimerCounter.POLARITY_ACTIVE_STATE_HIGH); + // tc0.setExternalTimerEnableMode(TimerCounter.TIMER_ENABLED_ONLY_VIA_MTEN_AND_TRIGGER); + // tc0.setReloadRegisterValue(100); + // tc0.setExternalStartTriggerMode(TimerCounter.NO_EXTERNAL_START_TRIGGER); + // tc0.setMasterTimerEnabled(true); + // tc0.setGlobalInterruptEnabled(true); + // tc0.setTimeOutInterruptEnabled(true); + // tc0.setTimerTriggerRegister(false); + // System.out.println("PWMNative: Constructor completed 1...."); + /* + * tc1 = tcSet[1] = new TimerCounter ( 1 ); tc1.setMode_IO_Line_A( + * TimerCounter.TIMER_1_OUTPUT ); //bring TIMER_0_OUTPUT_DIVIDE_BY_2 out via + * IO_Line_B tc1.setMode_IO_Line_B( TimerCounter.TIMER_1_OUTPUT_DIVIDE_BY_2 + * ); //In JemBuilder, go to Pin Setup 2 and allocate Port E bit 6 to //be + * Timer IO_Line_B. + * tc1.set_IO_Line_A_Polarity(TimerCounter.POLARITY_ACTIVE_STATE_HIGH); + * tc1.set_IO_Line_B_Polarity(TimerCounter.POLARITY_ACTIVE_STATE_HIGH); + * tc1.setExternalTimerEnableMode + * (TimerCounter.TIMER_ENABLED_ONLY_VIA_MTEN_AND_TRIGGER ); + * tc1.setReloadRegisterValue( 100 ); + * tc1.setExternalStartTriggerMode(TimerCounter.NO_EXTERNAL_START_TRIGGER ); + * tc1.setMasterTimerEnabled( true ); tc1.setGlobalInterruptEnabled( true); + * tc1.setTimeOutInterruptEnabled( true); tc1.setTimerTriggerRegister( false + * ); + */ + /* + * // Add interrupt event listener for GPTC + * InterruptController.addInterruptListener( this, + * InterruptController.GPTC_INTERRUPT ); + * + * // Turn on interrupts InterruptController.enableInterrupt( + * InterruptController.GPTC_INTERRUPT ); + * + * // start all prescaler based timers TimerCounter.setPrescalerEnabled( + * true ); + */ + // t2 = new Thread(this); + // t2.start(); + // t2.setPriority(20); + System.out.println("PWMNative: Constructor return....."); + } + + public void setUpTime(int upTime) { + // synchronized (obj) { + pulseUpTime = upTime; + // } + } + + /* + * public void interruptEvent() { TimerCounter tc; int tcIntrState; + * + * System.out.println("PWMNative: InterruptEvent"); do { for ( int tcNum=0; + * tcNum<2; tcNum++ ) { tc = tcSet[ tcNum ]; + * if(tc.readAndClear_TimeOutInterruptStatus()){ switch(tcNum){ case 0: + * System.out.println("PWMNative: Interrupt case 0"); synchronized(tc0Obj){ + * System.out.println("PWMNative: Interrupt notify 0"); tc0Obj.notify(); } + * break; case 1: System.out.println("PWMNative: Interrupt case 1"); + * synchronized(tc1Obj){ System.out.println("PWMNative: Interrupt notify 1"); + * tc1Obj.notify(); } break; default:; } } } } while ( + * TimerCounter.isGPTCInterruptPending() ); } + */ + public void run() { + // + // System.out.println("PWMNative: run method........"); + // int upTime0 = 150; // 1.5 milli seconds = 0 speed + // int upTime1 = 150; // 1.5 milli seconds = 0 speed + // + // while (true) { + // synchronized (obj) { + // /* + // * System.out.println("PWMNative: Updating Up Times......Left = " + + // * Integer.toString(motorLeftUpTime) + " Right = " + + // * Integer.toString(motorRightUpTime)); + // */ + // upTime0 = motorLeftUpTime; + // upTime1 = motorRightUpTime; + // } + // + // // Timer number 1 + // tc0.setReloadRegisterValue(upTime0); + // outToPortMLeft(PULSE_HIGH); + // tc0.setTimerTriggerRegister(true); + // do { + // } while (tc0.didTimeOutInterruptOccur()); + // outToPortMLeft(PULSE_LOW); + // tc0.setTimerTriggerRegister(false); + // tc0.resetTimeOutInterruptStatus(); + // + // // System.out.println("PWMNative: Big loop long suspend1"); + // try { + // tc0Obj.wait(18, 500000); + // } catch (Exception e) { + // } + // // System.out.println("PWMNative: Big loop long suspend2"); + // + // tc0.setReloadRegisterValue(upTime1); + // outToPortMRight(PULSE_HIGH); + // tc0.setTimerTriggerRegister(true); + // do { + // } while (tc0.didTimeOutInterruptOccur()); + // outToPortMRight(PULSE_LOW); + // tc0.setTimerTriggerRegister(false); + // tc0.resetTimeOutInterruptStatus(); + // + // try { + // tc0Obj.wait(18, 500000); + // } catch (Exception e) { + // } + + /* + * // Timer number 2 tc1.setReloadRegisterValue( upTime1 ); + * tc1.setTimerTriggerRegister( true ); synchronized(tc1Obj){ try{ + * System.out.println("PWMNative: Sleep 3"); tc1Obj.wait(); + * System.out.println("PWMNative: Wake Up 3"); }catch(Exception e){ } } + * tc1.setTimerTriggerRegister( false ); tc1.resetTimeOutInterruptStatus(); + * tc1.setReloadRegisterValue( PULSE_INTERVAL - upTime1 ); //this sets pulse + * interval tc1.setTimerTriggerRegister( true ); synchronized(tc1Obj){ try{ + * System.out.println("PWMNative: Sleep 3"); tc1Obj.wait(); + * System.out.println("PWMNative: Wake Up 3"); }catch(Exception e){ } } + * tc1.setTimerTriggerRegister( false ); tc1.resetTimeOutInterruptStatus(); + */ + // } + } + + public void setManualMode() { + if (DEBUG) + System.out.println("PWMControl: setManualMode... "); + // synchronized (obj) { + if (manualMode == false) { + manualMode = true; + } + // } + } + + public void setAutomatedMode() { + if (DEBUG) + System.out.println("PWMControl: setAutomatedMode... "); + /* + * synchronized(obj){ if(manualMode == true){ + * System.out.println("PWMControl: wake me up... "); obj.notifyAll(); + * manualMode = false; } } + */ + } + + /** + * setSpeedSpin - Set speed for the spin case motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedSpinLeft(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* 100-input to get reverse polarity for this motor */ + /* since it's mounted in reverse direction to the other motor */ + + if (DEBUG) { + System.out.println("setSpeedSpinLeft: input-> " + Integer.toString(timePosition)); + } + int timePos = timePosition + NATIVE_OFFSET; + int motorUpTime = (int) (timePos * agilityFactor * speedFactor) / 10000; + + if (DEBUG) { + System.out.println("setSpeedSpinLeft: output-> = " + Integer.toString(motorUpTime)); + } + // synchronized (obj) { + /* Factor in the speed and agility factors */ + motorLeftUpTime = motorUpTime; + // } + } + + /** + * setSpeedSpinRight - Set speed for the spin case right motor. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedSpinRight(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* An input of 50 should result in 0 speed. */ + /* 100 should result in full speed forward */ + /* while 0 should result in full speed backwords */ + if (DEBUG) { + System.out.println("setSpeedSpinRight: input-> " + Integer.toString(timePosition)); + } + int timePos = timePosition + NATIVE_OFFSET; + int motorUpTime = (int) ((timePos) * agilityFactor * speedFactor) / 10000; + + if (DEBUG) { + System.out.println("setSpeedSpinRight: output-> = " + Integer.toString(motorUpTime)); + } + // synchronized (obj) { + /* Factor in the speed and agility factors */ + motorRightUpTime = motorUpTime; + // } + } + + /** + * setSpeedTurnM1 - set speed considering agility factor for motor 1 + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedTurnLeft(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* 100-input to get reverse polarity for this motor */ + /* since it's mounted in reverse direction to the other motor */ + if (DEBUG) { + System.out.println("setSpeedTurnLeft: input-> " + Integer.toString(timePosition)); + } + int timePosLocal = timePosition + NATIVE_OFFSET; + int motorUpTime = + ((timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor) / 10000; + if (DEBUG) { + System.out.println("setSpeedTurnLeft: output-> = " + Integer.toString(motorUpTime)); + } + // synchronized (obj) { + /* Factor in the speed and agility factors */ + motorLeftUpTime = motorUpTime; + // } + } + + /** + * setSpeedTurnM1 - set speed considering agility factor for motor 2 + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedTurnRight(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + if (DEBUG) { + System.out.println("setSpeedTurnRight: input-> " + Integer.toString(timePosition)); + } + int timePos = timePosition + NATIVE_OFFSET; + int motorUpTime = + (((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor) / 10000; + + if (DEBUG) { + System.out.println("setSpeedTurnRight: output-> " + Integer.toString(motorUpTime)); + } + // synchronized (obj) { + /* Factor in the speed and agility factors */ + motorRightUpTime = motorUpTime; + // } + } + + /** + * setSpeedLeft - speed control for motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedLeft(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* 100-input to get reverse polarity for this motor */ + /* since it's mounted in reverse direction to the other motor */ + if (DEBUG) { + System.out.println("setSpeedLeft: input-> " + Integer.toString(timePosition)); + } + int timePos = timePosition + NATIVE_OFFSET; + int motorUpTime = (int) ((timePos * 100) * speedFactor) / 10000; + + if (DEBUG) { + System.out.println("setSpeedLeft: output-> " + Integer.toString(motorUpTime)); + } + // synchronized (obj) { + /* Factor in speedFactor */ + motorLeftUpTime = motorUpTime; + // } + } + + /** + * setSpeedRight - speed control for motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedRight(int timePosition) { + if (DEBUG) { + System.out.println("setSpeedRight: input-> " + Integer.toString(timePosition)); + } + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + int timePos = timePosition + NATIVE_OFFSET; + int motorUpTime = (int) (((timePos * 100) * speedFactor) / 10000); + + if (DEBUG) { + System.out.println("setSpeedRight: output-> " + Integer.toString(motorUpTime)); + } + // synchronized (obj) { + /* Factor in speedFactor */ + motorRightUpTime = motorUpTime; + // } + } + + public void setSpeedAgilityFactors(int speed, int agility) { + // synchronized (obj) { + speedFactor = speed; + agilityFactor = agility; + // } + } + + public void setUrgentReverse() { + // synchronized (obj) { + motorLeftUpTime = 1; + motorRightUpTime = 1; + // } + } + + /** + * Control debug messageing. true - Activate debug messages false - deactivate + * debug messages + */ + public void setDebug(boolean debug) { + DEBUG = debug; + } + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/PWMRtsj.java b/Robust/src/Benchmarks/SSJava/JavaNator/PWMRtsj.java new file mode 100644 index 00000000..1bb41904 --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/PWMRtsj.java @@ -0,0 +1,322 @@ +/* + * PWMRtsj.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +/** + * This class is motor controller specific. In our case the motor controller + * require for 0 speed 1.5 ms out of 10-20ms cycle and a change between 1 to 2 + * seconds for max reverse and forward speed. These values: 1, 1.5, 2 and 20 ms + * are thus this class specific + * + * @author Michael Gesundheit + * @version 1.0 + */ + +public class PWMRtsj extends PWMControl { + + // RelativeTime zeroSpeedDuration; + // RelativeTime timeUpDuration; + // RelativeTime timeDownDuration; + // RelativeTime cycleTime; + boolean updateTime; + int sleepUpDurationNano = 500000; + long sleepUpDurationMilli = 1; + int sleepDownDurationNano = 500000; + long sleepDownDurationMilli = 18; + int pulseWidth; + // Object obj; + + private static final int GPIO_A_OER = 0x09002000; + private static final int GPIO_A_OUT = GPIO_A_OER + 4; + private static final int GPIO_A_IN = GPIO_A_OER + 8; + + /** + * Constructor - Start a standard Java thread. The thread is suspended and + * will wake up evey 18 ms. It will issue a 1-2ms pulse and suspends itself + * again to 18ms. This is to have a total of 20ms or less yet it's the maxim + * possible cycle so as to load the cpu as little as possible. + */ + public PWMRtsj(PWMManager pwmMan, int motor1bit, int motor2bit) { + + super(pwmMan, motor1bit, motor2bit); // This is papa + + motorLeftUpTime = 450000; // Nano seconds + motorRightUpTime = 450000; // Nano seconds + + if (DEBUG) { + System.out.println("PWMRtsj: About to start RoboThread..."); + } + + // t2 = new RoboThread(); + // t2.start(); + // t2.setPriority(10); + } + + // A poor's man ajustimg for the 0 speed which found + // to be 450000 nano seconds. + private int normalizeTime(int timePosition) { + if ((timePosition <= 50) && (timePosition >= 44)) { + return 45; + } + return timePosition; + } + + /** + * setSpeedSpin - Set speed for the spin case motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedSpinLeft(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* 100-input to get reverse polarity for this motor */ + /* since it's mounted in reverse direction to the other motor */ + if (DEBUG) { + System.out.println("setSpeedSpinLeft: input-> " + Integer.toString(timePosition)); + } + int timePos = normalizeTime(timePosition); + + int motorUpTime = (int) (timePos * agilityFactor * speedFactor); + // System.out.println("Left Motor UpTime1: " + + // Integer.toString(motorUpTime)); + // Since the right motor is hanging in reverse position + // the direction should be opposit + // Bug in wait. Can't take 0 nanoseconds + if (motorUpTime == 0) { + motorUpTime = 1; + // System.out.println("returning...."); + // return; // ndr + } else if (motorUpTime == 1000000) { + motorUpTime--; + } + + if (DEBUG) { + System.out.println("setSpeedSpinLeft: output-> = " + Integer.toString(motorUpTime)); + } +// synchronized (this) { + /* Factor in the speed and agility factors */ + motorLeftUpTime = motorUpTime; +// } + } + + /** + * setSpeedSpinRight - Set speed for the spin case right motor. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedSpinRight(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* An input of 50 should result in 0 speed. */ + /* 100 should result in full speed forward */ + /* while 0 should result in full speed backwords */ + if (DEBUG) { + System.out.println("setSpeedSpinRight: input-> " + Integer.toString(timePosition)); + } + int timePos = normalizeTime(timePosition); + + int motorUpTime = (int) ((timePos) * agilityFactor * speedFactor); + // Bug in wait. Cant take 0 nanoseconds + if (motorUpTime == 0) { + motorUpTime = 1; + // System.out.println("returning...."); + // return; // ndr + } else if (motorUpTime == 1000000) { + motorUpTime--; + } + + if (DEBUG) { + System.out.println("setSpeedSpinRight: output-> = " + Integer.toString(motorUpTime)); + } +// synchronized (this) { + /* Factor in the speed and agility factors */ + motorRightUpTime = motorUpTime; +// } + } + + /** + * setSpeedTurnM1 - set speed considering agility factor for motor 1 + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedTurnLeft(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* 100-input to get reverse polarity for this motor */ + /* since it's mounted in reverse direction to the other motor */ + if (DEBUG) { + System.out.println("setSpeedTurnLeft: input-> " + Integer.toString(timePosition)); + } + int timePosLocal = normalizeTime(timePosition); + int motorUpTime = + (timePosLocal * 100 + ((100 - timePosLocal) * (100 - agilityFactor))) * speedFactor; + if (motorUpTime == 0) { + motorUpTime = 1; + // System.out.println("returning...."); + // return; // ndr + } else if (motorUpTime == 1000000) { + motorUpTime--; + } + if (DEBUG) { + System.out.println("setSpeedTurnLeft: output-> = " + Integer.toString(motorUpTime)); + } +// synchronized (this) { + /* Factor in the speed and agility factors */ + motorLeftUpTime = motorUpTime; +// } + } + + /** + * setSpeedTurnM1 - set speed considering agility factor for motor 2 + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedTurnRight(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + if (DEBUG) { + System.out.println("setSpeedTurnRight: input-> " + Integer.toString(timePosition)); + } + int timePos = normalizeTime(timePosition); + int motorUpTime = ((timePos * 100) + ((100 - timePos) * (100 - agilityFactor))) * speedFactor; + if (motorUpTime == 0) { + motorUpTime = 1; + // System.out.println("returning...."); + // return; // ndr + } else if (motorUpTime == 1000000) { + motorUpTime--; + } + + if (DEBUG) { + System.out.println("setSpeedTurnRight: output-> " + Integer.toString(motorUpTime)); + } +// synchronized (this) { + /* Factor in the speed and agility factors */ + motorRightUpTime = motorUpTime; +// } + } + + /** + * setSpeedLeft - speed control for motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedLeft(int timePosition) { + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + /* 100-input to get reverse polarity for this motor */ + /* since it's mounted in reverse direction to the other motor */ + if (DEBUG) { + System.out.println("setSpeedLeft: input-> " + Integer.toString(timePosition)); + } + int timePos = normalizeTime(timePosition); + int motorUpTime = (int) (timePos * 100) * speedFactor; + /* + * System.out.println("motorUpTime = " + Integer.toString(motorUpTime) + + * " timePos = " + Integer.toString((int)timePos) + " timePosition = " + + * Integer.toString((int)timePosition) + " speedFactor = " + + * Integer.toString(speedFactor)); + */ + if (motorUpTime == 0) { + motorUpTime = 1; + // System.out.println("returning...."); + // return; // ndr + } else if (motorUpTime == 1000000) { + motorUpTime--; + } + if (DEBUG) { + System.out.println("setSpeedLeft: output-> " + Integer.toString(motorUpTime)); + } +// synchronized (this) { + /* Factor in speedFactor */ + motorLeftUpTime = motorUpTime; +// } + } + + /** + * setSpeedRight - speed control for motor 1. + * + * @param uptime + * pulse width (time position) + */ + public void setSpeedRight(int timePosition) { + if (DEBUG) { + System.out.println("setSpeedRight: input-> " + Integer.toString(timePosition)); + } + /* Speed comes in as a number between 0 - 100 */ + /* It represents values between 1 to 2 ms */ + int timePos = normalizeTime(timePosition); + int motorUpTime = (int) (timePos * 100) * speedFactor; + if (motorUpTime == 0) { + motorUpTime = 1; + // System.out.println("returning...."); + // return; // ndr + } else if (motorUpTime == 1000000) { + motorUpTime--; + } + if (DEBUG) { + System.out.println("setSpeedRight: output-> " + Integer.toString(motorUpTime)); + } +// synchronized (this) { + /* Factor in speedFactor */ + motorRightUpTime = motorUpTime; +// } + } + + public void setSpeedAgilityFactors(int speed, int agility) { +// synchronized (this) { + speedFactor = speed; + agilityFactor = agility; +// } + } + + public void setUrgentReverse() { +// synchronized (this) { + motorLeftUpTime = 1; + motorRightUpTime = 1; +// } + } + + public void setUrgentStraight() { +// synchronized (this) { + motorLeftUpTime = 99; + motorRightUpTime = 99; +// } + } + + public void justSync() { +// synchronized (this) { + motorLeftUpTime = motorLeftUpTime; + motorRightUpTime = motorRightUpTime; +// } + } + + /** + * Control debug messageing. true - Activate debug messages false - deactivate + * debug messages + */ + public void setDebug(boolean debug) { + DEBUG = debug; + } + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java b/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java new file mode 100644 index 00000000..6c1aa904 --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/RCBridge.java @@ -0,0 +1,40 @@ +/* + * PWMControl.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +/** + * Manage the software link between two IO port lines. + *

+ * Copyright: Copyright (c) 2002 + *

+ * + * @author Michael Gesundheit + * @version 1.0 + */ +public class RCBridge { + + public void setManualMode(){ +// rcLleft.activate(); +// rcLright.activate(); +} + +public void setAutomatedMode(){ + // rcLleft.deActivate(); + // rcLright.deActivate(); +} +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java b/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java new file mode 100644 index 00000000..381e10cd --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/RobotMain.java @@ -0,0 +1,296 @@ +/* + * RobotMain.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +/** + * Robot's Main class - instantiates all required classes and resources. + * + * @author Michael Gesundheit + * @version 1.0 + */ +public class RobotMain { + + private static boolean DEBUG1 = true; + private static boolean DEBUG = false; + 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 LINE_SENSORS = 64; // 0x40 + private static final int SONAR_SENSORS = 96; // 0x60 + public static final int ALL_COMMANDS = 0xe0; + + public static byte LF_FRONT = 0x1; + public static byte RT_FRONT = 0x2; + public static byte RT_SIDE = 0x4; + public static byte BK_SIDE = 0x8; + public static byte LF_SIDE = 0x10; + public static byte ALL_SONARS = 0x1f; + public static byte LF_RT_FRONT = 0x3; // LF_FRONT | RT_FRONT; + public static byte LS_LEFT = 0x1; + public static byte LS_RIGHT = 0x2; + public static byte LS_REAR = 0x4; + public static byte LS_LEFT_RIGHT = 0x3; + public static byte LS_LEFT_REAR = 0x5; + public static byte LS_RIGHT_REAR = 0x6; + public static byte LS_ALL = 0x7; + private static int ALL_DATA = 0x1f; + + private static PWMManager pwmm; + private static StrategyMgr strategyMgr; + + private static int onOffMode = ON_MODE; + private static int manualAutonomusMode = AUTONOMUS_MODE; + private static byte lineSensorsMask; + private static byte sonarSensors; + private static byte[] command; + private static byte currentCommand; + private static Object obj; + private static Object obj1; + private static byte privSonars; + private static byte privLineSensors; + private static byte currentSonars; + private static byte currentLineSensors; + public static String pwmSelection; + + /** + * Constructor for the class for the robot main thread. + */ + 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. + */ + static 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. + */ + static void processLineSensors() { + strategyMgr.processLineSensors(lineSensorsMask); + resume(); + } + + /** + * Resumes motors as per the last sonar command. + */ + public static void resume() { + processSonars(); + } + + /** + * Extracts sonar sensor data from the adjunct sensor controller and from line + * sensor data from the JStamp line sensor pins. + */ + private static void processIOCommand() { + + int data = 0; + int opCode = 0; + // synchronized (obj1) { + data = (int) (currentCommand & ALL_DATA); + opCode = (int) (currentCommand & 0xe0); // ALL_COMMANDS); + // } + + if (DEBUG) { + // System.out.println("processIOCommand: Getting in opCode = " + // + Integer.toHexString((int) opCode) + " data = " + + // Integer.toHexString((int) data)); + } + switch ((int) opCode) { + case ON_OFF: + if (DEBUG) { + System.out.println("processIO: ON_OFF...."); + } + if ((data & 0x1) == 0x1) { + System.out.println("processIO: ON MODE........"); + onOffMode = ON_MODE; + processLineSensors(); + processSonars(); + } else { + System.out.println("processIO: OFF MODE......."); + onOffMode = OFF_MODE; + strategyMgr.stop(); + } + break; + case MANUAL_AUTONOMUS: + if (DEBUG) { + System.out.println("processIO: Setting manual_autonomus mode"); + } + if ((data & 0x1) == 0x1) { + manualAutonomusMode = MANUAL_MODE; + pwmm.setManualMode(); + } else { + manualAutonomusMode = AUTONOMUS_MODE; + pwmm.setAutomatedMode(); + processLineSensors(); + processSonars(); + } + break; + case LINE_SENSORS: + if (DEBUG) { + // System.out.println("processIO: Line Sensors.................." + // + Integer.toBinaryString((int) (data & LS_ALL))); + } + lineSensorsMask = (byte) (data & LS_ALL); + + /* + * 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); + return; + } + if ((onOffMode == ON_MODE) && (manualAutonomusMode == AUTONOMUS_MODE)) { + if (DEBUG) + System.out.println("processIO: Line Sensors..Process...!!!"); + processLineSensors(); + } + break; + case SONAR_SENSORS: + if (DEBUG) { + // System.out.println("processIO: SONAR_SENORS: bits = ......" + // + Integer.toBinaryString((int) (currentCommand & ALL_SONARS))); + } + currentSonars = (byte) (data & ALL_SONARS); + /* + * 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)) { + processSonars(); + } + break; + default: + System.out.println("processIOCommand: Default: opCode = " + Integer.toString((int) opCode) + + " data = " + Integer.toString((int) data)); + } + } + + /** + * Sets the simulation mode on in the IOManager. + */ + // static public void setSimulation() { + // sm.setSimulation(); + // } + + /** + * Resets the simulation mode in the IOManager. + */ + // static public void resetSimulation() { + // sm.resetSimulation(); + // } + + /** + * Saves the current IOManager command byte locally. + */ + static public void setIOManagerCommand(byte[] cmd) { + // synchronized (obj1) { + currentCommand = cmd[0]; + // } + // synchronized (obj) { + try { + // obj.notify(); + } catch (IllegalMonitorStateException ie) { + System.out.println("IllegalMonitorStateException caught trying to notify"); + } + // } + } + + /** + * Sets debug messaging state: true - Activate debug messages false - + * deactivate debug messages + */ + static public void setDebug(boolean debug) { + DEBUG = debug; + } + + /** + * Runs the robot's main thread. + */ + public static void main(String args[]) { + + boolean active = true; + /** + * 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). + */ + pwmSelection = "rtsj"; + + System.out.println("PWM Selction is: " + pwmSelection); + + pwmm = new PWMManager(pwmSelection); + + // Pass in the PWMManager for callbacks. + // sm = new IOManager(pwmm); + // ram = new RemoteApplicationManager(pwmm); + strategyMgr = new StrategyMgr(pwmm); + + /* + * 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. + */ + // issueCommand("OFF"); + + int count = 0; + + while (active && count < 10000) { + try { + 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(); + processIOCommand(); + // Nothing to do + } catch (Exception e) { + } + count++; + } + System.exit(0); + } + +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/StrategyMgr.java b/Robust/src/Benchmarks/SSJava/JavaNator/StrategyMgr.java new file mode 100644 index 00000000..c8d12f55 --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/StrategyMgr.java @@ -0,0 +1,256 @@ +/* + * StragegyMgr.java + * + * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF + * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. + */ + +/** + * StrategyMgr - an isolation class ment for programmers to modify and create + * thier own code for robot strategy. + * + * @author Michael Gesundheit + * @version 1.0 + */ +public class StrategyMgr { + + private PWMControl pwmControl; + private int zeroSpeed = 45; + private Random rand; + private boolean DEBUGL = true; + // private boolean DEBUGL = false; + + // private boolean DEBUG = true; + private boolean DEBUG = false; + + /** + * Constructor - Invoke communication to remote application thread + */ + StrategyMgr(PWMManager pwmManager) { + this.pwmControl = pwmManager.getPWMControl(); + rand = new Random(); + } + + + + void processSonars(byte sonarSensors) { + + // 5 sensors. 1,2 are fromnt left and right. + // Sensor 3 is right side, 4 back and 5 is left side. + if ((sonarSensors & 0x1f) == 0) { + // No sensor data may mean dead area between sensors. + // Continue with the last gesture until any sensor + // provide data. + if (DEBUG) { + System.out.println("sonar: NO SONARS!!!!!!!!"); + } + } else if ((sonarSensors & (RobotMain.LF_RT_FRONT)) == (RobotMain.LF_RT_FRONT)) { + if (DEBUG) { + System.out.println("sonar: straight"); + } + straight(); + } else if ((sonarSensors & RobotMain.LF_FRONT) == RobotMain.LF_FRONT) { + if (DEBUG) { + System.out.println("sonar: bearLeft"); + } + bearLeft(); + } else if ((sonarSensors & RobotMain.RT_FRONT) == RobotMain.RT_FRONT) { + if (DEBUG) { + System.out.println("sonar: bearRight"); + } + bearRight(); + } else if ((sonarSensors & RobotMain.RT_SIDE) == RobotMain.RT_SIDE) { + if (DEBUG) { + System.out.println("sonar: right"); + } + spinRight(); + } else if ((sonarSensors & RobotMain.LF_SIDE) == RobotMain.LF_SIDE) { + if (DEBUG) { + System.out.println("sonar: left"); + } + spinLeft(); + } else if ((sonarSensors & RobotMain.BK_SIDE) == RobotMain.BK_SIDE) { + if (DEBUG) { + System.out.println("sonar: spin180"); + } + spin180(); + } + } + + void processLineSensors(byte lineSensorsMask) { + while ((lineSensorsMask & RobotMain.LS_ALL) != 0) { + if ((lineSensorsMask & RobotMain.LS_ALL) == RobotMain.LS_ALL) { + if (DEBUGL) + System.out.println("Line Sensors - ALL"); + stop(); + } else if ((lineSensorsMask & RobotMain.LS_LEFT_RIGHT) == RobotMain.LS_LEFT_RIGHT) { + if (DEBUGL) + System.out.println("Line Sensors - Left & Right"); + back(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + spin180(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + } else if ((lineSensorsMask & RobotMain.LS_LEFT_REAR) == RobotMain.LS_LEFT_REAR) { + if (DEBUGL) + System.out.println("Line Sensors - Left & Rear"); + bearRight(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + } else if ((lineSensorsMask & RobotMain.LS_RIGHT_REAR) == RobotMain.LS_RIGHT_REAR) { + if (DEBUGL) + System.out.println("Line Sensors - Right & Rear"); + bearLeft(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + } else if ((lineSensorsMask & RobotMain.LS_LEFT) == RobotMain.LS_LEFT) { + if (DEBUGL) + System.out.println("Line Sensors - Left"); + backBearRight(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + } else if ((lineSensorsMask & RobotMain.LS_RIGHT) == RobotMain.LS_RIGHT) { + if (DEBUGL) + System.out.println("Line Sensors - Right"); + backBearLeft(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + } else if ((lineSensorsMask & RobotMain.LS_REAR) == RobotMain.LS_REAR) { + if (DEBUGL) + System.out.println("Line Sensors - Rear"); + straight(); + try { + // Thread.sleep(1000); + } catch (InterruptedException ie) { + } + } + + // TODO + // lineSensorsMask = sm.getLineSensorsState(); + + }// while loop + } + + public void stop() { + if (DEBUG) + System.out.println("StrageyMgr: stop...."); + pwmControl.setSpeedLeft(zeroSpeed); + pwmControl.setSpeedRight(zeroSpeed); + } + + public void search() { + if (DEBUG) + System.out.println("StrategyMgr: search...."); + pwmControl.setSpeedLeft(70); + pwmControl.setSpeedRight(50); + } + + public void straight() { + if (DEBUG) + System.out.println("StrategyMgr: strait...."); + pwmControl.setSpeedLeft(100); + pwmControl.setSpeedRight(100); + } + + public void spinRight() { + if (DEBUG) + System.out.println("StrategyMgr: spinRight...."); + pwmControl.setSpeedSpinLeft(100); + pwmControl.setSpeedSpinRight(0); + } + + public void spinLeft() { + if (DEBUG) + System.out.println("StrategyMgr: spinLeft...."); + pwmControl.setSpeedSpinLeft(0); + pwmControl.setSpeedSpinRight(100); + } + + public void spin180() { + int mod = (rand.nextInt() % 2); + + if (DEBUG) + System.out.println("StrategyMgr: spin180...."); + if (mod == 1) { + pwmControl.setSpeedSpinLeft(0); + pwmControl.setSpeedSpinRight(100); + } else { + pwmControl.setSpeedSpinLeft(100); + pwmControl.setSpeedSpinRight(0); + } + } + + public void right() { + if (DEBUG) + System.out.println("StrategyMgr: right...."); + pwmControl.setSpeedTurnLeft(100); + pwmControl.setSpeedRight(zeroSpeed); + } + + public void left() { + if (DEBUG) + System.out.println("StrategyMgr: left...."); + pwmControl.setSpeedLeft(zeroSpeed); + pwmControl.setSpeedTurnRight(100); + } + + public void bearRight() { + if (DEBUG) + System.out.println("StrategyMgr: bearRight...."); + pwmControl.setSpeedTurnLeft(100); + pwmControl.setSpeedTurnRight(60); + } + + public void bearLeft() { + if (DEBUG) + System.out.println("StrategyMgr: bearLeft...."); + pwmControl.setSpeedTurnLeft(60); + pwmControl.setSpeedTurnRight(100); + } + + public void back() { + if (DEBUG) + System.out.println("StrategyMgr: back...."); + pwmControl.setSpeedLeft(0); + pwmControl.setSpeedRight(0); + } + + public void backBearLeft() { + if (DEBUG) + System.out.println("StrategyMgr: backBearLeft...."); + pwmControl.setSpeedLeft(30); + pwmControl.setSpeedRight(0); + } + + public void backBearRight() { + if (DEBUG) + System.out.println("StrategyMgr: backBearRight...."); + pwmControl.setSpeedLeft(0); + pwmControl.setSpeedRight(30); + } +} diff --git a/Robust/src/Benchmarks/SSJava/JavaNator/TestSensorInput.java b/Robust/src/Benchmarks/SSJava/JavaNator/TestSensorInput.java new file mode 100644 index 00000000..4ca1a31d --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/JavaNator/TestSensorInput.java @@ -0,0 +1,14 @@ +public class TestSensorInput { + + FileInputStream inputFile; + + public void init() { + inputFile = new FileInputStream("input.dat"); + } + + public static byte getCommand() { + // return Byte.parseInt(inputFile.readLine()); + return 0; + } + +}