ukcrobots.simplecore
Class Motor

java.lang.Object
  |
  +--ukcrobots.simplecore.Motor

public class Motor
extends Object

Model a motor. Only one instance may be created for each output port. This class is based on josx.platform.rcx.Motor

Version:
2003.04.01

Field Summary
static int DEVICE_MODE_BACKWARD
           
static int DEVICE_MODE_FLOATING
           
static int DEVICE_MODE_FORWARD
           
static int DEVICE_MODE_STOPPED
           
 
Constructor Summary
Motor(char port)
          Create a motor.
 
Method Summary
 void backward()
          Causes the device to rotate backwards.
 void flt()
          Causes the motor to float.
 void forward()
          Causes the device to rotate forward.
 int getMode()
          Return one of the following values: DEVICE_MODE_STOPPED - the device is stopped DEVICE_MODE_FORWARD - the device is running forward DEVICE_MODE_BACKWARD - the device is running backward DEVICE_MODE_FLOATING - the device is floating
 int getPower()
          Returns the motor's current power level.
 boolean isBackward()
           
 boolean isFloating()
           
 boolean isForward()
           
 boolean isMoving()
           
 boolean isStopped()
           
 void reverse()
          Reverses direction of the device.
 void setPower(int power)
          Sets power to a value between 0 and 7.
 void stop()
          Causes the motor to stop, pretty much instantaneously.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Field Detail

DEVICE_MODE_FORWARD

public static final int DEVICE_MODE_FORWARD
See Also:
Constant Field Values

DEVICE_MODE_BACKWARD

public static final int DEVICE_MODE_BACKWARD
See Also:
Constant Field Values

DEVICE_MODE_STOPPED

public static final int DEVICE_MODE_STOPPED
See Also:
Constant Field Values

DEVICE_MODE_FLOATING

public static final int DEVICE_MODE_FLOATING
See Also:
Constant Field Values
Constructor Detail

Motor

public Motor(char port)
      throws NoSuchDeviceException,
             AlreadyCreatedException
Create a motor.

Parameters:
port - Which output port the motor is attached to. This should have a value of 'A', 'B', or 'C'.
Throws:
NoSuchDeviceException - If the value of id is incorrect.
AlreadyCreatedException - If a Motor has already been created for this output port.
Method Detail

setPower

public void setPower(int power)
Sets power to a value between 0 and 7.


forward

public void forward()
Causes the device to rotate forward.


backward

public void backward()
Causes the device to rotate backwards.


reverse

public void reverse()
Reverses direction of the device. It only has effect if the device is moving.


getPower

public int getPower()
Returns the motor's current power level.


getMode

public int getMode()
Return one of the following values: DEVICE_MODE_STOPPED - the device is stopped DEVICE_MODE_FORWARD - the device is running forward DEVICE_MODE_BACKWARD - the device is running backward DEVICE_MODE_FLOATING - the device is floating

Returns:
The mode this device is in.

stop

public void stop()
Causes the motor to stop, pretty much instantaneously. In other words, the device doesn't just stop; it will resist any further motion.


flt

public void flt()
Causes the motor to float. The motor will lose all power, but this is not the same as stopping.


isMoving

public boolean isMoving()
Returns:
true iff the device is currently in motion.

isForward

public boolean isForward()
Returns:
true iff the motor is currently moving forward.

isBackward

public boolean isBackward()
Returns:
true iff the motor is currently moving backward.

isFloating

public boolean isFloating()
Returns:
true iff the motor is currently in float mode.

isStopped

public boolean isStopped()
Returns:
true iff the motor is currently in float mode.