lejos.nxt.addon
Class RCXRotationSensor
java.lang.Object
java.lang.Thread
lejos.nxt.addon.RCXRotationSensor
- All Implemented Interfaces:
- Runnable, SensorConstants
public class RCXRotationSensor
- extends Thread
- implements 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
WARNING: THIS CLASS IS SHARED BETWEEN THE classes AND pccomms PROJECTS.
DO NOT EDIT THE VERSION IN pccomms AS IT WILL BE OVERWRITTEN WHEN THE PROJECT IS BUILT.
| 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_CUSTOM, 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 |
|
Method Summary |
int |
getCount()
Returns the current count. |
protected int |
getPhase()
Returns the current phase of the sensor. |
void |
resetCount()
Resets the current count to zero. |
| Methods inherited from class java.lang.Thread |
currentThread, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, run, setDaemon, setPriority, sleep, start, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ONE_ROTATION
public static final int ONE_ROTATION
- 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.
RCXRotationSensor
public RCXRotationSensor(LegacySensorPort port)
- Create an RCX rotation sensor object attached to the specified port.
- Parameters:
port - port, e.g. Port.S1
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.
getCount
public int getCount()
- Returns the current count.
- Returns:
- the current count
resetCount
public void resetCount()
- Resets the current count to zero.