lejos.nxt.addon
Class OpticalDistanceSensor

java.lang.Object
  extended by lejos.nxt.I2CSensor
      extended by lejos.nxt.addon.OpticalDistanceSensor
All Implemented Interfaces:
SensorConstants, RangeFinder

public class OpticalDistanceSensor
extends I2CSensor
implements RangeFinder

Supports Mindsensors DIST-Nx series of Optical Distance Sensor.
This sensor is used for greater precision than the Ultrasonic Sensor.

Author:
Michael Smith

Lum, Many thanks for helping me test this class.

Field Summary
static byte CUSTOM
          Custom sensor
static byte GP2D12
           
static byte GP2D120
          DIST-Nx-Short
static byte GP2YA02
          DIST-Nx-Long
static byte GP2YA21
          DIST-Nx-Medium
 
Fields inherited from class lejos.nxt.I2CSensor
address, DEFAULT_I2C_ADDRESS, port, REG_PRODUCT_ID, REG_VENDOR_ID, REG_VERSION
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, 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, WHITE, YELLOW
 
Constructor Summary
OpticalDistanceSensor(I2CPort port)
           
OpticalDistanceSensor(I2CPort port, int address)
           
 
Method Summary
 int getCurveCount()
          Gets the number of points that will be in the curve.
 int getDistance()
          Returns the distance from the object in millimeters.
 int getDistLSB()
          Returns the current distance in millimeters for the LSB.
 int getDistMaxLSB()
          Gets the max value in millimeters for the LSB.
Used for recalibrating the sensor.
 int getDistMaxMSB()
          Gets the max value in millimeters for the MSB.
Used for recalibrating the sensor.
 int getDistMinLSB()
          Gets the min value in millimeters for the LSB.
Used for recalibrating the sensor.
 int getDistMinMSB()
          Gets the min value in millimeters for the MSB.
Used for recalibrating the sensor.
 int getDistMSB()
          Returns the current distance in millimeters for MSB.
 int getDistPointLSB(int index)
          Gets millimeter value of the specific index for the LSB.
Used for recalibrating the sensor.
 int getDistPointMSB(int index)
          Gets millimeter value of the specific index for the MSB.
 float getRange()
          Returns the range to the object in centimeters.
 float[] getRanges()
          If the sensor is capable, this method returns multiple range values from a single scan.
 int getSensorModule()
          Used to determine the sensor module that is configured.
 int getVoltLSB()
          Returns the current voltage level in millivolts for the LSB.
 int getVoltMSB()
          Returns the current voltage level in millivolts for the MSB.
 int getVoltPointLSB(int index)
          Gets millivolts value of the specific index for the LSB.
 int getVoltPointMSB(int index)
          Gets millivolts value of the specific index for the MSB.
 void powerOff()
          Turns power to the sensor module off.
 void powerOn()
          Turns the sensor module on.
 void setAPDAOff()
          Disables (ADPA) Auto Detecting Parallel Architecture.
Disabled by default.
 void setAPDAOn()
          Enables (ADPA) Auto Detecting Parallel Architecture.
 void setCurveCount(int value)
          Sets the number of points that will be in the configured curve.
 void setDistMaxLSB(int value)
          Sets the max value in millimeters for LSB.
Used for recalibrating the sensor.
 void setDistMaxMSB(int value)
          Sets the max value in millimeters for the MSB.
Used for recalibrating the sensor.
 void setDistMinLSB(int value)
          Sets the min value in millimeters for the LSB.
Used for recalibrating the sensor.
 void setDistMinMSB(int value)
          Sets the min value in millimeters for the MSB.
Used for recalibrating the sensor.
 void setDistPointLSB(int index, int value)
          Sets millimeter value of the specific index for the LSB.
 void setDistPointMSB(int index, int value)
          Sets millimeter value of the specific index for the MSB.
 void setSensorModule(byte module)
          This only needs the be run if you are changing the sensor.
 void setVoltPointLSB(int index, int value)
          Sets millivolts value of the specific index for the LSB.
 void setVoltPointMSB(int index, int value)
          Sets millivolts value of the specific index for the MSB.
 
Methods inherited from class lejos.nxt.I2CSensor
fetchString, getAddress, getData, getData, getData, getId, getProductID, getVendorID, getVersion, sendData, sendData, sendData, setAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GP2D12

public static final byte GP2D12
See Also:
Constant Field Values

GP2D120

public static final byte GP2D120
DIST-Nx-Short

See Also:
Constant Field Values

GP2YA21

public static final byte GP2YA21
DIST-Nx-Medium

See Also:
Constant Field Values

GP2YA02

public static final byte GP2YA02
DIST-Nx-Long

See Also:
Constant Field Values

CUSTOM

public static final byte CUSTOM
Custom sensor

See Also:
Constant Field Values
Constructor Detail

OpticalDistanceSensor

public OpticalDistanceSensor(I2CPort port)
Parameters:
port - NXT sensor port 1-4

OpticalDistanceSensor

public OpticalDistanceSensor(I2CPort port,
                             int address)
Parameters:
port - NXT sensor port 1-4
address - I2C address for the sensor
Method Detail

setSensorModule

public void setSensorModule(byte module)
This only needs the be run if you are changing the sensor.

Parameters:
module - changes the sensor module attached the he board.

getDistance

public int getDistance()
Returns the distance from the object in millimeters. This returns the same value as getDistLSB.

Returns:
int

getRange

public float getRange()
Returns the range to the object in centimeters.

Specified by:
getRange in interface RangeFinder
Returns:
the range as a float

powerOn

public void powerOn()
Turns the sensor module on.
Power is turned on by the constructor method.


powerOff

public void powerOff()
Turns power to the sensor module off.


setAPDAOn

public void setAPDAOn()
Enables (ADPA) Auto Detecting Parallel Architecture.
Once you have enabled it you don't have to enable again.


setAPDAOff

public void setAPDAOff()
Disables (ADPA) Auto Detecting Parallel Architecture.
Disabled by default.


getDistLSB

public int getDistLSB()
Returns the current distance in millimeters for the LSB.

Returns:
int

getDistMSB

public int getDistMSB()
Returns the current distance in millimeters for MSB.

Returns:
int

getVoltLSB

public int getVoltLSB()
Returns the current voltage level in millivolts for the LSB.

Returns:
int

getVoltMSB

public int getVoltMSB()
Returns the current voltage level in millivolts for the MSB.

Returns:
int

getSensorModule

public int getSensorModule()
Used to determine the sensor module that is configured. This can be helpful if the sensor is not working properly.

Returns:
int

getCurveCount

public int getCurveCount()
Gets the number of points that will be in the curve. This corresponds with the set/get Volt and Distance methods.
Used for recalibrating the sensor.

Returns:
int

setCurveCount

public void setCurveCount(int value)
Sets the number of points that will be in the configured curve. This corresponds with the set/get Vold and Distance points methods.
Used for recalibrating the sensor.

Parameters:
value - max 39

getDistMinLSB

public int getDistMinLSB()
Gets the min value in millimeters for the LSB.
Used for recalibrating the sensor.

Returns:
int

setDistMinLSB

public void setDistMinLSB(int value)
Sets the min value in millimeters for the LSB.
Used for recalibrating the sensor.

Parameters:
value - int

getDistMinMSB

public int getDistMinMSB()
Gets the min value in millimeters for the MSB.
Used for recalibrating the sensor.

Returns:
int

setDistMinMSB

public void setDistMinMSB(int value)
Sets the min value in millimeters for the MSB.
Used for recalibrating the sensor.

Parameters:
value - int

getDistMaxLSB

public int getDistMaxLSB()
Gets the max value in millimeters for the LSB.
Used for recalibrating the sensor.

Returns:
int

setDistMaxLSB

public void setDistMaxLSB(int value)
Sets the max value in millimeters for LSB.
Used for recalibrating the sensor.

Parameters:
value - int

getDistMaxMSB

public int getDistMaxMSB()
Gets the max value in millimeters for the MSB.
Used for recalibrating the sensor.

Returns:
int

setDistMaxMSB

public void setDistMaxMSB(int value)
Sets the max value in millimeters for the MSB.
Used for recalibrating the sensor.

Parameters:
value - int

getVoltPointLSB

public int getVoltPointLSB(int index)
Gets millivolts value of the specific index for the LSB. These will correspond with the point methods index value.
Used for recalibrating the sensor.

Parameters:
index - max 39
Returns:
int

setVoltPointLSB

public void setVoltPointLSB(int index,
                            int value)
Sets millivolts value of the specific index for the LSB. These will correspond with the point methods index value.
Used for recalibrating the sensor.

Parameters:
index - max 39
value - int

getVoltPointMSB

public int getVoltPointMSB(int index)
Gets millivolts value of the specific index for the MSB. These will correspond with the point methods index value.
Used for recalibrating the sensor.

Parameters:
index - max 39
Returns:
Returns int

setVoltPointMSB

public void setVoltPointMSB(int index,
                            int value)
Sets millivolts value of the specific index for the MSB. These will correspond with the point methods index value.
Used for recalibrating the sensor.

Parameters:
index - max 39
value - int

getDistPointLSB

public int getDistPointLSB(int index)
Gets millimeter value of the specific index for the LSB.
Used for recalibrating the sensor.

Parameters:
index - max 39
Returns:
Returns int

setDistPointLSB

public void setDistPointLSB(int index,
                            int value)
Sets millimeter value of the specific index for the LSB.
Used for recalibrating the sensor.

Parameters:
index - max 39
value - int

getDistPointMSB

public int getDistPointMSB(int index)
Gets millimeter value of the specific index for the MSB.
Used for recalibrating the sensor.

Parameters:
index - max 39
Returns:
int

setDistPointMSB

public void setDistPointMSB(int index,
                            int value)
Sets millimeter value of the specific index for the MSB.
Used for recalibrating the sensor.

Parameters:
index - max 39.
value - int

getRanges

public float[] getRanges()
Description copied from interface: RangeFinder
If the sensor is capable, this method returns multiple range values from a single scan. Sensors that can only return a single value should return an array containing a single value.

Specified by:
getRanges in interface RangeFinder
Returns:
an array of ranges, ordered from closest to farthest.