lejos.robotics
Class MirrorMotor

java.lang.Object
  extended by lejos.robotics.MirrorMotor
All Implemented Interfaces:
BaseMotor, Encoder, RegulatedMotor, RegulatedMotorListener, Tachometer

public class MirrorMotor
extends java.lang.Object
implements RegulatedMotor, RegulatedMotorListener

This class returns a motor that rotates in the reverse direction of a regular motor. All tachometer readings are also reversed.

Use the factory method MirrorMotor.invertMotor(RegulatedMotor) to retrieve an inverted motor.

Author:
BB

Method Summary
 void addListener(RegulatedMotorListener listener)
          Adds a listener object that will be notified when rotation has started or stopped
 void backward()
          Causes motor to rotate backwards until stop() or flt() is called.
 void flt()
          Motor loses all power, causing the rotor to float freely to a stop.
 void flt(boolean immediateReturn)
          Set the motor into float mode.
 void forward()
          Causes motor to rotate forward until stop() or flt() is called.
 int getLimitAngle()
          Return the limit angle (if any)
 float getMaxSpeed()
          Returns the maximim speed of the motor.
 int getRotationSpeed()
          Returns the actual speed.
 int getSpeed()
          Returns the current motor speed.
 int getTachoCount()
          Returns the tachometer count.
static EncoderMotor invertMotor(EncoderMotor motor)
          Returns an inverted EncoderMotor.
static RegulatedMotor invertMotor(RegulatedMotor motor)
          Returns an inverted RegulatedMotor.
 boolean isMoving()
          Return true if the motor is moving.
 boolean isStalled()
          returns true if motor is stalled
 RegulatedMotorListener removeListener()
          Removes the RegulatedMotorListener from this class.
 void resetTachoCount()
          Reset the tachometer count.
 void rotate(int angle)
          Causes motor to rotate by a specified angle.
 void rotate(int angle, boolean immediateReturn)
          causes motor to rotate through angle;
iff immediateReturn is true, method returns immediately and the motor stops by itself
If any motor method is called before the limit is reached, the rotation is canceled.
 void rotateTo(int angle)
          Causes motor to rotate to limitAngle;
Then getTachoCount should be within +- 2 degrees of the limit angle when the method returns
 void rotateTo(int angle, boolean immediateReturn)
          causes motor to rotate to limitAngle;
if immediateReturn is true, method returns immediately and the motor stops by itself
and getTachoCount should be within +- 2 degrees if the limit angle If any motor method is called before the limit is reached, the rotation is canceled.
 void rotationStarted(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)
          Called when the motor starts rotating.
 void rotationStopped(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)
          Called when the motor stops rotating.
 void setAcceleration(int acceleration)
          Set the required rate of acceleration degrees/s/s
 void setSpeed(int speed)
          Set motor speed.
 void setStallThreshold(int error, int time)
          Set the parameters for detecting a stalled motor.
 void stop()
          Causes motor to stop immediately.
 void stop(boolean immediateReturn)
          Causes motor to stop, pretty much instantaneously.
 void waitComplete()
          Wait until the current movement operation is complete (this can include the motor stalling).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

invertMotor

public static RegulatedMotor invertMotor(RegulatedMotor motor)
Returns an inverted RegulatedMotor.

Parameters:
motor - A RegulatedMotor, such as Motor.A.
Returns:
An inverted RegulatedMotor.

invertMotor

public static EncoderMotor invertMotor(EncoderMotor motor)
Returns an inverted EncoderMotor.

Parameters:
motor - An EncoderMotor, such as NXTMotor.
Returns:
An inverted EncoderMotor.

addListener

public void addListener(RegulatedMotorListener listener)
Description copied from interface: RegulatedMotor
Adds a listener object that will be notified when rotation has started or stopped

Specified by:
addListener in interface RegulatedMotor

removeListener

public RegulatedMotorListener removeListener()
Description copied from interface: RegulatedMotor
Removes the RegulatedMotorListener from this class.

Specified by:
removeListener in interface RegulatedMotor
Returns:
The RegulatedMotorListener that was removed, if any. Null if none existed.

flt

public void flt(boolean immediateReturn)
Description copied from interface: RegulatedMotor
Set the motor into float mode. This will stop the motor without braking and the position of the motor will not be maintained.

Specified by:
flt in interface RegulatedMotor
Parameters:
immediateReturn - If true do not wait for the motor to actually stop

getLimitAngle

public int getLimitAngle()
Description copied from interface: RegulatedMotor
Return the limit angle (if any)

Specified by:
getLimitAngle in interface RegulatedMotor
Returns:
the current limit angle

getMaxSpeed

public float getMaxSpeed()
Description copied from interface: RegulatedMotor
Returns the maximim speed of the motor.

Specified by:
getMaxSpeed in interface RegulatedMotor
Returns:
the maximum speed of the Motor in degrees per second.

getSpeed

public int getSpeed()
Description copied from interface: RegulatedMotor
Returns the current motor speed.

Specified by:
getSpeed in interface RegulatedMotor
Returns:
motor speed in degrees per second

isStalled

public boolean isStalled()
Description copied from interface: RegulatedMotor
returns true if motor is stalled

Specified by:
isStalled in interface RegulatedMotor
Returns:
true if stalled

rotate

public void rotate(int angle)
Description copied from interface: RegulatedMotor
Causes motor to rotate by a specified angle. The resulting tachometer count should be within +- 2 degrees on the NXT. This method does not return until the rotation is completed.

Specified by:
rotate in interface RegulatedMotor
Parameters:
angle - by which the motor will rotate.

rotate

public void rotate(int angle,
                   boolean immediateReturn)
Description copied from interface: RegulatedMotor
causes motor to rotate through angle;
iff immediateReturn is true, method returns immediately and the motor stops by itself
If any motor method is called before the limit is reached, the rotation is canceled. When the angle is reached, the method isMoving() returns false;

Specified by:
rotate in interface RegulatedMotor
Parameters:
angle - through which the motor will rotate
immediateReturn - iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.
See Also:
RegulatedMotor.rotate(int, boolean)

rotateTo

public void rotateTo(int angle)
Description copied from interface: RegulatedMotor
Causes motor to rotate to limitAngle;
Then getTachoCount should be within +- 2 degrees of the limit angle when the method returns

Specified by:
rotateTo in interface RegulatedMotor
Parameters:
angle - to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.

rotateTo

public void rotateTo(int angle,
                     boolean immediateReturn)
Description copied from interface: RegulatedMotor
causes motor to rotate to limitAngle;
if immediateReturn is true, method returns immediately and the motor stops by itself
and getTachoCount should be within +- 2 degrees if the limit angle If any motor method is called before the limit is reached, the rotation is canceled. When the angle is reached, the method isMoving() returns false;

Specified by:
rotateTo in interface RegulatedMotor
Parameters:
angle - to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.
immediateReturn - iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.

setAcceleration

public void setAcceleration(int acceleration)
Description copied from interface: RegulatedMotor
Set the required rate of acceleration degrees/s/s

Specified by:
setAcceleration in interface RegulatedMotor

setSpeed

public void setSpeed(int speed)
Description copied from interface: RegulatedMotor
Set motor speed. As a rule of thumb 100 degrees per second are possible for each volt on an NXT motor. Therefore, disposable alkaline batteries can achieve a top speed of 900 deg/sec, while a rechargable lithium battery pack can achieve 740 deg/sec.

Specified by:
setSpeed in interface RegulatedMotor
Parameters:
speed - in degrees per second.

setStallThreshold

public void setStallThreshold(int error,
                              int time)
Description copied from interface: RegulatedMotor
Set the parameters for detecting a stalled motor. A motor will be recognized as stalled if the movement error (the amount the motor lags the regulated position) is greater than error for a period longer than time.

Specified by:
setStallThreshold in interface RegulatedMotor
Parameters:
error - The error threshold
time - The time that the error threshold needs to be exceeded for.

stop

public void stop(boolean immediateReturn)
Description copied from interface: RegulatedMotor
Causes motor to stop, pretty much instantaneously. In other words, the motor doesn't just stop; it will resist any further motion. Cancels any rotate() orders in progress

Specified by:
stop in interface RegulatedMotor
Parameters:
immediateReturn - if true do not wait for the motor to actually stop

waitComplete

public void waitComplete()
Description copied from interface: RegulatedMotor
Wait until the current movement operation is complete (this can include the motor stalling).

Specified by:
waitComplete in interface RegulatedMotor

backward

public void backward()
Description copied from interface: BaseMotor
Causes motor to rotate backwards until stop() or flt() is called.

Specified by:
backward in interface BaseMotor

flt

public void flt()
Description copied from interface: BaseMotor
Motor loses all power, causing the rotor to float freely to a stop. This is not the same as stopping, which locks the rotor.

Specified by:
flt in interface BaseMotor

forward

public void forward()
Description copied from interface: BaseMotor
Causes motor to rotate forward until stop() or flt() is called.

Specified by:
forward in interface BaseMotor

isMoving

public boolean isMoving()
Description copied from interface: BaseMotor
Return true if the motor is moving.

Specified by:
isMoving in interface BaseMotor
Returns:
true if the motor is currently in motion, false if stopped.

stop

public void stop()
Description copied from interface: BaseMotor
Causes motor to stop immediately. It will resist any further motion. Cancels any rotate() orders in progress.

Specified by:
stop in interface BaseMotor

getRotationSpeed

public int getRotationSpeed()
Description copied from interface: Tachometer
Returns the actual speed.

Specified by:
getRotationSpeed in interface Tachometer
Returns:
speed in degrees per second, negative value means motor is rotating backward

getTachoCount

public int getTachoCount()
Description copied from interface: Encoder
Returns the tachometer count.

Specified by:
getTachoCount in interface Encoder
Returns:
tachometer count in degrees

resetTachoCount

public void resetTachoCount()
Description copied from interface: Encoder
Reset the tachometer count.

Specified by:
resetTachoCount in interface Encoder

rotationStarted

public void rotationStarted(RegulatedMotor motor,
                            int tachoCount,
                            boolean stalled,
                            long timeStamp)
Description copied from interface: RegulatedMotorListener
Called when the motor starts rotating.

Specified by:
rotationStarted in interface RegulatedMotorListener

rotationStopped

public void rotationStopped(RegulatedMotor motor,
                            int tachoCount,
                            boolean stalled,
                            long timeStamp)
Description copied from interface: RegulatedMotorListener
Called when the motor stops rotating. This includes both Motor.stop() which locks the shaft, and Motor.flt() in which the shaft floats freely after power is cut to the motor. Beware: In the second case, it's possible the tachomoter reading will continue changing after notification.

Specified by:
rotationStopped in interface RegulatedMotorListener