ch.aplu.ftcontroller
Class FtController

java.lang.Object
  extended by ch.aplu.ftcontroller.FtController

public class FtController
extends java.lang.Object

Class to handle a fischertechnik ROBO interface connected directly to the USB port or using the wireless RF Data Link. A FtController instance communicates with the umFish40.dll using the Java API Wrapper (JAW) framework based on the Java Native Interface (JNI). Any changes on input ports are considered as events. A high performance native thread polls the interface and reports changes to a Java thread that fires listener callback methods that conform to the Java event model. All listener callbacks run in the Event Dispatch Thread EDT, so it is safe to use Swing methods directly.


Field Summary
 AnalogIn analogIn1
          A reference to the analogIn 1 instance.
 AnalogIn analogIn2
          A reference to the analogIn 2 instance.
 AnalogIn[] analogInAry
          Array of all analogIn instances.
 Counter counter1
          A reference to the counter 1 instance.
 Counter counter2
          A reference to the counter 2 instance.
 Counter counter3
          A reference to the counter 3 instance.
 Counter counter4
          A reference to the counter 4 instance.
 Counter counter5
          A reference to the counter 5 instance.
 Counter counter6
          A reference to the counter 6 instance.
 Counter counter7
          A reference to the counter 7 instance.
 Counter counter8
          A reference to the counter 8 instance.
 Counter[] counterAry
          Array of all counter instances.
 DigitalIn digitalIn
          A reference to the digitalIn instance.
 DistanceIn distanceIn1
          A reference to the distanceIn 1 instance.
 DistanceIn distanceIn2
          A reference to the distanceIn 2 instance.
 DistanceIn[] distanceInAry
          Array of all distanceIn instances.
 InfraredIn infraredIn
          A reference to the infraredIn instance.
 Lamp lamp1
          A reference to the lamp 1 instance.
 Lamp lamp2
          A reference to the lamp 2 instance.
 Lamp lamp3
          A reference to the lamp 3 instance.
 Lamp lamp4
          A reference to the lamp 4 instance.
 Lamp lamp5
          A reference to the lamp 5 instance.
 Lamp lamp6
          A reference to the lamp 6 instance.
 Lamp lamp7
          A reference to the lamp 7 instance.
 Lamp lamp8
          A reference to the lamp 8 instance.
 Lamp[] lampAry
          Array of all lamp instances.
 Motor motor1
          A reference to the motor 1 instance.
 Motor motor2
          A reference to the motor 2 instance.
 Motor motor3
          A reference to the motor 3 instance.
 Motor motor4
          A reference to the motor 4 instance.
 Motor[] motorAry
          Array of all motors instances.
 ResistorIn resistorIn1
          A reference to the resistorIn 1 instance.
 ResistorIn resistorIn2
          A reference to the resistorIn 2 instance.
 ResistorIn[] resistorInAry
          Array of all resistorIn instances.
 
Constructor Summary
FtController()
          Same as FtController("ftcontroller", true, 20, 20)
FtController(boolean doConnect)
          Same as FtController("ftcontroller", doConnect, 20, 20)
FtController(java.lang.String dll)
          Same as FtController(dll, true, 20, 20)
FtController(java.lang.String dll, boolean doConnect)
          Same as FtController(dll, doConnect, 20, 20)
FtController(java.lang.String dll, boolean doConnect, int controllerPollPeriod, int queuePollPeriod)
          Creates a FtController instance using the given Windows dll.
 
Method Summary
 void addAnalogListener(AnalogListener analogListener, int portNb)
          Same as addAnalogListener(analogListener, portNb, 0).
 void addAnalogListener(AnalogListener analogListener, int portNb, int jitter)
          Registers the given AnalogListener.
 void addConnectionListener(ConnectionListener connectionListener)
          Registers the given ConnectionListener.
 void addCounterListener(CounterListener counterListener, int counterNb)
          Registers the given CounterListener.
 void addDigitalListener(DigitalListener digitalListener)
          Registers the given DigitalListener.
 void addDistanceListener(DistanceListener distanceListener, int portNb)
          Registers the given DistanceListener.
 void addInfraredListener(InfraredListener infraredListener)
          Registers the given InfraredListener.
 void addMotorListener(MotorListener motorListener, int motorNb)
          Registers the given MotorListener for the given motor.
 void addMotorListener(MotorListener motorListener, Motor motor)
          Same as addMotorListener(MotorListener motorListener, int motorNb) for given motor.
 void addResistorListener(ResistorListener resistorListener, int portNb)
          Same as addResistorListener(resistorListener, portNb, 0).
 void addResistorListener(ResistorListener resistorListener, int portNb, int jitter)
          Registers the given ResitorListener.
 void clearAllCounters()
          Set all counters to zero.
 boolean connect()
          Establishes a connection to the controller with USB or RF Data Link by calling the native function rbOpenInterfaceUSBdis(0, 0, ftiDisUltra) (ports D1/D2 used for ultrasonic distance sensors).
static void delay(int ms)
          Delay the execution for the given time.
 void dispose()
          Releases all resources.
 void exit()
          Releases all resources and call System.exit(0).
 java.lang.String getDeviceName()
          Returns the device name.
 int getDeviceType()
          Returns the device type.
 java.lang.String getFirmwareInfo()
          Returns the firmware information.
 int getFirmwareNumber()
          Returns the firmware number.
 int getMotorsStatus()
          Returns status of all motors as a bit mask.
 int getSerialNumber()
          Returns the device serial number.
static java.lang.String getVersion()
          Returns the version information.
 boolean isConnected()
          Returns true, if connected; otherwise false.
 void waitCount(int counterNb, int count)
          Set the count of the specified counter to zero and blocks until the specified counter reaches the given count.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

motor1

public Motor motor1
A reference to the motor 1 instance.


motor2

public Motor motor2
A reference to the motor 2 instance.


motor3

public Motor motor3
A reference to the motor 3 instance.


motor4

public Motor motor4
A reference to the motor 4 instance.


motorAry

public Motor[] motorAry
Array of all motors instances. Index 0 corresponds to motor 1.


counter1

public Counter counter1
A reference to the counter 1 instance.


counter2

public Counter counter2
A reference to the counter 2 instance.


counter3

public Counter counter3
A reference to the counter 3 instance.


counter4

public Counter counter4
A reference to the counter 4 instance.


counter5

public Counter counter5
A reference to the counter 5 instance.


counter6

public Counter counter6
A reference to the counter 6 instance.


counter7

public Counter counter7
A reference to the counter 7 instance.


counter8

public Counter counter8
A reference to the counter 8 instance.


counterAry

public Counter[] counterAry
Array of all counter instances. Index 0 corresponds to counter 1.


digitalIn

public DigitalIn digitalIn
A reference to the digitalIn instance.


analogIn1

public AnalogIn analogIn1
A reference to the analogIn 1 instance.


analogIn2

public AnalogIn analogIn2
A reference to the analogIn 2 instance.


analogInAry

public AnalogIn[] analogInAry
Array of all analogIn instances. Index 0 corresponds to analogIn 1.


resistorIn1

public ResistorIn resistorIn1
A reference to the resistorIn 1 instance.


resistorIn2

public ResistorIn resistorIn2
A reference to the resistorIn 2 instance.


resistorInAry

public ResistorIn[] resistorInAry
Array of all resistorIn instances. Index 0 corresponds to resistorIn 1.


distanceIn1

public DistanceIn distanceIn1
A reference to the distanceIn 1 instance.


distanceIn2

public DistanceIn distanceIn2
A reference to the distanceIn 2 instance.


distanceInAry

public DistanceIn[] distanceInAry
Array of all distanceIn instances. Index 0 corresponds to distanceIn 1.


infraredIn

public InfraredIn infraredIn
A reference to the infraredIn instance.


lamp1

public Lamp lamp1
A reference to the lamp 1 instance.


lamp2

public Lamp lamp2
A reference to the lamp 2 instance.


lamp3

public Lamp lamp3
A reference to the lamp 3 instance.


lamp4

public Lamp lamp4
A reference to the lamp 4 instance.


lamp5

public Lamp lamp5
A reference to the lamp 5 instance.


lamp6

public Lamp lamp6
A reference to the lamp 6 instance.


lamp7

public Lamp lamp7
A reference to the lamp 7 instance.


lamp8

public Lamp lamp8
A reference to the lamp 8 instance.


lampAry

public Lamp[] lampAry
Array of all lamp instances. Index 0 corresponds to lamp 1.

Constructor Detail

FtController

public FtController()
Same as FtController("ftcontroller", true, 20, 20)

See Also:
FtController(String dll, boolean doConnect, int controllerPollPeriod, int queuePollPeriod)

FtController

public FtController(boolean doConnect)
Same as FtController("ftcontroller", doConnect, 20, 20)

See Also:
FtController(String dll, boolean doConnect, int controllerPollPeriod, int queuePollPeriod)

FtController

public FtController(java.lang.String dll)
Same as FtController(dll, true, 20, 20)

See Also:
FtController(String dll, boolean doConnect, int controllerPollPeriod, int queuePollPeriod)

FtController

public FtController(java.lang.String dll,
                    boolean doConnect)
Same as FtController(dll, doConnect, 20, 20)

See Also:
FtController(String dll, boolean doConnect, int controllerPollPeriod, int queuePollPeriod)

FtController

public FtController(java.lang.String dll,
                    boolean doConnect,
                    int controllerPollPeriod,
                    int queuePollPeriod)
Creates a FtController instance using the given Windows dll. If doConnect = true, tries to establish a connection to the controller using connect(). If it fails, an error message is displayed and when closed the application terminates. If you want to handle the connection error yourself, set doConnect = false and check the return value when calling connect().

Parameters:
dll - either the fully qualified filename to the Windows DLL or simply the name of the DLL without extension. In this case the DLL must be found in the operating system's path.
doConnect - if true, tries to establish a connection
controllerPollPeriod - the period in ms for the native polling thread
queuePollPeriod - the period in ms for the Java polling thread
See Also:
connect()
Method Detail

connect

public boolean connect()
Establishes a connection to the controller with USB or RF Data Link by calling the native function rbOpenInterfaceUSBdis(0, 0, ftiDisUltra) (ports D1/D2 used for ultrasonic distance sensors). After the connection is lost, you cannot reestablish it by calling connect, you must restart the program.

Returns:
true if successful or already connected; false, if connection fails

dispose

public void dispose()
Releases all resources. You should call dispose in any case before quitting the program.


exit

public void exit()
Releases all resources and call System.exit(0).


delay

public static void delay(int ms)
Delay the execution for the given time.

Parameters:
ms - the wait time in milliseconds

clearAllCounters

public void clearAllCounters()
Set all counters to zero.


getDeviceType

public int getDeviceType()
Returns the device type.

Returns:
the active device type, -1 if not connected

getSerialNumber

public int getSerialNumber()
Returns the device serial number.

Returns:
the active device serial number, -1 if not connected

getFirmwareNumber

public int getFirmwareNumber()
Returns the firmware number.

Returns:
the active device firmware number , -1 if not connected

getFirmwareInfo

public java.lang.String getFirmwareInfo()
Returns the firmware information.

Returns:
the active device firmware information, empty if not connected

getDeviceName

public java.lang.String getDeviceName()
Returns the device name.

Returns:
the active device name, empty if not connected

getMotorsStatus

public int getMotorsStatus()
Returns status of all motors as a bit mask. Request is made to the hardware controller. Motor 1 left: b0
Motor 1 right: b1
Motor 2 left: b2
Motor 2 right: b3
Motor 3 left: b4
Motor 3 right: b5
Motor 4 left: b6
Motor 4 right: b7


addDigitalListener

public void addDigitalListener(DigitalListener digitalListener)
Registers the given DigitalListener. Starts polling the event queue if not yet done for another listener. For the isPortChanged() callback, the initializing port state corresponds to the state when this or the connect method is called.

Parameters:
digitalListener - the DigitalListener to register

addAnalogListener

public void addAnalogListener(AnalogListener analogListener,
                              int portNb,
                              int jitter)
Registers the given AnalogListener. Starts polling the event queue if not yet done for another listener.

Parameters:
analogListener - the AnalogListener to register
portNb - the port number to monitor (1, 2)
jitter - the dead zone around the current value that must be exceeded to report an event

addAnalogListener

public void addAnalogListener(AnalogListener analogListener,
                              int portNb)
Same as addAnalogListener(analogListener, portNb, 0).


addResistorListener

public void addResistorListener(ResistorListener resistorListener,
                                int portNb,
                                int jitter)
Registers the given ResitorListener. Starts polling the event queue if not yet done for another listener.

Parameters:
resistorListener - the ResistorListener to register
portNb - the port number to monitor (1, 2)
jitter - the dead zone around the current value that must be exceeded to report an event

addResistorListener

public void addResistorListener(ResistorListener resistorListener,
                                int portNb)
Same as addResistorListener(resistorListener, portNb, 0).


addDistanceListener

public void addDistanceListener(DistanceListener distanceListener,
                                int portNb)
Registers the given DistanceListener. Starts polling the event queue if not yet done for another listener.

Parameters:
distanceListener - the DistanceListener to register
portNb - the port number to monitor (1, 2)

addInfraredListener

public void addInfraredListener(InfraredListener infraredListener)
Registers the given InfraredListener. Starts polling the event queue if not yet done for another listener.

Parameters:
infraredListener - the InfraredListener to register

addCounterListener

public void addCounterListener(CounterListener counterListener,
                               int counterNb)
Registers the given CounterListener. Starts polling the event queue if not yet done for another listener.

Parameters:
counterListener - the CounterListener to register
counterNb - the counter number to monitor (1..8)

addMotorListener

public void addMotorListener(MotorListener motorListener,
                             Motor motor)
Same as addMotorListener(MotorListener motorListener, int motorNb) for given motor.


addMotorListener

public void addMotorListener(MotorListener motorListener,
                             int motorNb)
Registers the given MotorListener for the given motor. Starts polling the event queue if not yet done for another listener. The listener assumes that the motor will run in RobMode, where some of the counters are used to for this purpose (more information in class Motor).

Parameters:
motorListener - the MotorListener to register
motorNb - the number of the motor
See Also:
Motor

addConnectionListener

public void addConnectionListener(ConnectionListener connectionListener)
Registers the given ConnectionListener. Starts polling the event queue if not yet done for another listener.

Parameters:
connectionListener - the ConnectionListener to register

isConnected

public boolean isConnected()
Returns true, if connected; otherwise false.

Returns:
Connection state

waitCount

public void waitCount(int counterNb,
                      int count)
Set the count of the specified counter to zero and blocks until the specified counter reaches the given count. A registered CounterListener still gets the count events. Warning: This method should never be used from the Event Dispatch Thread (e.g. in a GUI control callback), because the EDT will be blocked and the step counter no longer reports when the number of steps are reached.

Parameters:
counterNb - the counter number to wait for (1..8)
count - the minimum count until the method returns

getVersion

public static java.lang.String getVersion()
Returns the version information.

Returns:
the current version number