icommand.nxt
Class UltrasonicSensor

java.lang.Object
  extended by icommand.nxt.I2CSensor
      extended by icommand.nxt.UltrasonicSensor

public class UltrasonicSensor
extends I2CSensor


Field Summary
 
Fields inherited from class icommand.nxt.I2CSensor
DEFAULT_ADDRESS, PRODUCT_ID, SENSOR_TYPE, STOP, VERSION
 
Constructor Summary
UltrasonicSensor(SensorPort s)
          Sets the sensor to LOWSPEED_9V and puts it into continuous measurement.
 
Method Summary
 void calibrate(byte scaleFactor, byte scaleDivisor, byte zero)
          If your sensor readings seem off, you can calibrate the sensor to make it different from factory settings.
 int getDistance()
          Returns the distance to the closest object.
 byte[] getDistances()
          The ultrasonic sensor is capable of sending a ping and recording up to 8 echoes.
 int getFactoryScaleDivisor()
          Gets the default scale factor, which produces either cm's, inches, or some other unit.
 int getFactoryScaleFactor()
          Gets the default scale factor, which produces either cm's, inches, or some other unit.
 int getFactoryZero()
          Gets the default "zero" point, which is 0.
 int getMeasurementInterval()
          The time interval between measurements in continuous mode.
 java.lang.String getMeasurementUnits()
          Returns some sort of string that indicates measurement units.
 int getScaleFactor()
          Gets the scale factor, which produces either cm's, inches, or some other unit.
 void setMeasurementInterval(byte interval)
           
 void setMetric(boolean isMetric)
          Determines if the sensor produces distances in cm or inches.
 void setScaleDivisor(byte divisor)
           
 void setScaleFactor(byte scale)
          Sets the scale factor, producing either cm's, inches, or some other unit.
 void setSensorMode(byte modeEnumeration)
          Sets the state for the sensor.
 void setZero(byte zeroPoint)
           
 
Methods inherited from class icommand.nxt.I2CSensor
fetchString, getData, getData, getId, getProductID, getSensorType, getVersion, sendData, sendData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UltrasonicSensor

public UltrasonicSensor(SensorPort s)
Sets the sensor to LOWSPEED_9V and puts it into continuous measurement.

Parameters:
s -
Method Detail

setSensorMode

public void setSensorMode(byte modeEnumeration)
Sets the state for the sensor. e.g. off, single pulse, continuous, passive, warm reset.

Parameters:
modeEnumeration - e.g. OFF, SINGLE_SHOT, CONTINUOUS_MEASUREMENT, EVENT_CAPTURE, REQUEST_WARM_RESET

getDistance

public int getDistance()
Returns the distance to the closest object.

Returns:
Default value is in centimeters.

setMetric

public void setMetric(boolean isMetric)
Determines if the sensor produces distances in cm or inches. NOT CURRENTLY IMPLEMENTED (cm default)

Parameters:
isMetric - true = cm's, false = inches

getDistances

public byte[] getDistances()
The ultrasonic sensor is capable of sending a ping and recording up to 8 echoes. A SINGLE_SHOT command is used, rather than continuous pings. This method returns an array of up to 8 distances picked up by the UltrasonicSensor sensor.

Returns:
eight distance values, mostly will be 0.

getMeasurementInterval

public int getMeasurementInterval()
The time interval between measurements in continuous mode.

Returns:
Value 0-255 in MS

setScaleFactor

public void setScaleFactor(byte scale)
Sets the scale factor, producing either cm's, inches, or some other unit.

Parameters:
scale - Can be a number 0 to 255 likely. Need to use short.

setZero

public void setZero(byte zeroPoint)

setScaleDivisor

public void setScaleDivisor(byte divisor)

calibrate

public void calibrate(byte scaleFactor,
                      byte scaleDivisor,
                      byte zero)
If your sensor readings seem off, you can calibrate the sensor to make it different from factory settings.

Parameters:
scaleFactor - Raw reading is multiplied by this number. 1 = factory setting.
scaleDivisor - Raw reading divides by this number. 14 = factory setting
zero - e.g. If you find the real distance is 10 cm and the sensor says 12 cm you can adjust the zero. 0 = factory setting.

getScaleFactor

public int getScaleFactor()
Gets the scale factor, which produces either cm's, inches, or some other unit.

Returns:
0-255

getFactoryScaleFactor

public int getFactoryScaleFactor()
Gets the default scale factor, which produces either cm's, inches, or some other unit.

Returns:
0-255

getFactoryScaleDivisor

public int getFactoryScaleDivisor()
Gets the default scale factor, which produces either cm's, inches, or some other unit.

Returns:
0-255

getFactoryZero

public int getFactoryZero()
Gets the default "zero" point, which is 0.


setMeasurementInterval

public void setMeasurementInterval(byte interval)
Parameters:
interval - !! Can be a number 0 to 255 likely. Need to use short.

getMeasurementUnits

public java.lang.String getMeasurementUnits()
Returns some sort of string that indicates measurement units. NOTE: A little unreliable at the moment due to a bug in firmware. Keep trying if it doesn't get it the first time.

Returns:
e.g. "10E-2m"


Copyright 2006. All Rights Reserved.