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

Motor Class Reference

Motor control interface. More...

#include <c++/Motor.H>

Collaboration diagram for Motor:

[legend]
List of all members.

Public Types

enum  Port { A, B, C }
 valid port designators. More...

enum  Limits { min = 0, max = 255 }
 motor speed range. More...


Public Methods

 Motor (const Port port)
 construct a motor connected to {port}. More...

 ~Motor ()
 destroy our motor instance. More...

const void speed (const unsigned char speed) const
 set the motor speed. More...

const void direction (const MotorDirection dir) const
 set the motor direction. More...

const void forward () const
 set motor direction to forward. More...

const void forward (const unsigned char s) const
 set motor direction to forward at speed {s}. More...

const void reverse () const
 set the motor direction to reverse. More...

const void reverse (const unsigned char s) const
 set the motor direction to reverse at speed {s}. More...

const void brake () const
 set the motor to brake. More...

const void brake (int duration) const
 set the motor to brake and delay return. More...

const void off () const
 turn the motor off this disables power and the motor coasts to a stop. More...


Private Attributes

void(* ms )(unsigned char speed)
 current velocity setting for this motor instance. More...

void(* md )(const MotorDirection dir)
 current direction setting for this motor instance. More...


Detailed Description

Motor control interface.

This class is designed to manipulate motors attached to an RCX

See also:
The other control classes: MotorPair, Sound, Lamp
Design Note
I avoided using derived classes since they were typically three times larger. Also, if one is using Motor(Motor::A), all the decision logic is optimized away in the compiler, so no extra space is used for that.

Definition at line 38 of file Motor.H.


Member Enumeration Documentation

enum Motor::Limits
 

motor speed range.

Enumeration values:
min  Minimum velocity (0).
max  Maximum velocity (255).

Definition at line 52 of file Motor.H.

enum Motor::Port
 

valid port designators.

Enumeration values:
A  RCX output pad A.
B  RCX output pad B.
C  RCX output pad C.

Definition at line 43 of file Motor.H.

Referenced by Motor(), and MotorPair::MotorPair().


Constructor & Destructor Documentation

Motor::Motor const Port    port [inline]
 

construct a motor connected to {port}.

Parameters:
port  designator of pad to which this motor is connected

Definition at line 61 of file Motor.H.

References A, B, md, motor_a_dir(), motor_a_speed(), motor_b_dir(), motor_b_speed(), motor_c_dir(), motor_c_speed(), ms, and Port.

Motor::~Motor   [inline]
 

destroy our motor instance.

Side Effects:
When the class is destroyed, the motor is turned off.

Definition at line 74 of file Motor.H.


Member Function Documentation

const void Motor::brake int    duration const [inline]
 

set the motor to brake and delay return.

Parameters:
duration  time in mSec to delay before returning
Returns:
nothing
Todo:
describe what brake means

Definition at line 124 of file Motor.H.

const void Motor::brake   const [inline]
 

set the motor to brake.

Returns:
nothing
Todo:
describe what brake means

Definition at line 117 of file Motor.H.

Referenced by MotorPair::pivotLeft(), and MotorPair::pivotRight().

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

set the motor direction.

Parameters:
dir  must be one of the MotorDirection values
Returns:
Nothing

Definition at line 87 of file Motor.H.

Referenced by MotorPair::brake(), MotorPair::direction(), MotorPair::left(), MotorPair::off(), MotorPair::pivotLeft(), MotorPair::pivotRight(), and MotorPair::right().

const void Motor::forward const unsigned char    s const [inline]
 

set motor direction to forward at speed {s}.

Parameters:
s  the desired speed. Must be between min (0) and max (255)
Returns:
Nothing

Definition at line 99 of file Motor.H.

const void Motor::forward   const [inline]
 

set motor direction to forward.

Returns:
Nothing

Definition at line 92 of file Motor.H.

const void Motor::off   const [inline]
 

turn the motor off this disables power and the motor coasts to a stop.

Returns:
nothing

Definition at line 130 of file Motor.H.

References md, MotorDirection, ms, and speed().

const void Motor::reverse const unsigned char    s const [inline]
 

set the motor direction to reverse at speed {s}.

Parameters:
s  the desired speed. Must be between min (0) and max (255)
Returns:
Nothing

Definition at line 111 of file Motor.H.

const void Motor::reverse   const [inline]
 

set the motor direction to reverse.

Returns:
Nothing

Definition at line 104 of file Motor.H.

const void Motor::speed const unsigned char    speed const [inline]
 

set the motor speed.

Parameters:
speed  the desired setting. Must be between min (0) and max (255)
Returns:
Nothing

Definition at line 81 of file Motor.H.

Referenced by off(), and MotorPair::speed().


Member Data Documentation

void(* Motor::md)(const MotorDirection dir) [private]
 

current direction setting for this motor instance.

Referenced by Motor(), and off().

void(* Motor::ms)(unsigned char speed) [private]
 

current velocity setting for this motor instance.

Referenced by Motor(), and off().


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:19 2002 for brickOS Kernel Developer by doxygen 1.2.15