class Tinkerforge::BrickIMU

Full fledged AHRS with 9 degrees of freedom

Constants

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.

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.

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.

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.

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.

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.

Public Class Methods

new(uid, ipcon) click to toggle source

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

Calls superclass method
# File lib/tinkerforge/brick_imu.rb, line 118
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 4]

  @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[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_SET_SPITFP_BAUDRATE_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SPITFP_BAUDRATE_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_SEND_TIMEOUT_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_SPITFP_BAUDRATE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SPITFP_BAUDRATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = 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_WRITE_BRICKLET_PLUGIN] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_READ_BRICKLET_PLUGIN] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_ACCELERATION] = [14, 's s s']
  @callback_formats[CALLBACK_MAGNETIC_FIELD] = [14, 's s s']
  @callback_formats[CALLBACK_ANGULAR_VELOCITY] = [14, 's s s']
  @callback_formats[CALLBACK_ALL_DATA] = [28, 's s s s s s s s s s']
  @callback_formats[CALLBACK_ORIENTATION] = [14, 's s s']
  @callback_formats[CALLBACK_QUATERNION] = [24, 'e e e e']

  @ipcon.add_device self
end

Public Instance Methods

are_leds_on() click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 309
def are_leds_on
  check_validity

  send_request FUNCTION_ARE_LEDS_ON, [], '', 9, '?'
end
disable_status_led() click to toggle source

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)

# File lib/tinkerforge/brick_imu.rb, line 676
def disable_status_led
  check_validity

  send_request FUNCTION_DISABLE_STATUS_LED, [], '', 8, ''
end
enable_status_led() click to toggle source

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)

# File lib/tinkerforge/brick_imu.rb, line 662
def enable_status_led
  check_validity

  send_request FUNCTION_ENABLE_STATUS_LED, [], '', 8, ''
end
get_acceleration() click to toggle source

Returns the calibrated acceleration from the accelerometer for the x, y and z axis.

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

# File lib/tinkerforge/brick_imu.rb, line 188
def get_acceleration
  check_validity

  send_request FUNCTION_GET_ACCELERATION, [], '', 14, 's s s'
end
get_acceleration_period() click to toggle source

Returns the period as set by BrickIMU#set_acceleration_period.

# File lib/tinkerforge/brick_imu.rb, line 435
def get_acceleration_period
  check_validity

  send_request FUNCTION_GET_ACCELERATION_PERIOD, [], '', 12, 'L'
end
get_acceleration_range() click to toggle source

Not implemented yet.

# File lib/tinkerforge/brick_imu.rb, line 323
def get_acceleration_range
  check_validity

  send_request FUNCTION_GET_ACCELERATION_RANGE, [], '', 9, 'C'
end
get_all_data() click to toggle source

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.

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

# File lib/tinkerforge/brick_imu.rb, line 225
def get_all_data
  check_validity

  send_request FUNCTION_GET_ALL_DATA, [], '', 28, 's s s s s s s s s s'
end
get_all_data_period() click to toggle source

Returns the period as set by BrickIMU#set_all_data_period.

# File lib/tinkerforge/brick_imu.rb, line 480
def get_all_data_period
  check_validity

  send_request FUNCTION_GET_ALL_DATA_PERIOD, [], '', 12, 'L'
end
get_angular_velocity() click to toggle source

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_ANGULAR_VELOCITY callback and set the period with BrickIMU#set_angular_velocity_period.

# File lib/tinkerforge/brick_imu.rb, line 213
def get_angular_velocity
  check_validity

  send_request FUNCTION_GET_ANGULAR_VELOCITY, [], '', 14, 's s s'
end
get_angular_velocity_period() click to toggle source

Returns the period as set by BrickIMU#set_angular_velocity_period.

# File lib/tinkerforge/brick_imu.rb, line 465
def get_angular_velocity_period
  check_validity

  send_request FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, [], '', 12, 'L'
end
get_calibration(typ) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 420
def get_calibration(typ)
  check_validity

  send_request FUNCTION_GET_CALIBRATION, [typ], 'C', 28, 's10'
end
get_chip_temperature() click to toggle source

Returns the temperature 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.

# File lib/tinkerforge/brick_imu.rb, line 708
def get_chip_temperature
  check_validity

  send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
end
get_convergence_speed() click to toggle source

Returns the convergence speed as set by BrickIMU#set_convergence_speed.

# File lib/tinkerforge/brick_imu.rb, line 375
def get_convergence_speed
  check_validity

  send_request FUNCTION_GET_CONVERGENCE_SPEED, [], '', 10, 'S'
end
get_identity() click to toggle source

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 is the position in the stack from '0' (bottom) to '8' (top).

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

# File lib/tinkerforge/brick_imu.rb, line 756
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
get_imu_temperature() click to toggle source

Returns the temperature of the IMU Brick.

# File lib/tinkerforge/brick_imu.rb, line 287
def get_imu_temperature
  check_validity

  send_request FUNCTION_GET_IMU_TEMPERATURE, [], '', 10, 's'
end
get_magnetic_field() click to toggle source

Returns the calibrated magnetic field from the magnetometer for the x, y and z axis.

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

# File lib/tinkerforge/brick_imu.rb, line 200
def get_magnetic_field
  check_validity

  send_request FUNCTION_GET_MAGNETIC_FIELD, [], '', 14, 's s s'
end
get_magnetic_field_period() click to toggle source

Returns the period as set by BrickIMU#set_magnetic_field_period.

# File lib/tinkerforge/brick_imu.rb, line 450
def get_magnetic_field_period
  check_validity

  send_request FUNCTION_GET_MAGNETIC_FIELD_PERIOD, [], '', 12, 'L'
end
get_magnetometer_range() click to toggle source

Not implemented yet.

# File lib/tinkerforge/brick_imu.rb, line 337
def get_magnetometer_range
  check_validity

  send_request FUNCTION_GET_MAGNETOMETER_RANGE, [], '', 9, 'C'
end
get_orientation() click to toggle source

Returns the current orientation (roll, pitch, yaw) of the IMU Brick as Euler angles. Note that Euler angles always experience a `gimbal lock <CALLBACK_ORIENTATION callback and set the period with BrickIMU#set_orientation_period.

# File lib/tinkerforge/brick_imu.rb, line 243
def get_orientation
  check_validity

  send_request FUNCTION_GET_ORIENTATION, [], '', 14, 's s s'
end
get_orientation_period() click to toggle source

Returns the period as set by BrickIMU#set_orientation_period.

# File lib/tinkerforge/brick_imu.rb, line 495
def get_orientation_period
  check_validity

  send_request FUNCTION_GET_ORIENTATION_PERIOD, [], '', 12, 'L'
end
get_protocol1_bricklet_name(port) click to toggle source

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.

# File lib/tinkerforge/brick_imu.rb, line 696
def get_protocol1_bricklet_name(port)
  check_validity

  send_request FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 52, 'C C3 Z40'
end
get_quaternion_period() click to toggle source

Returns the period as set by BrickIMU#set_quaternion_period.

# File lib/tinkerforge/brick_imu.rb, line 510
def get_quaternion_period
  check_validity

  send_request FUNCTION_GET_QUATERNION_PERIOD, [], '', 12, 'L'
end
get_send_timeout_count(communication_method) click to toggle source

Returns the timeout count for the different communication methods.

The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.

This function is mostly used for debugging during development, in normal operation the counters should nearly always stay at 0.

.. versionadded

2.3.3$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 599
def get_send_timeout_count(communication_method)
  check_validity

  send_request FUNCTION_GET_SEND_TIMEOUT_COUNT, [communication_method], 'C', 12, 'L'
end
get_spitfp_baudrate(bricklet_port) click to toggle source

Returns the baudrate for a given Bricklet port, see BrickIMU#set_spitfp_baudrate.

.. versionadded

2.3.3$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 629
def get_spitfp_baudrate(bricklet_port)
  check_validity

  send_request FUNCTION_GET_SPITFP_BAUDRATE, [bricklet_port], 'k', 12, 'L'
end
get_spitfp_baudrate_config() click to toggle source

Returns the baudrate config, see BrickIMU#set_spitfp_baudrate_config.

.. versionadded

2.3.5$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 585
def get_spitfp_baudrate_config
  check_validity

  send_request FUNCTION_GET_SPITFP_BAUDRATE_CONFIG, [], '', 13, '? L'
end
get_spitfp_error_count(bricklet_port) click to toggle source

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,

  • message checksum errors,

  • framing errors and

  • overflow errors.

The errors counts are for errors that occur on the Brick side. All Bricklets have a similar function that returns the errors on the Bricklet side.

.. versionadded

2.3.3$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 648
def get_spitfp_error_count(bricklet_port)
  check_validity

  send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [bricklet_port], 'k', 24, 'L L L L'
end
is_orientation_calculation_on() click to toggle source

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

.. versionadded

2.0.2$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 550
def is_orientation_calculation_on
  check_validity

  send_request FUNCTION_IS_ORIENTATION_CALCULATION_ON, [], '', 9, '?'
end
is_status_led_enabled() click to toggle source

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

.. versionadded

2.3.1$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 685
def is_status_led_enabled
  check_validity

  send_request FUNCTION_IS_STATUS_LED_ENABLED, [], '', 9, '?'
end
leds_off() click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 301
def leds_off
  check_validity

  send_request FUNCTION_LEDS_OFF, [], '', 8, ''
end
leds_on() click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 294
def leds_on
  check_validity

  send_request FUNCTION_LEDS_ON, [], '', 8, ''
end
orientation_calculation_off() click to toggle source

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)

# File lib/tinkerforge/brick_imu.rb, line 540
def orientation_calculation_off
  check_validity

  send_request FUNCTION_ORIENTATION_CALCULATION_OFF, [], '', 8, ''
end
orientation_calculation_on() click to toggle source

Turns the orientation calculation of the IMU Brick on.

As default the calculation is on.

.. versionadded

2.0.2$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 521
def orientation_calculation_on
  check_validity

  send_request FUNCTION_ORIENTATION_CALCULATION_ON, [], '', 8, ''
end
read_bricklet_plugin(port, offset) click to toggle source

Reads 32 bytes of firmware from the bricklet attached at the given port. The bytes are read starting at the position offset * 32.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

# File lib/tinkerforge/brick_imu.rb, line 742
def read_bricklet_plugin(port, offset)
  check_validity

  send_request FUNCTION_READ_BRICKLET_PLUGIN, [port, offset], 'k C', 40, 'C32'
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/brick_imu.rb, line 761
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end
reset() click to toggle source

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!

# File lib/tinkerforge/brick_imu.rb, line 720
def reset
  check_validity

  send_request FUNCTION_RESET, [], '', 8, ''
end
set_acceleration_period(period) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 428
def set_acceleration_period(period)
  check_validity

  send_request FUNCTION_SET_ACCELERATION_PERIOD, [period], 'L', 8, ''
end
set_acceleration_range(range) click to toggle source

Not implemented yet.

# File lib/tinkerforge/brick_imu.rb, line 316
def set_acceleration_range(range)
  check_validity

  send_request FUNCTION_SET_ACCELERATION_RANGE, [range], 'C', 8, ''
end
set_all_data_period(period) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 473
def set_all_data_period(period)
  check_validity

  send_request FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 8, ''
end
set_angular_velocity_period(period) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 458
def set_angular_velocity_period(period)
  check_validity

  send_request FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, [period], 'L', 8, ''
end
set_calibration(typ, data) click to toggle source

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.

# File lib/tinkerforge/brick_imu.rb, line 413
def set_calibration(typ, data)
  check_validity

  send_request FUNCTION_SET_CALIBRATION, [typ, data], 'C s10', 8, ''
end
set_convergence_speed(speed) click to toggle source

Sets the convergence speed of the IMU Brick. 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.

# File lib/tinkerforge/brick_imu.rb, line 368
def set_convergence_speed(speed)
  check_validity

  send_request FUNCTION_SET_CONVERGENCE_SPEED, [speed], 'S', 8, ''
end
set_magnetic_field_period(period) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 443
def set_magnetic_field_period(period)
  check_validity

  send_request FUNCTION_SET_MAGNETIC_FIELD_PERIOD, [period], 'L', 8, ''
end
set_magnetometer_range(range) click to toggle source

Not implemented yet.

# File lib/tinkerforge/brick_imu.rb, line 330
def set_magnetometer_range(range)
  check_validity

  send_request FUNCTION_SET_MAGNETOMETER_RANGE, [range], 'C', 8, ''
end
set_orientation_period(period) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 488
def set_orientation_period(period)
  check_validity

  send_request FUNCTION_SET_ORIENTATION_PERIOD, [period], 'L', 8, ''
end
set_quaternion_period(period) click to toggle source

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

# File lib/tinkerforge/brick_imu.rb, line 503
def set_quaternion_period(period)
  check_validity

  send_request FUNCTION_SET_QUATERNION_PERIOD, [period], 'L', 8, ''
end
set_spitfp_baudrate(bricklet_port, baudrate) click to toggle source

Sets the baudrate for a specific Bricklet port.

If you want to increase the throughput of Bricklets you can increase the baudrate. If you get a high error count because of high interference (see BrickIMU#get_spitfp_error_count) you can decrease the baudrate.

If the dynamic baudrate feature is enabled, the baudrate set by this function corresponds to the maximum baudrate (see BrickIMU#set_spitfp_baudrate_config).

Regulatory testing is done with the default baudrate. If CE compatibility or similar is necessary in your applications we recommend to not change the baudrate.

.. versionadded

2.3.3$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 620
def set_spitfp_baudrate(bricklet_port, baudrate)
  check_validity

  send_request FUNCTION_SET_SPITFP_BAUDRATE, [bricklet_port, baudrate], 'k L', 8, ''
end
set_spitfp_baudrate_config(enable_dynamic_baudrate, minimum_dynamic_baudrate) click to toggle source

The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is enabled, the Brick will try to adapt the baudrate for the communication between Bricks and Bricklets according to the amount of data that is transferred.

The baudrate will be increased exponentially if lots of data is sent/received and decreased linearly if little data is sent/received.

This lowers the baudrate in applications where little data is transferred (e.g. a weather station) and increases the robustness. If there is lots of data to transfer (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.

In cases where some data has to transferred as fast as possible every few seconds (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn the dynamic baudrate off to get the highest possible performance.

The maximum value of the baudrate can be set per port with the function BrickIMU#set_spitfp_baudrate. If the dynamic baudrate is disabled, the baudrate as set by BrickIMU#set_spitfp_baudrate will be used statically.

.. versionadded

2.3.5$nbsp;(Firmware)

# File lib/tinkerforge/brick_imu.rb, line 576
def set_spitfp_baudrate_config(enable_dynamic_baudrate, minimum_dynamic_baudrate)
  check_validity

  send_request FUNCTION_SET_SPITFP_BAUDRATE_CONFIG, [enable_dynamic_baudrate, minimum_dynamic_baudrate], '? L', 8, ''
end
write_bricklet_plugin(port, offset, chunk) click to toggle source

Writes 32 bytes of firmware to the bricklet attached at the given port. The bytes are written to the position offset * 32.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

# File lib/tinkerforge/brick_imu.rb, line 731
def write_bricklet_plugin(port, offset, chunk)
  check_validity

  send_request FUNCTION_WRITE_BRICKLET_PLUGIN, [port, offset, chunk], 'k C C32', 8, ''
end