The leJOS Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail

Trail: Essential leJOS classes
Lesson: Utilities

Utilities: Servo

The josx.platform.rcx.Servo class is a utility to encapsulate a common task of navigation: to rotate your robot to a given position.

The class uses a rotation sensor in connection with a motor, so an instance is constructed by


            public Servo(Sensor aSensor,Motor aMotor,int aSlack)
        
where aSlack is the amount of deviation accepted when rotating.

To rotate,


            public boolean rotateTo(int aPosition)
        
is used: the robot will rotate to the given position (+/- the slack). The value depends on the gearing between the motor and the sensor as well as between the motor and the wheels.
The method returns false, if the robot is on the given position already, else true.

Note that rotateTo returns immediately: it doesn't block until the robot has in fact rotated to the desired position.

The Servo API

may be found here.
The leJOS Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail