com.phidgets
Class StepperPhidget

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

public final class StepperPhidget
extends Phidget

This class represents a Phidget Stepper Controller. All methods to to control a stepper controller and read back stepper data are implemented in this class.

The Phidget Stepper is able to control 1 or more Stepper motors. Motor Acceleration and Velocity are controllable, and micro-stepping is used. The type and number of motors that can be controlled depend on the Stepper Controller. Digital inputs are available on select Phidget Stepper Controllers.

Author:
Phidgets Inc.

Field Summary
 
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
StepperPhidget()
           
 
Method Summary
 void addCurrentChangeListener(CurrentChangeListener l)
          Adds a current change listener.
 void addInputChangeListener(InputChangeListener l)
          Adds an input change listener.
 void addStepperPositionChangeListener(StepperPositionChangeListener l)
          Adds a position change listener.
 void addStepperVelocityChangeListener(StepperVelocityChangeListener l)
          Adds a velocity change listener.
 double getAcceleration(int index)
          Returns a motor's acceleration.
 double getAccelerationMax(int index)
          Returns the maximum acceleration that a motor will accept, or return.
 double getAccelerationMin(int index)
          Returns the minimum acceleration that a motor will accept, or return.
 double getCurrent(int index)
          Returns a motor's current usage.
 double getCurrentLimit(int index)
          Returns the current limit.
 double getCurrentMax(int index)
          Returns the maximum current that a stepper motor will accept, or return.
 double getCurrentMin(int index)
          Returns the minimum current that a stepper motor will accept, or return.
 long getCurrentPosition(int index)
          Returns a motor's current position.
 boolean getEngaged(int index)
          Returns the engaged state of a motor.
 int getInputCount()
          Returns the number of digital inputs.
 boolean getInputState(int index)
          Returns the state of a digital input.
 int getMotorCount()
          Returns the number of stepper motors supported by this Phidget.
 long getPositionMax(int index)
          Returns the maximum position that a stepper motor will accept, or return.
 long getPositionMin(int index)
          Returns the minimum position that a stepper motor will accept, or return.
 boolean getStopped(int index)
          Returns the stopped state of a motor.
 long getTargetPosition(int index)
          Returns a motor's target position.
 double getVelocity(int index)
          Returns a motor's current velocity.
 double getVelocityLimit(int index)
          Returns a motor's velocity limit.
 double getVelocityMax(int index)
          Returns the maximum velocity that a stepper motor will accept, or return.
 double getVelocityMin(int index)
          Returns the minimum velocity that a stepper motor will accept, or return.
 void removeCurrentChangeListener(CurrentChangeListener l)
           
 void removeInputChangeListener(InputChangeListener l)
           
 void removeStepperPositionChangeListener(StepperPositionChangeListener l)
           
 void removeStepperVelocityChangeListener(StepperVelocityChangeListener l)
           
 void setAcceleration(int index, double acceleration)
          Sets a motor's acceleration.
 void setCurrentLimit(int index, double current)
          Sets a motor's current usage limit.
 void setCurrentPosition(int index, long position)
          Sets a motor's current position.
 void setEngaged(int index, boolean state)
          Engage or disengage a motor.
 void setTargetPosition(int index, long position)
          Sets a motor's target position.
 void setVelocityLimit(int index, double velocity)
          Sets a motor's velocity limit.
 
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
 

Constructor Detail

StepperPhidget

public StepperPhidget()
               throws PhidgetException
Method Detail

getMotorCount

public int getMotorCount()
                  throws PhidgetException
Returns the number of stepper motors supported by this Phidget. This does not neccesarily correspond to the number of motors actually attached to the board.

Returns:
number of supported motors
Throws:
PhidgetException - If this Phidget is not opened and attached. See open for information on determining if a device is attached.

getInputCount

public int getInputCount()
                  throws PhidgetException
Returns the number of digital inputs. Not all Stepper Controllers have digital inputs.

Returns:
number of digital inputs
Throws:
PhidgetException - If this Phidget is not opened and attached. See open for information on determining if a device is attached.

getInputState

public boolean getInputState(int index)
                      throws PhidgetException
Returns the state of a digital input. True means that the input is activated, and False indicated the default state.

Parameters:
index - index of the input
Returns:
state of the input
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is invalid. See open for information on determining if a device is attached.

getAcceleration

public double getAcceleration(int index)
                       throws PhidgetException
Returns a motor's acceleration. The valid range is between getAccelerationMin and getAccelerationMax, and refers to how fast the Stepper Controller will change the speed of a motor.

This value is in (micro)steps per second squared. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second squared.

Parameters:
index - index of motor
Returns:
acceleration of motor
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, or if the acceleration is unknown. See open for information on determining if a device is attached.

getAccelerationMax

public double getAccelerationMax(int index)
                          throws PhidgetException
Returns the maximum acceleration that a motor will accept, or return.

This value uses the same units as setAcceleration/getAcceleration.

Parameters:
index - Index of the motor
Returns:
Maximum acceleration
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is invalid. See open for information on determining if a device is attached.

getAccelerationMin

public double getAccelerationMin(int index)
                          throws PhidgetException
Returns the minimum acceleration that a motor will accept, or return.

This value uses the same units as setAcceleration/getAcceleration.

Parameters:
index - Index of the motor
Returns:
Minimum acceleration
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is invalid. See open for information on determining if a device is attached.

setAcceleration

public void setAcceleration(int index,
                            double acceleration)
                     throws PhidgetException
Sets a motor's acceleration. The valid range is between getAccelerationMin and getAccelerationMax. This controls how fast the motor changes speed.

This value is in (micro)steps per second squared. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second squared.

Parameters:
index - index of the motor
acceleration - requested acceleration for that motor
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index or acceleration are invalid. See open for information on determining if a device is attached.

getVelocity

public double getVelocity(int index)
                   throws PhidgetException
Returns a motor's current velocity. The valid range is between getVelocityMin and getVelocityMax, with 0 being stopped.

This value is in (micro)steps per second. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.

Parameters:
index - index of the motor
Returns:
current speed of the motor
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, or if the velocity in unknown. See open for information on determining if a device is attached.

getVelocityMax

public double getVelocityMax(int index)
                      throws PhidgetException
Returns the maximum velocity that a stepper motor will accept, or return.

This value uses the same units as setVelocityLimit/getVelocityLimit and getVelocity.

Parameters:
index - Index of the motor
Returns:
Maximum velocity
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is invalid. See open for information on determining if a device is attached.

getVelocityMin

public double getVelocityMin(int index)
                      throws PhidgetException
Returns the minimum velocity that a stepper motor will accept, or return.

This value uses the same units as setVelocityLimit/getVelocityLimit and getVelocity.

Parameters:
index - Index of the motor
Returns:
Minimum velocity
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is invalid. See open for information on determining if a device is attached.

setVelocityLimit

public void setVelocityLimit(int index,
                             double velocity)
                      throws PhidgetException
Sets a motor's velocity limit. This is the maximum velocity that the motor will turn at. The valid range is between getVelocityMin and getVelocityMax, with 0 being stopped.

This value is in (micro)steps per second. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.

Parameters:
index - index of the motor
velocity - requested velocity for the motor
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index or velocity are invalid. See open for information on determining if a device is attached.

getVelocityLimit

public double getVelocityLimit(int index)
                        throws PhidgetException
Returns a motor's velocity limit. This is the maximum velocity that the motor will turn at. The valid range is between getVelocityMin and getVelocityMax, with 0 being stopped.

This value is in (micro)steps per second. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.

Parameters:
index - index of the motor
Returns:
current speed of the motor
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, or if the velocity in unknown. See open for information on determining if a device is attached.

getPositionMax

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

This value uses the same units as setTargetPosition/getTargetPosition and setCurrentPosition/getCurrentPosition.

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

getPositionMin

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

This value uses the same units as setTargetPosition/getTargetPosition and setCurrentPosition/getCurrentPosition.

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

setCurrentPosition

public void setCurrentPosition(int index,
                               long position)
                        throws PhidgetException
Sets a motor's current position. Use this is (re)set the current physical position of the motor to a specific position value. This does not move the motor, and if the motor is moving, calling this will cause it to stop moving. Use setTargetPosition to move the motor to a position. The valid range is between getPositionMin and getPositionMax.

This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.

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

getCurrentPosition

public long getCurrentPosition(int index)
                        throws PhidgetException
Returns a motor's current position. This is the actual step position that the motor is at right now. The valid range is between getPositionMin and getPositionMax.

This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.

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

setTargetPosition

public void setTargetPosition(int index,
                              long position)
                       throws PhidgetException
Sets a motor's target position. Use this is set the target position for the stepper. If the stepper is engaged it will start moving towards this target position. The valid range is between getPositionMin and getPositionMax.

This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.

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

getTargetPosition

public long getTargetPosition(int index)
                       throws PhidgetException
Returns a motor's target position. This is the position that the motor wants to be at. If the motor is not moving, it probably has reached the target position, and this will match current position. The valid range is between getPositionMin and getPositionMax.

This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.

Parameters:
index - index of the motor
Returns:
target position of the motor
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, or if the position in unknown. See open for information on determining if a device is attached.

getCurrent

public double getCurrent(int index)
                  throws PhidgetException
Returns a motor's current usage. The valid range is between getCurrentMin and getCurrentMax. This value is in Amps.

Note that this is not supported on all stepper controllers.

Parameters:
index - index of the motor
Returns:
current usage of the motor
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported. See open for information on determining if a device is attached.

getCurrentLimit

public double getCurrentLimit(int index)
                       throws PhidgetException
Returns the current limit.

This value is in Amps.

Parameters:
index - Index of the motor
Returns:
Current Limit
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported. See open for information on determining if a device is attached.

setCurrentLimit

public void setCurrentLimit(int index,
                            double current)
                     throws PhidgetException
Sets a motor's current usage limit. The valid range is between getCurrentMin and getCurrentMax. This sets the maximum current that a motor will be allowed to draw. Use this with the Bipolar stepper controller to get smooth micro stepping - see the product manual for more details. This value is in Amps.

Note that this is not supported on all stepper controllers.

Parameters:
index - index of the motor
current - current limit for the motor
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported. See open for information on determining if a device is attached.

getCurrentMax

public double getCurrentMax(int index)
                     throws PhidgetException
Returns the maximum current that a stepper motor will accept, or return.

This value is in Amps.

Parameters:
index - Index of the motor
Returns:
Maximum current
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, or if this is not supported. See open for information on determining if a device is attached.

getCurrentMin

public double getCurrentMin(int index)
                     throws PhidgetException
Returns the minimum current that a stepper motor will accept, or return.

This value is in Amps.

Parameters:
index - Index of the motor
Returns:
Minimum current
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is invalid, or if this is not supported. 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 motor.

This engages or disengages the stepper motor. The motors are by default disengaged when the stepper controller is plugged in. When the stepper is disengaged, position, velocity, etc. can all be set, but the motor will not start moving until it is engaged. If position is read when a motor is disengaged, it will throw an exception.

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.

getEngaged

public boolean getEngaged(int index)
                   throws PhidgetException
Returns the engaged state of a 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.

getStopped

public boolean getStopped(int index)
                   throws PhidgetException
Returns the stopped state of a motor. Use this to determine if the motor is moving and/or up to date with the latest commands you have sent. If this is true, the motor is guaranteed to be stopped and to have processed every command issued. Generally, this would be polled after a target position is set to wait until that position is reached.

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.

addStepperPositionChangeListener

public final void addStepperPositionChangeListener(StepperPositionChangeListener l)
Adds a position change listener. The position change handler is a method that will be called when the stepper position has changed.

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

Parameters:
l - An implemetation of the StepperPositionChangeListener interface

removeStepperPositionChangeListener

public final void removeStepperPositionChangeListener(StepperPositionChangeListener l)

addStepperVelocityChangeListener

public final void addStepperVelocityChangeListener(StepperVelocityChangeListener l)
Adds a velocity change listener. The velocity change handler is a method that will be called when the stepper velocity has changed.

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

Parameters:
l - An implemetation of the StepperVelocityChangeListener interface

removeStepperVelocityChangeListener

public final void removeStepperVelocityChangeListener(StepperVelocityChangeListener l)

addCurrentChangeListener

public final void addCurrentChangeListener(CurrentChangeListener l)
Adds a current change listener. The current change handler is a method that will be called when the stepper current has changed.

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

Note that not all stepper controllers support current sensing.

Parameters:
l - An implemetation of the CurrentChangeListener interface

removeCurrentChangeListener

public final void removeCurrentChangeListener(CurrentChangeListener l)

addInputChangeListener

public final void addInputChangeListener(InputChangeListener l)
Adds an input change listener. The input change handler is a method that will be called when an input on this Stepper Controller board has changed.

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

Parameters:
l - An implemetation of the InputChangeListener interface

removeInputChangeListener

public final void removeInputChangeListener(InputChangeListener l)