Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

MotorPair Class Reference

\class MotorPair MotorPair.H c++/MotorPair.H 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:
Note:
both motors will be turned off when this class is destroyed.
See also:
The other control classes: Motor, Sound, Lamp.
More...

#include <MotorPair.H>

Collaboration diagram for MotorPair:

[legend]
List of all members.

Public Types

enum  Limits { min = Motor::min, max = Motor::max }
 the minimum and maximum speeds a motor can go, its limits. More...


Public Methods

 MotorPair (const Motor::Port lport, const Motor::Port rport)
 define a pair of motors specifying the connection of each to the RCX. More...

 ~MotorPair ()
 destroy this MotorPair instance
Note:
both motors will be turned off when this class is destroyed.
More...


void speed (const int s) const
 set the speed of our two motors. More...

void direction (const MotorDirection dir) const
 set the direction of our two motors
Parameters:
dir  one of the MotorDirection values.
More...


void forward () const
 move forward. More...

void reverse () const
 move reverse. More...

void brake () const
 stop without coasting. More...

void off () const
 stop but allow coasting. More...

void left () const
 turn left about the center of the robot
Note:
both motors in the pair are turning.
More...


void pivotLeft () const
 turn left about the left wheel of the robot
Note:
the left motor is brake'd while the right motor is turning.
More...


void right () const
 turn right about the center of the robot
Note:
both motors in the pair are turning.
More...


void pivotRight () const
 turn right about the right wheel of the robot
Note:
the right motor is brake'd while the left motor is turning.
More...


void forward (const int s) const
 move forward at speed {s}
Parameters:
s  the desired speed (power level).
More...


void reverse (const int s) const
 move reverse (go backwards) at speed {s}
Parameters:
s  the desired speed (power level).
More...


void left (const int s) const
 turn left at speed {s}
Parameters:
s  the desired speed (power level)
Note:
spins about the center of the motor pair.
More...


void pivotLeft (const int s) const
 turn left at speed {s} but pivot around left wheel
Parameters:
s  the desired speed (power level)
Note:
spins about the left wheel.
More...


void right (const int s) const
 turn right at speed {s}
Parameters:
s  the desired speed (power level)
Note:
spins about the center of the motor pair.
More...


void pivotRight (const int s) const
 turn right at speed {s} but pivot around right wheel
Parameters:
s  the desired speed (power level)
Note:
spins about the right wheel.
More...


void brake (const int ms) const
 apply the brakes to both motors then delay for {ms} mSec
Parameters:
ms  the time in mSec to wait before returning to caller.
More...



Detailed Description

\class MotorPair MotorPair.H c++/MotorPair.H 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:
Note:
both motors will be turned off when this class is destroyed.
See also:
The other control classes: Motor, Sound, Lamp.

Definition at line 57 of file MotorPair.H.


Member Enumeration Documentation

enum MotorPair::Limits
 

the minimum and maximum speeds a motor can go, its limits.

Enumeration values:
min  minimum motor speed setting.
max  maximum motor speed setting.

Definition at line 167 of file MotorPair.H.


Constructor & Destructor Documentation

MotorPair::MotorPair const Motor::Port    lport,
const Motor::Port    rport
[inline]
 

define a pair of motors specifying the connection of each to the RCX.

Definition at line 62 of file MotorPair.H.

References Motor::Port.

MotorPair::~MotorPair   [inline]
 

destroy this MotorPair instance

Note:
both motors will be turned off when this class is destroyed.

Definition at line 67 of file MotorPair.H.


Member Function Documentation

void MotorPair::brake const int    ms const [inline]
 

apply the brakes to both motors then delay for {ms} mSec

Parameters:
ms  the time in mSec to wait before returning to caller.

Definition at line 164 of file MotorPair.H.

References brake(), and delay().

void MotorPair::brake   const [inline]
 

stop without coasting.

Definition at line 94 of file MotorPair.H.

References Motor::direction().

Referenced by brake().

void MotorPair::direction const MotorDirection    dir const [inline]
 

set the direction of our two motors

Parameters:
dir  one of the MotorDirection values.

Definition at line 74 of file MotorPair.H.

References Motor::direction(), and MotorDirection.

Referenced by forward(), and reverse().

void MotorPair::forward const int    s const [inline]
 

move forward at speed {s}

Parameters:
s  the desired speed (power level).

Definition at line 136 of file MotorPair.H.

References forward(), and speed().

void MotorPair::forward   const [inline]
 

move forward.

Definition at line 88 of file MotorPair.H.

References direction().

Referenced by forward().

void MotorPair::left const int    s const [inline]
 

turn left at speed {s}

Parameters:
s  the desired speed (power level)
Note:
spins about the center of the motor pair.

Definition at line 145 of file MotorPair.H.

References left(), and speed().

void MotorPair::left   const [inline]
 

turn left about the center of the robot

Note:
both motors in the pair are turning.

Definition at line 107 of file MotorPair.H.

References Motor::direction().

Referenced by left().

void MotorPair::off   const [inline]
 

stop but allow coasting.

Definition at line 100 of file MotorPair.H.

References Motor::direction().

void MotorPair::pivotLeft const int    s const [inline]
 

turn left at speed {s} but pivot around left wheel

Parameters:
s  the desired speed (power level)
Note:
spins about the left wheel.

Definition at line 150 of file MotorPair.H.

References pivotLeft(), and speed().

void MotorPair::pivotLeft   const [inline]
 

turn left about the left wheel of the robot

Note:
the left motor is brake'd while the right motor is turning.

Definition at line 114 of file MotorPair.H.

References Motor::brake(), and Motor::direction().

Referenced by pivotLeft().

void MotorPair::pivotRight const int    s const [inline]
 

turn right at speed {s} but pivot around right wheel

Parameters:
s  the desired speed (power level)
Note:
spins about the right wheel.

Definition at line 160 of file MotorPair.H.

References pivotRight(), and speed().

void MotorPair::pivotRight   const [inline]
 

turn right about the right wheel of the robot

Note:
the right motor is brake'd while the left motor is turning.

Definition at line 128 of file MotorPair.H.

References Motor::brake(), and Motor::direction().

Referenced by pivotRight().

void MotorPair::reverse const int    s const [inline]
 

move reverse (go backwards) at speed {s}

Parameters:
s  the desired speed (power level).

Definition at line 140 of file MotorPair.H.

References reverse(), and speed().

void MotorPair::reverse   const [inline]
 

move reverse.

Definition at line 91 of file MotorPair.H.

References direction().

Referenced by reverse().

void MotorPair::right const int    s const [inline]
 

turn right at speed {s}

Parameters:
s  the desired speed (power level)
Note:
spins about the center of the motor pair.

Definition at line 155 of file MotorPair.H.

References right(), and speed().

void MotorPair::right   const [inline]
 

turn right about the center of the robot

Note:
both motors in the pair are turning.

Definition at line 121 of file MotorPair.H.

References Motor::direction().

Referenced by right().

void MotorPair::speed const int    s const [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().


The documentation for this class was generated from the following file:
brickOS is released under the Mozilla Public License.
Original code copyright 1998-2002 by the authors.

Generated on Tue Dec 10 00:09:08 2002 for brickOS C++ by doxygen 1.2.15