Package lejos.hardware.sensor
Class RCXRotationSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.AnalogSensor
-
- lejos.hardware.sensor.RCXRotationSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorConstants,SensorMode,SensorModes,Encoder,SampleProvider,Tachometer
public class RCXRotationSensor extends AnalogSensor 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
Nested Classes Modifier and Type Class Description protected classRCXRotationSensor.Reader
-
Field Summary
Fields Modifier and Type Field Description protected intcountprotected static int[][]incThe following table when indexed by [previous phase][current phase] provides the current direction of rotation.static intONE_ROTATIONThe incremental count for one whole rotation (360 degrees).protected RCXRotationSensor.Readerreaderprotected static intUPDATE_TIME-
Fields inherited from class lejos.hardware.sensor.AnalogSensor
currentType, port
-
Fields inherited from class lejos.hardware.sensor.BaseSensor
currentMode, modes
-
Fields inherited from interface lejos.hardware.sensor.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, BROWN, GREEN, GREEN_INDEX, MAX_TYPE, MIN_TYPE, MODE_RAW, NXT_ADC_RES, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HIGHSPEED, TYPE_HIGHSPEED_9V, 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, WHITE, YELLOW
-
-
Constructor Summary
Constructors Constructor Description RCXRotationSensor(Port p)Create an RCX rotation sensor object attached to the specified port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intgetPhase()Returns the current phase of the sensor.intgetRawTachoCount()Returns the raw values from the rotation sensor instead of degrees.intgetRotationSpeed()Returns the actual speed.intgetTachoCount()Returns the tachometer count.voidresetTachoCount()Reset the tacho count to zero.-
Methods inherited from class lejos.hardware.sensor.AnalogSensor
normalize, NXTRawIntValue, NXTRawValue, switchType
-
Methods inherited from class lejos.hardware.sensor.BaseSensor
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes
-
Methods inherited from class lejos.hardware.Device
close, releaseOnClose
-
-
-
-
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
-
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(Port p)
Create an RCX rotation sensor object attached to the specified port.- Parameters:
p- 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:
getTachoCountin interfaceEncoder- 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:
resetTachoCountin interfaceEncoder
-
getRotationSpeed
public int getRotationSpeed()
Description copied from interface:TachometerReturns the actual speed.- Specified by:
getRotationSpeedin interfaceTachometer- Returns:
- speed in degrees per second, negative value means motor is rotating backward
-
-