com.phidgets
Class ServoPhidget

java.lang.Object
  extended bycom.phidgets.Phidget
      extended bycom.phidgets.ServoPhidget

public final class ServoPhidget
extends Phidget

This class represents a Phidget servo Controller. All methods to control a Servo Controller are implemented in this class.

The Phidget Sevo controller simply outputs varying widths of PWM, which is what most servo motors take as an input driving signal.

Author:
Phidgets Inc.

Field Summary
static int PHIDGET_SERVO_DEFAULT
          Default - This is what the servo API been historically used, originally based on the Futaba FP-S148.
static int PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R
          Firgelli L12 Linear Actuator 100mm 100:1.
static int PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R
          Firgelli L12 Linear Actuator 100mm 50:1.
static int PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R
          Firgelli L12 Linear Actuator 30mm 50:1.
static int PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R
          Firgelli L12 Linear Actuator 50mm 100:1.
static int PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R
          Firgelli L12 Linear Actuator 50mm 210:1.
static int PHIDGET_SERVO_HITEC_805BB
          HiTec HS-805BB Mega Quarter Scale Servo.
static int PHIDGET_SERVO_HITEC_815BB
          HiTec HS-815BB Mega Sail Servo.
static int PHIDGET_SERVO_HITEC_HS322HD
          HiTec HS-322HD Standard Servo.
static int PHIDGET_SERVO_HITEC_HS422
          HiTec HS-422 Standard Servo.
static int PHIDGET_SERVO_HITEC_HS485HB
          HiTec HS-485HB Deluxe Servo.
static int PHIDGET_SERVO_HITEC_HS5245MG
          HiTec HS-5245MG Digital Mini Servo.
static int PHIDGET_SERVO_HITEC_HS645MG
          HiTec HS-645MG Ultra Torque Servo.
static int PHIDGET_SERVO_HITEC_HS785HB
          HiTec HS-785HB Sail Winch Servo.
static int PHIDGET_SERVO_HITEC_HSR1425CR
          HiTec HSR-1425CR Continuous Rotation Servo.
static int PHIDGET_SERVO_RAW_us_MODE
          Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees.
static int PHIDGET_SERVO_SPRINGRC_SM_S2313M
          SpringRC SM-S2313M Micro Servo.
static int PHIDGET_SERVO_SPRINGRC_SM_S3317M
          SpringRC SM-S3317M Small Servo.
static int PHIDGET_SERVO_SPRINGRC_SM_S3317SR
          SpringRC SM-S3317SR Small Continuous Rotation Servo.
static int PHIDGET_SERVO_SPRINGRC_SM_S4303R
          SpringRC SM-S4303R Standard Continuous Rotation Servo.
static int PHIDGET_SERVO_SPRINGRC_SM_S4315M
          SpringRC SM-S4315M High Torque Servo.
static int PHIDGET_SERVO_SPRINGRC_SM_S4315R
          SpringRC SM-S4315R High Torque Continuous Rotation Servo.
static int PHIDGET_SERVO_SPRINGRC_SM_S4505B
          SpringRC SM-S4505B Standard Servo.
static int PHIDGET_SERVO_TOWERPRO_MG90
          Tower Pro MG90 Micro Servo.
static int PHIDGET_SERVO_USER_DEFINED
          User Defined servo parameters.
 
Fields inherited from class com.phidgets.Phidget
PHIDCLASS_ACCELEROMETER, PHIDCLASS_ADVANCEDSERVO, PHIDCLASS_ANALOG, PHIDCLASS_BRIDGE, PHIDCLASS_ENCODER, PHIDCLASS_FREQUENCYCOUNTER, PHIDCLASS_GPS, PHIDCLASS_INTERFACEKIT, PHIDCLASS_LED, PHIDCLASS_MOTORCONTROL, PHIDCLASS_NOTHING, PHIDCLASS_PHSENSOR, PHIDCLASS_RFID, PHIDCLASS_SERVO, PHIDCLASS_STEPPER, PHIDCLASS_TEMPERATURESENSOR, PHIDCLASS_TEXTLCD, PHIDCLASS_TEXTLED, PHIDCLASS_WEIGHTSENSOR, PHIDGET_LOG_CRITICAL, PHIDGET_LOG_DEBUG, PHIDGET_LOG_ERROR, PHIDGET_LOG_INFO, PHIDGET_LOG_VERBOSE, PHIDGET_LOG_WARNING, PHIDID_ACCELEROMETER_2AXIS, PHIDID_ACCELEROMETER_3AXIS, PHIDID_ADVANCEDSERVO_1MOTOR, PHIDID_ADVANCEDSERVO_8MOTOR, PHIDID_ANALOG_4OUTPUT, PHIDID_BIPOLAR_STEPPER_1MOTOR, PHIDID_BRIDGE_4INPUT, PHIDID_ENCODER_1ENCODER_1INPUT, PHIDID_ENCODER_HS_1ENCODER, PHIDID_ENCODER_HS_4ENCODER_4INPUT, PHIDID_FREQUENCYCOUNTER_2INPUT, PHIDID_GPS, PHIDID_INTERFACEKIT_0_0_4, PHIDID_INTERFACEKIT_0_0_8, PHIDID_INTERFACEKIT_0_16_16, PHIDID_INTERFACEKIT_0_8_8_w_LCD, PHIDID_INTERFACEKIT_2_2_2, PHIDID_INTERFACEKIT_4_8_8, PHIDID_INTERFACEKIT_8_8_8, PHIDID_INTERFACEKIT_8_8_8_w_LCD, PHIDID_IR, PHIDID_LED_64, PHIDID_LED_64_ADV, PHIDID_LINEAR_TOUCH, PHIDID_MOTORCONTROL_1MOTOR, PHIDID_MOTORCONTROL_HC_2MOTOR, PHIDID_MOTORCONTROL_LV_2MOTOR_4INPUT, PHIDID_NOTHING, PHIDID_PHSENSOR, PHIDID_RFID, PHIDID_RFID_2OUTPUT, PHIDID_RFID_2OUTPUT_READ_WRITE, PHIDID_ROTARY_TOUCH, PHIDID_SERVO_1MOTOR, PHIDID_SERVO_1MOTOR_OLD, PHIDID_SERVO_4MOTOR, PHIDID_SERVO_4MOTOR_OLD, PHIDID_SPATIAL_ACCEL_3AXIS, PHIDID_SPATIAL_ACCEL_GYRO_COMPASS, PHIDID_TEMPERATURESENSOR, PHIDID_TEMPERATURESENSOR_4, PHIDID_TEMPERATURESENSOR_IR, PHIDID_TEXTLCD_2x20, PHIDID_TEXTLCD_2x20_w_0_8_8, PHIDID_TEXTLCD_2x20_w_8_8_8, PHIDID_TEXTLCD_ADAPTER, PHIDID_TEXTLED_1x8, PHIDID_TEXTLED_4x8, PHIDID_UNIPOLAR_STEPPER_4MOTOR, PHIDID_WEIGHTSENSOR
 
Constructor Summary
ServoPhidget()
           
 
Method Summary
 void addServoPositionChangeListener(ServoPositionChangeListener l)
          Adds a servo position change listener.
 boolean getEngaged(int index)
          Returns the engaged state or a servo.
 int getMotorCount()
          Returns the number of motors this Phidget can support.
 boolean getMotorOn(int index)
          Deprecated. Replaced by getEngaged(int)
 double getPosition(int index)
          Returns the position of a servo motor.
 double getPositionMax(int index)
          Returns the maximum position that a servo will accept, or return.
 double getPositionMin(int index)
          Returns the minimum position that a servo will accept, or return.
 int getServoType(int index)
          Returns the servo type for an index.
 void removeServoPositionChangeListener(ServoPositionChangeListener l)
           
 void setEngaged(int index, boolean state)
          Engage or disengage a servo motor.
 void setMotorOn(int index, boolean state)
          Deprecated. Replaced by setEngaged(int, boolean)
 void setPosition(int index, double position)
          Sets the position of a servo motor.
 void setServoParameters(int index, double minUs, double maxUs, double degrees)
          Sets the servo parameters for a custom servo definition.
 void setServoType(int index, int type)
          Sets the servo type for an index.
 
Methods inherited from class com.phidgets.Phidget
addAttachListener, addDetachListener, addErrorListener, addServerConnectListener, addServerDisconnectListener, close, disableLogging, enableLogging, equals, getDeviceClass, getDeviceID, getDeviceLabel, getDeviceName, getDeviceType, getDeviceVersion, getLibraryVersion, getSerialNumber, getServerAddress, getServerID, getServerPort, isAttached, isAttachedToServer, log, open, open, open, open, open, openAny, openAny, openAny, openAny, openAny, openLabel, openLabel, openLabel, openLabel, openLabel, removeAttachListener, removeDetachListener, removeErrorListener, removeServerConnectListener, removeServerDisconnectListener, setDeviceLabel, toString, waitForAttachment, waitForAttachment
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PHIDGET_SERVO_DEFAULT

public static final int PHIDGET_SERVO_DEFAULT
Default - This is what the servo API been historically used, originally based on the Futaba FP-S148. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_RAW_us_MODE

public static final int PHIDGET_SERVO_RAW_us_MODE
Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HS322HD

public static final int PHIDGET_SERVO_HITEC_HS322HD
HiTec HS-322HD Standard Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HS5245MG

public static final int PHIDGET_SERVO_HITEC_HS5245MG
HiTec HS-5245MG Digital Mini Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_805BB

public static final int PHIDGET_SERVO_HITEC_805BB
HiTec HS-805BB Mega Quarter Scale Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HS422

public static final int PHIDGET_SERVO_HITEC_HS422
HiTec HS-422 Standard Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_TOWERPRO_MG90

public static final int PHIDGET_SERVO_TOWERPRO_MG90
Tower Pro MG90 Micro Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HSR1425CR

public static final int PHIDGET_SERVO_HITEC_HSR1425CR
HiTec HSR-1425CR Continuous Rotation Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HS785HB

public static final int PHIDGET_SERVO_HITEC_HS785HB
HiTec HS-785HB Sail Winch Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HS485HB

public static final int PHIDGET_SERVO_HITEC_HS485HB
HiTec HS-485HB Deluxe Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_HS645MG

public static final int PHIDGET_SERVO_HITEC_HS645MG
HiTec HS-645MG Ultra Torque Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_HITEC_815BB

public static final int PHIDGET_SERVO_HITEC_815BB
HiTec HS-815BB Mega Sail Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R

public static final int PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R
Firgelli L12 Linear Actuator 30mm 50:1. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R

public static final int PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R
Firgelli L12 Linear Actuator 50mm 100:1. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R

public static final int PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R
Firgelli L12 Linear Actuator 50mm 210:1. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R

public static final int PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R
Firgelli L12 Linear Actuator 100mm 50:1. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R

public static final int PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R
Firgelli L12 Linear Actuator 100mm 100:1. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S2313M

public static final int PHIDGET_SERVO_SPRINGRC_SM_S2313M
SpringRC SM-S2313M Micro Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S3317M

public static final int PHIDGET_SERVO_SPRINGRC_SM_S3317M
SpringRC SM-S3317M Small Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S3317SR

public static final int PHIDGET_SERVO_SPRINGRC_SM_S3317SR
SpringRC SM-S3317SR Small Continuous Rotation Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S4303R

public static final int PHIDGET_SERVO_SPRINGRC_SM_S4303R
SpringRC SM-S4303R Standard Continuous Rotation Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S4315M

public static final int PHIDGET_SERVO_SPRINGRC_SM_S4315M
SpringRC SM-S4315M High Torque Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S4315R

public static final int PHIDGET_SERVO_SPRINGRC_SM_S4315R
SpringRC SM-S4315R High Torque Continuous Rotation Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_SPRINGRC_SM_S4505B

public static final int PHIDGET_SERVO_SPRINGRC_SM_S4505B
SpringRC SM-S4505B Standard Servo. This is used with getServoType and setServoType

See Also:
Constant Field Values

PHIDGET_SERVO_USER_DEFINED

public static final int PHIDGET_SERVO_USER_DEFINED
User Defined servo parameters. This is used with getServoType

See Also:
Constant Field Values
Constructor Detail

ServoPhidget

public ServoPhidget()
             throws PhidgetException
Method Detail

getMotorCount

public int getMotorCount()
                  throws PhidgetException
Returns the number of motors this Phidget can support. Note that there is no way of programatically determining how many motors are actaully attached to the board.

Returns:
number of motors
Throws:
PhidgetException

getPosition

public double getPosition(int index)
                   throws PhidgetException
Returns the position of a servo motor. Note that since servo motors do not offer any feedback in their interface, this value is simply whatever the servo was last set to. There is no way of determining the position of a servo that has been plugged in, until it's position has been set. Therefore, if an initial position is important, it should be set as part of initialization.

If the servo is not engaged, the position is unknown and calling this function will throw an exception.

The range here is between getPositionMin and getPositionMax, and corresponds aproximately to an angle in degrees. Note that most servos will not be able to operate accross this entire range.

Parameters:
index - index of the motor
Returns:
current position of the selected motor
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

getPositionMax

public double getPositionMax(int index)
                      throws PhidgetException
Returns the maximum position that a servo will accept, or return.

Parameters:
index - Index of the servo
Returns:
Maximum position in degrees
Throws:
PhidgetException - If this Phidget is not opened and attached. See open for information on determining if a device is attached.

getPositionMin

public double getPositionMin(int index)
                      throws PhidgetException
Returns the minimum position that a servo will accept, or return.

Parameters:
index - Index of the servo
Returns:
Minimum position in degrees
Throws:
PhidgetException - If this Phidget is not opened and attached. See open for information on determining if a device is attached.

setPosition

public void setPosition(int index,
                        double position)
                 throws PhidgetException
Sets the position of a servo motor.

The range here is between getPositionMin and getPositionMax, and corresponds aproximately to an angle in degrees. Note that most servos will not be able to operate accross this entire range. Typically, the range might be 25 - 180 degrees, but this depends on the servo

Parameters:
index - index of the motor
position - desired position
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index or position is out of range. See open for information on determining if a device is attached.

setEngaged

public void setEngaged(int index,
                       boolean state)
                throws PhidgetException
Engage or disengage a servo motor.

This engages or disengages the servo. The motor is engaged whenever you set a position, use this function to disengage, and reengage without setting a position.

Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

setMotorOn

public void setMotorOn(int index,
                       boolean state)
                throws PhidgetException
Deprecated. Replaced by setEngaged(int, boolean)

Throws:
PhidgetException

getEngaged

public boolean getEngaged(int index)
                   throws PhidgetException
Returns the engaged state or a servo.

Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

getMotorOn

public boolean getMotorOn(int index)
                   throws PhidgetException
Deprecated. Replaced by getEngaged(int)

Throws:
PhidgetException

getServoType

public int getServoType(int index)
                 throws PhidgetException
Returns the servo type for an index. The possible values for type are PHIDGET_SERVO_DEFAULT, PHIDGET_SERVO_RAW_us_MODE, PHIDGET_SERVO_HITEC_HS322HD, PHIDGET_SERVO_HITEC_HS5245MG, PHIDGET_SERVO_HITEC_805BB, PHIDGET_SERVO_HITEC_HS422, etc.

Parameters:
index - Input
Returns:
Servo Type
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

setServoType

public void setServoType(int index,
                         int type)
                  throws PhidgetException
Sets the servo type for an index.

This constrains the PCM to the valid range of the servo, and sets the degrees-to-PCM ratio to match the actual servo rotation.

The possible values for type are PHIDGET_SERVO_DEFAULT, PHIDGET_SERVO_RAW_us_MODE, PHIDGET_SERVO_HITEC_HS322HD, PHIDGET_SERVO_HITEC_HS5245MG, PHIDGET_SERVO_HITEC_805BB, PHIDGET_SERVO_HITEC_HS422, etc.

Support for other servo types can be achieved by using setServoParameters.

The default setting is PHIDGET_SERVO_DEFAULT, which is used for historical (backwards compatibility) reasons.

Parameters:
index - Input
type - Servo Type
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

setServoParameters

public void setServoParameters(int index,
                               double minUs,
                               double maxUs,
                               double degrees)
                        throws PhidgetException
Sets the servo parameters for a custom servo definition.

This constrains the PCM to the valid range of the servo, and sets the degrees-to-PCM ratio to match the actual servo rotation.

Parameters:
index - Servo Index
minUs - Minimum PCM supported in microseconds
maxUs - Maximum PCM supported in microseconds
degrees - Degrees of rotation represented by the given PCM range
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

addServoPositionChangeListener

public final void addServoPositionChangeListener(ServoPositionChangeListener l)
Adds a servo position change listener. The servo position change handler is a method that will be called when the servo position has changed. The event will get fired after every call to setPosition.

There is no limit on the number of servo position change handlers that can be registered for a particular Phidget.

Parameters:
l - An implemetation of the ServoPositionChangeListener interface

removeServoPositionChangeListener

public final void removeServoPositionChangeListener(ServoPositionChangeListener l)