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.
CALLBACK_ACCELERATION 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.
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::RESPONSE_EXPECTED_ALWAYS_FALSE, 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, #registered_callbacks, #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 in °C.
-
#initialize(uid, ipcon) ⇒ BrickletAccelerometer
constructor
Creates an object with the unique device ID
uidand 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
idto the blockblock. -
#set_acceleration_callback_period(period) ⇒ Object
Sets the period in ms 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 in ms with which the threshold callback.
Methods inherited from Device
#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.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 76 def initialize(uid, ipcon) super uid, ipcon @api_version = [2, 0, 1] @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD] = RESPONSE_EXPECTED_TRUE @response_expected[FUNCTION_GET_ACCELERATION_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_GET_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_CONFIGURATION] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_LED_ON] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_LED_OFF] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_IS_LED_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[CALLBACK_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[CALLBACK_ACCELERATION_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_ACCELERATION] = 's s s' @callback_formats[CALLBACK_ACCELERATION_REACHED] = 's s s' end |
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²), not to be confused with grams.
If you want to get the acceleration periodically, it is recommended to use the callback CALLBACK_ACCELERATION and set the period with BrickletAccelerometer#set_acceleration_callback_period.
108 109 110 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 108 def get_acceleration send_request(FUNCTION_GET_ACCELERATION, [], '', 6, 's s s') end |
#get_acceleration_callback_period ⇒ Object
Returns the period as set by BrickletAccelerometer#set_acceleration_callback_period.
124 125 126 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 124 def get_acceleration_callback_period send_request(FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD, [], '', 4, 'L') end |
#get_acceleration_callback_threshold ⇒ Object
Returns the threshold as set by BrickletAccelerometer#set_acceleration_callback_threshold.
146 147 148 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 146 def get_acceleration_callback_threshold send_request(FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD, [], '', 13, 'k s s s s s s') end |
#get_configuration ⇒ Object
Returns the configuration as set by BrickletAccelerometer#set_configuration.
192 193 194 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 192 def get_configuration send_request(FUNCTION_GET_CONFIGURATION, [], '', 3, 'C C C') end |
#get_debounce_period ⇒ Object
Returns the debounce period as set by BrickletAccelerometer#set_debounce_period.
166 167 168 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 166 def get_debounce_period send_request(FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 4, '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’ or ‘d’.
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
219 220 221 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 219 def get_identity send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S') end |
#get_temperature ⇒ Object
Returns the temperature of the accelerometer in °C.
171 172 173 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 171 def get_temperature send_request(FUNCTION_GET_TEMPERATURE, [], '', 2, 's') end |
#is_led_on ⇒ Object
Returns true if the LED is enabled, false otherwise.
207 208 209 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 207 def is_led_on send_request(FUNCTION_IS_LED_ON, [], '', 1, '?') end |
#led_off ⇒ Object
Disables the LED on the Bricklet.
202 203 204 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 202 def led_off send_request(FUNCTION_LED_OFF, [], '', 0, '') end |
#led_on ⇒ Object
Enables the LED on the Bricklet.
197 198 199 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 197 def led_on send_request(FUNCTION_LED_ON, [], '', 0, '') end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id to the block block.
224 225 226 227 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 224 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#set_acceleration_callback_period(period) ⇒ Object
Sets the period in ms with which the CALLBACK_ACCELERATION callback is triggered periodically. A value of 0 turns the callback off.
CALLBACK_ACCELERATION is only triggered if the acceleration has changed since the last triggering.
The default value is 0.
119 120 121 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 119 def set_acceleration_callback_period(period) send_request(FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD, [period], 'L', 0, '') 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)"
The default value is (‘x’, 0, 0, 0, 0, 0, 0).
141 142 143 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 141 def set_acceleration_callback_threshold(option, min_x, max_x, min_y, max_y, min_z, max_z) 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', 0, '') 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 to 2G up to -16G to 16G.
-
Filter bandwidth between 50Hz and 800Hz.
Decreasing data rate or full scale range will also decrease the noise on the data.
The default values are 100Hz data rate, -4G to +4G range and 200Hz filter bandwidth.
187 188 189 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 187 def set_configuration(data_rate, full_scale, filter_bandwidth) send_request(FUNCTION_SET_CONFIGURATION, [data_rate, full_scale, filter_bandwidth], 'C C C', 0, '') end |
#set_debounce_period(debounce) ⇒ Object
Sets the period in ms with which the threshold callback
-
CALLBACK_ACCELERATION_REACHED
is triggered, if the threshold
-
BrickletAccelerometer#set_acceleration_callback_threshold
keeps being reached.
The default value is 100.
161 162 163 |
# File 'lib/tinkerforge/bricklet_accelerometer.rb', line 161 def set_debounce_period(debounce) send_request(FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'L', 0, '') end |