icommand.platform.nxt
Class Motor

java.lang.Object
  extended by icommand.platform.nxt.Motor
All Implemented Interfaces:
NXTProtocol

public class Motor
extends java.lang.Object
implements NXTProtocol

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

Version:
0.2 4-September-2006
Author:
Brian Bagnall

Field Summary
static Motor A
          Motor A.
static Motor B
          Motor B.
static Motor C
          Motor C.
 
Fields inherited from interface icommand.nxtcomm.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, 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
 
Method Summary
 int backward()
          Causes motor to rotate backward.
 int backward(long count)
          Causes the motor to rotate backward a certain count.
 int backward(long count, boolean returnNow)
          Causes the motor to rotate backward a certain count.
 int flt()
          Stops the motor without using brakes.
 int forward()
          Causes motor to rotate forward indefinitely.
 int forward(long count)
          Causes the motor to rotate forward a certain count.
 int forward(long count, boolean returnNow)
          Causes the motor to rotate forward a certain count.
 int getBlockTacho()
          Block Tachometer Count is the count used to synchronize motors with one another.
 char getId()
          Get the ID of the motor.
 int getRotationCount()
          Returns the rotation count for the motor.
 int getTacho()
          Returns the tachometer count for the motor.
 int resetBlockTacho()
          Resets the block tachometer (docs say something about relative to the last position.)
 int resetRotationCounter()
          Resets the rotation counter.
 int rotateTo(long target)
          Rotates to a desired tacho count.
 int rotateTo(long target, boolean returnNow)
          Rotates to a desired tacho count.
 void setRegulationMode(int mode)
          This method determines if and how the motor will be regulated.
 void setSpeed(int speed)
          Changes the power to the motor.
 int stop()
          Stops the motor using brakes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A

public static final Motor A
Motor A.


B

public static final Motor B
Motor B.


C

public static final Motor C
Motor C.

Method Detail

getId

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


forward

public int forward()
Causes motor to rotate forward indefinitely.

Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

backward

public int backward()
Causes motor to rotate backward.

Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

setSpeed

public void setSpeed(int speed)
Changes the power to the motor. Currently, if motor is already turning it will not change the power until the next motor call.

Parameters:
power - - Value between 0 and 100

getTacho

public int getTacho()
Returns the tachometer count for the motor. The NXT remembers the tachometer count, even when you run a new program. The tachometer is reset to zero when the NXT is turned off.

Returns:
Tachometer count.

getRotationCount

public int getRotationCount()
Returns the rotation count for the motor. The rotation count is something like the trip odometer on your car?

Returns:
rotation count.

getBlockTacho

public int getBlockTacho()
Block Tachometer Count is the count used to synchronize motors with one another. This count is reset each time a new function is called in SyncMotors.

Returns:
Block Tachometer count.
See Also:
SyncMotors

forward

public int forward(long count,
                   boolean returnNow)
Causes the motor to rotate forward a certain count. The motor will also backtrack to the desired count when done. NOTE: This method returns almost immediately if returnNow = true.

Parameters:
count - Number of counts to rotate motor.
returnNow - When true, method returns before the rotation is complete.
Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

forward

public int forward(long count)
Causes the motor to rotate forward a certain count. This method returns after the rotation is completed. NOTE: This method monitors the tacho count and stops motor when completed, then the method returns. Due to Bluetooth lag, it overshoots the tacho target. We are working to improve this for future versions.

Parameters:
count - Number of counts to rotate motor.
Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

backward

public int backward(long count,
                    boolean returnNow)
Causes the motor to rotate backward a certain count. The motor will also backtrack to the desired count when done. NOTE: This method returns almost immediately if returnNow = true.

Parameters:
count - Number of counts to rotate motor.
returnNow - When true, method returns before the rotation is complete.
Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

backward

public int backward(long count)
Causes the motor to rotate backward a certain count. This method returns after the rotation is completed. NOTE: This method monitors the tacho count and stops when completed. Due to Bluetooth lag, it overshoots the tacho target. We are working to improve this for future versions.

Parameters:
count - Number of counts to rotate motor.
Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

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 int rotateTo(long target)
Rotates to a desired tacho count. Does not return until rotation done. Note: The tachocount can not be reset to zero.

Parameters:
target -

rotateTo

public int rotateTo(long target,
                    boolean returnNow)
Rotates to a desired tacho count. Returns before the rotation is done if you include true as the argument.

Parameters:
target -

resetRotationCounter

public int resetRotationCounter()
Resets the rotation counter.

Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

resetBlockTacho

public int resetBlockTacho()
Resets the block tachometer (docs say something about relative to the last position.)

Parameters:
relative - TRUE: position relative to last movement, FALSE: absolute position
Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

stop

public int stop()
Stops the motor using brakes.

Returns:
Error value. 0 means succcess. See icommand.nxtcomm.ErrorMessages for details.

flt

public int flt()
Stops the motor without using brakes. UNTESTED

Returns: