MotorPair.H
Go to the documentation of this file.
1 
7 //
8 // The contents of this file are subject to the Mozilla Public License
9 // Version 1.0 (the "License"); you may not use this file except in
10 // compliance with the License. You may obtain a copy of the License
11 // at http://www.mozilla.org/MPL/
12 //
13 // Software distributed under the License is distributed on an "AS IS"
14 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15 // the License for the specific language governing rights and
16 // limitations under the License.
17 //
18 // This software was developed as part of the legOS project.
19 //
20 // Contributor: Pat Welch (legOS@mousebrains.com)
21 
22 #ifndef _MotorPair_H_
23 #define _MotorPair_H_
24 
25 #include <config.h>
26 
27 #if defined(CONF_DMOTOR)
28 
29 #include <conio.h> // for the delay() function
30 #include <c++/Motor.H>
31 
57 class MotorPair {
58 public:
59 
62  MotorPair(const Motor::Port lport, const Motor::Port rport)
63  : mLeft(lport), mRight(rport) {}
64 
68 
70  void speed(const int s) const { mLeft.speed(s); mRight.speed(s); }
71 
74  void direction(const MotorDirection dir) const {
75  if (dir == ::fwd) {
76  mLeft.direction(::fwd);
77  mRight.direction(::rev);
78  } else if (dir == ::rev) {
79  mLeft.direction(::rev);
80  mRight.direction(::fwd);
81  } else {
82  mLeft.direction(dir);
83  mRight.direction(dir);
84  }
85  }
86 
88  void forward() const { direction(::fwd); }
89 
91  void reverse() const { direction(::rev); }
92 
94  void brake() const {
95  mLeft.direction(::brake);
96  mRight.direction(::brake);
97  }
98 
100  void off() const {
101  mLeft.direction(::off);
102  mRight.direction(::off);
103  }
104 
107  void left() const {
108  mLeft.direction(::fwd);
109  mRight.direction(::fwd);
110  }
111 
114  void pivotLeft() const {
115  mLeft.brake();
116  mRight.direction(::rev);
117  }
118 
121  void right() const {
122  mLeft.direction(::rev);
123  mRight.direction(::rev);
124  }
125 
128  void pivotRight() const {
129  mLeft.direction(::fwd);
130  mRight.brake();
131  }
132 
133 
136  void forward(const int s) const { forward(); speed(s); }
137 
140  void reverse(const int s) const { reverse(); speed(s); }
141 
145  void left(const int s) const { left(); speed(s); }
146 
150  void pivotLeft(const int s) const { pivotLeft(); speed(s); }
151 
155  void right(const int s) const { right(); speed(s); }
156 
160  void pivotRight(const int s) const { pivotRight(); speed(s); }
161 
164  void brake(const int ms) const { brake(); delay(ms); }
165 
167  enum Limits {
170  };
171 
172 private:
173  const Motor mLeft;
174  const Motor mRight;
175 };
176 
177 #else // CONF_DMOTOR
178 #warning Enable CONF_DMOTOR to use MotorPair.H
179 #endif // CONF_DMOTOR
180 #endif // _MotorPair_H_
conio.h
Interface: console input / output.
Motor::min
Minimum velocity (0)
Definition: Motor.H:53
Motor::speed
const void speed(const unsigned char speed) const
set the motor speed
Definition: Motor.H:80
rev
reverse
Definition: dmotor.h:47
MotorPair::MotorPair
MotorPair(const Motor::Port lport, const Motor::Port rport)
define a pair of motors specifying the connection of each to the RCX
Definition: MotorPair.H:62
MotorPair::brake
void brake(const int ms) const
apply the brakes to both motors then delay for {ms} mSec
Definition: MotorPair.H:164
MotorPair::pivotLeft
void pivotLeft() const
turn left about the left wheel of the robot
Definition: MotorPair.H:114
MotorPair::pivotLeft
void pivotLeft(const int s) const
turn left at speed {s} but pivot around left wheel
Definition: MotorPair.H:150
MotorPair::direction
void direction(const MotorDirection dir) const
set the direction of our two motors
Definition: MotorPair.H:74
delay
void delay(unsigned ms)
delay approximately ms mSec
MotorPair::~MotorPair
~MotorPair()
destroy this MotorPair instance
Definition: MotorPair.H:67
MotorDirection
MotorDirection
the motor directions
Definition: dmotor.h:44
MotorPair::speed
void speed(const int s) const
set the speed of our two motors
Definition: MotorPair.H:70
MotorPair::off
void off() const
stop but allow coasting
Definition: MotorPair.H:100
MotorPair::forward
void forward(const int s) const
move forward at speed {s}
Definition: MotorPair.H:136
Motor::brake
const void brake() const
set the motor to brake
Definition: Motor.H:116
MotorPair::forward
void forward() const
move forward
Definition: MotorPair.H:88
MotorPair::max
maximum motor speed setting
Definition: MotorPair.H:169
Motor.H
C++ Motor Class Interface.
MotorPair::right
void right(const int s) const
turn right at speed {s}
Definition: MotorPair.H:155
MotorPair::right
void right() const
turn right about the center of the robot
Definition: MotorPair.H:121
MotorPair::reverse
void reverse() const
move reverse
Definition: MotorPair.H:91
Motor::Port
Port
valid port designators
Definition: Motor.H:43
MotorPair::min
minimum motor speed setting
Definition: MotorPair.H:168
MotorPair
Definition: MotorPair.H:57
MotorPair::left
void left(const int s) const
turn left at speed {s}
Definition: MotorPair.H:145
MotorPair::left
void left() const
turn left about the center of the robot
Definition: MotorPair.H:107
Motor::max
Maximum velocity (255)
Definition: Motor.H:54
MotorPair::reverse
void reverse(const int s) const
move reverse (go backwards) at speed {s}
Definition: MotorPair.H:140
Motor
Definition: Motor.H:38
MotorPair::brake
void brake() const
stop without coasting
Definition: MotorPair.H:94
Motor::direction
const void direction(const MotorDirection dir) const
set the motor direction
Definition: Motor.H:86
MotorPair::pivotRight
void pivotRight() const
turn right about the right wheel of the robot
Definition: MotorPair.H:128
MotorPair::Limits
Limits
the minimum and maximum speeds a motor can go, its limits.
Definition: MotorPair.H:167
MotorPair::pivotRight
void pivotRight(const int s) const
turn right at speed {s} but pivot around right wheel
Definition: MotorPair.H:160
fwd
forward
Definition: dmotor.h:46

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS C++ by doxygen 1.8.16