public class Motor extends Part
ABOUT, ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, 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_FIND_FIRST, NXJ_FIND_NEXT, 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, TITLE, TITLEMP, TRANSITIONCNTMODE, VERSION, WRITE
Constructor and Description |
---|
Motor(MotorPort port)
Creates a motor instance that is plugged into given port.
|
Modifier and Type | Method and Description |
---|---|
void |
addMotionListener(MotionListener motionListener)
Registers the given motion listener.
|
Motor |
backward()
Starts the backward rotation with preset speed.
|
Motor |
continueRelativeTo(int count)
Same as rotateTo(int count), but the rotation counter
is not set to zero.
|
Motor |
continueRelativeTo(int count,
boolean blocking)
Same as rotateTo(int count, boolean blocking), but the rotation counter
is not set to zero.
|
Motor |
continueTo(int count)
Same as rotateTo(int count), but the rotation counter
is not set to zero.
|
Motor |
continueTo(int count,
boolean blocking)
Same as rotateTo(int count, boolean blocking), but the rotation counter
is not set to zero.
|
Motor |
forward()
Starts the forward rotation with preset speed.
|
int |
getMotorCount()
Returns current value of the rotation counter.
|
int |
getPortId()
Returns the port number.
|
java.lang.String |
getPortLabel()
Returns the port label.
|
int |
getSpeed()
Returns the current speed (arbitrary units).
|
double |
getVelocity()
Returns the current velocity.
|
boolean |
isMoving()
Checks if the motor is rotating.
|
void |
resetMotorCount()
Resets the rotation counter to zero.
|
Motor |
rotateTo(int count)
Sets the rotation counter to zero and rotates the motor until the given count is reached.
|
Motor |
rotateTo(int count,
boolean blocking)
Sets the rotation counter to zero and rotates the motor until the given count is reached.
|
Motor |
setSpeed(int speed)
Sets the speed to the given value (arbitrary units).
|
void |
setSpeedFactor(double value)
Sets the motor speed factor to given value.
|
Motor |
setVelocity(double velocity)
Sets the velocity to the given value.
|
double |
speedToVelocity(int speed)
Conversion from speed to velocity.
|
Motor |
stop()
Stops the motor.
|
int |
velocityToSpeed(double velocity)
Conversion from velocity to speed.
|
public Motor(MotorPort port)
port
- the port where the motor is plugged-in (MotorPort.A, MotorPort.B, MotorPort.C)public int getPortId()
public java.lang.String getPortLabel()
public void addMotionListener(MotionListener motionListener)
motionListener
- a reference to a MotionListenerMotionListener
,
rotateTo(int count, boolean blocking)
public Motor forward()
public Motor backward()
public Motor setSpeed(int speed)
speed
- the speed 0..100public int getSpeed()
public Motor setVelocity(double velocity)
velocity
- the velocity in m/spublic double getVelocity()
public Motor stop()
public void setSpeedFactor(double value)
value
- the velocity per speed unitpublic double speedToVelocity(int speed)
speed
- the speed as set in setSpeed()setSpeedFactor(double value)
public int velocityToSpeed(double velocity)
velocity
- the velocity in m/ssetSpeedFactor(double value)
public int getMotorCount()
public void resetMotorCount()
rotateTo(int count)
public Motor rotateTo(int count)
count
- the rotation counter value to be reachedaddMotionListener(MotionListener motionListener)
,
rotateTo(int count, boolean blocking)
public Motor rotateTo(int count, boolean blocking)
count
- the rotation counter value to be reachedblocking
- if true, the method blocks until the count is reached, otherwise it returns immediatelyaddMotionListener(MotionListener motionListener)
,
rotateTo(int count)
public Motor continueTo(int count)
count
- the rotation counter value to be reachedrotateTo(int count)
public Motor continueTo(int count, boolean blocking)
count
- the rotation counter value to be reachedblocking
- if true, the method blocks until the count is reached, otherwise it returns immediatelyrotateTo(int count, boolean blocking)
public Motor continueRelativeTo(int count)
count
- the rotation counter value to be increased/decreasedrotateTo(int count)
public Motor continueRelativeTo(int count, boolean blocking)
count
- the rotation counter value to be increased/decreasedblocking
- if true, the method blocks until the count is reached, otherwise it returns immediatelyrotateTo(int count, boolean blocking)
public boolean isMoving()