lejos.nxt.addon.tetrix
Class TetrixRegulatedMotor

java.lang.Object
  extended by lejos.nxt.addon.tetrix.TetrixMotor
      extended by lejos.nxt.addon.tetrix.TetrixEncoderMotor
          extended by lejos.nxt.addon.tetrix.TetrixRegulatedMotor
All Implemented Interfaces:
BaseMotor, DCMotor, Encoder, RegulatedMotor, Tachometer

public class TetrixRegulatedMotor
extends TetrixEncoderMotor
implements RegulatedMotor

Tetrix DC motor abstraction with encoder support that implements RegulatedMotor. The Tetrix motor must have an encoder installed and connected to the controller for the methods in this class to work. If an encoder is not installed, use the TetrixMotor class instead.

Use TetrixMotorController.getRegulatedMotor(int) to retrieve a TetrixRegulatedMotor instance.

Author:
Kirk P. Thompson

Constructor Summary
TetrixRegulatedMotor(TetrixMotorController mc, int channel)
           
 
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(boolean immediateReturn)
          Set the motor into float mode.
 void forward()
          Causes motor to rotate forward until stop() or flt() is called.
 float getMaxSpeed()
          NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.
 int getRotationSpeed()
          Return the current rotational speed calculated from the encoder position every 100 ms.
 int getSpeed()
          Return the speed value calculated from the actual power value as:
 boolean isStalled()
          NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.
 RegulatedMotorListener removeListener()
          Removes the RegulatedMotorListener from this class.
 void rotate(int angle)
          Rotate by the requested number of degrees while blocking until completion.
 void rotate(int degrees, boolean immediateReturn)
          Rotate by the requested number of degrees with option for wait until completion or immediate return where the motor completes its rotation asynchronously.
 void rotateTo(int limitAngle)
          Rotate to the target angle while blocking until completion.
 void rotateTo(int limitAngle, boolean immediateReturn)
          Rotate to the target angle with option for wait until completion or immediate return where the motor completes its rotation asynchronously.
 void setAcceleration(int acceleration)
          NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.
 void setRegulate(boolean regulate)
          OVERRIDDEN TO NOT ALLOW CHANGE OF REGULATED STATE as the TetrixRegulatedMotor class must use regulation.
 void setSpeed(int speed)
          Sets desired motor speed, in degrees per second.
 void setStallThreshold(int error, int time)
          NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.
 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 lejos.nxt.addon.tetrix.TetrixEncoderMotor
getLimitAngle, getTachoCount, resetTachoCount
 
Methods inherited from class lejos.nxt.addon.tetrix.TetrixMotor
flt, getPower, isMoving, setPower, setReverse, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface lejos.robotics.RegulatedMotor
getLimitAngle
 
Methods inherited from interface lejos.robotics.BaseMotor
flt, isMoving, stop
 
Methods inherited from interface lejos.robotics.Encoder
getTachoCount, resetTachoCount
 

Constructor Detail

TetrixRegulatedMotor

public TetrixRegulatedMotor(TetrixMotorController mc,
                            int channel)
Method Detail

setRegulate

public void setRegulate(boolean regulate)
OVERRIDDEN TO NOT ALLOW CHANGE OF REGULATED STATE as the TetrixRegulatedMotor class must use regulation. Motors are always in regulated mode when using the TetrixRegulatedMotor class.

Overrides:
setRegulate in class TetrixEncoderMotor
Parameters:
regulate - Ignored

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.

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

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

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

rotate

public void rotate(int angle)
Rotate by the requested number of degrees while blocking until completion.

Specified by:
rotate in interface RegulatedMotor
Parameters:
angle - number of degrees to rotate relative to the current position.

rotate

public void rotate(int degrees,
                   boolean immediateReturn)
Description copied from class: TetrixEncoderMotor
Rotate by the requested number of degrees with option for wait until completion or immediate return where the motor completes its rotation asynchronously.

Specified by:
rotate in interface RegulatedMotor
Overrides:
rotate in class TetrixEncoderMotor
Parameters:
degrees - number of degrees to rotate relative to the current position.
immediateReturn - if true, do not wait for the move to complete. false will block until the rotation completes.
See Also:
RegulatedMotor.rotate(int, boolean)

rotateTo

public void rotateTo(int limitAngle)
Rotate to the target angle while blocking until completion.

Specified by:
rotateTo in interface RegulatedMotor
Parameters:
limitAngle - Angle [in degrees] to rotate to.

rotateTo

public void rotateTo(int limitAngle,
                     boolean immediateReturn)
Description copied from class: TetrixEncoderMotor
Rotate to the target angle with option for wait until completion or immediate return where the motor completes its rotation asynchronously.

Specified by:
rotateTo in interface RegulatedMotor
Overrides:
rotateTo in class TetrixEncoderMotor
Parameters:
limitAngle - Angle [in degrees] to rotate to.
immediateReturn - if true, do not wait for the move to complete. false will block until the rotation completes.

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
Overrides:
forward in class TetrixMotor

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
Overrides:
backward in class TetrixMotor

setSpeed

public void setSpeed(int speed)
Sets desired motor speed, in degrees per second. Since the TETRIX Motor Controller only has power adjustment, the power value is derived from the passed speed value as:
  power = Math.round((speed - 0.5553f) * 0.102247398f);
and as such, the actual speed value will not be exact.

The maximum reliably sustainable velocity for the TETRIX DC Gear motor P/N 739023 (which was used as the test case for creating this class) is 154 RPM => 924 degs/sec.

Specified by:
setSpeed in interface RegulatedMotor
Parameters:
speed - value in degrees/sec
See Also:
getSpeed()

getSpeed

public int getSpeed()
Return the speed value calculated from the actual power value as:
  speed = Math.round(9.7802f * super.getPower() + 0.5553f);
and as such, the actual speed value may not be what was set with setSpeed.

Specified by:
getSpeed in interface RegulatedMotor
Returns:
The speed value (converted from power value) in degrees/sec
See Also:
setSpeed(int)

getRotationSpeed

public int getRotationSpeed()
Return the current rotational speed calculated from the encoder position every 100 ms. This will likely differ from what was specified in setSpeed.

Specified by:
getRotationSpeed in interface Tachometer
Returns:
The current rotational speed in deg/sec

getMaxSpeed

public float getMaxSpeed()
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.

Specified by:
getMaxSpeed in interface RegulatedMotor
Returns:
Always 924 degrees/sec

isStalled

public boolean isStalled()
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.

Specified by:
isStalled in interface RegulatedMotor
Returns:
Always false

setStallThreshold

public void setStallThreshold(int error,
                              int time)
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.

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

setAcceleration

public void setAcceleration(int acceleration)
NOT IMPLEMENTED as the TEXTRIX motor controller does not support this command.

Specified by:
setAcceleration in interface RegulatedMotor
Parameters:
acceleration - Ignored