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
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. |
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);
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
- Following copied from interface:
josx.platform.rcx.SensorListener
- Parameters:
aSource
- The sensor that generated the event.aOldValue
- The old sensor value.aNewValue
- The new sensor value.