lejos.nxt.addon.tetrix
Class TetrixServoController

java.lang.Object
  extended by lejos.nxt.I2CSensor
      extended by lejos.nxt.addon.tetrix.TetrixServoController
All Implemented Interfaces:
SensorConstants

public class TetrixServoController
extends I2CSensor

HiTechnic Servo Controller abstraction. Provides TetrixServo instances which are used to control the Tetrix servos.

Servos are driven by a PWM signal with varying pulse widths controlling the rotational position of the servo actuator. The pulse nominally ranges from 1.0 ms to 2.0 ms with 1.5 ms always being center of range. Pulse widths outside this range can be used for "overtravel" -moving the servo beyond its normal range.

As an example, for a servo with a 90 deg. travel range, a pulse width of 1.5 ms (1500 microseconds) will typically set the servo to its "neutral" position or 45 degrees, a pulse of 1.25 ms could set it to 0 degrees and a pulse of 1.75 ms to 90 degrees. The physical limits and timings of the servo hardware varies between brands and models, but a general 90 degree servo's angular motion will travel somewhere in the range of 90 deg. - 120 deg. and the neutral position is almost always at 1.5 ms. This is the "standard pulse servo mode" used by all hobby analog servos.

The HiTechic Servo Controller allows setting of the PWM output from 0.75 - 2.25ms. Note that some servos may hit their internal mechanical limits at each end of this range causing them to consume excessive current and potentially be damaged.

Use TetrixControllerFactory.newServoController() to retrieve a TetrixServoController instance.

Author:
Kirk P. Thompson
See Also:
TetrixControllerFactory

Field Summary
static int SERVO_1
          Represents the servo connected to Channel 1 as indicated on the controller
static int SERVO_2
          Represents the servo connected to Channel 2 as indicated on the controller
static int SERVO_3
          Represents the servo connected to Channel 3 as indicated on the controller
static int SERVO_4
          Represents the servo connected to Channel 4 as indicated on the controller
static int SERVO_5
          Represents the servo connected to Channel 5 as indicated on the controller
static int SERVO_6
          Represents the servo connected to Channel 6 as indicated on the controller
 
Fields inherited from class lejos.nxt.I2CSensor
address, DEFAULT_I2C_ADDRESS, port, REG_PRODUCT_ID, REG_VENDOR_ID, REG_VERSION
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
 
Constructor Summary
TetrixServoController(I2CPort port, int daisyChainPosition)
          Instantiate for a HiTechnic TETRIX Servo Controller connected to the given port and daisy chain position.
 
Method Summary
 void flt()
          Set all servos connected to this controller to float mode.
 TetrixServo getServo(int servoID)
          Get the TetrixServo instance that is associated with the passed servoID.
 int getStepTime()
          Gets the step time used for all servos on this controller.
 boolean isMoving()
          Returns whether or not there are servos on this controller that are moving.
 void setStepTime(int step)
          Sets the step time used for all servos on this controller.
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getAddress, getData, getData, getPort, getProductID, getVendorID, getVersion, sendData, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVO_1

public static final int SERVO_1
Represents the servo connected to Channel 1 as indicated on the controller

See Also:
Constant Field Values

SERVO_2

public static final int SERVO_2
Represents the servo connected to Channel 2 as indicated on the controller

See Also:
Constant Field Values

SERVO_3

public static final int SERVO_3
Represents the servo connected to Channel 3 as indicated on the controller

See Also:
Constant Field Values

SERVO_4

public static final int SERVO_4
Represents the servo connected to Channel 4 as indicated on the controller

See Also:
Constant Field Values

SERVO_5

public static final int SERVO_5
Represents the servo connected to Channel 5 as indicated on the controller

See Also:
Constant Field Values

SERVO_6

public static final int SERVO_6
Represents the servo connected to Channel 6 as indicated on the controller

See Also:
Constant Field Values
Constructor Detail

TetrixServoController

public TetrixServoController(I2CPort port,
                             int daisyChainPosition)
Instantiate for a HiTechnic TETRIX Servo Controller connected to the given port and daisy chain position.

Parameters:
port - The sensor port the controller (if daisy-chained, the first) is connected to.
daisyChainPosition - The position of the controller in the daisy chain.
Throws:
IllegalStateException - if a Servo Controller was not found with given port and daisyChainPosition
See Also:
TetrixControllerFactory.DAISY_CHAIN_POSITION_1, TetrixControllerFactory.DAISY_CHAIN_POSITION_2, TetrixControllerFactory.DAISY_CHAIN_POSITION_3, TetrixControllerFactory.DAISY_CHAIN_POSITION_4, SensorPort
Method Detail

getServo

public TetrixServo getServo(int servoID)
Get the TetrixServo instance that is associated with the passed servoID.

Parameters:
servoID - The motor ID number SERVO_1 to SERVO_6. This is indicated on the HiTechnic Servo Controller.
Returns:
The TetrixServo instance associated with the labeled channel
See Also:
SERVO_1, SERVO_2, SERVO_3, SERVO_4, SERVO_5, SERVO_6

isMoving

public boolean isMoving()
Returns whether or not there are servos on this controller that are moving. This method always returns false when the step time is set to 0 (disabled).

Returns:
true if any servo is moving to position.
See Also:
setStepTime(int)

flt

public void flt()
Set all servos connected to this controller to float mode. This means they are powered down and will not attempt to hold their current position. The next call to any motion command for any servo will re-enable power to all servo channels.


setStepTime

public void setStepTime(int step)
Sets the step time used for all servos on this controller. This sets the step time for the servo channel which has the furthest to move. Other servo channels which are not at their designated positions yet will run at a slower rate to ensure they reach their destination positions at the same time. The controller defaults to 0 on power-up.

The step time can be considered a delay before progressing to the next step. For example, if a servo is positioned at 1500 microseconds pulse width, and you give it a new position command of 2000 microseconds, it will normally go as fast as it can to get to the new position. If you want it to go to the new position but not at the maximum output, you can set the step to a value from 0 to 15.

One of the main things it could be useful for, is if you have two servos with different loads, and you want them to be as much in sync as possible. You can set the speed to slow the controller from changing the servo signals instantly.

The isMoving() method always returns false if the step time is set to zero.

Parameters:
step - Step Time, 0-15. Setting to 0 disables step time.
Throws:
IllegalArgumentException - If step is not in the range 0 to 15
See Also:
getStepTime(), isMoving()

getStepTime

public int getStepTime()
Gets the step time used for all servos on this controller.

Returns:
The step time 0-15. 0 means step is disabled.
See Also:
setStepTime(int)