|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.I2CSensor lejos.nxt.UltrasonicSensor
public class UltrasonicSensor
Abstraction for a NXT Ultrasonic Sensor. The sensor knows four modes: off, continuous, ping and capture. In continuous mode, the device periodically tests, whether and object in range. In ping mode, the sensor sends a single ping, and records the distance of up to 8 objects. In capture mode, the sensor listens for signals from other UltraSonic devices. At the present time, we (the leJOS team) are not sure, how the capture mode works. Please let us know about your experience with it.
Field Summary | |
---|---|
static byte |
MODE_CAPTURE
|
static byte |
MODE_CONTINUOUS
|
static byte |
MODE_OFF
|
static byte |
MODE_PING
|
static byte |
MODE_RESET
|
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 | |
---|---|
UltrasonicSensor(I2CPort port)
|
Method Summary | |
---|---|
int |
capture()
Set capture mode Set the sensor into capture mode. |
int |
continuous()
Switch to continuous mode. |
int |
getActualMode()
Returns the current operating mode of the sensor. |
int |
getCalibrationData(byte[] data)
Return 3 bytes of calibration data. |
int |
getContinuousInterval()
Return the interval used in continuous mode. |
int |
getData(int register,
byte[] buf,
int off,
int len)
Executes an I2C read transaction and waits for the result. |
int |
getDistance()
Return distance to an object. |
int |
getDistances(int[] dist)
Return an array of distances. |
int |
getDistances(int[] dist,
int off,
int len)
Return an array of distances. |
int |
getFactoryData(byte[] data)
Return 10 bytes of factory calibration data. |
int |
getMode()
Returns the current operating mode of the sensor. |
float |
getRange()
Get the range to the nearest object |
float[] |
getRanges()
If the sensor is capable, this method returns multiple range values from a single scan. |
String |
getUnits()
Return a string indicating the type of units in use by the unit. |
int |
off()
Turn off the sensor. |
int |
ping()
Send a single ping. |
int |
reset()
Reset the device. |
int |
sendData(int register,
byte[] buf,
int off,
int len)
Executes an I2C write transaction. |
int |
setCalibrationData(byte[] data)
Set 3 bytes of calibration data. |
int |
setContinuousInterval(int interval)
Set the ping inetrval used when in continuous mode. |
int |
setMode(int mode)
Set the sensor into the specified mode. |
Methods inherited from class lejos.nxt.I2CSensor |
---|
fetchString, getAddress, getData, getPort, getProductID, getVendorID, getVersion, sendData, sendData, setAddress |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte MODE_OFF
public static final byte MODE_PING
public static final byte MODE_CONTINUOUS
public static final byte MODE_CAPTURE
public static final byte MODE_RESET
Constructor Detail |
---|
public UltrasonicSensor(I2CPort port)
Method Detail |
---|
public int getData(int register, byte[] buf, int off, int len)
I2CSensor
getData
in class I2CSensor
register
- I2C register, e.g 0x41buf
- Buffer to return dataoff
- Offset of the start of the datalen
- Length of the return data
public int sendData(int register, byte[] buf, int off, int len)
I2CSensor
sendData
in class I2CSensor
register
- I2C register, e.g 0x42buf
- Buffer containing data to sendoff
- Offset of the start of the datalen
- Length of data to send
public int getDistance()
public float getRange()
getRange
in interface RangeFinder
public int getDistances(int[] dist)
getDistances(dist, 0, dist.length)
.
dist
- the destination array
public int getDistances(int[] dist, int off, int len)
len
. If the distance data is not yet available the
method will wait until it is. The LEGO ultrasonic sensor can return multiple
readings in approx. 75 ms.
dist
- the destination arrayoff
- the index of the first distancelen
- the number of distances to read
public int setMode(int mode)
MODE_RESET
will reset the sensor. After a reset, the sensor will be off. A value of
MODE_PING
sends a single ping.
mode
- the mode, either MODE_OFF
, MODE_RESET
, MODE_CONTINUOUS
, MODE_PING
, or MODE_CAPTURE
ping()
,
continuous()
,
capture()
,
reset()
,
off()
public int ping()
getDistances(int[])
or
getDistances(int[], int, int)
and passing a suitable array.
A delay is required between the call to ping()
and
obtaining the results. The getDistances methods automatically takes
care of this. getDistance()
may also be used with ping, returning
information for the first echo.
public int continuous()
getDistance()
. Calling getDistances(int[])
and getDistances(int[], int, int)
is also supported,
but at most 1 distance is returned.
ping()
public int off()
public int capture()
public int reset()
public int getFactoryData(byte[] data)
public String getUnits()
public int getCalibrationData(byte[] data)
public int setCalibrationData(byte[] data)
public int getContinuousInterval()
public int setContinuousInterval(int interval)
public int getMode()
MODE_OFF
,
MODE_CONTINUOUS
,
MODE_PING
,
MODE_CAPTURE
public int getActualMode()
getMode()
, this method determines the operation mode by actually
querying the hardware.
MODE_OFF
,
MODE_CONTINUOUS
,
MODE_PING
,
MODE_CAPTURE
public float[] getRanges()
RangeFinder
getRanges
in interface RangeFinder
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |