lejos.nxt.remote
Class RemoteMotor
java.lang.Object
lejos.nxt.remote.RemoteMotor
- All Implemented Interfaces:
- NXTProtocol, DCMotor, Encoder, Tachometer, TachoMotor
public class RemoteMotor
- extends Object
- implements TachoMotor, NXTProtocol
Motor class. Contains three instances of Motor.
Usage: Motor.A.forward(500);
- Author:
- Brian Bagnall
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_FIND_FIRST, NXJ_FIND_NEXT, NXJ_PACKET_MODE, 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 |
void |
backward()
Causes motor to rotate backwards until stop is called. |
void |
flt()
Motor loses all power, causing the rotor to float freely to a stop. |
void |
forward()
Causes motor to rotate forward until stop is called. |
int |
getBlockTacho()
Deprecated. |
char |
getId()
Get the ID 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 if the motor is moving. |
boolean |
isRotating()
CURRENTLY NOT IMPLEMENTED! Use isMoving() for now. |
void |
regulateSpeed(boolean yes)
Turns speed regulation on/off. |
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 |
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 |
smoothAcceleration(boolean yes)
Enables smoother acceleration. |
void |
stop()
Causes motor to stop immediately. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
turnRatio
public byte turnRatio
RemoteMotor
public RemoteMotor(NXTCommand nxtCommand,
int id)
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:
DCMotor
- Causes motor to rotate forward until stop is called.
- Specified by:
forward
in interface DCMotor
backward
public void backward()
- Description copied from interface:
DCMotor
- Causes motor to rotate backwards until stop is called.
- Specified by:
backward
in interface DCMotor
setSpeed
public void setSpeed(int speed)
- Description copied from interface:
TachoMotor
- Set motor speed. As a rule of thumb 100 degrees per second are possible for each volt on an NXT motor.
- Specified by:
setSpeed
in interface TachoMotor
- Parameters:
speed
- in degrees per second.
setPower
public void setPower(int power)
- Sets the power of the motor
- Parameters:
power
- the power (-100 to +100)
getSpeed
public int getSpeed()
- Description copied from interface:
TachoMotor
- Returns the current motor speed.
- Specified by:
getSpeed
in interface TachoMotor
- Returns:
- motor speed in degrees per second
getPower
public int getPower()
- Return the power that the motor is set to
- 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
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
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:
TachoMotor
- 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 isRotating() returns false;
- Specified by:
rotate
in interface TachoMotor
- Parameters:
count
- through which the motor will rotatereturnNow
- iff true, method returns immediately, thus allowing monitoring of sensors in the calling thread.- See Also:
TachoMotor.rotate(int, boolean)
isMoving
public boolean isMoving()
- Description copied from interface:
DCMotor
- Return if the motor is moving.
- Specified by:
isMoving
in interface DCMotor
- Returns:
- true if the motor is currently in motion
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:
TachoMotor
- 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 TachoMotor
- 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:
TachoMotor
- 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 TachoMotor
- 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:
TachoMotor
- 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 isRotating() returns false;
- Specified by:
rotateTo
in interface TachoMotor
- 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.
resetTachoCount
public void resetTachoCount()
- Description copied from interface:
Encoder
- Reset the tachometer count.
- Specified by:
resetTachoCount
in interface Encoder
resetBlockTacho
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()
- Description copied from interface:
DCMotor
- Causes motor to stop immediately. It will resist any further motion. Cancels any rotate() orders in progress.
- Specified by:
stop
in interface DCMotor
flt
public void flt()
- Description copied from interface:
DCMotor
- 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 DCMotor
regulateSpeed
public void regulateSpeed(boolean yes)
- Description copied from interface:
TachoMotor
- Turns speed regulation on/off. Cumulative speed error is within about 1 degree after initial acceleration on the
NXT.
- Specified by:
regulateSpeed
in interface TachoMotor
- Parameters:
yes
- is true for speed regulation.
smoothAcceleration
public void smoothAcceleration(boolean yes)
- Description copied from interface:
TachoMotor
- Enables smoother acceleration. Motor speed increases gently, and does not overshoot when regulate Speed is used.
- Specified by:
smoothAcceleration
in interface TachoMotor
- Parameters:
yes
- is true for smooth acceleration.
getRotationSpeed
public int getRotationSpeed()
- Description copied from interface:
Tachometer
- Returns the actual speed. This value is calculated every 100 ms on the NXT.
TODO: getRotationSpeed() is an alternate method name, but then we are again competing with Motor.getSpeed()
- Specified by:
getRotationSpeed
in interface Tachometer
- Returns:
- speed in degrees per second, negative value means motor is rotating backward