Class TetrixControllerFactory
- java.lang.Object
-
- lejos.hardware.device.tetrix.TetrixControllerFactory
-
public class TetrixControllerFactory extends java.lang.ObjectHiTechnic 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 areTetrixMotorControllerandTetrixServoController.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
Fields Modifier and Type Field Description static intDAISY_CHAIN_POSITION_1Position 1 (nearest to the NXT) in the daisy chain.static intDAISY_CHAIN_POSITION_2Position 2 in the daisy chain.static intDAISY_CHAIN_POSITION_3Position 3 in the daisy chain.static intDAISY_CHAIN_POSITION_4Position 3 (furthest from the NXT)in the daisy chain.
-
Constructor Summary
Constructors Constructor Description TetrixControllerFactory(Port port)Instantiate aTetrixControllerFactoryusing the specified NXT sensor port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TetrixMotorControllernewMotorController()Get the next available Tetrix Motor controller.TetrixServoControllernewServoController()Get the next available Tetrix Servo controller.
-
-
-
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(Port port)
Instantiate aTetrixControllerFactoryusing 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
TetrixMotorControllerinstance. - Throws:
java.lang.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
TetrixServoControllerinstance. - Throws:
java.lang.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()
-
-