public class TetrixControllerFactory
extends java.lang.Object
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();
TetrixMotorController
,
TetrixServoController
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
TetrixControllerFactory(Port port)
Instantiate a
TetrixControllerFactory using the specified NXT sensor port. |
Modifier and Type | Method and Description |
---|---|
TetrixMotorController |
newMotorController()
Get the next available Tetrix Motor controller.
|
TetrixServoController |
newServoController()
Get the next available Tetrix Servo controller.
|
public static final int DAISY_CHAIN_POSITION_1
public static final int DAISY_CHAIN_POSITION_2
public static final int DAISY_CHAIN_POSITION_3
public static final int DAISY_CHAIN_POSITION_4
public TetrixControllerFactory(Port port)
TetrixControllerFactory
using the specified NXT sensor port.port
- The NXT sensor port the Tetrix controller is connected topublic TetrixMotorController newMotorController()
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.
TetrixMotorController
instance.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.newServoController()
public TetrixServoController newServoController()
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.
TetrixServoController
instance.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.newMotorController()