ch.aplu.ftcontroller
Class Motor

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

public class Motor
extends java.lang.Object

Class to handle the 4 motors at motor ports M1..M4. For all methods with a step parameter, the motor is put in the so-called "RobMode". Two switches/counters are used: The "step switch" is preset to the number of steps and counts left each time the switch is pressed/released. When the count reaches 0, the motor stops. When the "end switch" is pressed the step switch is set to 0 and the motor stops immediately. The end switch is only active, if the motor turns left (if motor.right(n) is called). The following switch assignement is assumed:

motor nb 1: end switch I1, step switch I2
motor nb 2: end switch I3, step switch I4
motor nb 3: end switch I5, step switch I6
motor nb 4: end switch I7, step switch I8

In RobMode a registered counter listener at the step switch reports the count changes, but the counter at the end switch is disabled and a registered counter listener at the end switch will not report the press event. It is recommended to register a MotorListener that reports each step change and information whether the motor stopped because the step is reached or the end switch is pressed.


Method Summary
 int getNumber()
          Returns number of motor (1..4).
 boolean isRotating()
          Returns state of motor.
 Motor left()
          Starts turning the motor to the left (seen from front).
 Motor left(int steps)
          Turns right given nb of steps to the left (seen from front).
 Motor left(int steps, boolean blocking)
          Same as left(steps) but if blocking = true, blocks until steps is reached or the end switch is pressed.
 Motor right()
          Starts turning the motor to the right (seen from front).
 Motor right(int steps)
          Turns right given nb of steps to the right (seen from front).
 Motor right(int steps, boolean blocking)
          Same as right(steps) but if blocking = true, blocks until steps is reached.
 Motor setSpeed(int speed)
          Sets the rotation speed.
 Motor stop()
          Stops the motor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNumber

public int getNumber()
Returns number of motor (1..4).

Returns:
the number of the motor

setSpeed

public Motor setSpeed(int speed)
Sets the rotation speed. Keep in mind that the new speed is not modified until the next right/left method invocation. Default value: 8.

Parameters:
speed - the speed value 1..8 (1 is slowest)
Returns:
a reference to the motor to allow chaining

stop

public Motor stop()
Stops the motor. If the motor is not rotating, nothing happens.

Returns:
a reference to the motor to allow chaining

left

public Motor left()
Starts turning the motor to the left (seen from front).

Returns:
a reference to the motor to allow chaining

right

public Motor right()
Starts turning the motor to the right (seen from front).

Returns:
a reference to the motor to allow chaining

left

public Motor left(int steps)
Turns right given nb of steps to the left (seen from front). After the motor is started, the method returns. If the end switch is pressed, the motor stops immediately. The motor is put in RobMode (see comment in the Motor class overview).

Parameters:
steps - the number of switch actuations (press or release) of the step switch
Returns:
a reference to the motor to allow chaining

right

public Motor right(int steps)
Turns right given nb of steps to the right (seen from front). After the motor is started, the method returns. The end switch is inactive. The motor is put in RobMode (see comment in the Motor class overview).

Parameters:
steps - the number of switch actuations (press or release) of the step switch (see comment in the Motor class overview).
Returns:
a reference to the motor to allow chaining

left

public Motor left(int steps,
                  boolean blocking)
Same as left(steps) but if blocking = true, blocks until steps is reached or the end switch is pressed. Warning: This method should never be used with blocking = true 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. The callback methods of a registered MotorListener are still invoked.

Parameters:
steps - the number of switch actuations (press or release)
blocking - if true, the methods blocks until the step is reached

right

public Motor right(int steps,
                   boolean blocking)
Same as right(steps) but if blocking = true, blocks until steps is reached. The end switch is inactive. Warning: This method should never be used with blocking = true 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. The callback methods of a registered MotorListener are still invoked.

Parameters:
steps - the number of switch actuations (press or release)
blocking - if true, the methods blocks until the step is reached

isRotating

public boolean isRotating()
Returns state of motor.

Returns:
true, if rotating, otherwise false