ch.aplu.nxt
Class Gear
java.lang.Object
  
ch.aplu.nxt.Part
      
ch.aplu.nxt.Gear
- All Implemented Interfaces: 
 - SharedConstants
 
public class Gear
- extends Part
 
Combines two motors on an axis to perform a car-like movement.
 
| Fields inherited from class ch.aplu.nxt.Part | 
robot | 
 
| Fields inherited from interface ch.aplu.nxt.SharedConstants | 
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 Summary | 
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 left motor plugged into port1, right motor plugged into port2. | 
 
| 
Method Summary | 
 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. | 
protected  void | 
cleanup()
 
            | 
 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. | 
protected  void | 
init()
 
            | 
 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 turning 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. | 
 
 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
 
Gear
public Gear(MotorPort port1,
            MotorPort port2)
- Creates a gear instance with left motor plugged into port1, right motor plugged into port2.
- Parameters:
 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)
 
Gear
public Gear()
- Creates a gear instance with left motor plugged into port A, right motor plugged into port B.
 
init
protected void init()
- Specified by:
 init in class Part
 
 
cleanup
protected void cleanup()
- Specified by:
 cleanup in class Part
 
 
getSpeed
public int getSpeed()
- Returns the current speed (arbitrary units).
- Returns:
 - speed 0..100
 
 
 
getVelocity
public double getVelocity()
- Returns the current velocity.
 The velocity in m/s with some inaccuracy.
 velocity = MotorSpeedFactor * speed (default: MotorSpeedFactor set in
 NxtLib.properties).
- Returns:
 - velocity in m/s
 
 
 
setSpeed
public Gear setSpeed(int speed)
- Sets the speed to the given value (arbitrary units).
 The speed will be changed to the new value at the next movement call only.
- Parameters:
 speed - 0..100
- Returns:
 - the object reference to allow method chaining
 
 
 
setVelocity
public Gear setVelocity(double velocity)
- Sets the velocity to the given value.
 The velocity will be changed to the new value at the next movement call only.
 velocity = MotorSpeedFactor * speed (default MotorSpeedFactor set in
 NxtLib.properties).
- Parameters:
 velocity - in m/s
- Returns:
 - the object reference to allow method chaining.
 
 
 
stop
public Gear stop()
- Stops the gear.
- Returns:
 - the object reference to allow method chaining.
 
 
 
moveTo
public Gear moveTo(int count,
                   boolean blocking)
- Sets the rotation counter to zero and rotate both motors until the given count is reached.
 If count is negative, the motors turn backwards.
 If blocking = false, the method returns immediately.
 You may register a motion listener with addMotionListener() to get a callback
 when the count is reached and the  motors stop.
 If blocking = true, the method returns when the count is reached and
 the motors stop.
 The motors start smoothly if the speed is not too fast.
- Returns:
 - the object reference to allow method chaining
 - See Also:
 addMotionListener(MotionListener motionListener), 
moveTo(int count)
 
 
moveTo
public Gear moveTo(int count)
- Same as moveTo(int count, boolean blocking) with blocking = true.
- See Also:
 moveTo(int count, boolean blocking)
 
 
turnTo
public Gear turnTo(int count)
- Same as turnTo(int count, boolean blocking) with blocking = true.
- See Also:
 turnTo(int count, boolean blocking)
 
 
turnTo
public Gear turnTo(int count,
                   boolean blocking)
- Sets the rotation counter to zero and turn with the motors running in
 opposite direction.
 If count is positive, turns clockwise, otherwise anti-clockwise
 (MotorPort.A is right, MotorPort.B is left motor).
 If blocking = false, the method returns immediately.
 If blocking = true, the method returns when the count is reached and
 the motors stop.
- Returns:
 - the object reference to allow method chaining.
 - See Also:
 turnTo(int count)
 
 
addMotionListener
public void addMotionListener(MotionListener motionListener)
- Register the given motion listener.
 When calling moveTo() a motion detector thread is started that checks
 the motion of the motors. When the motion stops because the rotation count
 is reached or stop() is called, the MotionListener's callback
 motionStopped() is invoked and the motion detector thread terminates.
- Parameters:
 motionListener - the MotionListener to be registered
 
 
forward
public Gear forward()
- Starts the forward movement with preset speed.
 Method returns immediately, while the movement continues.
- Returns:
 - the object reference to allow method chaining.
 
 
 
forward
public Gear forward(int duration)
- Starts the forward movement for the given duration (in ms) with preset speed.
 Method returns at the end of the given duration, but the
 movement continues for 200 ms. Then it stops unless another movement method
 call (forward, backward, left, right, leftArc, rightArc) is
 invoked within that time.
 Calling several movement methods one after the other will result
 a seamless movement without intermediate stops.
 To use it without problems in a callback method, it returns quickly
 when NxtRobot.disconnect is called.
- Parameters:
 duration - the duration (in ms)
- Returns:
 - the object reference to allow method chaining
 
 
 
backward
public Gear backward()
- Same as forward(), but move in reverse direction.
- See Also:
 forward()
 
 
backward
public Gear backward(int duration)
- Same as forward(int duration), but move in reverse direction.
- See Also:
 forward(int duration)
 
 
left
public Gear left()
- Starts turning left with left motor stopped and right motor at preset speed.
 Method returns immediately, while the movement continues.
- Returns:
 - the object reference to allow method chaining
 
 
 
left
public Gear left(int duration)
- Starts turning left for the given duration (in ms) with preset speed.
 Method returns at the end of the given duration but the
 movement continues for 200 ms. Then it stops unless another movement method
 call (forward, backward, left, right, leftArc, rightArc) is
 invoked within that time.
 Calling several movement methods one after the other will result
 a seamless movement without intermediate stops.
- Parameters:
 duration - the duration (in ms)
- Returns:
 - the object reference to allow method chaining
 
 
 
right
public Gear right()
- Same as left(), but turning in the opposite direction.
- See Also:
 left()
 
 
right
public Gear right(int duration)
- Same as left(int duration), but turning in the opposite direction.
- See Also:
 left(int duration)
 
 
leftArc
public Gear leftArc(double radius)
- Starts turning to the left on an arc with given radius (in m).
 If the radius is negative, turns left backwards.
 The accuracy is limited and depends on the distance between the
 two wheels (default: AxeLength set in NxtLib.properties).
 Method returns immediately, while the movement continues.
- Parameters:
 radius - the radius of the arc (in m)
- Returns:
 - the object reference to allow method chaining
 
 
 
leftArc
public 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.
 If the radius is negative, turns left backwards.
 The accuracy is limited and depends on the distance between the
 two wheels (default: AxeLength set in NxtLib.properties).
 Method returns at the end of the given duration but the
 movement continues for 200 ms. Then it stops unless another movement method
 call (forward, backward, left, right, leftArc, rightArc) is
 invoked within that time.
 Calling several movement methods one after the other will result
 a seamless movement without intermediate stops.
- Parameters:
 radius - the radius of the arc (in m)duration - the duration (in ms)
- Returns:
 - the object reference to allow method chaining
 
 
 
rightArc
public Gear rightArc(double radius)
- Same as leftArc(double radius), but turns in the right.
- See Also:
 leftArc(double radius)
 
 
rightArc
public Gear rightArc(double radius,
                     int duration)
- Same as leftArc(double radius, int duration), but turns to the right.
- See Also:
 leftArc(double radius, int duration)
 
 
getMotRight
public Motor getMotRight()
- Returns right motor of the gear.
- Returns:
 - the reference of the right motor
 
 
 
getMotLeft
public Motor getMotLeft()
- Returns left motor of the gear.
- Returns:
 - the reference of the left motor