class Tinkerforge::BrickletLaserRangeFinder
Measures distance up to 40m with laser light
Constants
- CALLBACK_DISTANCE
This callback is triggered periodically with the period that is set by
BrickletLaserRangeFinder#set_distance_callback_period
. The parameter is the distance value of the sensor.The
CALLBACK_DISTANCE
callback is only triggered if the distance value has changed since the last triggering.- CALLBACK_DISTANCE_REACHED
This callback is triggered when the threshold as set by
BrickletLaserRangeFinder#set_distance_callback_threshold
is reached. The parameter is the distance value of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletLaserRangeFinder#set_debounce_period
.- CALLBACK_VELOCITY
This callback is triggered periodically with the period that is set by
BrickletLaserRangeFinder#set_velocity_callback_period
. The parameter is the velocity value of the sensor.The
CALLBACK_VELOCITY
callback is only triggered if the velocity has changed since the last triggering.- CALLBACK_VELOCITY_REACHED
This callback is triggered when the threshold as set by
BrickletLaserRangeFinder#set_velocity_callback_threshold
is reached. The parameter is the velocity value of the sensor.If the threshold keeps being reached, the callback is triggered periodically with the period as set by
BrickletLaserRangeFinder#set_debounce_period
.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 90 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_GET_DISTANCE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_DISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_DISTANCE_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_VELOCITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_VELOCITY_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_VELOCITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_VELOCITY_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_DEBOUNCE_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_MOVING_AVERAGE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_MOVING_AVERAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_MODE] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_ENABLE_LASER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_DISABLE_LASER] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_IS_LASER_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_SENSOR_HARDWARE_VERSION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_DISTANCE] = [10, 'S'] @callback_formats[CALLBACK_VELOCITY] = [10, 's'] @callback_formats[CALLBACK_DISTANCE_REACHED] = [10, 'S'] @callback_formats[CALLBACK_VELOCITY_REACHED] = [10, 's'] @ipcon.add_device self end
Public Instance Methods
Deactivates the laser of the LIDAR.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 329 def disable_laser check_validity send_request FUNCTION_DISABLE_LASER, [], '', 8, '' end
Activates the laser of the LIDAR.
We recommend that you wait 250ms after enabling the laser before the first call of BrickletLaserRangeFinder#get_distance
to ensure stable measurements.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 322 def enable_laser check_validity send_request FUNCTION_ENABLE_LASER, [], '', 8, '' end
Returns the configuration as set by BrickletLaserRangeFinder#set_configuration
.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 391 def get_configuration check_validity send_request FUNCTION_GET_CONFIGURATION, [], '', 13, 'C ? C S' end
Returns the debounce period as set by BrickletLaserRangeFinder#set_debounce_period
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 265 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end
Returns the measured distance.
Sensor hardware version 1 (see BrickletLaserRangeFinder#get_sensor_hardware_version
) cannot measure distance and velocity at the same time. Therefore, the distance mode has to be enabled using BrickletLaserRangeFinder#set_mode
. Sensor hardware version 3 can measure distance and velocity at the same time. Also the laser has to be enabled, see BrickletLaserRangeFinder#enable_laser
.
If you want to get the distance periodically, it is recommended to use the CALLBACK_DISTANCE
callback and set the period with BrickletLaserRangeFinder#set_distance_callback_period
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 138 def get_distance check_validity send_request FUNCTION_GET_DISTANCE, [], '', 10, 'S' end
Returns the period as set by BrickletLaserRangeFinder#set_distance_callback_period
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 175 def get_distance_callback_period check_validity send_request FUNCTION_GET_DISTANCE_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletLaserRangeFinder#set_distance_callback_threshold
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 217 def get_distance_callback_threshold check_validity send_request FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end
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|
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 407 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns the mode as set by BrickletLaserRangeFinder#set_mode
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 312 def get_mode check_validity send_request FUNCTION_GET_MODE, [], '', 9, 'C' end
Returns the length moving average as set by BrickletLaserRangeFinder#set_moving_average
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 283 def get_moving_average check_validity send_request FUNCTION_GET_MOVING_AVERAGE, [], '', 10, 'C C' end
Returns the LIDAR-Lite hardware version.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 345 def get_sensor_hardware_version check_validity send_request FUNCTION_GET_SENSOR_HARDWARE_VERSION, [], '', 9, 'C' end
Returns the measured velocity.
Sensor hardware version 1 (see BrickletLaserRangeFinder#get_sensor_hardware_version
) cannot measure distance and velocity at the same time. Therefore, the velocity mode has to be enabled using BrickletLaserRangeFinder#set_mode
. 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 (see BrickletLaserRangeFinder#set_configuration
) is configured. Also the laser has to be enabled, see BrickletLaserRangeFinder#enable_laser
.
If you want to get the velocity periodically, it is recommended to use the CALLBACK_VELOCITY
callback and set the period with BrickletLaserRangeFinder#set_velocity_callback_period
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 157 def get_velocity check_validity send_request FUNCTION_GET_VELOCITY, [], '', 10, 's' end
Returns the period as set by BrickletLaserRangeFinder#set_velocity_callback_period
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 193 def get_velocity_callback_period check_validity send_request FUNCTION_GET_VELOCITY_CALLBACK_PERIOD, [], '', 12, 'L' end
Returns the threshold as set by BrickletLaserRangeFinder#set_velocity_callback_threshold
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 241 def get_velocity_callback_threshold check_validity send_request FUNCTION_GET_VELOCITY_CALLBACK_THRESHOLD, [], '', 13, 'k s s' end
Returns true if the laser is enabled, false otherwise.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 336 def is_laser_enabled check_validity send_request FUNCTION_IS_LASER_ENABLED, [], '', 9, '?' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 412 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
- .. note
-
This function is only available if you have a LIDAR-Lite sensor with hardware version 3. Use
BrickletLaserRangeFinder#set_mode
for hardware version 1. You can check the sensor hardware version usingBrickletLaserRangeFinder#get_sensor_hardware_version
.
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)
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 382 def set_configuration(acquisition_count, enable_quick_termination, threshold_value, measurement_frequency) check_validity send_request FUNCTION_SET_CONFIGURATION, [acquisition_count, enable_quick_termination, threshold_value, measurement_frequency], 'C ? C S', 8, '' end
Sets the period with which the threshold callbacks
are triggered, if the thresholds
keep being reached.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 258 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end
Sets the period with which the CALLBACK_DISTANCE
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_DISTANCE
callback is only triggered if the distance value has changed since the last triggering.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 168 def set_distance_callback_period(period) check_validity send_request FUNCTION_SET_DISTANCE_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_DISTANCE_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the distance value is *outside* the min and max values" "'i'", "Callback is triggered when the distance value is *inside* the min and max values" "'<'", "Callback is triggered when the distance value is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the distance value is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 210 def set_distance_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD, [option, min, max], 'k S S', 8, '' end
- .. note
-
This function is only available if you have a LIDAR-Lite sensor with hardware version 1. Use
BrickletLaserRangeFinder#set_configuration
for hardware version 3. You can check the sensor hardware version usingBrickletLaserRangeFinder#get_sensor_hardware_version
.
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
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 305 def set_mode(mode) check_validity send_request FUNCTION_SET_MODE, [mode], 'C', 8, '' end
Sets the length of a `moving averaging <
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 276
def set_moving_average(distance_average_length, velocity_average_length)
check_validity
send_request FUNCTION_SET_MOVING_AVERAGE, [distance_average_length, velocity_average_length], 'C C', 8, ''
end
Sets the period with which the CALLBACK_VELOCITY
callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_VELOCITY
callback is only triggered if the velocity value has changed since the last triggering.
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 186 def set_velocity_callback_period(period) check_validity send_request FUNCTION_SET_VELOCITY_CALLBACK_PERIOD, [period], 'L', 8, '' end
Sets the thresholds for the CALLBACK_VELOCITY_REACHED
callback.
The following options are possible:
"Option", "Description" "'x'", "Callback is turned off" "'o'", "Callback is triggered when the velocity is *outside* the min and max values" "'i'", "Callback is triggered when the velocity is *inside* the min and max values" "'<'", "Callback is triggered when the velocity is smaller than the min value (max is ignored)" "'>'", "Callback is triggered when the velocity is greater than the min value (max is ignored)"
# File lib/tinkerforge/bricklet_laser_range_finder.rb, line 234 def set_velocity_callback_threshold(option, min, max) check_validity send_request FUNCTION_SET_VELOCITY_CALLBACK_THRESHOLD, [option, min, max], 'k s s', 8, '' end