public class Gear 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 |
---|
Gear()
Creates a gear instance with left motor plugged into port A, right motor plugged into port B.
|
Gear(MotorPort port1,
MotorPort port2)
Creates a gear instance with right motor plugged into port1, left motor plugged into port2.
|
Modifier and Type | Method and Description |
---|---|
void |
addMotionListener(MotionListener motionListener)
Register the given motion listener.
|
Gear |
backward()
Same as forward(), but move in reverse direction.
|
Gear |
backward(int duration)
Same as forward(int duration), but move in reverse direction.
|
Gear |
forward()
Starts the forward movement with preset speed.
|
Gear |
forward(int duration)
Starts the forward movement for the given duration (in ms) with preset speed.
|
Motor |
getMotLeft()
Returns left motor of the gear.
|
Motor |
getMotRight()
Returns right motor of the gear.
|
int |
getSpeed()
Returns the current speed (arbitrary units).
|
double |
getVelocity()
Returns the current velocity.
|
boolean |
isMoving()
Checks if one or both motors are rotating.
|
Gear |
left()
Starts turning left with left motor stopped and right motor at preset speed.
|
Gear |
left(int duration)
Starts turning left for the given duration (in ms) with preset speed.
|
Gear |
leftArc(double radius)
Starts turning to the left on an arc with given radius (in m).
|
Gear |
leftArc(double radius,
int duration)
Starts turning to the left on an arc with given radius (in m) for the given
duration (in ms) with preset speed.
|
Gear |
moveTo(int count)
Same as moveTo(int count, boolean blocking) with blocking = true.
|
Gear |
moveTo(int count,
boolean blocking)
Sets the rotation counter to zero and rotate both motors until the given count is reached.
|
Gear |
right()
Same as left(), but turns in the opposite direction.
|
Gear |
right(int duration)
Same as left(int duration), but turning in the opposite direction.
|
Gear |
rightArc(double radius)
Same as leftArc(double radius), but turns in the right.
|
Gear |
rightArc(double radius,
int duration)
Same as leftArc(double radius, int duration), but turns to the right.
|
Gear |
setSpeed(int speed)
Sets the speed to the given value (arbitrary units).
|
Gear |
setVelocity(double velocity)
Sets the velocity to the given value.
|
Gear |
stop()
Stops the gear.
|
Gear |
turnTo(int count)
Same as turnTo(int count, boolean blocking) with blocking = true.
|
Gear |
turnTo(int count,
boolean blocking)
Sets the rotation counter to zero and turn with the motors running in
opposite direction.
|
public Gear(MotorPort port1, MotorPort port2)
port1
- MotorPort.A or MotorPort.B or MotorPort.C (not both the same)port2
- MotorPort.A or MotorPort.B or MotorPort.C (not both the same)public Gear()
public int getSpeed()
public double getVelocity()
public Gear setSpeed(int speed)
speed
- 0..100public Gear setVelocity(double velocity)
velocity
- in m/spublic Gear stop()
public Gear moveTo(int count, boolean blocking)
addMotionListener(MotionListener motionListener)
,
moveTo(int count)
public Gear moveTo(int count)
moveTo(int count, boolean blocking)
public Gear turnTo(int count)
turnTo(int count, boolean blocking)
public Gear turnTo(int count, boolean blocking)
turnTo(int count)
public void addMotionListener(MotionListener motionListener)
motionListener
- the MotionListener to be registeredpublic Gear forward()
public Gear forward(int duration)
duration
- the duration (in ms)public Gear backward()
forward()
public Gear backward(int duration)
forward(int duration)
public Gear left()
public Gear left(int duration)
duration
- the duration (in ms)public Gear right(int duration)
left(int duration)
public Gear leftArc(double radius)
radius
- the radius of the arc (in m)public Gear leftArc(double radius, int duration)
radius
- the radius of the arc (in m)duration
- the duration (in ms)public Gear rightArc(double radius)
leftArc(double radius)
public Gear rightArc(double radius, int duration)
leftArc(double radius, int duration)
public Motor getMotRight()
public Motor getMotLeft()
public boolean isMoving()