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.
Modifier and Type | Method and Description |
---|---|
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 |
close()
Close the port, the port can not be used after this call.
|
void |
endSynchronization()
Complete a set of synchronized motor operations.
|
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 maximum speed that can be maintained by the regulation system based upon the
current state of the battery.
|
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 |
startSynchronization()
Begin a set of synchronized motor operations
|
void |
stop()
Causes motor to stop immediately.
|
void |
stop(boolean immediateReturn)
Causes motor to stop, pretty much
instantaneously.
|
void |
synchronizeWith(RegulatedMotor[] syncList)
Specify a set of motors that should be kept in synchronization with this one.
|
void |
waitComplete()
Wait until the current movement operation is complete (this can include
the motor stalling).
|
public static RegulatedMotor invertMotor(RegulatedMotor motor)
motor
- A RegulatedMotor, such as Motor.A.public static EncoderMotor invertMotor(EncoderMotor motor)
motor
- An EncoderMotor, such as NXTMotor.public void addListener(RegulatedMotorListener listener)
RegulatedMotor
addListener
in interface RegulatedMotor
public RegulatedMotorListener removeListener()
RegulatedMotor
removeListener
in interface RegulatedMotor
public void flt(boolean immediateReturn)
RegulatedMotor
flt
in interface RegulatedMotor
immediateReturn
- If true do not wait for the motor to actually stoppublic int getLimitAngle()
RegulatedMotor
getLimitAngle
in interface RegulatedMotor
public float getMaxSpeed()
RegulatedMotor
getMaxSpeed
in interface RegulatedMotor
public int getSpeed()
RegulatedMotor
getSpeed
in interface RegulatedMotor
public boolean isStalled()
RegulatedMotor
isStalled
in interface RegulatedMotor
public void rotate(int angle)
RegulatedMotor
rotate
in interface RegulatedMotor
angle
- by which the motor will rotate.public void rotate(int angle, boolean immediateReturn)
RegulatedMotor
rotate
in interface RegulatedMotor
angle
- through which the motor will rotateimmediateReturn
- iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.RegulatedMotor.rotate(int, boolean)
public void rotateTo(int angle)
RegulatedMotor
rotateTo
in interface RegulatedMotor
angle
- to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.public void rotateTo(int angle, boolean immediateReturn)
RegulatedMotor
rotateTo
in interface RegulatedMotor
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.public void setAcceleration(int acceleration)
RegulatedMotor
setAcceleration
in interface RegulatedMotor
public void setSpeed(int speed)
RegulatedMotor
setSpeed
in interface RegulatedMotor
speed
- in degrees per second.public void setStallThreshold(int error, int time)
RegulatedMotor
setStallThreshold
in interface RegulatedMotor
error
- The error thresholdtime
- The time that the error threshold needs to be exceeded for.public void stop(boolean immediateReturn)
RegulatedMotor
stop
in interface RegulatedMotor
immediateReturn
- if true do not wait for the motor to actually stoppublic void waitComplete()
RegulatedMotor
waitComplete
in interface RegulatedMotor
public void backward()
BaseMotor
stop()
or flt()
is called.public void flt()
BaseMotor
public void forward()
BaseMotor
stop()
or flt()
is called.public boolean isMoving()
BaseMotor
true
if the motor is moving.public void stop()
BaseMotor
public int getRotationSpeed()
Tachometer
getRotationSpeed
in interface Tachometer
public int getTachoCount()
Encoder
getTachoCount
in interface Encoder
public void resetTachoCount()
Encoder
resetTachoCount
in interface Encoder
public void rotationStarted(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)
RegulatedMotorListener
rotationStarted
in interface RegulatedMotorListener
public void rotationStopped(RegulatedMotor motor, int tachoCount, boolean stalled, long timeStamp)
RegulatedMotorListener
rotationStopped
in interface RegulatedMotorListener
public void close()
RegulatedMotor
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface RegulatedMotor
public void synchronizeWith(RegulatedMotor[] syncList)
RegulatedMotor
synchronizeWith
in interface RegulatedMotor
syncList
- an array of motors to synchronize with.public void startSynchronization()
RegulatedMotor
startSynchronization
in interface RegulatedMotor
public void endSynchronization()
RegulatedMotor
endSynchronization
in interface RegulatedMotor