lejos.nxt.addon.tetrix
Class TetrixControllerFactory

java.lang.Object
  extended by lejos.nxt.addon.tetrix.TetrixControllerFactory

public class TetrixControllerFactory
extends Object

HiTechnic Tetrix Motor and Servo Controller factory class used to provide Motor and Servo controller abstractions. These are then used to obtain motor and servo instances respectively. These abstraction classes are TetrixMotorController and TetrixServoController.

Motor and servo controllers are enumerated starting at the controller connected to one of the NXT's sensor ports and then working outwards along the daisy chain. 4 controllers can be daisy-chained, with a mixture of servo and/or motor controllers. No other sensors can be connected to the daisy-chain.

Code Example:

 // Instantiate the factory and get a Motor and servo controller. We assume that there is one of 
 // each daisy-chained.
 TetrixControllerFactory cf = new TetrixControllerFactory(SensorPort.S1);
 TetrixMotorController mc = cf.newMotorController();
 TetrixServoController sc = cf.newServoController();
 
 // Display the voltage from the motor controller
 System.out.println("v=" + mc.getVoltage());'
 
 // Get an encoder motor instance. The physical motor (with encoder) is connected to the Motor 2 terminals on the controller
 TetrixEncoderMotor mot1 = mc.getEncoderMotor(TetrixMotorController.MOTOR_2);
 
 // Start the motor
 mot1.forward();
 

Author:
Kirk P. Thompson
See Also:
TetrixMotorController, TetrixServoController

Field Summary
static int DAISY_CHAIN_POSITION_1
          Position 1 (nearest to the NXT) in the daisy chain.
static int DAISY_CHAIN_POSITION_2
          Position 2 in the daisy chain.
static int DAISY_CHAIN_POSITION_3
          Position 3 in the daisy chain.
static int DAISY_CHAIN_POSITION_4
          Position 3 (furthest from the NXT)in the daisy chain.
 
Constructor Summary
TetrixControllerFactory(I2CPort port)
          Instantiate a TetrixControllerFactory using the specified NXT sensor port.
 
Method Summary
 TetrixMotorController newMotorController()
          Get the next available Tetrix Motor controller.
 TetrixServoController newServoController()
          Get the next available Tetrix Servo controller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DAISY_CHAIN_POSITION_1

public static final int DAISY_CHAIN_POSITION_1
Position 1 (nearest to the NXT) in the daisy chain. Use this if only one controller.

See Also:
Constant Field Values

DAISY_CHAIN_POSITION_2

public static final int DAISY_CHAIN_POSITION_2
Position 2 in the daisy chain.

See Also:
Constant Field Values

DAISY_CHAIN_POSITION_3

public static final int DAISY_CHAIN_POSITION_3
Position 3 in the daisy chain.

See Also:
Constant Field Values

DAISY_CHAIN_POSITION_4

public static final int DAISY_CHAIN_POSITION_4
Position 3 (furthest from the NXT)in the daisy chain.

See Also:
Constant Field Values
Constructor Detail

TetrixControllerFactory

public TetrixControllerFactory(I2CPort port)
Instantiate a TetrixControllerFactory using the specified NXT sensor port.

Parameters:
port - The NXT sensor port the Tetrix controller is connected to
Method Detail

newMotorController

public TetrixMotorController newMotorController()
Get the next available Tetrix Motor controller. Servo controllers in the daisy-chain (if any) are skipped in the search.

Successive controllers in a daisy-chain logically go "outwards" from the controller closest to the NXT as #1 to #4 for each controller in the chain. Once a specific, logical controller has been retrieved using this method, it cannot be retrieved again.

A combination of Servo and Motor controllers can be daisy-chained.

Returns:
The next available TetrixMotorController instance.
Throws:
IllegalStateException - If no more motor controllers can be returned. If there are no motor controllers in the daisy-chain, this exception is also thrown.
See Also:
newServoController()

newServoController

public TetrixServoController newServoController()
Get the next available Tetrix Servo controller. Motor controllers in the daisy-chain (if any) are skipped in the search.

Successive controllers in a daisy-chain logically go "outwards" from the controller closest to the NXT as #1 to #4 for each controller in the chain. Once a specific, logical controller has been retrieved using this method, it cannot be retrieved again.

A combination of Servo and Motor controllers can be daisy-chained.

Returns:
The next available TetrixServoController instance.
Throws:
IllegalStateException - If no more servo controllers can be returned. If there are no servo controllers in the daisy-chain, this exception is also thrown.
See Also:
newMotorController()