Class: Tinkerforge::BrickletAccelerometer
- Defined in:
- lib/tinkerforge/bricklet_accelerometer.rb
Overview
Measures acceleration in three axis
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
250
- DEVICE_DISPLAY_NAME =
:nodoc:
'Accelerometer Bricklet'
- CALLBACK_ACCELERATION =
This callback is triggered periodically with the period that is set by BrickletAccelerometer#set_acceleration_callback_period. The parameters are the X, Y and Z acceleration. The range is configured with BrickletAccelerometer#set_configuration.
The CALLBACK_ACCELERATION callback is only triggered if the acceleration has changed since the last triggering.
14
- CALLBACK_ACCELERATION_REACHED =
This callback is triggered when the threshold as set by BrickletAccelerometer#set_acceleration_callback_threshold is reached. The parameters are the X, Y and Z acceleration. The range is configured with BrickletAccelerometer#set_configuration.
If the threshold keeps being reached, the callback is triggered periodically with the period as set by BrickletAccelerometer#set_debounce_period.
15
- FUNCTION_GET_ACCELERATION =
:nodoc:
1
- FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD =
:nodoc:
2
- FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD =
:nodoc:
3
- FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD =
:nodoc:
4
- FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD =
:nodoc:
5
- FUNCTION_SET_DEBOUNCE_PERIOD =
:nodoc:
6
- FUNCTION_GET_DEBOUNCE_PERIOD =
:nodoc:
7
- FUNCTION_GET_TEMPERATURE =
:nodoc:
8
- FUNCTION_SET_CONFIGURATION =
:nodoc:
9
- FUNCTION_GET_CONFIGURATION =
:nodoc:
10
- FUNCTION_LED_ON =
:nodoc:
11
- FUNCTION_LED_OFF =
:nodoc:
12
- FUNCTION_IS_LED_ON =
:nodoc:
13
- 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:
'>'
- DATA_RATE_OFF =
:nodoc:
0
- DATA_RATE_3HZ =
:nodoc:
1
- DATA_RATE_6HZ =
:nodoc:
2
- DATA_RATE_12HZ =
:nodoc:
3
- DATA_RATE_25HZ =
:nodoc:
4
- DATA_RATE_50HZ =
:nodoc:
5
- DATA_RATE_100HZ =
:nodoc:
6
- DATA_RATE_400HZ =
:nodoc:
7
- DATA_RATE_800HZ =
:nodoc:
8
- DATA_RATE_1600HZ =
:nodoc:
9
- FULL_SCALE_2G =
:nodoc:
0
- FULL_SCALE_4G =
:nodoc:
1
- FULL_SCALE_6G =
:nodoc:
2
- FULL_SCALE_8G =
:nodoc:
3
- FULL_SCALE_16G =
:nodoc:
4
- FILTER_BANDWIDTH_800HZ =
:nodoc:
0
- FILTER_BANDWIDTH_400HZ =
:nodoc:
1
- FILTER_BANDWIDTH_200HZ =
:nodoc:
2
- FILTER_BANDWIDTH_50HZ =
: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
-
#get_acceleration ⇒ Object
Returns the acceleration in x, y and z direction.
-
#get_acceleration_callback_period ⇒ Object
Returns the period as set by BrickletAccelerometer#set_acceleration_callback_period.
-
#get_acceleration_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAccelerometer#set_acceleration_callback_threshold.
-
#get_configuration ⇒ Object
Returns the configuration as set by BrickletAccelerometer#set_configuration.
-
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAccelerometer#set_debounce_period.
-
#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_temperature ⇒ Object
Returns the temperature of the accelerometer.
-
#initialize(uid, ipcon) ⇒ BrickletAccelerometer
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#is_led_on ⇒ Object
Returns true if the LED is enabled, false otherwise.
-
#led_off ⇒ Object
Disables the LED on the Bricklet.
-
#led_on ⇒ Object
Enables the LED on the Bricklet.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#set_acceleration_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ACCELERATION callback is triggered periodically.
-
#set_acceleration_callback_threshold(option, min_x, max_x, min_y, max_y, min_z, max_z) ⇒ Object
Sets the thresholds for the CALLBACK_ACCELERATION_REACHED callback.
-
#set_configuration(data_rate, full_scale, filter_bandwidth) ⇒ Object
Configures the data rate, full scale range and filter bandwidth.
-
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold 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) ⇒ BrickletAccelerometer
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#get_acceleration ⇒ Object
Returns the acceleration in x, y and z direction. The values are given in gₙ/1000 (1gₙ = 9.80665m/s²). The range is configured with BrickletAccelerometer#set_configuration.
If you want to get the acceleration periodically, it is recommended to use the CALLBACK_ACCELERATION callback and set the period with BrickletAccelerometer#set_acceleration_callback_period.
113 114 115 116 117 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 113 def get_acceleration check_validity send_request FUNCTION_GET_ACCELERATION, [], '', 14, 's s s' end |
#get_acceleration_callback_period ⇒ Object
Returns the period as set by BrickletAccelerometer#set_acceleration_callback_period.
131 132 133 134 135 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 131 def get_acceleration_callback_period check_validity send_request FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD, [], '', 12, 'L' end |
#get_acceleration_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAccelerometer#set_acceleration_callback_threshold.
155 156 157 158 159 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 155 def get_acceleration_callback_threshold check_validity send_request FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD, [], '', 21, 'k s s s s s s' end |
#get_configuration ⇒ Object
Returns the configuration as set by BrickletAccelerometer#set_configuration.
206 207 208 209 210 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 206 def get_configuration check_validity send_request FUNCTION_GET_CONFIGURATION, [], '', 11, 'C C C' end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAccelerometer#set_debounce_period.
177 178 179 180 181 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 177 def get_debounce_period check_validity send_request FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 12, 'L' 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|
243 244 245 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 243 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_temperature ⇒ Object
Returns the temperature of the accelerometer.
184 185 186 187 188 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 184 def get_temperature check_validity send_request FUNCTION_GET_TEMPERATURE, [], '', 10, 's' end |
#is_led_on ⇒ Object
Returns true if the LED is enabled, false otherwise.
227 228 229 230 231 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 227 def is_led_on check_validity send_request FUNCTION_IS_LED_ON, [], '', 9, '?' end |
#led_off ⇒ Object
Disables the LED on the Bricklet.
220 221 222 223 224 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 220 def led_off check_validity send_request FUNCTION_LED_OFF, [], '', 8, '' end |
#led_on ⇒ Object
Enables the LED on the Bricklet.
213 214 215 216 217 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 213 def led_on check_validity send_request FUNCTION_LED_ON, [], '', 8, '' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
248 249 250 251 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 248 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_acceleration_callback_period(period) ⇒ Object
Sets the period with which the CALLBACK_ACCELERATION callback is triggered periodically. A value of 0 turns the callback off.
The CALLBACK_ACCELERATION callback is only triggered if the acceleration has changed since the last triggering.
124 125 126 127 128 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 124 def set_acceleration_callback_period(period) check_validity send_request FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD, [period], 'L', 8, '' end |
#set_acceleration_callback_threshold(option, min_x, max_x, min_y, max_y, min_z, max_z) ⇒ Object
Sets the thresholds for the CALLBACK_ACCELERATION_REACHED callback.
The following options are possible:
"Option", "Description"
"'x'", "Callback is turned off"
"'o'", "Callback is triggered when the acceleration is *outside* the min and max values"
"'i'", "Callback is triggered when the acceleration is *inside* the min and max values"
"'<'", "Callback is triggered when the acceleration is smaller than the min value (max is ignored)"
"'>'", "Callback is triggered when the acceleration is greater than the min value (max is ignored)"
148 149 150 151 152 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 148 def set_acceleration_callback_threshold(option, min_x, max_x, min_y, max_y, min_z, max_z) check_validity send_request FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD, [option, min_x, max_x, min_y, max_y, min_z, max_z], 'k s s s s s s', 8, '' end |
#set_configuration(data_rate, full_scale, filter_bandwidth) ⇒ Object
Configures the data rate, full scale range and filter bandwidth. Possible values are:
-
Data rate of 0Hz to 1600Hz.
-
Full scale range of ±2gₙ up to ±16gₙ.
-
Filter bandwidth between 50Hz and 800Hz.
Decreasing data rate or full scale range will also decrease the noise on the data.
199 200 201 202 203 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 199 def set_configuration(data_rate, full_scale, filter_bandwidth) check_validity send_request FUNCTION_SET_CONFIGURATION, [data_rate, full_scale, filter_bandwidth], 'C C C', 8, '' end |
#set_debounce_period(debounce) ⇒ Object
Sets the period with which the threshold callback
-
CALLBACK_ACCELERATION_REACHED
is triggered, if the threshold
-
BrickletAccelerometer#set_acceleration_callback_threshold
keeps being reached.
170 171 172 173 174 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 170 def set_debounce_period(debounce) check_validity send_request FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 8, '' end |