00001 00007 // 00008 // The contents of this file are subject to the Mozilla Public License 00009 // Version 1.0 (the "License"); you may not use this file except in 00010 // compliance with the License. You may obtain a copy of the License 00011 // at http://www.mozilla.org/MPL/ 00012 // 00013 // Software distributed under the License is distributed on an "AS IS" 00014 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00015 // the License for the specific language governing rights and 00016 // limitations under the License. 00017 // 00018 // This software was developed as part of the legOS project. 00019 // 00020 // Contributor: Pat Welch (legOS@mousebrains.com) 00021 00022 #ifndef _MotorPair_H_ 00023 #define _MotorPair_H_ 00024 00025 #include <config.h> 00026 00027 #if defined(CONF_DMOTOR) 00028 00029 #include <conio.h> // for the delay() function 00030 #include <c++/Motor.H> 00031 00057 class MotorPair { 00058 public: 00059 00062 MotorPair(const Motor::Port lport, const Motor::Port rport) 00063 : mLeft(lport), mRight(rport) {} 00064 00067 ~MotorPair() {} 00068 00070 void speed(const int s) const { mLeft.speed(s); mRight.speed(s); } 00071 00074 void direction(const MotorDirection dir) const { 00075 if (dir == ::fwd) { 00076 mLeft.direction(::fwd); 00077 mRight.direction(::rev); 00078 } else if (dir == ::rev) { 00079 mLeft.direction(::rev); 00080 mRight.direction(::fwd); 00081 } else { 00082 mLeft.direction(dir); 00083 mRight.direction(dir); 00084 } 00085 } 00086 00088 void forward() const { direction(::fwd); } 00089 00091 void reverse() const { direction(::rev); } 00092 00094 void brake() const { 00095 mLeft.direction(::brake); 00096 mRight.direction(::brake); 00097 } 00098 00100 void off() const { 00101 mLeft.direction(::off); 00102 mRight.direction(::off); 00103 } 00104 00107 void left() const { 00108 mLeft.direction(::fwd); 00109 mRight.direction(::fwd); 00110 } 00111 00114 void pivotLeft() const { 00115 mLeft.brake(); 00116 mRight.direction(::rev); 00117 } 00118 00121 void right() const { 00122 mLeft.direction(::rev); 00123 mRight.direction(::rev); 00124 } 00125 00128 void pivotRight() const { 00129 mLeft.direction(::fwd); 00130 mRight.brake(); 00131 } 00132 00133 00136 void forward(const int s) const { forward(); speed(s); } 00137 00140 void reverse(const int s) const { reverse(); speed(s); } 00141 00145 void left(const int s) const { left(); speed(s); } 00146 00150 void pivotLeft(const int s) const { pivotLeft(); speed(s); } 00151 00155 void right(const int s) const { right(); speed(s); } 00156 00160 void pivotRight(const int s) const { pivotRight(); speed(s); } 00161 00164 void brake(const int ms) const { brake(); delay(ms); } 00165 00167 enum Limits { 00168 min = Motor::min, 00169 max = Motor::max 00170 }; 00171 00172 private: 00173 const Motor mLeft; 00174 const Motor mRight; 00175 }; 00176 00177 #else // CONF_DMOTOR 00178 #warning Enable CONF_DMOTOR to use MotorPair.H 00179 #endif // CONF_DMOTOR 00180 #endif // _MotorPair_H_
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |