4 * Copyright (c) 1993-2002 Sun Microsystems, Inc. All Rights Reserved.
\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
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
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
27 * @author Michael Gesundheit
\r
31 public abstract class PWMControl {
\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
52 int motorLeftUpTime = 150;
\r
53 int motorRightUpTime = 150;
\r
54 boolean manualMode = false;
\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
66 public void setManualMode() {
\r
68 System.out.println("PWMContolr: setManualMode... ");
\r
69 // synchronized (obj) {
\r
70 if (manualMode == false) {
\r
76 public void setAutomatedMode() {
\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
84 System.out.println("PWMControl: wake me up...... tried!!!");
\r
90 * OutPut value to motor control line
\r
92 public void outToPortMLeft(byte value) {
\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
98 if (value == PULSE_HIGH) {
\r
99 pwmManager.writeToPort(m1BitPos, m1HighMask);
\r
101 pwmManager.writeToPort(m1BitPos, lowMask);
\r
105 public void outToPortMRight(byte value) {
\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
111 if (value == PULSE_HIGH) {
\r
112 pwmManager.writeToPort(m2BitPos, m2HighMask);
\r
114 pwmManager.writeToPort(m2BitPos, lowMask);
\r
119 * setSpeedSpin - Set speed for the spin case motor 1.
\r
122 * pulse width (time position)
\r
124 public void setSpeedSpinLeft(int timePosition) {
\r
128 * setSpeedSpinRight - Set speed for the spin case right motor.
\r
131 * pulse width (time position)
\r
133 public void setSpeedSpinRight(int timePosition) {
\r
137 * setSpeedTurnM1 - set speed considering agility factor for motor 1
\r
140 * pulse width (time position)
\r
142 public void setSpeedTurnLeft(int timePosition) {
\r
146 * setSpeedTurnM1 - set speed considering agility factor for motor 2
\r
149 * pulse width (time position)
\r
151 public void setSpeedTurnRight(int timePosition) {
\r
155 * setSpeedLeft - speed control for motor 1.
\r
158 * pulse width (time position)
\r
160 public void setSpeedLeft(int timePosition) {
\r
164 * setSpeedRight - speed control for motor 1.
\r
167 * pulse width (time position)
\r
169 public void setSpeedRight(int timePosition) {
\r
172 public void setSpeedAgilityFactors(int speed, int agility) {
\r
173 // synchronized (this) {
\r
174 speedFactor = speed;
\r
175 agilityFactor = agility;
\r
179 public void setUrgentReverse() {
\r
182 public void setUrgentStraight() {
\r
186 * Control debug messageing. true - Activate debug messages false - deactivate
\r
189 public void setDebug(boolean debug) {
\r