Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## josx.platform.rcx
Class Servo

    java.lang.Object
      josx.platform.rcx.Servo

All Implemented Interfaces:
  SensorListener

    public class Servo

extends Object
implements SensorListener

Implmentation of a servo using a Motor and a Rotation Sensor.

Author:
  Paul Andrews

Constructor Summary
`Servo(Sensor sensor, Motor motor)` Constructor.
`Servo(Sensor sensor, Motor motor, int slack)` Constructor.

Method Summary
`boolean` | `rotateTo(int pos)` Set the motor rotating to the specified position.
`void` | `stateChanged(Sensor sensor, int oldValue, int newValue)` Called by the sensor listener thread when the value of the rotation sensor changes.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait`

Constructor Detail

### Servo

    public Servo(Sensor sensor,
                 Motor motor,
                 int slack)

  Constructor. Initializes the sensor and sets the current postion to zero.

  Parameters:
    `sensor` - the Sensor to which the rotation sensor is connected.
    `motor` - the Motor to control.
    `slack` - accept positions +/- this value.

### Servo

    public Servo(Sensor sensor,
                 Motor motor)

  Constructor. Same as Servo(sensor, motor, 0);

Method Detail

### rotateTo

    public boolean rotateTo(int pos)

  Set the motor rotating to the specified position. The method returns immediately.

  Parameters:
    `pos` - the position to rotate to. The effect will depend on the gearing used between the motor and the sensor and the motor and the wheels (or whatever).
  Returns:
    true if the servo is already at the specified position. False otherwise.

### stateChanged

    public void stateChanged(Sensor sensor,
                             int oldValue,
                             int newValue)

  Called by the sensor listener thread when the value of the rotation sensor changes. Once the motor has rotated to the desired value, +/- slack, stop it and notify anyone waiting on this object's monitor.

  Specified by:
    `stateChanged` in interface `SensorListener`
  Parameters:
    `sensor` - The sensor that generated the event.
    `oldValue` - The old sensor value.
    `newValue` - The new sensor value.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD