Class Servo

  extended byjosx.platform.rcx.Servo
All Implemented Interfaces:

public class Servo
extends Object
implements SensorListener

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

Constructor Summary
Servo(Sensor sensor, Motor motor)
Servo(Sensor sensor, Motor motor, int slack)
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


public Servo(Sensor sensor,
             Motor motor,
             int slack)
Constructor. Initializes the sensor and sets the current postion to zero.

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


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

Method Detail


public boolean rotateTo(int pos)
Set the motor rotating to the specified position. The method returns immediately.

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).
true if the servo is already at the specified position. False otherwise.


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
sensor - The sensor that generated the event.
oldValue - The old sensor value.
newValue - The new sensor value.