lejos.nxt.remote
Class RemoteMotor

java.lang.Object
  extended by lejos.nxt.remote.RemoteMotor
All Implemented Interfaces:
NXTProtocol, BaseMotor, DCMotor, Encoder, RegulatedMotor, Tachometer

public class RemoteMotor
extends Object
implements RegulatedMotor, DCMotor, NXTProtocol

Motor class. Contains three instances of Motor. Usage: Motor.A.forward(500);

Author:
Brian Bagnall

Field Summary
protected  RegulatedMotorListener listener
           
 byte turnRatio
           
 
Fields inherited from interface lejos.nxt.remote.NXTProtocol
ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, NXJ_DEFRAG, NXJ_DISCONNECT, NXJ_GET_AUTO_RUN, NXJ_GET_DEFAULT_PROGRAM, NXJ_GET_KEY_CLICK_VOLUME, NXJ_GET_SLEEP_TIME, NXJ_GET_VERSION, NXJ_GET_VOLUME, NXJ_PACKET_MODE, NXJ_SET_AUTO_RUN, NXJ_SET_DEFAULT_PROGRAM, NXJ_SET_KEY_CLICK_VOLUME, NXJ_SET_SLEEP_TIME, NXJ_SET_VOLUME, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TRANSITIONCNTMODE, WRITE
 
Constructor Summary
RemoteMotor(NXTCommand nxtCommand, int id)
           
 
Method Summary
 void addListener(RegulatedMotorListener listener)
          Currently not completely implemented in RemoteMotor!
 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 returnNow)
          Set the motor into float mode.
 void forward()
          Causes motor to rotate forward until stop() or flt() is called.
 int getBlockTacho()
          Deprecated.  
 char getId()
          Get the ID of the motor.
 int getLimitAngle()
          RegulatedMotor for NXT need this
 float getMaxSpeed()
          Returns the maximim speed of the motor.
 int getPower()
          Return the power that the motor is set to
 int getRotationCount()
          Deprecated.  
 int getRotationSpeed()
          Returns the actual speed.
 int getSpeed()
          Returns the current motor speed.
 int getTachoCount()
          Returns the tachometer count.
 boolean isMoving()
          Return true if the motor is moving.
 boolean isRotating()
          CURRENTLY NOT IMPLEMENTED! Use isMoving() for now.
 boolean isStalled()
          returns true if motor is stalled
 void regulateSpeed(boolean yes)
           
 RegulatedMotorListener removeListener()
          Removes the RegulatedMotorListener from this class.
 int resetBlockTacho()
          Deprecated.  
 void resetTachoCount()
          Reset the tachometer count.
 void rotate(int count)
          Causes motor to rotate by a specified angle.
 void rotate(int count, boolean returnNow)
          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 limitAngle)
          Causes motor to rotate to limitAngle;
Then getTachoCount should be within +- 2 degrees of the limit angle when the method returns
 void rotateTo(int limitAngle, boolean returnNow)
          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 setAcceleration(int acceleration)
          Set the required rate of acceleration degrees/s/s
 void setPower(int power)
          Sets the power of the motor
 void setRegulationMode(int mode)
          This method determines if and how the motor will be regulated.
 void setSpeed(int speed)
          Set motor speed.
 void setStallThreshold(int error, int time)
          Set the parameters for detecting a stalled motor.
 void smoothAcceleration(boolean yes)
           
 void stop()
          Causes motor to stop immediately.
 void stop(boolean returnNow)
          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
 

Field Detail

turnRatio

public byte turnRatio

listener

protected RegulatedMotorListener listener
Constructor Detail

RemoteMotor

public RemoteMotor(NXTCommand nxtCommand,
                   int id)
Method Detail

getId

public final char getId()
Get the ID of the motor. One of 'A', 'B' or 'C'.


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

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

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.

setPower

public void setPower(int power)
Sets the power of the motor

Specified by:
setPower in interface DCMotor
Parameters:
power - the power (-100 to +100)

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

getPower

public int getPower()
Return the power that the motor is set to

Specified by:
getPower in interface DCMotor
Returns:
the power (-100 to +100)

getTachoCount

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

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

getRotationCount

@Deprecated
public int getRotationCount()
Deprecated. 

Returns the rotation count for the motor. The rotation count is something like the trip odometer on your car. This count is reset each time a new function is called in Pilot.

Returns:
rotation count.

getBlockTacho

@Deprecated
public int getBlockTacho()
Deprecated. 

Block Encoder Count is the count used to synchronize motors with one another. NOTE: If you are using leJOS NXJ firmware this will always return 0 because this variable is not used in in leJOS NXJ firmware. Use getRotationCount() instead.

Returns:
Block Encoder count.

rotate

public void rotate(int count,
                   boolean returnNow)
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:
count - through which the motor will rotate
returnNow - iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.
See Also:
RegulatedMotor.rotate(int, boolean)

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.

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

isRotating

public boolean isRotating()
CURRENTLY NOT IMPLEMENTED! Use isMoving() for now. returns true when motor is rotating toward a specified angle


rotate

public void rotate(int count)
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:
count - by which the motor will rotate.

setRegulationMode

public void setRegulationMode(int mode)
This method determines if and how the motor will be regulated. REGULATION_MODE_IDLE turns off regulation REGULATION_MODE_MOTOR_SPEED regulates the speed (I think) REGULATION_MODE_MOTOR_SYNC synchronizes this and any other motor with SYNC enabled.

Parameters:
mode - See NXTProtocol for enumerations: REGULATION_MODE_MOTOR_SYNC, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_IDLE

rotateTo

public void rotateTo(int limitAngle)
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:
limitAngle - 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 limitAngle,
                     boolean returnNow)
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:
limitAngle - to which the motor will rotate, and then stop (in degrees). Includes any positive or negative int, even values > 360.
returnNow - iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.

getLimitAngle

public int getLimitAngle()
RegulatedMotor for NXT need this

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

resetTachoCount

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

Specified by:
resetTachoCount in interface Encoder

resetBlockTacho

@Deprecated
public int resetBlockTacho()
Deprecated. 

Resets the block tachometer. NOTE: If you are using leJOS NXJ firmware this will not do anything because BlockTacho is not used in the leJOS NXJ firmware. Use resetRotationCounter() instead.

Returns:
Error value. 0 means success. See lejos.pc.comm.ErrorMessages for details.

stop

public void stop(boolean returnNow)
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:
returnNow - if true do not wait for the motor to actually stop

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

flt

public void flt(boolean returnNow)
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:
returnNow - If true do not wait for the motor to actually stop

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

regulateSpeed

public void regulateSpeed(boolean yes)

smoothAcceleration

public void smoothAcceleration(boolean yes)

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

addListener

public void addListener(RegulatedMotorListener listener)
Currently not completely implemented in RemoteMotor!

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.

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

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

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.

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.