Class: Tinkerforge::BrickletLaserRangeFinder
- Defined in:
- lib/tinkerforge/bricklet_laser_range_finder.rb
Overview
Measures distance up to 40m with laser light
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
255
- DEVICE_DISPLAY_NAME =
:nodoc:
'Laser Range Finder Bricklet'
- 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.
20
- 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.
21
- 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.
22
- 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.
23
- FUNCTION_GET_DISTANCE =
:nodoc:
1
- FUNCTION_GET_VELOCITY =
:nodoc:
2
- FUNCTION_SET_DISTANCE_CALLBACK_PERIOD =
:nodoc:
3
- FUNCTION_GET_DISTANCE_CALLBACK_PERIOD =
:nodoc:
4
- FUNCTION_SET_VELOCITY_CALLBACK_PERIOD =
:nodoc:
5
- FUNCTION_GET_VELOCITY_CALLBACK_PERIOD =
:nodoc:
6
- FUNCTION_SET_DISTANCE_CALLBACK_THRESHOLD =
:nodoc:
7
- FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD =
:nodoc:
8
- FUNCTION_SET_VELOCITY_CALLBACK_THRESHOLD =
:nodoc:
9
- FUNCTION_GET_VELOCITY_CALLBACK_THRESHOLD =
:nodoc:
10
- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
11
- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
12
- FUNCTION_SET_MOVING_AVERAGE =
:nodoc:
13
- FUNCTION_GET_MOVING_AVERAGE =
:nodoc:
14
- FUNCTION_SET_MODE =
:nodoc:
15
- FUNCTION_GET_MODE =
:nodoc:
16
- FUNCTION_ENABLE_LASER =
:nodoc:
17
- FUNCTION_DISABLE_LASER =
:nodoc:
18
- FUNCTION_IS_LASER_ENABLED =
:nodoc:
19
- FUNCTION_GET_SENSOR_HARDWARE_VERSION =
:nodoc:
24
- FUNCTION_SET_CONFIGURATION =
:nodoc:
25
- FUNCTION_GET_CONFIGURATION =
:nodoc:
26
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- THRESHOLD_OPTION_OFF =
:nodoc:
'x'
- THRESHOLD_OPTION_OUTSIDE =
:nodoc:
'o'
- THRESHOLD_OPTION_INSIDE =
:nodoc:
'i'
- THRESHOLD_OPTION_SMALLER =
:nodoc:
'<'
- THRESHOLD_OPTION_GREATER =
:nodoc:
'>'
- MODE_DISTANCE =
:nodoc:
0
- MODE_VELOCITY_MAX_13MS =
:nodoc:
1
- MODE_VELOCITY_MAX_32MS =
:nodoc:
2
- MODE_VELOCITY_MAX_64MS =
:nodoc:
3
- MODE_VELOCITY_MAX_127MS =
:nodoc:
4
- VERSION_1 =
:nodoc:
1
- VERSION_3 =
:nodoc:
3
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE
Instance Attribute Summary
Attributes inherited from Device
#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#disable_laser ⇒ Object
Deactivates the laser of the LIDAR.
-
#enable_laser ⇒ Object
Activates the laser of the LIDAR.
-
#get_configuration ⇒ Object
Returns the configuration as set by BrickletLaserRangeFinder#set_configuration.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletLaserRangeFinder#set_debounce_period.
-
#get_distance ⇒ Object
Returns the measured distance.
-
#get_distance_callback_period ⇒ Object
Returns the period as set by BrickletLaserRangeFinder#set_distance_callback_period.
-
#get_distance_callback_threshold ⇒ Object
Returns the threshold as set by BrickletLaserRangeFinder#set_distance_callback_threshold.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_mode ⇒ Object
Returns the mode as set by BrickletLaserRangeFinder#set_mode.
-
#get_moving_average ⇒ Object
Returns the length moving average as set by BrickletLaserRangeFinder#set_moving_average.
-
#get_sensor_hardware_version ⇒ Object
Returns the LIDAR-Lite hardware version.
-
#get_velocity ⇒ Object
Returns the measured velocity.
-
#get_velocity_callback_period ⇒ Object
Returns the period as set by BrickletLaserRangeFinder#set_velocity_callback_period.
-
#get_velocity_callback_threshold ⇒ Object
Returns the threshold as set by BrickletLaserRangeFinder#set_velocity_callback_threshold.
-
#initialize(uid, ipcon) ⇒ BrickletLaserRangeFinder
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#is_laser_enabled ⇒ Object
Returns true if the laser is enabled, false otherwise.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_configuration(acquisition_count, enable_quick_termination, threshold_value, measurement_frequency) ⇒ Object
..
-
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks.
-
#set_distance_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_DISTANCE callback is triggered periodically.
-
#set_distance_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_DISTANCE_REACHED callback.
-
#set_mode(mode) ⇒ Object
..
-
#set_moving_average(distance_average_length, velocity_average_length) ⇒ Object
Sets the length of a ‘moving averaging <en.wikipedia.org/wiki/Moving_average>`__ for the distance and velocity.
-
#set_velocity_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_VELOCITY callback is triggered periodically.
-
#set_velocity_callback_threshold(option, min, max) ⇒ Object
Sets the thresholds for the CALLBACK_VELOCITY_REACHED callback.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickletLaserRangeFinder
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#disable_laser ⇒ Object
Deactivates the laser of the LIDAR.
330 331 332 333 334 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 330 def disable_laser check_validity send_request FUNCTION_DISABLE_LASER, [], '', 8, '' end |
#enable_laser ⇒ Object
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.
323 324 325 326 327 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 323 def enable_laser check_validity send_request FUNCTION_ENABLE_LASER, [], '', 8, '' end |
#get_configuration ⇒ Object
Returns the configuration as set by BrickletLaserRangeFinder#set_configuration.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
392 393 394 395 396 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 392 def get_configuration check_validity send_request FUNCTION_GET_CONFIGURATION, [], '', 13, 'C ? C S' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletLaserRangeFinder#set_debounce_period.
266 267 268 269 270 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 266 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' end |
#get_distance ⇒ Object
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.
139 140 141 142 143 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 139 def get_distance check_validity send_request FUNCTION_GET_DISTANCE, [], '', 10, 'S' end |
#get_distance_callback_period ⇒ Object
Returns the period as set by BrickletLaserRangeFinder#set_distance_callback_period.
176 177 178 179 180 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 176 def get_distance_callback_period check_validity send_request FUNCTION_GET_DISTANCE_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_distance_callback_threshold ⇒ Object
Returns the threshold as set by BrickletLaserRangeFinder#set_distance_callback_threshold.
218 219 220 221 222 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 218 def get_distance_callback_threshold check_validity send_request FUNCTION_GET_DISTANCE_CALLBACK_THRESHOLD, [], '', 13, 'k S S' end |
#get_identity ⇒ Object
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|
408 409 410 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 408 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_mode ⇒ Object
Returns the mode as set by BrickletLaserRangeFinder#set_mode.
313 314 315 316 317 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 313 def get_mode check_validity send_request FUNCTION_GET_MODE, [], '', 9, 'C' end |
#get_moving_average ⇒ Object
Returns the length moving average as set by BrickletLaserRangeFinder#set_moving_average.
284 285 286 287 288 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 284 def get_moving_average check_validity send_request FUNCTION_GET_MOVING_AVERAGE, [], '', 10, 'C C' end |
#get_sensor_hardware_version ⇒ Object
Returns the LIDAR-Lite hardware version.
- .. versionadded
-
2.0.3$nbsp;(Plugin)
346 347 348 349 350 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 346 def get_sensor_hardware_version check_validity send_request FUNCTION_GET_SENSOR_HARDWARE_VERSION, [], '', 9, 'C' end |
#get_velocity ⇒ Object
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.
158 159 160 161 162 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 158 def get_velocity check_validity send_request FUNCTION_GET_VELOCITY, [], '', 10, 's' end |
#get_velocity_callback_period ⇒ Object
Returns the period as set by BrickletLaserRangeFinder#set_velocity_callback_period.
194 195 196 197 198 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 194 def get_velocity_callback_period check_validity send_request FUNCTION_GET_VELOCITY_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_velocity_callback_threshold ⇒ Object
Returns the threshold as set by BrickletLaserRangeFinder#set_velocity_callback_threshold.
242 243 244 245 246 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 242 def get_velocity_callback_threshold check_validity send_request FUNCTION_GET_VELOCITY_CALLBACK_THRESHOLD, [], '', 13, 'k s s' end |
#is_laser_enabled ⇒ Object
Returns true if the laser is enabled, false otherwise.
337 338 339 340 341 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 337 def is_laser_enabled check_validity send_request FUNCTION_IS_LASER_ENABLED, [], '', 9, '?' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
413 414 415 416 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 413 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_configuration(acquisition_count, enable_quick_termination, threshold_value, measurement_frequency) ⇒ Object
- .. 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 using BrickletLaserRangeFinder#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)
383 384 385 386 387 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 383 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 |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callbacks
-
CALLBACK_DISTANCE_REACHED,
-
CALLBACK_VELOCITY_REACHED,
are triggered, if the thresholds
-
BrickletLaserRangeFinder#set_distance_callback_threshold,
-
BrickletLaserRangeFinder#set_velocity_callback_threshold,
keep being reached.
259 260 261 262 263 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 259 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |
#set_distance_callback_period(period) ⇒ Object
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.
169 170 171 172 173 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 169 def set_distance_callback_period(period) check_validity send_request FUNCTION_SET_DISTANCE_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_distance_callback_threshold(option, min, max) ⇒ Object
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)"
211 212 213 214 215 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 211 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 |
#set_mode(mode) ⇒ Object
- .. 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 using BrickletLaserRangeFinder#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
306 307 308 309 310 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 306 def set_mode(mode) check_validity send_request FUNCTION_SET_MODE, [mode], 'C', 8, '' end |
#set_moving_average(distance_average_length, velocity_average_length) ⇒ Object
Sets the length of a ‘moving averaging <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.
277 278 279 280 281 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 277 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 |
#set_velocity_callback_period(period) ⇒ Object
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.
187 188 189 190 191 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 187 def set_velocity_callback_period(period) check_validity send_request FUNCTION_SET_VELOCITY_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_velocity_callback_threshold(option, min, max) ⇒ Object
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)"
235 236 237 238 239 |
# File 'lib/tinkerforge/bricklet_laser_range_finder.rb', line 235 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 |