Class: Tinkerforge::BrickIMU

Inherits:
Device
  • Object
show all
Defined in:
lib/tinkerforge/brick_imu.rb

Overview

Full fledged AHRS with 9 degrees of freedom

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

16
DEVICE_DISPLAY_NAME =

:nodoc:

'IMU Brick'
CALLBACK_ACCELERATION =

This callback is triggered periodically with the period that is set by BrickIMU#set_acceleration_period. The parameters are the acceleration for the x, y and z axis.

31
CALLBACK_MAGNETIC_FIELD =

This callback is triggered periodically with the period that is set by BrickIMU#set_magnetic_field_period. The parameters are the magnetic field for the x, y and z axis.

32
CALLBACK_ANGULAR_VELOCITY =

This callback is triggered periodically with the period that is set by BrickIMU#set_angular_velocity_period. The parameters are the angular velocity for the x, y and z axis.

33
CALLBACK_ALL_DATA =

This callback is triggered periodically with the period that is set by BrickIMU#set_all_data_period. The parameters are the acceleration, the magnetic field and the angular velocity for the x, y and z axis as well as the temperature of the IMU Brick.

34
CALLBACK_ORIENTATION =

This callback is triggered periodically with the period that is set by BrickIMU#set_orientation_period. The parameters are the orientation (roll, pitch and yaw) of the IMU Brick in Euler angles. See BrickIMU#get_orientation for details.

35
CALLBACK_QUATERNION =

This callback is triggered periodically with the period that is set by BrickIMU#set_quaternion_period. The parameters are the orientation (x, y, z, w) of the IMU Brick in quaternions. See BrickIMU#get_quaternion for details.

36
FUNCTION_GET_ACCELERATION =

:nodoc:

1
FUNCTION_GET_MAGNETIC_FIELD =

:nodoc:

2
FUNCTION_GET_ANGULAR_VELOCITY =

:nodoc:

3
FUNCTION_GET_ALL_DATA =

:nodoc:

4
FUNCTION_GET_ORIENTATION =

:nodoc:

5
FUNCTION_GET_QUATERNION =

:nodoc:

6
FUNCTION_GET_IMU_TEMPERATURE =

:nodoc:

7
FUNCTION_LEDS_ON =

:nodoc:

8
FUNCTION_LEDS_OFF =

:nodoc:

9
FUNCTION_ARE_LEDS_ON =

:nodoc:

10
FUNCTION_SET_ACCELERATION_RANGE =

:nodoc:

11
FUNCTION_GET_ACCELERATION_RANGE =

:nodoc:

12
FUNCTION_SET_MAGNETOMETER_RANGE =

:nodoc:

13
FUNCTION_GET_MAGNETOMETER_RANGE =

:nodoc:

14
FUNCTION_SET_CONVERGENCE_SPEED =

:nodoc:

15
FUNCTION_GET_CONVERGENCE_SPEED =

:nodoc:

16
FUNCTION_SET_CALIBRATION =

:nodoc:

17
FUNCTION_GET_CALIBRATION =

:nodoc:

18
FUNCTION_SET_ACCELERATION_PERIOD =

:nodoc:

19
FUNCTION_GET_ACCELERATION_PERIOD =

:nodoc:

20
FUNCTION_SET_MAGNETIC_FIELD_PERIOD =

:nodoc:

21
FUNCTION_GET_MAGNETIC_FIELD_PERIOD =

:nodoc:

22
FUNCTION_SET_ANGULAR_VELOCITY_PERIOD =

:nodoc:

23
FUNCTION_GET_ANGULAR_VELOCITY_PERIOD =

:nodoc:

24
FUNCTION_SET_ALL_DATA_PERIOD =

:nodoc:

25
FUNCTION_GET_ALL_DATA_PERIOD =

:nodoc:

26
FUNCTION_SET_ORIENTATION_PERIOD =

:nodoc:

27
FUNCTION_GET_ORIENTATION_PERIOD =

:nodoc:

28
FUNCTION_SET_QUATERNION_PERIOD =

:nodoc:

29
FUNCTION_GET_QUATERNION_PERIOD =

:nodoc:

30
FUNCTION_ORIENTATION_CALCULATION_ON =

:nodoc:

37
FUNCTION_ORIENTATION_CALCULATION_OFF =

:nodoc:

38
FUNCTION_IS_ORIENTATION_CALCULATION_ON =

:nodoc:

39
FUNCTION_ENABLE_STATUS_LED =

:nodoc:

238
FUNCTION_DISABLE_STATUS_LED =

:nodoc:

239
FUNCTION_IS_STATUS_LED_ENABLED =

:nodoc:

240
FUNCTION_GET_PROTOCOL1_BRICKLET_NAME =

:nodoc:

241
FUNCTION_GET_CHIP_TEMPERATURE =

:nodoc:

242
FUNCTION_RESET =

:nodoc:

243
FUNCTION_GET_IDENTITY =

:nodoc:

255
CALIBRATION_TYPE_ACCELEROMETER_GAIN =

:nodoc:

0
CALIBRATION_TYPE_ACCELEROMETER_BIAS =

:nodoc:

1
CALIBRATION_TYPE_MAGNETOMETER_GAIN =

:nodoc:

2
CALIBRATION_TYPE_MAGNETOMETER_BIAS =

:nodoc:

3
CALIBRATION_TYPE_GYROSCOPE_GAIN =

:nodoc:

4
CALIBRATION_TYPE_GYROSCOPE_BIAS =

:nodoc:

5

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

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) ⇒ BrickIMU

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/tinkerforge/brick_imu.rb', line 101

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 1]

  @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_MAGNETIC_FIELD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ANGULAR_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ORIENTATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_QUATERNION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IMU_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_LEDS_ON] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_LEDS_OFF] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_ARE_LEDS_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ACCELERATION_RANGE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_ACCELERATION_RANGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MAGNETOMETER_RANGE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MAGNETOMETER_RANGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CONVERGENCE_SPEED] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CONVERGENCE_SPEED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CALIBRATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MAGNETIC_FIELD_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_MAGNETIC_FIELD_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ANGULAR_VELOCITY_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ANGULAR_VELOCITY_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ORIENTATION_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ORIENTATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_QUATERNION_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_QUATERNION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[CALLBACK_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_MAGNETIC_FIELD] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_ANGULAR_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_ORIENTATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_QUATERNION] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_ORIENTATION_CALCULATION_ON] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_ORIENTATION_CALCULATION_OFF] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_IS_ORIENTATION_CALCULATION_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_ACCELERATION] = 's s s'
  @callback_formats[CALLBACK_MAGNETIC_FIELD] = 's s s'
  @callback_formats[CALLBACK_ANGULAR_VELOCITY] = 's s s'
  @callback_formats[CALLBACK_ALL_DATA] = 's s s s s s s s s s'
  @callback_formats[CALLBACK_ORIENTATION] = 's s s'
  @callback_formats[CALLBACK_QUATERNION] = 'e e e e'
end

Instance Method Details

#are_leds_onObject

Returns true if the orientation and direction LEDs of the IMU Brick are on, false otherwise.



273
274
275
# File 'lib/tinkerforge/brick_imu.rb', line 273

def are_leds_on
  send_request(FUNCTION_ARE_LEDS_ON, [], '', 1, '?')
end

#disable_status_ledObject

Disables the status LED.

The status LED is the blue LED next to the USB connector. If enabled is is on and it flickers if data is transfered. If disabled it is always off.

The default state is enabled.

.. versionadded

2.3.1$nbsp;(Firmware)



496
497
498
# File 'lib/tinkerforge/brick_imu.rb', line 496

def disable_status_led
  send_request(FUNCTION_DISABLE_STATUS_LED, [], '', 0, '')
end

#enable_status_ledObject

Enables the status LED.

The status LED is the blue LED next to the USB connector. If enabled is is on and it flickers if data is transfered. If disabled it is always off.

The default state is enabled.

.. versionadded

2.3.1$nbsp;(Firmware)



484
485
486
# File 'lib/tinkerforge/brick_imu.rb', line 484

def enable_status_led
  send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
end

#get_accelerationObject

Returns the calibrated acceleration from the accelerometer for the x, y and z axis in g/1000 (1g = 9.80665m/s²).

If you want to get the acceleration periodically, it is recommended to use the callback CALLBACK_ACCELERATION and set the period with BrickIMU#set_acceleration_period.



167
168
169
# File 'lib/tinkerforge/brick_imu.rb', line 167

def get_acceleration
  send_request(FUNCTION_GET_ACCELERATION, [], '', 6, 's s s')
end

#get_acceleration_periodObject

Returns the period as set by BrickIMU#set_acceleration_period.



383
384
385
# File 'lib/tinkerforge/brick_imu.rb', line 383

def get_acceleration_period
  send_request(FUNCTION_GET_ACCELERATION_PERIOD, [], '', 4, 'L')
end

#get_acceleration_rangeObject

Not implemented yet.



283
284
285
# File 'lib/tinkerforge/brick_imu.rb', line 283

def get_acceleration_range
  send_request(FUNCTION_GET_ACCELERATION_RANGE, [], '', 1, 'C')
end

#get_all_dataObject

Returns the data from BrickIMU#get_acceleration, BrickIMU#get_magnetic_field and BrickIMU#get_angular_velocity as well as the temperature of the IMU Brick.

The temperature is given in °C/100.

If you want to get the data periodically, it is recommended to use the callback CALLBACK_ALL_DATA and set the period with BrickIMU#set_all_data_period.



200
201
202
# File 'lib/tinkerforge/brick_imu.rb', line 200

def get_all_data
  send_request(FUNCTION_GET_ALL_DATA, [], '', 20, 's s s s s s s s s s')
end

#get_all_data_periodObject

Returns the period as set by BrickIMU#set_all_data_period.



416
417
418
# File 'lib/tinkerforge/brick_imu.rb', line 416

def get_all_data_period
  send_request(FUNCTION_GET_ALL_DATA_PERIOD, [], '', 4, 'L')
end

#get_angular_velocityObject

Returns the calibrated angular velocity from the gyroscope for the x, y and z axis in °/14.375s (you have to divide by 14.375 to get the value in °/s).

If you want to get the angular velocity periodically, it is recommended to use the callback CALLBACK_ANGULAR_VELOCITY and set the period with BrickIMU#set_angular_velocity_period.



188
189
190
# File 'lib/tinkerforge/brick_imu.rb', line 188

def get_angular_velocity
  send_request(FUNCTION_GET_ANGULAR_VELOCITY, [], '', 6, 's s s')
end

#get_angular_velocity_periodObject

Returns the period as set by BrickIMU#set_angular_velocity_period.



405
406
407
# File 'lib/tinkerforge/brick_imu.rb', line 405

def get_angular_velocity_period
  send_request(FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, [], '', 4, 'L')
end

#get_calibration(typ) ⇒ Object

Returns the calibration for a given type as set by BrickIMU#set_calibration.



370
371
372
# File 'lib/tinkerforge/brick_imu.rb', line 370

def get_calibration(typ)
  send_request(FUNCTION_GET_CALIBRATION, [typ], 'C', 20, 's10')
end

#get_chip_temperatureObject

Returns the temperature in °C/10 as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has an accuracy of +-15%. Practically it is only useful as an indicator for temperature changes.



522
523
524
# File 'lib/tinkerforge/brick_imu.rb', line 522

def get_chip_temperature
  send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
end

#get_convergence_speedObject

Returns the convergence speed as set by BrickIMU#set_convergence_speed.



329
330
331
# File 'lib/tinkerforge/brick_imu.rb', line 329

def get_convergence_speed
  send_request(FUNCTION_GET_CONVERGENCE_SPEED, [], '', 2, 'S')
end

#get_identityObject

Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘0’-‘8’ (stack position).

The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|



544
545
546
# File 'lib/tinkerforge/brick_imu.rb', line 544

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_imu_temperatureObject

Returns the temperature of the IMU Brick. The temperature is given in °C/100.



257
258
259
# File 'lib/tinkerforge/brick_imu.rb', line 257

def get_imu_temperature
  send_request(FUNCTION_GET_IMU_TEMPERATURE, [], '', 2, 's')
end

#get_magnetic_fieldObject

Returns the calibrated magnetic field from the magnetometer for the x, y and z axis in mG (Milligauss or Nanotesla).

If you want to get the magnetic field periodically, it is recommended to use the callback CALLBACK_MAGNETIC_FIELD and set the period with BrickIMU#set_magnetic_field_period.



177
178
179
# File 'lib/tinkerforge/brick_imu.rb', line 177

def get_magnetic_field
  send_request(FUNCTION_GET_MAGNETIC_FIELD, [], '', 6, 's s s')
end

#get_magnetic_field_periodObject

Returns the period as set by BrickIMU#set_magnetic_field_period.



394
395
396
# File 'lib/tinkerforge/brick_imu.rb', line 394

def get_magnetic_field_period
  send_request(FUNCTION_GET_MAGNETIC_FIELD_PERIOD, [], '', 4, 'L')
end

#get_magnetometer_rangeObject

Not implemented yet.



293
294
295
# File 'lib/tinkerforge/brick_imu.rb', line 293

def get_magnetometer_range
  send_request(FUNCTION_GET_MAGNETOMETER_RANGE, [], '', 1, 'C')
end

#get_orientationObject

Returns the current orientation (roll, pitch, yaw) of the IMU Brick as Euler angles in one-hundredth degree. Note that Euler angles always experience a ‘gimbal lock <en.wikipedia.org/wiki/Gimbal_lock>`__.

We recommend that you use quaternions instead.

The order to sequence in which the orientation values should be applied is roll, yaw, pitch.

If you want to get the orientation periodically, it is recommended to use the callback CALLBACK_ORIENTATION and set the period with BrickIMU#set_orientation_period.



216
217
218
# File 'lib/tinkerforge/brick_imu.rb', line 216

def get_orientation
  send_request(FUNCTION_GET_ORIENTATION, [], '', 6, 's s s')
end

#get_orientation_periodObject

Returns the period as set by BrickIMU#set_orientation_period.



427
428
429
# File 'lib/tinkerforge/brick_imu.rb', line 427

def get_orientation_period
  send_request(FUNCTION_GET_ORIENTATION_PERIOD, [], '', 4, 'L')
end

#get_protocol1_bricklet_name(port) ⇒ Object

Returns the firmware and protocol version and the name of the Bricklet for a given port.

This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet plugins.



512
513
514
# File 'lib/tinkerforge/brick_imu.rb', line 512

def get_protocol1_bricklet_name(port)
  send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
end

#get_quaternionObject

Returns the current orientation (x, y, z, w) of the IMU as ‘quaternions <en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__.

You can go from quaternions to Euler angles with the following formula

xAngle = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z) yAngle = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z) zAngle = asin(2*x*y + 2*z*w)

This process is not reversible, because of the ‘gimbal lock <en.wikipedia.org/wiki/Gimbal_lock>`__.

It is also possible to calculate independent angles. You can calculate yaw, pitch and roll in a right-handed vehicle coordinate system according to DIN70000

with

yaw = atan2(2*x*y + 2*w*z, w*w + x*x - y*y - z*z) pitch = -asin(2*w*y - 2*x*z) roll = -atan2(2*y*z + 2*w*x, -w*w + x*x + y*y - z*z))

Converting the quaternions to an OpenGL transformation matrix is

possible with the following formula

matrix = [[1 - 2*(y*y + z*z), 2*(x*y - w*z), 2*(x*z + w*y), 0],

[    2*(x*y + w*z), 1 - 2*(x*x + z*z),     2*(y*z - w*x), 0],
[    2*(x*z - w*y),     2*(y*z + w*x), 1 - 2*(x*x + y*y), 0],
[                0,                 0,                 0, 1]]

If you want to get the quaternions periodically, it is recommended to use the callback CALLBACK_QUATERNION and set the period with BrickIMU#set_quaternion_period.



251
252
253
# File 'lib/tinkerforge/brick_imu.rb', line 251

def get_quaternion
  send_request(FUNCTION_GET_QUATERNION, [], '', 16, 'e e e e')
end

#get_quaternion_periodObject

Returns the period as set by BrickIMU#set_quaternion_period.



438
439
440
# File 'lib/tinkerforge/brick_imu.rb', line 438

def get_quaternion_period
  send_request(FUNCTION_GET_QUATERNION_PERIOD, [], '', 4, 'L')
end

#is_orientation_calculation_onObject

Returns true if the orientation calculation of the IMU Brick is on, false otherwise.

.. versionadded

2.0.2$nbsp;(Firmware)



472
473
474
# File 'lib/tinkerforge/brick_imu.rb', line 472

def is_orientation_calculation_on
  send_request(FUNCTION_IS_ORIENTATION_CALCULATION_ON, [], '', 1, '?')
end

#is_status_led_enabledObject

Returns true if the status LED is enabled, false otherwise.

.. versionadded

2.3.1$nbsp;(Firmware)



503
504
505
# File 'lib/tinkerforge/brick_imu.rb', line 503

def is_status_led_enabled
  send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
end

#leds_offObject

Turns the orientation and direction LEDs of the IMU Brick off.



267
268
269
# File 'lib/tinkerforge/brick_imu.rb', line 267

def leds_off
  send_request(FUNCTION_LEDS_OFF, [], '', 0, '')
end

#leds_onObject

Turns the orientation and direction LEDs of the IMU Brick on.



262
263
264
# File 'lib/tinkerforge/brick_imu.rb', line 262

def leds_on
  send_request(FUNCTION_LEDS_ON, [], '', 0, '')
end

#orientation_calculation_offObject

Turns the orientation calculation of the IMU Brick off.

If the calculation is off, BrickIMU#get_orientation will return the last calculated value until the calculation is turned on again.

The trigonometric functions that are needed to calculate the orientation are very expensive. We recommend to turn the orientation calculation off if the orientation is not needed, to free calculation time for the sensor fusion algorithm.

As default the calculation is on.

.. versionadded

2.0.2$nbsp;(Firmware)



464
465
466
# File 'lib/tinkerforge/brick_imu.rb', line 464

def orientation_calculation_off
  send_request(FUNCTION_ORIENTATION_CALCULATION_OFF, [], '', 0, '')
end

#orientation_calculation_onObject

Turns the orientation calculation of the IMU Brick on.

As default the calculation is on.

.. versionadded

2.0.2$nbsp;(Firmware)



447
448
449
# File 'lib/tinkerforge/brick_imu.rb', line 447

def orientation_calculation_on
  send_request(FUNCTION_ORIENTATION_CALCULATION_ON, [], '', 0, '')
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



549
550
551
552
# File 'lib/tinkerforge/brick_imu.rb', line 549

def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end

#resetObject

Calling this function will reset the Brick. Calling this function on a Brick inside of a stack will reset the whole stack.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!



532
533
534
# File 'lib/tinkerforge/brick_imu.rb', line 532

def reset
  send_request(FUNCTION_RESET, [], '', 0, '')
end

#set_acceleration_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.

The default value is 0.



378
379
380
# File 'lib/tinkerforge/brick_imu.rb', line 378

def set_acceleration_period(period)
  send_request(FUNCTION_SET_ACCELERATION_PERIOD, [period], 'L', 0, '')
end

#set_acceleration_range(range) ⇒ Object

Not implemented yet.



278
279
280
# File 'lib/tinkerforge/brick_imu.rb', line 278

def set_acceleration_range(range)
  send_request(FUNCTION_SET_ACCELERATION_RANGE, [range], 'C', 0, '')
end

#set_all_data_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_ALL_DATA callback is triggered periodically. A value of 0 turns the callback off.



411
412
413
# File 'lib/tinkerforge/brick_imu.rb', line 411

def set_all_data_period(period)
  send_request(FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 0, '')
end

#set_angular_velocity_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_ANGULAR_VELOCITY callback is triggered periodically. A value of 0 turns the callback off.



400
401
402
# File 'lib/tinkerforge/brick_imu.rb', line 400

def set_angular_velocity_period(period)
  send_request(FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, [period], 'L', 0, '')
end

#set_calibration(typ, data) ⇒ Object

There are several different types that can be calibrated:

"Type", "Description", "Values"

"0",    "Accelerometer Gain", "``[mul x, mul y, mul z, div x, div y, div z, 0, 0, 0, 0]``"
"1",    "Accelerometer Bias", "``[bias x, bias y, bias z, 0, 0, 0, 0, 0, 0, 0]``"
"2",    "Magnetometer Gain",  "``[mul x, mul y, mul z, div x, div y, div z, 0, 0, 0, 0]``"
"3",    "Magnetometer Bias",  "``[bias x, bias y, bias z, 0, 0, 0, 0, 0, 0, 0]``"
"4",    "Gyroscope Gain",     "``[mul x, mul y, mul z, div x, div y, div z, 0, 0, 0, 0]``"
"5",    "Gyroscope Bias",     "``[bias xl, bias yl, bias zl, temp l, bias xh, bias yh, bias zh, temp h, 0, 0]``"
The calibration via gain and bias is done with the following formula

new_value = (bias + orig_value) * gain_mul / gain_div

If you really want to write your own calibration software, please keep in mind that you first have to undo the old calibration (set bias to 0 and gain to 1/1) and that you have to average over several thousand values to obtain a usable result in the end.

The gyroscope bias is highly dependent on the temperature, so you have to calibrate the bias two times with different temperatures. The values xl, yl, zl and “temp l“ are the bias for x, y, z and the corresponding temperature for a low temperature. The values xh, yh, zh and “temp h“ are the same for a high temperatures. The temperature difference should be at least 5°C. If you have a temperature where the IMU Brick is mostly used, you should use this temperature for one of the sampling points.

.. note

We highly recommend that you use the Brick Viewer to calibrate your IMU Brick.



365
366
367
# File 'lib/tinkerforge/brick_imu.rb', line 365

def set_calibration(typ, data)
  send_request(FUNCTION_SET_CALIBRATION, [typ, data], 'C s10', 0, '')
end

#set_convergence_speed(speed) ⇒ Object

Sets the convergence speed of the IMU Brick in °/s. The convergence speed determines how the different sensor measurements are fused.

If the orientation of the IMU Brick is off by 10° and the convergence speed is set to 20°/s, it will take 0.5s until the orientation is corrected. However, if the correct orientation is reached and the convergence speed is too high, the orientation will fluctuate with the fluctuations of the accelerometer and the magnetometer.

If you set the convergence speed to 0, practically only the gyroscope is used to calculate the orientation. This gives very smooth movements, but errors of the gyroscope will not be corrected. If you set the convergence speed to something above 500, practically only the magnetometer and the accelerometer are used to calculate the orientation. In this case the movements are abrupt and the values will fluctuate, but there won’t be any errors that accumulate over time.

In an application with high angular velocities, we recommend a high convergence speed, so the errors of the gyroscope can be corrected fast. In applications with only slow movements we recommend a low convergence speed. You can change the convergence speed on the fly. So it is possible (and recommended) to increase the convergence speed before an abrupt movement and decrease it afterwards again.

You might want to play around with the convergence speed in the Brick Viewer to get a feeling for a good value for your application.

The default value is 30.



324
325
326
# File 'lib/tinkerforge/brick_imu.rb', line 324

def set_convergence_speed(speed)
  send_request(FUNCTION_SET_CONVERGENCE_SPEED, [speed], 'S', 0, '')
end

#set_magnetic_field_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_MAGNETIC_FIELD callback is triggered periodically. A value of 0 turns the callback off.



389
390
391
# File 'lib/tinkerforge/brick_imu.rb', line 389

def set_magnetic_field_period(period)
  send_request(FUNCTION_SET_MAGNETIC_FIELD_PERIOD, [period], 'L', 0, '')
end

#set_magnetometer_range(range) ⇒ Object

Not implemented yet.



288
289
290
# File 'lib/tinkerforge/brick_imu.rb', line 288

def set_magnetometer_range(range)
  send_request(FUNCTION_SET_MAGNETOMETER_RANGE, [range], 'C', 0, '')
end

#set_orientation_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_ORIENTATION callback is triggered periodically. A value of 0 turns the callback off.



422
423
424
# File 'lib/tinkerforge/brick_imu.rb', line 422

def set_orientation_period(period)
  send_request(FUNCTION_SET_ORIENTATION_PERIOD, [period], 'L', 0, '')
end

#set_quaternion_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_QUATERNION callback is triggered periodically. A value of 0 turns the callback off.



433
434
435
# File 'lib/tinkerforge/brick_imu.rb', line 433

def set_quaternion_period(period)
  send_request(FUNCTION_SET_QUATERNION_PERIOD, [period], 'L', 0, '')
end