|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.aplu.nxt.Part ch.aplu.nxt.Sensor ch.aplu.nxt.I2CSensor ch.aplu.nxt.UltrasonicSensor
public class UltrasonicSensor
Class that represents an ultrasonic sensor. Most of the code and the documentation taken from the leJOS library (lejos.sourceforge.net, with thanks to the autor.
Field Summary | |
---|---|
static byte |
CONTINUOUS_MEASUREMENT
Sensor making continuous readings at set intervals. |
static byte |
EVENT_CAPTURE
Puts the sensor in passive mode to record pings that might come from other sonar sensors. |
static byte |
OFF
Turn off sensor. |
static byte |
REQUEST_WARM_RESET
Resets the sensor. |
static byte |
SINGLE_SHOT
Sensor sends out one ping and records result. |
Fields inherited from class ch.aplu.nxt.Part |
---|
robot |
Constructor Summary | |
---|---|
UltrasonicSensor()
Creates a sensor instance connected to port S1. |
|
UltrasonicSensor(SensorPort port)
Creates a sensor instance connected to the given port. |
Method Summary | |
---|---|
void |
addUltrasonicListener(UltrasonicListener ultrasonicListener,
int triggerLevel)
Registers the given ultrasonic listener for the given trigger level. |
void |
calibrate(byte scaleFactor,
byte scaleDivisor,
byte zero)
Calibrates the sensor. |
protected void |
cleanup()
|
int |
getDistance()
Polls the sensor. |
byte[] |
getDistances()
The ultrasonic sensor is capable of sending a ping and recording up to 8 echoes. |
int |
getFactoryScaleDivisor()
Gets the default scale divisor, 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 should be 0. |
int |
getMeasurementInterval()
Returns the time interval between measurements in continuous mode. |
int |
getScaleFactor()
Gets the scale factor, which produces either cm's, inches, or some other unit. |
void |
setMeasurementInterval(byte interval)
Sets the time interval between measurements in continuous mode. |
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. e.g. off, single pulse, continuous, passive, warm reset. |
protected void |
startUltrasonicThread()
|
protected void |
stopUltrasonicThread()
|
Methods inherited from class ch.aplu.nxt.I2CSensor |
---|
fetchString, getData, init, sendData, sendData |
Methods inherited from class ch.aplu.nxt.Sensor |
---|
getPort, getPortId, getPortLabel, LSRead, LSWrite, readBooleanValue, readNormalizedValue, readRawValue, readScaledValue, setTypeAndMode |
Methods inherited from class ch.aplu.nxt.Part |
---|
setRobot |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static byte OFF
public static byte SINGLE_SHOT
public static byte CONTINUOUS_MEASUREMENT
public static byte EVENT_CAPTURE
public static byte REQUEST_WARM_RESET
Constructor Detail |
---|
public UltrasonicSensor(SensorPort port)
port
- the port where the sensor is plugged-inpublic UltrasonicSensor()
Method Detail |
---|
public void setSensorMode(byte modeEnumeration)
modeEnumeration
- e.g. OFF, SINGLE_SHOT, CONTINUOUS_MEASUREMENT, EVENT_CAPTURE, REQUEST_WARM_RESETprotected void cleanup()
cleanup
in class I2CSensor
public void addUltrasonicListener(UltrasonicListener ultrasonicListener, int triggerLevel)
ultrasonicListener
- the UltrasonicListener to become registered.triggerLevel
- the trigger level where the callback is triggeredprotected void startUltrasonicThread()
protected void stopUltrasonicThread()
public int getDistance()
public byte[] getDistances()
public int getMeasurementInterval()
public void setScaleFactor(byte scale)
scale
- a number 0 .. 255public void calibrate(byte scaleFactor, byte scaleDivisor, byte zero)
scaleFactor
- Raw reading is multiplied by this number. 1 = factory settingscaleDivisor
- Raw reading divides by this number. 14 = factory settingzero
- e.g. If you find the real distance is 10 cm and the sensor
says 12 cm you can adjust the zero. 0 = factory settingpublic int getScaleFactor()
public int getFactoryScaleFactor()
public int getFactoryScaleDivisor()
public int getFactoryZero()
public void setMeasurementInterval(byte interval)
interval
- the time interval in ms (0 .. 255)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |