lejos.nxt.addon
Class RCXRotationSensor

java.lang.Object
  extended by java.lang.Thread
      extended by lejos.nxt.addon.RCXRotationSensor
All Implemented Interfaces:
Runnable, SensorConstants, Encoder, Tachometer

public class RCXRotationSensor
extends Thread
implements Tachometer, SensorConstants

Provide access to the Lego RCX Rotation Sensor. The sensor records the direction and degree of rotation. A full rotation will result in a count of +/-16. Thus each count is 22.5 degrees.

Author:
Andy Shaw

Nested Class Summary
protected  class RCXRotationSensor.Reader
           
 
Field Summary
protected  int count
           
protected static int[][] inc
          The following table when indexed by [previous phase][current phase] provides the current direction of rotation.
static int ONE_ROTATION
          The incremental count for one whole rotation (360 degrees).
protected  LegacySensorPort port
           
protected  RCXRotationSensor.Reader reader
           
protected static int UPDATE_TIME
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface lejos.nxt.SensorConstants
MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE
 
Constructor Summary
RCXRotationSensor(LegacySensorPort port)
          Create an RCX rotation sensor object attached to the specified port.
 
Method Summary
protected  int getPhase()
          Returns the current phase of the sensor.
 int getRawTachoCount()
          Returns the raw values from the rotation sensor instead of degrees.
 int getRotationSpeed()
          Returns the actual speed.
 int getTachoCount()
          Returns the tachometer count.
 void resetTachoCount()
          Reset the tacho count to zero.
 
Methods inherited from class java.lang.Thread
currentThread, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, run, setDaemon, setName, setPriority, sleep, start, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_ROTATION

public static final int ONE_ROTATION
The incremental count for one whole rotation (360 degrees).

See Also:
Constant Field Values

UPDATE_TIME

protected static final int UPDATE_TIME
See Also:
Constant Field Values

port

protected LegacySensorPort port

count

protected int count

reader

protected final RCXRotationSensor.Reader reader

inc

protected static final int[][] inc
The following table when indexed by [previous phase][current phase] provides the current direction of rotation. Invalid phase combinations result in zero.

Constructor Detail

RCXRotationSensor

public RCXRotationSensor(LegacySensorPort port)
Create an RCX rotation sensor object attached to the specified port.

Parameters:
port - port, e.g. Port.S1
Method Detail

getPhase

protected int getPhase()
Returns the current phase of the sensor. The sensor returns four distinct values read by the ADC port. Each value represents a phase in the rotation. The sequence of the phases is: 0 1 3 2 and 0 2 3 1 The transition from one phase to another can be used to identify the direction of rotation.

Returns:
the current rotation phase.

getTachoCount

public int getTachoCount()
Returns the tachometer count. NOTE: Because the RCX rotation sensor only counts 16 increments for a full rotation, the degree values are only accurate to +- 22.5 degrees.

Specified by:
getTachoCount in interface Encoder
Returns:
tachometer count in degrees, in increments of 22.5 degrees (rounded off)

getRawTachoCount

public int getRawTachoCount()
Returns the raw values from the rotation sensor instead of degrees. A full rotation of 360 degrees results in count increasing by 16.

Returns:
the raw tachometer reading

resetTachoCount

public void resetTachoCount()
Reset the tacho count to zero.

Specified by:
resetTachoCount in interface Encoder

getRotationSpeed

public int getRotationSpeed()
Description copied from interface: Tachometer
Returns the actual speed. This value is calculated every 100 ms on the NXT. TODO: getRotationSpeed() is an alternate method name, but then we are again competing with Motor.getSpeed()

Specified by:
getRotationSpeed in interface Tachometer
Returns:
speed in degrees per second, negative value means motor is rotating backward