Main Page
Related Pages
Modules
Classes
Files
File List
File Members
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
67
~MotorPair
() {}
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
{
168
min
=
Motor::min
,
169
max
=
Motor::max
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_
brickOS
is released under the
Mozilla Public License
.
Original code copyright 1998-2005 by the authors.
Generated on Sat Mar 15 2014 11:28:19 for brickOS C++ by
1.8.1.2