changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / Benchmarks / SSJava / JavaNator / PWMControl.java
1 /*\r
2  * PWMControl.java\r
3  *\r
4  * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved.\r
5  *\r
6  * This software is the confidential and proprietary information of Sun\r
7  * Microsystems, Inc. ("Confidential Information").  You shall not\r
8  * disclose such Confidential Information and shall use it only in\r
9  * accordance with the terms of the license agreement you entered into\r
10  * with Sun.\r
11  *\r
12  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF\r
13  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\r
14  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r
15  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR\r
16  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR\r
17  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.\r
18  */\r
19 \r
20 /**\r
21  * This class is the super class of all motor control classes. The class\r
22  * represent a generic interface to such class. In our case the motor controller\r
23  * require for 0 speed 1.5 ms out of 10-20ms cycle and a change between 1 to 2\r
24  * seconds for max reverse and forward speed. These values: 1, 1.5, 2 and 20 ms\r
25  * are thus this class specific\r
26  * \r
27  * @author Michael Gesundheit\r
28  * @version 1.0\r
29  */\r
30 \r
31 public abstract class PWMControl {\r
32 \r
33   PWMManager pwmManager;\r
34   boolean DEBUG = false;\r
35   // boolean DEBUG = true;\r
36   static final byte PULSE_HIGH = 1;\r
37   static final byte PULSE_LOW = 0;\r
38   int highMask;\r
39   int m1HighMask;\r
40   int m2HighMask;\r
41   int lowMask;\r
42   int myOwnBit;\r
43   int myBitPos;\r
44   int m1BitPos;\r
45   int m2BitPos;\r
46   int speedFactor;\r
47   int agilityFactor;\r
48   boolean updateTime;\r
49   int pulseWidth;\r
50   Object obj;\r
51 \r
52   int motorLeftUpTime = 150;\r
53   int motorRightUpTime = 150;\r
54   boolean manualMode = false;\r
55 \r
56   PWMControl(PWMManager pwmMan, int motor1bit, int motor2bit) {\r
57     pwmManager = pwmMan; // This is papa\r
58     m1BitPos = 0x1 << motor1bit;\r
59     m2BitPos = 0x1 << motor2bit;\r
60     m1HighMask = 0x1 << motor1bit;\r
61     m2HighMask = 0x1 << motor2bit;\r
62     lowMask = 0x0;\r
63     obj = new Object();\r
64   }\r
65 \r
66   public void setManualMode() {\r
67     if (DEBUG)\r
68       System.out.println("PWMContolr: setManualMode... ");\r
69 //    synchronized (obj) {\r
70       if (manualMode == false) {\r
71         manualMode = true;\r
72       }\r
73 //    }\r
74   }\r
75 \r
76   public void setAutomatedMode() {\r
77     if (DEBUG)\r
78       System.out.println("PWMControl: setAutomatedMode... ");\r
79 //    synchronized (obj) {\r
80       if (manualMode == true) {\r
81         System.out.println("PWMControl: wake me up... ");\r
82         manualMode = false;\r
83         // obj.notify();\r
84         System.out.println("PWMControl: wake me up...... tried!!!");\r
85       }\r
86 //    }\r
87   }\r
88 \r
89   /**\r
90    * OutPut value to motor control line\r
91    */\r
92   public void outToPortMLeft(byte value) {\r
93     /*\r
94      * System.out.println("PWMControl " + Integer.toString(myOwnBit) +\r
95      * //" bit position = 0x" + Integer.toHexString(myOwnBit) +\r
96      * " output value = 0x" + Integer.toHexString(value));\r
97      */\r
98     if (value == PULSE_HIGH) {\r
99       pwmManager.writeToPort(m1BitPos, m1HighMask);\r
100     } else {\r
101       pwmManager.writeToPort(m1BitPos, lowMask);\r
102     }\r
103   }\r
104 \r
105   public void outToPortMRight(byte value) {\r
106     /*\r
107      * System.out.println("PWMControl " + Integer.toString(myOwnBit) +\r
108      * //" bit position = 0x" + Integer.toHexString(myOwnBit) +\r
109      * " output value = 0x" + Integer.toHexString(value));\r
110      */\r
111     if (value == PULSE_HIGH) {\r
112       pwmManager.writeToPort(m2BitPos, m2HighMask);\r
113     } else {\r
114       pwmManager.writeToPort(m2BitPos, lowMask);\r
115     }\r
116   }\r
117 \r
118   /**\r
119    * setSpeedSpin - Set speed for the spin case motor 1.\r
120    * \r
121    * @param uptime\r
122    *          pulse width (time position)\r
123    */\r
124   public void setSpeedSpinLeft(int timePosition) {\r
125   }\r
126 \r
127   /**\r
128    * setSpeedSpinRight - Set speed for the spin case right motor.\r
129    * \r
130    * @param uptime\r
131    *          pulse width (time position)\r
132    */\r
133   public void setSpeedSpinRight(int timePosition) {\r
134   }\r
135 \r
136   /**\r
137    * setSpeedTurnM1 - set speed considering agility factor for motor 1\r
138    * \r
139    * @param uptime\r
140    *          pulse width (time position)\r
141    */\r
142   public void setSpeedTurnLeft(int timePosition) {\r
143   }\r
144 \r
145   /**\r
146    * setSpeedTurnM1 - set speed considering agility factor for motor 2\r
147    * \r
148    * @param uptime\r
149    *          pulse width (time position)\r
150    */\r
151   public void setSpeedTurnRight(int timePosition) {\r
152   }\r
153 \r
154   /**\r
155    * setSpeedLeft - speed control for motor 1.\r
156    * \r
157    * @param uptime\r
158    *          pulse width (time position)\r
159    */\r
160   public void setSpeedLeft(int timePosition) {\r
161   }\r
162 \r
163   /**\r
164    * setSpeedRight - speed control for motor 1.\r
165    * \r
166    * @param uptime\r
167    *          pulse width (time position)\r
168    */\r
169   public void setSpeedRight(int timePosition) {\r
170   }\r
171 \r
172   public void setSpeedAgilityFactors(int speed, int agility) {\r
173 //    synchronized (this) {\r
174       speedFactor = speed;\r
175       agilityFactor = agility;\r
176 //    }\r
177   }\r
178 \r
179   public void setUrgentReverse() {\r
180   }\r
181 \r
182   public void setUrgentStraight() {\r
183   }\r
184 \r
185   /**\r
186    * Control debug messageing. true - Activate debug messages false - deactivate\r
187    * debug messages\r
188    */\r
189   public void setDebug(boolean debug) {\r
190     DEBUG = debug;\r
191   }\r
192 }\r