com.phidgets
Class MotorControlPhidget

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

public final class MotorControlPhidget
extends Phidget

This class represents a Phidget Motor Controller. All Methods to to control a motor controller and read back motor data are implemented in this class.

The Motor Control Phidget is able to control 1 or more DC motors. Both speed and acceleration are controllable. Speed is controlled via PWM. The size of the motors that can be driven depends on the motor controller. See your hardware documentation for more information.

The motor Controller boards also has 0 or more digital inputs.

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
MotorControlPhidget()
           
 
Method Summary
 void addBackEMFUpdateListener(BackEMFUpdateListener l)
          Adds a Back EMF update listener.
 void addCurrentChangeListener(CurrentChangeListener l)
          Adds a current change listener.
 void addCurrentUpdateListener(CurrentUpdateListener l)
          Adds a current update listener.
 void addEncoderPositionChangeListener(EncoderPositionChangeListener l)
          Adds a position change listener.
 void addEncoderPositionUpdateListener(EncoderPositionUpdateListener l)
          Adds a position update listener.
 void addInputChangeListener(InputChangeListener l)
          Adds an input change listener.
 void addMotorVelocityChangeListener(MotorVelocityChangeListener l)
          Adds a velocity change listener.
 void addSensorUpdateListener(SensorUpdateListener l)
          Adds a sensor update 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 getBackEMF(int index)
          Sets the Back EMF voltage for a specific motor.
 boolean getBackEMFSensingState(int index)
          Returns the Back EMF sensing state for a specific motor.
 double getBraking(int index)
          Returns the braking value for a specific motor.
 double getCurrent(int index)
          Returns a motor's current usage.
 int getEncoderCount()
          Returns the number of encoders.
 int getEncoderPosition(int index)
          Returns the position of an encoder.
 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 motors supported by this Phidget.
 boolean getRatiometric()
          Returns the ratiometric state of a sensor.
 int getSensorCount()
          Returns the number of analog inputs.
 int getSensorRawValue(int index)
          Returns the raw value of a sensor(12-bit).
 int getSensorValue(int index)
          Returns the value of a sensor.
 double getSpeed(int index)
          Deprecated. Replaced by getVelocity(int)
 double getSupplyVoltage()
          Sets the supply voltage for the motors.
 double getVelocity(int index)
          Returns a motor's velocity.
 void removeBackEMFUpdateListener(BackEMFUpdateListener l)
           
 void removeCurrentChangeListener(CurrentChangeListener l)
           
 void removeCurrentUpdateListener(CurrentUpdateListener l)
           
 void removeEncoderPositionChangeListener(EncoderPositionChangeListener l)
           
 void removeEncoderPositionUpdateListener(EncoderPositionUpdateListener l)
           
 void removeInputChangeListener(InputChangeListener l)
           
 void removeMotorVelocityChangeListener(MotorVelocityChangeListener l)
           
 void removeSensorUpdateListener(SensorUpdateListener l)
           
 void setAcceleration(int index, double acceleration)
          Sets a motor's acceleration.
 void setBackEMFSensingState(int index, boolean bEMFState)
          Sets the Back EMF sensing state for a specific motor.
 void setBraking(int index, double braking)
          Sets the braking value for a specific motor.
 void setEncoderPosition(int index, int position)
          Sets the position of a specific encoder.
 void setRatiometric(boolean ratiometric)
          Sets the ratiometric state.
 void setSpeed(int index, double speed)
          Deprecated. Replaced by setVelocity(int, double)
 void setVelocity(int index, double velocity)
          Sets a motor's velocity.
 
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

MotorControlPhidget

public MotorControlPhidget()
                    throws PhidgetException
Method Detail

getMotorCount

public int getMotorCount()
                  throws PhidgetException
Returns the number of 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 Motor 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.

getEncoderCount

public int getEncoderCount()
                    throws PhidgetException
Returns the number of encoders. Not all Motor Controllers have encoders.

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

getSensorCount

public int getSensorCount()
                   throws PhidgetException
Returns the number of analog inputs. Not all Motor Controllers have analog inputs.

Returns:
number of analog 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 indicates 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.

getEncoderPosition

public int getEncoderPosition(int index)
                       throws PhidgetException
Returns the position of an encoder. This is an absolute position as calcutated since the encoder was plugged in. This value can be reset to anything using setEncoderPosition. Not all Motor Controllers have encoders.

Parameters:
index - index of the encoder
Returns:
position of the encoder
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.

setEncoderPosition

public void setEncoderPosition(int index,
                               int position)
                        throws PhidgetException
Sets the position of a specific encoder. This resets the internal position count for an encoder. This call in no way actually sends information to the device, as an absolute position is maintained only in the library. After this call, position changes from the encoder will use the new value to calculate absolute position as reported by getEncoderPosition(int). Not all Motor Controllers have encoders.

Parameters:
index - index of the encoder
position - new position for a encoder.
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.

getSensorValue

public int getSensorValue(int index)
                   throws PhidgetException
Returns the value of a sensor. Not all Motor Controllers have analog sensors.

Parameters:
index - index of the sensor
Returns:
sensor value of the sensor. Range is 0-1000.
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.

getSensorRawValue

public int getSensorRawValue(int index)
                      throws PhidgetException
Returns the raw value of a sensor(12-bit). Not all Motor Controllers have analog sensors.

Parameters:
index - index of the sensor
Returns:
sensor raw value of the sensor. Range is 0-4096.
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.

getRatiometric

public boolean getRatiometric()
                       throws PhidgetException
Returns the ratiometric state of a sensor. Not all Motor Controllers have analog sensors.

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

setRatiometric

public void setRatiometric(boolean ratiometric)
                    throws PhidgetException
Sets the ratiometric state. This controls the voltage reference used for sampling the analog sensors.

Parameters:
ratiometric - new ratiometric state of the sensors
Throws:
PhidgetException - If this Phidget is not opened and attached. 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 Motor Controller will change the speed of a motor.

Parameters:
index - Index of motor
Returns:
acceleration of motor
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.

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 value are invalid. 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.

Parameters:
index - Index of the motor
Returns:
Maximum acceleration
Throws:
PhidgetException - If this Phidget is not opened and attached. 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.

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

getVelocity

public double getVelocity(int index)
                   throws PhidgetException
Returns a motor's velocity. The valid range is -100 - 100, with 0 being stopped.

Parameters:
index - index of the motor
Returns:
current velocity of the motor
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.

getSpeed

public double getSpeed(int index)
                throws PhidgetException
Deprecated. Replaced by getVelocity(int)

Throws:
PhidgetException

setVelocity

public void setVelocity(int index,
                        double velocity)
                 throws PhidgetException
Sets a motor's velocity. The valid range is from -100 to 100, with 0 being stopped. -100 and 100 both correspond to full voltage, with the value in between corresponding to different widths of PWM.

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 speed value are invalid. See open for information on determining if a device is attached.

setSpeed

public void setSpeed(int index,
                     double speed)
              throws PhidgetException
Deprecated. Replaced by setVelocity(int, double)

Throws:
PhidgetException

getCurrent

public double getCurrent(int index)
                  throws PhidgetException
Returns a motor's current usage. The valid range is 0 - 255. Note that this is not supported on all motor controllers.

Parameters:
index - index of the motor
Returns:
current usage of the motor
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.

getBackEMFSensingState

public boolean getBackEMFSensingState(int index)
                               throws PhidgetException
Returns the Back EMF sensing state for a specific motor. Note that this is not supported on all motor controllers.

Parameters:
index - Index of the motor
Returns:
Back EMF Sensing state for the motor
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.

setBackEMFSensingState

public void setBackEMFSensingState(int index,
                                   boolean bEMFState)
                            throws PhidgetException
Sets the Back EMF sensing state for a specific motor. Note that this is not supported on all motor controllers.

Parameters:
index - Index of the motor
bEMFState - new Back EMF Sensing State
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.

getBackEMF

public double getBackEMF(int index)
                  throws PhidgetException
Sets the Back EMF voltage for a specific motor. Note that this is not supported on all motor controllers.

Parameters:
index - Index of the motor
Returns:
Back EMF voltage of the motor
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.

getSupplyVoltage

public double getSupplyVoltage()
                        throws PhidgetException
Sets the supply voltage for the motors. This could be higher than the actual voltage. Note that this is not supported on all motor controllers.

Returns:
Supply voltage of the motor, in volts
Throws:
PhidgetException - If this Phidget is not opened and attached, the index is invalid, or if setBackEMFSensingState is not set. See open for information on determining if a device is attached.

getBraking

public double getBraking(int index)
                  throws PhidgetException
Returns the braking value for a specific motor. Note that this is not supported on all motor controllers.

Parameters:
index - index of the motor
Returns:
Braking value for the motor
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.

setBraking

public void setBraking(int index,
                       double braking)
                throws PhidgetException
Sets the braking value for a specific motor. This is applied when velocity is 0. Default is 0%. Note that this is not supported on all motor controllers. Range is 0-100.

Parameters:
index - index of the motor
braking - new braking value for a specific motor
Throws:
PhidgetException - If this Phidget is not opened and attached, the index is invalid, or the brake value is invalid See open for information on determining if a device is attached.

addMotorVelocityChangeListener

public final void addMotorVelocityChangeListener(MotorVelocityChangeListener l)
Adds a velocity change listener. The velocity change handler is a method that will be called when the velocity of a motor changes. These velocity changes are reported back from the Motor Controller and so correspond to actual motor speeds over time.

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 MotorVelocityChangeListener interface

removeMotorVelocityChangeListener

public final void removeMotorVelocityChangeListener(MotorVelocityChangeListener 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 current consumed by a motor changes. Note that this event is not supported with the current motor controller, but will be supported in the future

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

Parameters:
l - An implemetation of the CurrentChangeListener interface

removeCurrentChangeListener

public final void removeCurrentChangeListener(CurrentChangeListener l)

addCurrentUpdateListener

public final void addCurrentUpdateListener(CurrentUpdateListener l)
Adds a current update listener. The current change handler is a method that will be called every 8ms, regardless whether the current consumed by a motor changes. Note that this event is not supported with all motor controllers

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

Parameters:
l - An implemetation of the CurrentUpdateListener interface

removeCurrentUpdateListener

public final void removeCurrentUpdateListener(CurrentUpdateListener 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 Motor 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)

addEncoderPositionChangeListener

public final void addEncoderPositionChangeListener(EncoderPositionChangeListener l)
Adds a position change listener. The position change handler is a method that will be called when the position of an encoder changes. The position change event provides data about how many ticks have occured, and how much time has passed since the last position change event, but does not contain an absolute position. This can be obtained from getEncoderPosition(int).

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

Parameters:
l - An implemetation of the EncoderPositionChangeListener interface

removeEncoderPositionChangeListener

public final void removeEncoderPositionChangeListener(EncoderPositionChangeListener l)

addEncoderPositionUpdateListener

public final void addEncoderPositionUpdateListener(EncoderPositionUpdateListener l)
Adds a position update listener. The position update handler is a method that will be called at a constant rate; every 8ms, whether the encoder position has changed or not. The position update event provides data about how many ticks have occured since the last position update event, but does not contain an absolute position. This can be obtained from getEncoderPosition(int).

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

Parameters:
l - An implemetation of the EncoderPositionUpdateListener interface

removeEncoderPositionUpdateListener

public final void removeEncoderPositionUpdateListener(EncoderPositionUpdateListener l)

addBackEMFUpdateListener

public final void addBackEMFUpdateListener(BackEMFUpdateListener l)
Adds a Back EMF update listener. The Back EMF update handler is a method that will be called at a constant rate; every 8ms, whether the Back EMF value has changed or not.

There is no limit on the number of Back EMF update handlers that can be registered for a particular Phidget.

Parameters:
l - An implemetation of the BackEMFUpdateListener interface

removeBackEMFUpdateListener

public final void removeBackEMFUpdateListener(BackEMFUpdateListener l)

addSensorUpdateListener

public final void addSensorUpdateListener(SensorUpdateListener l)
Adds a sensor update listener. The sensor update handler is a method that will be called at a constant rate; every 8ms, whether the sensor value has changed or not.

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

Parameters:
l - An implemetation of the SensorUpdateListener interface

removeSensorUpdateListener

public final void removeSensorUpdateListener(SensorUpdateListener l)