RoboJDETM v2.0

com.ridgesoft.robotics
Class ContinuousRotationServo

java.lang.Object
  extended by com.ridgesoft.robotics.ContinuousRotationServo
All Implemented Interfaces:
Motor

public class ContinuousRotationServo
extends Object
implements Motor

This class implements the Motor interface to a servo that has been manufactured or modified to support continuous rotation.

Servos that have been manufactured or modified to support continuous rotation function similar to conventional motors. However, they are still controlled using the servo control signal and built-in electronics. This class creates a facade around a Servo object so the servo can be controlled in the same manner as a conventional DC motor.

Inorder to work properly with this class, the continuous rotation servo must be calibrated such that when its position is set to the midpoint, 50, its output shaft does not move. Calibration can be accomplished using a simple program to set the position of the servo to 50 and then using a screwdriver to adjust the position potentiometer such that the shaft does not rotate.

Once modified and calibrated, the power of the servo can be controlled based on how far from the midpoint the position signal is set. For example, setting the position to the maximum value, 100, will cause the servo to rotate forward at maximum power. Setting the position to the minimum value, 0, will cause the servo to rotate backward at maximum power. Unfortunately, the power ramp up or down does not typically extend over the entire range of the position signal and is dependant on the particular model of servo. Therefore, the motor power settings have to be scaled to match the behavior of the particular model of servo. For example, for Parallax continuous rotation servos, the power ramps to its maximum or minimum value over a range of +/-14 around the midpoint. Therefore, this class must scale motor power settings over the range 36 to 64 when used with Parallax continuous rotation servos.

See Also:
Servo

Field Summary
 
Fields inherited from interface com.ridgesoft.robotics.Motor
MAX_FORWARD, MAX_REVERSE, STOP
 
Constructor Summary
ContinuousRotationServo(Servo servo, boolean reverse)
          Constructs a ContinuousRotationServo object.
ContinuousRotationServo(Servo servo, boolean reverse, int range)
          Constructs a ContinuousRotationServo object.
ContinuousRotationServo(Servo servo, boolean reverse, int range, DirectionListener directionListener)
          Constructs a ContinuousRotationServo object.
 
Method Summary
 void brake()
          Active braking is not supported.
 void setDirectionListener(DirectionListener directionListener)
          Sets a DirectionListener.
 void setPower(int power)
          Sets the power.
 void stop()
          Turns the servo off.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

ContinuousRotationServo

public ContinuousRotationServo(Servo servo,
                               boolean reverse)
Constructs a ContinuousRotationServo object.

This constructor sets the range scaling to 50, which will scale the power over the full range of the servo control signal.

Parameters:
servo - reference to the Servo to control
reverse - true if the drive direction of the servo is reversed

ContinuousRotationServo

public ContinuousRotationServo(Servo servo,
                               boolean reverse,
                               int range)
Constructs a ContinuousRotationServo object.

Note: 14 is normally a good range value for Parallax continuous rotation servos

Parameters:
servo - reference to the Servo to control
reverse - true if the drive direction of the servo is reversed
range - the range to scale motor power values over

ContinuousRotationServo

public ContinuousRotationServo(Servo servo,
                               boolean reverse,
                               int range,
                               DirectionListener directionListener)
Constructs a ContinuousRotationServo object.

Note: 14 is normally a good range value for Parallax continuous rotation servos

Parameters:
servo - reference to the Servo to control
reverse - true if the drive direction of the servo is reversed
range - the range to scale motor power values over
directionListener - direction listener to notify when the direction changes - initial direction defaults to forward
Method Detail

brake

public void brake()
Active braking is not supported.

This method has the same effect as the stop method.

Specified by:
brake in interface Motor

setDirectionListener

public void setDirectionListener(DirectionListener directionListener)
Sets a DirectionListener.

This listener is notified each time the servo direction changes.

Parameters:
directionListener - direction listener to notify when the direction changes - initial direction defaults to forward

setPower

public void setPower(int power)
Sets the power.

Specified by:
setPower in interface Motor
Parameters:
power - The power level to set.
  • 16 = maximum forward power
  • 0 = no power, servo will be turned off
  • -16 = maximum reverse power

stop

public void stop()
Turns the servo off.

This method has the same effect as setPower(Motor.STOP) or setPower(0).

Specified by:
stop in interface Motor

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com