brickOS C++ v0.9.0
|
Pair-of-motors control interface. More...
#include <c++/MotorPair.H>
Public Types | |
enum | Limits { min = Motor::min , max = Motor::max } |
the minimum and maximum speeds a motor can go, its limits. More... | |
Public Member Functions | |
MotorPair (const Motor::Port lport, const Motor::Port rport) | |
define a pair of motors specifying the connection of each to the RCX | |
~MotorPair () | |
destroy this MotorPair instance | |
void | speed (const int s) const |
set the speed of our two motors | |
void | direction (const MotorDirection dir) const |
set the direction of our two motors | |
void | forward () const |
move forward | |
void | reverse () const |
move reverse | |
void | brake () const |
stop without coasting | |
void | off () const |
stop but allow coasting | |
void | left () const |
turn left about the center of the robot | |
void | pivotLeft () const |
turn left about the left wheel of the robot | |
void | right () const |
turn right about the center of the robot | |
void | pivotRight () const |
turn right about the right wheel of the robot | |
void | forward (const int s) const |
move forward at speed {s} | |
void | reverse (const int s) const |
move reverse (go backwards) at speed {s} | |
void | left (const int s) const |
turn left at speed {s} | |
void | pivotLeft (const int s) const |
turn left at speed {s} but pivot around left wheel | |
void | right (const int s) const |
turn right at speed {s} | |
void | pivotRight (const int s) const |
turn right at speed {s} but pivot around right wheel | |
void | brake (const int ms) const |
apply the brakes to both motors then delay for {ms} mSec | |
Pair-of-motors control interface.
Often our robots use two motors, one on either side, which should be controlled together as one. This class makes this simple by allowing the coder to treat the pair as a single motor.
The two motors can be connected to any of the output ports. When creating an instance of this class, simply specify which two output ports are involved.
The normal Motor methods speed(), direction(), forward(), reverse(), brake(), and off() still apply.
This class adds two new types of control:
Definition at line 57 of file MotorPair.H.
enum MotorPair::Limits |
the minimum and maximum speeds a motor can go, its limits.
Enumerator | |
---|---|
min | minimum motor speed setting |
max | maximum motor speed setting |
Definition at line 167 of file MotorPair.H.
|
inline |
define a pair of motors specifying the connection of each to the RCX
Definition at line 62 of file MotorPair.H.
|
inline |
destroy this MotorPair instance
Definition at line 67 of file MotorPair.H.
|
inline |
stop without coasting
Definition at line 94 of file MotorPair.H.
References brake(), and Motor::direction().
Referenced by brake().
|
inline |
apply the brakes to both motors then delay for {ms} mSec
ms | the time in mSec to wait before returning to caller |
Definition at line 164 of file MotorPair.H.
References brake(), and delay().
Referenced by brake().
|
inline |
set the direction of our two motors
dir | one of the MotorDirection values |
Definition at line 74 of file MotorPair.H.
References Motor::direction(), fwd, and rev.
|
inline |
|
inline |
move forward at speed {s}
s | the desired speed (power level) |
Definition at line 136 of file MotorPair.H.
References forward(), and speed().
Referenced by forward().
|
inline |
turn left about the center of the robot
Definition at line 107 of file MotorPair.H.
References Motor::direction(), and fwd.
|
inline |
turn left at speed {s}
s | the desired speed (power level) |
Definition at line 145 of file MotorPair.H.
References left(), and speed().
Referenced by left().
|
inline |
stop but allow coasting
Definition at line 100 of file MotorPair.H.
References Motor::direction(), and off().
Referenced by off().
|
inline |
turn left about the left wheel of the robot
Definition at line 114 of file MotorPair.H.
References Motor::brake(), Motor::direction(), and rev.
|
inline |
turn left at speed {s} but pivot around left wheel
s | the desired speed (power level) |
Definition at line 150 of file MotorPair.H.
References pivotLeft(), and speed().
Referenced by pivotLeft().
|
inline |
turn right about the right wheel of the robot
Definition at line 128 of file MotorPair.H.
References Motor::brake(), Motor::direction(), and fwd.
|
inline |
turn right at speed {s} but pivot around right wheel
s | the desired speed (power level) |
Definition at line 160 of file MotorPair.H.
References pivotRight(), and speed().
Referenced by pivotRight().
|
inline |
|
inline |
move reverse (go backwards) at speed {s}
s | the desired speed (power level) |
Definition at line 140 of file MotorPair.H.
References reverse(), and speed().
Referenced by reverse().
|
inline |
turn right about the center of the robot
Definition at line 121 of file MotorPair.H.
References Motor::direction(), and rev.
|
inline |
turn right at speed {s}
s | the desired speed (power level) |
Definition at line 155 of file MotorPair.H.
References right(), and speed().
Referenced by right().
|
inline |
set the speed of our two motors
Definition at line 70 of file MotorPair.H.
References Motor::speed().
Referenced by forward(), left(), pivotLeft(), pivotRight(), reverse(), and right().