Motor Class Reference

#include <c++/Motor.H>

Public Types

enum  Port { A, B, C }
 valid port designators More...
 
enum  Limits { min = 0, max = 255 }
 motor speed range More...
 

Public Member Functions

 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...
 

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

◆ Limits

motor speed range

Enumerator
min 

Minimum velocity (0)

max 

Maximum velocity (255)

Definition at line 52 of file Motor.H.

◆ Port

valid port designators

Enumerator

RCX output pad A.

RCX output pad B.

RCX output pad C.

Definition at line 43 of file Motor.H.

Constructor & Destructor Documentation

◆ Motor()

Motor::Motor ( const Port  port)
inline

construct a motor connected to {port}

Parameters
portdesignator of pad to which this motor is connected

Definition at line 61 of file Motor.H.

◆ ~Motor()

Motor::~Motor ( )
inline

destroy our motor instance

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

Definition at line 73 of file Motor.H.

References off().

Member Function Documentation

◆ brake() [1/2]

const void Motor::brake ( ) const
inline

set the motor to brake

Returns
nothing
Todo:
describe what brake means

Definition at line 116 of file Motor.H.

References direction().

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

◆ brake() [2/2]

const void Motor::brake ( int  duration) const
inline

set the motor to brake and delay return

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

Definition at line 123 of file Motor.H.

References brake(), and delay().

Referenced by brake().

◆ direction()

const void Motor::direction ( const MotorDirection  dir) const
inline

set the motor direction

Parameters
dirmust be one of the MotorDirection values
Returns
Nothing

Definition at line 86 of file Motor.H.

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

◆ forward() [1/2]

const void Motor::forward ( ) const
inline

set motor direction to forward

Returns
Nothing

Definition at line 91 of file Motor.H.

References direction(), and fwd.

◆ forward() [2/2]

const void Motor::forward ( const unsigned char  s) const
inline

set motor direction to forward at speed {s}

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

Definition at line 98 of file Motor.H.

References forward(), and speed().

Referenced by forward().

◆ off()

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 129 of file Motor.H.

References direction().

Referenced by ~Motor().

◆ reverse() [1/2]

const void Motor::reverse ( ) const
inline

set the motor direction to reverse

Returns
Nothing

Definition at line 103 of file Motor.H.

References direction(), and rev.

◆ reverse() [2/2]

const void Motor::reverse ( const unsigned char  s) const
inline

set the motor direction to reverse at speed {s}

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

Definition at line 110 of file Motor.H.

References reverse(), and speed().

Referenced by reverse().

◆ speed()

const void Motor::speed ( const unsigned char  speed) const
inline

set the motor speed

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

Definition at line 80 of file Motor.H.

References speed().

Referenced by forward(), reverse(), MotorPair::speed(), and speed().


The documentation for this class was generated from the following file:

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