Package com.tinkerforge
Class BrickletLaserRangeFinder
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletLaserRangeFinder
-
public class BrickletLaserRangeFinder extends Device
Measures distance up to 40m with laser light
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletLaserRangeFinder.Configuration
class
BrickletLaserRangeFinder.DistanceCallbackThreshold
static interface
BrickletLaserRangeFinder.DistanceListener
This listener is triggered periodically with the period that is set bysetDistanceCallbackPeriod(long)
.static interface
BrickletLaserRangeFinder.DistanceReachedListener
This listener is triggered when the threshold as set bysetDistanceCallbackThreshold(char, int, int)
is reached.class
BrickletLaserRangeFinder.MovingAverage
class
BrickletLaserRangeFinder.VelocityCallbackThreshold
static interface
BrickletLaserRangeFinder.VelocityListener
This listener is triggered periodically with the period that is set bysetVelocityCallbackPeriod(long)
.static interface
BrickletLaserRangeFinder.VelocityReachedListener
This listener is triggered when the threshold as set bysetVelocityCallbackThreshold(char, short, short)
is reached.-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BrickletLaserRangeFinder(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDistanceListener(BrickletLaserRangeFinder.DistanceListener listener)
Adds a Distance listener.void
addDistanceReachedListener(BrickletLaserRangeFinder.DistanceReachedListener listener)
Adds a DistanceReached listener.void
addVelocityListener(BrickletLaserRangeFinder.VelocityListener listener)
Adds a Velocity listener.void
addVelocityReachedListener(BrickletLaserRangeFinder.VelocityReachedListener listener)
Adds a VelocityReached listener.void
disableLaser()
Deactivates the laser of the LIDAR.void
enableLaser()
Activates the laser of the LIDAR.BrickletLaserRangeFinder.Configuration
getConfiguration()
Returns the configuration as set bysetConfiguration(short, boolean, short, int)
.long
getDebouncePeriod()
Returns the debounce period as set bysetDebouncePeriod(long)
.int
getDistance()
Returns the measured distance.long
getDistanceCallbackPeriod()
Returns the period as set bysetDistanceCallbackPeriod(long)
.BrickletLaserRangeFinder.DistanceCallbackThreshold
getDistanceCallbackThreshold()
Returns the threshold as set bysetDistanceCallbackThreshold(char, int, int)
.Device.Identity
getIdentity()
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.short
getMode()
Returns the mode as set bysetMode(short)
.BrickletLaserRangeFinder.MovingAverage
getMovingAverage()
Returns the length moving average as set bysetMovingAverage(short, short)
.short
getSensorHardwareVersion()
Returns the LIDAR-Lite hardware version.short
getVelocity()
Returns the measured velocity.long
getVelocityCallbackPeriod()
Returns the period as set bysetVelocityCallbackPeriod(long)
.BrickletLaserRangeFinder.VelocityCallbackThreshold
getVelocityCallbackThreshold()
Returns the threshold as set bysetVelocityCallbackThreshold(char, short, short)
.boolean
isLaserEnabled()
Returns *true* if the laser is enabled, *false* otherwise.void
removeDistanceListener(BrickletLaserRangeFinder.DistanceListener listener)
Removes a Distance listener.void
removeDistanceReachedListener(BrickletLaserRangeFinder.DistanceReachedListener listener)
Removes a DistanceReached listener.void
removeVelocityListener(BrickletLaserRangeFinder.VelocityListener listener)
Removes a Velocity listener.void
removeVelocityReachedListener(BrickletLaserRangeFinder.VelocityReachedListener listener)
Removes a VelocityReached listener.void
setConfiguration(short acquisitionCount, boolean enableQuickTermination, short thresholdValue, int measurementFrequency)
\note This function is only available if you have a LIDAR-Lite sensor with hardware version 3.void
setDebouncePeriod(long debounce)
Sets the period with which the threshold listeners *BrickletLaserRangeFinder.DistanceReachedListener
, *BrickletLaserRangeFinder.VelocityReachedListener
, are triggered, if the thresholds *setDistanceCallbackThreshold(char, int, int)
, *setVelocityCallbackThreshold(char, short, short)
, keep being reached.void
setDistanceCallbackPeriod(long period)
Sets the period with which theBrickletLaserRangeFinder.DistanceListener
listener is triggered periodically.void
setDistanceCallbackThreshold(char option, int min, int max)
Sets the thresholds for theBrickletLaserRangeFinder.DistanceReachedListener
listener.void
setMode(short mode)
\note This function is only available if you have a LIDAR-Lite sensor with hardware version 1.void
setMovingAverage(short distanceAverageLength, short velocityAverageLength)
Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__ for the distance and velocity.void
setVelocityCallbackPeriod(long period)
Sets the period with which theBrickletLaserRangeFinder.VelocityListener
listener is triggered periodically.void
setVelocityCallbackThreshold(char option, short min, short max)
Sets the thresholds for theBrickletLaserRangeFinder.VelocityReachedListener
listener.-
Methods inherited from class com.tinkerforge.DeviceBase
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
-
-
-
-
Field Detail
-
DEVICE_IDENTIFIER
public static final int DEVICE_IDENTIFIER
- See Also:
- Constant Field Values
-
DEVICE_DISPLAY_NAME
public static final java.lang.String DEVICE_DISPLAY_NAME
- See Also:
- Constant Field Values
-
FUNCTION_GET_DISTANCE
public static final byte FUNCTION_GET_DISTANCE
- See Also:
- Constant Field Values
-
FUNCTION_GET_VELOCITY
public static final byte FUNCTION_GET_VELOCITY
- See Also:
- Constant Field Values
-
FUNCTION_SET_DISTANCE_CALLBACK_PERIOD
public static final byte FUNCTION_SET_DISTANCE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DISTANCE_CALLBACK_PERIOD
public static final byte FUNCTION_GET_DISTANCE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_VELOCITY_CALLBACK_PERIOD
public static final byte FUNCTION_SET_VELOCITY_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_VELOCITY_CALLBACK_PERIOD
public static final byte FUNCTION_GET_VELOCITY_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_SET_VELOCITY_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_VELOCITY_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_VELOCITY_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_VELOCITY_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_SET_DEBOUNCE_PERIOD
public static final byte FUNCTION_SET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DEBOUNCE_PERIOD
public static final byte FUNCTION_GET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_MOVING_AVERAGE
public static final byte FUNCTION_SET_MOVING_AVERAGE
- See Also:
- Constant Field Values
-
FUNCTION_GET_MOVING_AVERAGE
public static final byte FUNCTION_GET_MOVING_AVERAGE
- See Also:
- Constant Field Values
-
FUNCTION_SET_MODE
public static final byte FUNCTION_SET_MODE
- See Also:
- Constant Field Values
-
FUNCTION_GET_MODE
public static final byte FUNCTION_GET_MODE
- See Also:
- Constant Field Values
-
FUNCTION_ENABLE_LASER
public static final byte FUNCTION_ENABLE_LASER
- See Also:
- Constant Field Values
-
FUNCTION_DISABLE_LASER
public static final byte FUNCTION_DISABLE_LASER
- See Also:
- Constant Field Values
-
FUNCTION_IS_LASER_ENABLED
public static final byte FUNCTION_IS_LASER_ENABLED
- See Also:
- Constant Field Values
-
FUNCTION_GET_SENSOR_HARDWARE_VERSION
public static final byte FUNCTION_GET_SENSOR_HARDWARE_VERSION
- See Also:
- Constant Field Values
-
FUNCTION_SET_CONFIGURATION
public static final byte FUNCTION_SET_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_GET_CONFIGURATION
public static final byte FUNCTION_GET_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OFF
public static final char THRESHOLD_OPTION_OFF
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OUTSIDE
public static final char THRESHOLD_OPTION_OUTSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_INSIDE
public static final char THRESHOLD_OPTION_INSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_SMALLER
public static final char THRESHOLD_OPTION_SMALLER
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_GREATER
public static final char THRESHOLD_OPTION_GREATER
- See Also:
- Constant Field Values
-
MODE_DISTANCE
public static final short MODE_DISTANCE
- See Also:
- Constant Field Values
-
MODE_VELOCITY_MAX_13MS
public static final short MODE_VELOCITY_MAX_13MS
- See Also:
- Constant Field Values
-
MODE_VELOCITY_MAX_32MS
public static final short MODE_VELOCITY_MAX_32MS
- See Also:
- Constant Field Values
-
MODE_VELOCITY_MAX_64MS
public static final short MODE_VELOCITY_MAX_64MS
- See Also:
- Constant Field Values
-
MODE_VELOCITY_MAX_127MS
public static final short MODE_VELOCITY_MAX_127MS
- See Also:
- Constant Field Values
-
VERSION_1
public static final short VERSION_1
- See Also:
- Constant Field Values
-
VERSION_3
public static final short VERSION_3
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletLaserRangeFinder
public BrickletLaserRangeFinder(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid. and adds it to the IP Connection \c ipcon.
-
-
Method Detail
-
getDistance
public int getDistance() throws TinkerforgeException
Returns the measured distance. Sensor hardware version 1 (seegetSensorHardwareVersion()
) cannot measure distance and velocity at the same time. Therefore, the distance mode has to be enabled usingsetMode(short)
. Sensor hardware version 3 can measure distance and velocity at the same time. Also the laser has to be enabled, seeenableLaser()
. If you want to get the distance periodically, it is recommended to use theBrickletLaserRangeFinder.DistanceListener
listener and set the period withsetDistanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
getVelocity
public short getVelocity() throws TinkerforgeException
Returns the measured velocity. Sensor hardware version 1 (seegetSensorHardwareVersion()
) cannot measure distance and velocity at the same time. Therefore, the velocity mode has to be enabled usingsetMode(short)
. Sensor hardware version 3 can measure distance and velocity at the same time, but the velocity measurement only produces stables results if a fixed measurement rate (seesetConfiguration(short, boolean, short, int)
) is configured. Also the laser has to be enabled, seeenableLaser()
. If you want to get the velocity periodically, it is recommended to use theBrickletLaserRangeFinder.VelocityListener
listener and set the period withsetVelocityCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setDistanceCallbackPeriod
public void setDistanceCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletLaserRangeFinder.DistanceListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletLaserRangeFinder.DistanceListener
listener is only triggered if the distance value has changed since the last triggering.- Throws:
TinkerforgeException
-
getDistanceCallbackPeriod
public long getDistanceCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetDistanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setVelocityCallbackPeriod
public void setVelocityCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletLaserRangeFinder.VelocityListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletLaserRangeFinder.VelocityListener
listener is only triggered if the velocity value has changed since the last triggering.- Throws:
TinkerforgeException
-
getVelocityCallbackPeriod
public long getVelocityCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetVelocityCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setDistanceCallbackThreshold
public void setDistanceCallbackThreshold(char option, int min, int max) throws TinkerforgeException
Sets the thresholds for theBrickletLaserRangeFinder.DistanceReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the distance value is *outside* the min and max values" "'i'", "Listener is triggered when the distance value is *inside* the min and max values" "'<'", "Listener is triggered when the distance value is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the distance value is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getDistanceCallbackThreshold
public BrickletLaserRangeFinder.DistanceCallbackThreshold getDistanceCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetDistanceCallbackThreshold(char, int, int)
.- Throws:
TinkerforgeException
-
setVelocityCallbackThreshold
public void setVelocityCallbackThreshold(char option, short min, short max) throws TinkerforgeException
Sets the thresholds for theBrickletLaserRangeFinder.VelocityReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the velocity is *outside* the min and max values" "'i'", "Listener is triggered when the velocity is *inside* the min and max values" "'<'", "Listener is triggered when the velocity is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the velocity is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getVelocityCallbackThreshold
public BrickletLaserRangeFinder.VelocityCallbackThreshold getVelocityCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetVelocityCallbackThreshold(char, short, short)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listeners *BrickletLaserRangeFinder.DistanceReachedListener
, *BrickletLaserRangeFinder.VelocityReachedListener
, are triggered, if the thresholds *setDistanceCallbackThreshold(char, int, int)
, *setVelocityCallbackThreshold(char, short, short)
, keep being reached.- Throws:
TinkerforgeException
-
getDebouncePeriod
public long getDebouncePeriod() throws TinkerforgeException
Returns the debounce period as set bysetDebouncePeriod(long)
.- Throws:
TinkerforgeException
-
setMovingAverage
public void setMovingAverage(short distanceAverageLength, short velocityAverageLength) throws TinkerforgeException
Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__ for the distance and velocity. Setting the length to 0 will turn the averaging completely off. With less averaging, there is more noise on the data.- Throws:
TinkerforgeException
-
getMovingAverage
public BrickletLaserRangeFinder.MovingAverage getMovingAverage() throws TinkerforgeException
Returns the length moving average as set bysetMovingAverage(short, short)
.- Throws:
TinkerforgeException
-
setMode
public void setMode(short mode) throws TinkerforgeException
\note This function is only available if you have a LIDAR-Lite sensor with hardware version 1. UsesetConfiguration(short, boolean, short, int)
for hardware version 3. You can check the sensor hardware version usinggetSensorHardwareVersion()
. The LIDAR-Lite sensor (hardware version 1) has five different modes. One mode is for distance measurements and four modes are for velocity measurements with different ranges. The following modes are available: * 0: Distance is measured with resolution 1.0 cm and range 0-4000 cm * 1: Velocity is measured with resolution 0.1 m/s and range is 0-12.7 m/s * 2: Velocity is measured with resolution 0.25 m/s and range is 0-31.75 m/s * 3: Velocity is measured with resolution 0.5 m/s and range is 0-63.5 m/s * 4: Velocity is measured with resolution 1.0 m/s and range is 0-127 m/s- Throws:
TinkerforgeException
-
getMode
public short getMode() throws TinkerforgeException
Returns the mode as set bysetMode(short)
.- Throws:
TinkerforgeException
-
enableLaser
public void enableLaser() throws TinkerforgeException
Activates the laser of the LIDAR. We recommend that you wait 250ms after enabling the laser before the first call ofgetDistance()
to ensure stable measurements.- Throws:
TinkerforgeException
-
disableLaser
public void disableLaser() throws TinkerforgeException
Deactivates the laser of the LIDAR.- Throws:
TinkerforgeException
-
isLaserEnabled
public boolean isLaserEnabled() throws TinkerforgeException
Returns *true* if the laser is enabled, *false* otherwise.- Throws:
TinkerforgeException
-
getSensorHardwareVersion
public short getSensorHardwareVersion() throws TinkerforgeException
Returns the LIDAR-Lite hardware version. .. versionadded:: 2.0.3$nbsp;(Plugin)- Throws:
TinkerforgeException
-
setConfiguration
public void setConfiguration(short acquisitionCount, boolean enableQuickTermination, short thresholdValue, int measurementFrequency) throws TinkerforgeException
\note This function is only available if you have a LIDAR-Lite sensor with hardware version 3. UsesetMode(short)
for hardware version 1. You can check the sensor hardware version usinggetSensorHardwareVersion()
. The **Acquisition Count** defines the number of times the Laser Range Finder Bricklet will integrate acquisitions to find a correlation record peak. With a higher count, the Bricklet can measure longer distances. With a lower count, the rate increases. The allowed values are 1-255. If you set **Enable Quick Termination** to true, the distance measurement will be terminated early if a high peak was already detected. This means that a higher measurement rate can be achieved and long distances can be measured at the same time. However, the chance of false-positive distance measurements increases. Normally the distance is calculated with a detection algorithm that uses peak value, signal strength and noise. You can however also define a fixed **Threshold Value**. Set this to a low value if you want to measure the distance to something that has very little reflection (e.g. glass) and set it to a high value if you want to measure the distance to something with a very high reflection (e.g. mirror). Set this to 0 to use the default algorithm. The other allowed values are 1-255. Set the **Measurement Frequency** to force a fixed measurement rate. If set to 0, the Laser Range Finder Bricklet will use the optimal frequency according to the other configurations and the actual measured distance. Since the rate is not fixed in this case, the velocity measurement is not stable. For a stable velocity measurement you should set a fixed measurement frequency. The lower the frequency, the higher is the resolution of the calculated velocity. The allowed values are 10Hz-500Hz (and 0 to turn the fixed frequency off). .. versionadded:: 2.0.3$nbsp;(Plugin)- Throws:
TinkerforgeException
-
getConfiguration
public BrickletLaserRangeFinder.Configuration getConfiguration() throws TinkerforgeException
Returns the configuration as set bysetConfiguration(short, boolean, short, int)
. .. versionadded:: 2.0.3$nbsp;(Plugin)- Throws:
TinkerforgeException
-
getIdentity
public Device.Identity getIdentity() throws TinkerforgeException
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier. The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'. The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|- Specified by:
getIdentity
in classDevice
- Throws:
TinkerforgeException
-
addDistanceListener
public void addDistanceListener(BrickletLaserRangeFinder.DistanceListener listener)
Adds a Distance listener.
-
removeDistanceListener
public void removeDistanceListener(BrickletLaserRangeFinder.DistanceListener listener)
Removes a Distance listener.
-
addVelocityListener
public void addVelocityListener(BrickletLaserRangeFinder.VelocityListener listener)
Adds a Velocity listener.
-
removeVelocityListener
public void removeVelocityListener(BrickletLaserRangeFinder.VelocityListener listener)
Removes a Velocity listener.
-
addDistanceReachedListener
public void addDistanceReachedListener(BrickletLaserRangeFinder.DistanceReachedListener listener)
Adds a DistanceReached listener.
-
removeDistanceReachedListener
public void removeDistanceReachedListener(BrickletLaserRangeFinder.DistanceReachedListener listener)
Removes a DistanceReached listener.
-
addVelocityReachedListener
public void addVelocityReachedListener(BrickletLaserRangeFinder.VelocityReachedListener listener)
Adds a VelocityReached listener.
-
removeVelocityReachedListener
public void removeVelocityReachedListener(BrickletLaserRangeFinder.VelocityReachedListener listener)
Removes a VelocityReached listener.
-
-