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

Field Summary
static int ONE_ROTATION
          The incremental count for one whole rotation (360 degrees).
 
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
 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, getId, getName, getPriority, init_thread, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, run, set_priority, setDaemon, setName, setPriority, sleep, start, yield
 
Methods inherited from class java.lang.Object
equals, 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
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

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