Package lejos.robotics
Class MirrorMotor
- java.lang.Object
-
- lejos.robotics.MirrorMotor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(RegulatedMotorListener listener)Adds a listener object that will be notified when rotation has started or stoppedvoidbackward()Causes motor to rotate backwards untilstop()orflt()is called.voidclose()Close the port, the port can not be used after this call.voidendSynchronization()Complete a set of synchronized motor operations.voidflt()Motor loses all power, causing the rotor to float freely to a stop.voidflt(boolean immediateReturn)Set the motor into float mode.voidforward()Causes motor to rotate forward untilstop()orflt()is called.intgetLimitAngle()Return the limit angle (if any)floatgetMaxSpeed()Returns the maximum speed that can be maintained by the regulation system based upon the current state of the battery.intgetRotationSpeed()Returns the actual speed.intgetSpeed()Returns the current motor speed.intgetTachoCount()Returns the tachometer count.static EncoderMotorinvertMotor(EncoderMotor motor)Returns an inverted EncoderMotor.static RegulatedMotorinvertMotor(RegulatedMotor motor)Returns an inverted RegulatedMotor.booleanisMoving()Returntrueif the motor is moving.booleanisStalled()returns true if motor is stalledRegulatedMotorListenerremoveListener()Removes the RegulatedMotorListener from this class.voidresetTachoCount()Reset the tachometer count.voidrotate(int angle)Causes motor to rotate by a specified angle.voidrotate(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.voidrotateTo(int angle)Causes motor to rotate to limitAngle;
Then getTachoCount should be within +- 2 degrees of the limit angle when the method returnsvoidrotateTo(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.voidrotationStarted(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)Called when the motor starts rotating.voidrotationStopped(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)Called when the motor stops rotating.voidsetAcceleration(int acceleration)Set the required rate of acceleration degrees/s/svoidsetSpeed(int speed)Set motor speed.voidsetStallThreshold(int error, int time)Set the parameters for detecting a stalled motor.voidstartSynchronization()Begin a set of synchronized motor operationsvoidstop()Causes motor to stop immediately.voidstop(boolean immediateReturn)Causes motor to stop, pretty much instantaneously.voidsynchronizeWith(RegulatedMotor[] syncList)Specify a set of motors that should be kept in synchronization with this one.voidwaitComplete()Wait until the current movement operation is complete (this can include the motor stalling).
-
-
-
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:RegulatedMotorAdds a listener object that will be notified when rotation has started or stopped- Specified by:
addListenerin interfaceRegulatedMotor
-
removeListener
public RegulatedMotorListener removeListener()
Description copied from interface:RegulatedMotorRemoves the RegulatedMotorListener from this class.- Specified by:
removeListenerin interfaceRegulatedMotor- Returns:
- The RegulatedMotorListener that was removed, if any. Null if none existed.
-
flt
public void flt(boolean immediateReturn)
Description copied from interface:RegulatedMotorSet the motor into float mode. This will stop the motor without braking and the position of the motor will not be maintained.- Specified by:
fltin interfaceRegulatedMotor- Parameters:
immediateReturn- If true do not wait for the motor to actually stop
-
getLimitAngle
public int getLimitAngle()
Description copied from interface:RegulatedMotorReturn the limit angle (if any)- Specified by:
getLimitAnglein interfaceRegulatedMotor- Returns:
- the current limit angle
-
getMaxSpeed
public float getMaxSpeed()
Description copied from interface:RegulatedMotorReturns the maximum speed that can be maintained by the regulation system based upon the current state of the battery.- Specified by:
getMaxSpeedin interfaceRegulatedMotor- Returns:
- the maximum speed of the Motor in degrees per second.
-
getSpeed
public int getSpeed()
Description copied from interface:RegulatedMotorReturns the current motor speed.- Specified by:
getSpeedin interfaceRegulatedMotor- Returns:
- motor speed in degrees per second
-
isStalled
public boolean isStalled()
Description copied from interface:RegulatedMotorreturns true if motor is stalled- Specified by:
isStalledin interfaceRegulatedMotor- Returns:
- true if stalled
-
rotate
public void rotate(int angle)
Description copied from interface:RegulatedMotorCauses 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:
rotatein interfaceRegulatedMotor- Parameters:
angle- by which the motor will rotate.
-
rotate
public void rotate(int angle, boolean immediateReturn)Description copied from interface:RegulatedMotorcauses 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:
rotatein interfaceRegulatedMotor- Parameters:
angle- through which the motor will rotateimmediateReturn- 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:RegulatedMotorCauses motor to rotate to limitAngle;
Then getTachoCount should be within +- 2 degrees of the limit angle when the method returns- Specified by:
rotateToin interfaceRegulatedMotor- 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:RegulatedMotorcauses 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:
rotateToin interfaceRegulatedMotor- 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:RegulatedMotorSet the required rate of acceleration degrees/s/s- Specified by:
setAccelerationin interfaceRegulatedMotor
-
setSpeed
public void setSpeed(int speed)
Description copied from interface:RegulatedMotorSet 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:
setSpeedin interfaceRegulatedMotor- Parameters:
speed- in degrees per second.
-
setStallThreshold
public void setStallThreshold(int error, int time)Description copied from interface:RegulatedMotorSet 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:
setStallThresholdin interfaceRegulatedMotor- Parameters:
error- The error thresholdtime- The time that the error threshold needs to be exceeded for.
-
stop
public void stop(boolean immediateReturn)
Description copied from interface:RegulatedMotorCauses 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:
stopin interfaceRegulatedMotor- Parameters:
immediateReturn- if true do not wait for the motor to actually stop
-
waitComplete
public void waitComplete()
Description copied from interface:RegulatedMotorWait until the current movement operation is complete (this can include the motor stalling).- Specified by:
waitCompletein interfaceRegulatedMotor
-
backward
public void backward()
Description copied from interface:BaseMotorCauses motor to rotate backwards untilstop()orflt()is called.
-
flt
public void flt()
Description copied from interface:BaseMotorMotor loses all power, causing the rotor to float freely to a stop. This is not the same as stopping, which locks the rotor.
-
forward
public void forward()
Description copied from interface:BaseMotorCauses motor to rotate forward untilstop()orflt()is called.
-
isMoving
public boolean isMoving()
Description copied from interface:BaseMotorReturntrueif the motor is moving.
-
stop
public void stop()
Description copied from interface:BaseMotorCauses motor to stop immediately. It will resist any further motion. Cancels any rotate() orders in progress.
-
getRotationSpeed
public int getRotationSpeed()
Description copied from interface:TachometerReturns the actual speed.- Specified by:
getRotationSpeedin interfaceTachometer- Returns:
- speed in degrees per second, negative value means motor is rotating backward
-
getTachoCount
public int getTachoCount()
Description copied from interface:EncoderReturns the tachometer count.- Specified by:
getTachoCountin interfaceEncoder- Returns:
- tachometer count in degrees
-
resetTachoCount
public void resetTachoCount()
Description copied from interface:EncoderReset the tachometer count.- Specified by:
resetTachoCountin interfaceEncoder
-
rotationStarted
public void rotationStarted(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)
Description copied from interface:RegulatedMotorListenerCalled when the motor starts rotating.- Specified by:
rotationStartedin interfaceRegulatedMotorListener
-
rotationStopped
public void rotationStopped(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)
Description copied from interface:RegulatedMotorListenerCalled 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:
rotationStoppedin interfaceRegulatedMotorListener
-
close
public void close()
Description copied from interface:RegulatedMotorClose the port, the port can not be used after this call.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceRegulatedMotor
-
synchronizeWith
public void synchronizeWith(RegulatedMotor[] syncList)
Description copied from interface:RegulatedMotorSpecify a set of motors that should be kept in synchronization with this one. The synchronization mechanism simply ensures that operations between a startSynchronization call and an endSynchronization call will all be executed at the same time (when the endSynchronization method is called). This is all that is needed to ensure that motors will operate in a synchronized fashion. The start/end methods can also be used to ensure that reads of the motor state will also be consistent.- Specified by:
synchronizeWithin interfaceRegulatedMotor- Parameters:
syncList- an array of motors to synchronize with.
-
startSynchronization
public void startSynchronization()
Description copied from interface:RegulatedMotorBegin a set of synchronized motor operations- Specified by:
startSynchronizationin interfaceRegulatedMotor
-
endSynchronization
public void endSynchronization()
Description copied from interface:RegulatedMotorComplete a set of synchronized motor operations.- Specified by:
endSynchronizationin interfaceRegulatedMotor
-
-