Class: Tinkerforge::BrickIMU
- 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_SET_SPITFP_BAUDRATE_CONFIG =
:nodoc:
231
- FUNCTION_GET_SPITFP_BAUDRATE_CONFIG =
:nodoc:
232
- FUNCTION_GET_SEND_TIMEOUT_COUNT =
:nodoc:
233
- FUNCTION_SET_SPITFP_BAUDRATE =
:nodoc:
234
- FUNCTION_GET_SPITFP_BAUDRATE =
:nodoc:
235
- FUNCTION_GET_SPITFP_ERROR_COUNT =
:nodoc:
237
- 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_WRITE_BRICKLET_PLUGIN =
:nodoc:
246
- FUNCTION_READ_BRICKLET_PLUGIN =
:nodoc:
247
- 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
- COMMUNICATION_METHOD_NONE =
:nodoc:
0
- COMMUNICATION_METHOD_USB =
:nodoc:
1
- COMMUNICATION_METHOD_SPI_STACK =
:nodoc:
2
- COMMUNICATION_METHOD_CHIBI =
:nodoc:
3
- COMMUNICATION_METHOD_RS485 =
:nodoc:
4
- COMMUNICATION_METHOD_WIFI =
:nodoc:
5
- COMMUNICATION_METHOD_ETHERNET =
:nodoc:
6
- COMMUNICATION_METHOD_WIFI_V2 =
:nodoc:
7
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
-
#are_leds_on ⇒ Object
Returns true if the orientation and direction LEDs of the IMU Brick are on, false otherwise.
-
#disable_status_led ⇒ Object
Disables the status LED.
-
#enable_status_led ⇒ Object
Enables the status LED.
-
#get_acceleration ⇒ Object
Returns the calibrated acceleration from the accelerometer for the x, y and z axis.
-
#get_acceleration_period ⇒ Object
Returns the period as set by BrickIMU#set_acceleration_period.
-
#get_acceleration_range ⇒ Object
Not implemented yet.
-
#get_all_data ⇒ Object
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.
-
#get_all_data_period ⇒ Object
Returns the period as set by BrickIMU#set_all_data_period.
-
#get_angular_velocity ⇒ Object
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).
-
#get_angular_velocity_period ⇒ Object
Returns the period as set by BrickIMU#set_angular_velocity_period.
-
#get_calibration(typ) ⇒ Object
Returns the calibration for a given type as set by BrickIMU#set_calibration.
-
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller.
-
#get_convergence_speed ⇒ Object
Returns the convergence speed as set by BrickIMU#set_convergence_speed.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_imu_temperature ⇒ Object
Returns the temperature of the IMU Brick.
-
#get_magnetic_field ⇒ Object
Returns the calibrated magnetic field from the magnetometer for the x, y and z axis.
-
#get_magnetic_field_period ⇒ Object
Returns the period as set by BrickIMU#set_magnetic_field_period.
-
#get_magnetometer_range ⇒ Object
Not implemented yet.
-
#get_orientation ⇒ Object
Returns the current orientation (roll, pitch, yaw) of the IMU Brick as Euler angles.
-
#get_orientation_period ⇒ Object
Returns the period as set by BrickIMU#set_orientation_period.
-
#get_protocol1_bricklet_name(port) ⇒ Object
Returns the firmware and protocol version and the name of the Bricklet for a given port.
-
#get_quaternion ⇒ Object
Returns the current orientation (x, y, z, w) of the IMU as ‘quaternions <en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__.
-
#get_quaternion_period ⇒ Object
Returns the period as set by BrickIMU#set_quaternion_period.
-
#get_send_timeout_count(communication_method) ⇒ Object
Returns the timeout count for the different communication methods.
-
#get_spitfp_baudrate(bricklet_port) ⇒ Object
Returns the baudrate for a given Bricklet port, see BrickIMU#set_spitfp_baudrate.
-
#get_spitfp_baudrate_config ⇒ Object
Returns the baudrate config, see BrickIMU#set_spitfp_baudrate_config.
-
#get_spitfp_error_count(bricklet_port) ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
-
#initialize(uid, ipcon) ⇒ BrickIMU
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#is_orientation_calculation_on ⇒ Object
Returns true if the orientation calculation of the IMU Brick is on, false otherwise.
-
#is_status_led_enabled ⇒ Object
Returns true if the status LED is enabled, false otherwise.
-
#leds_off ⇒ Object
Turns the orientation and direction LEDs of the IMU Brick off.
-
#leds_on ⇒ Object
Turns the orientation and direction LEDs of the IMU Brick on.
-
#orientation_calculation_off ⇒ Object
Turns the orientation calculation of the IMU Brick off.
-
#orientation_calculation_on ⇒ Object
Turns the orientation calculation of the IMU Brick on.
-
#read_bricklet_plugin(port, offset) ⇒ Object
Reads 32 bytes of firmware from the bricklet attached at the given port.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#reset ⇒ Object
Calling this function will reset the Brick.
-
#set_acceleration_period(period) ⇒ Object
Sets the period with which the CALLBACK_ACCELERATION callback is triggered periodically.
-
#set_acceleration_range(range) ⇒ Object
Not implemented yet.
-
#set_all_data_period(period) ⇒ Object
Sets the period with which the CALLBACK_ALL_DATA callback is triggered periodically.
-
#set_angular_velocity_period(period) ⇒ Object
Sets the period with which the CALLBACK_ANGULAR_VELOCITY callback is triggered periodically.
-
#set_calibration(typ, data) ⇒ Object
There are several different types that can be calibrated:.
-
#set_convergence_speed(speed) ⇒ Object
Sets the convergence speed of the IMU Brick.
-
#set_magnetic_field_period(period) ⇒ Object
Sets the period with which the CALLBACK_MAGNETIC_FIELD callback is triggered periodically.
-
#set_magnetometer_range(range) ⇒ Object
Not implemented yet.
-
#set_orientation_period(period) ⇒ Object
Sets the period with which the CALLBACK_ORIENTATION callback is triggered periodically.
-
#set_quaternion_period(period) ⇒ Object
Sets the period with which the CALLBACK_QUATERNION callback is triggered periodically.
-
#set_spitfp_baudrate(bricklet_port, baudrate) ⇒ Object
Sets the baudrate for a specific Bricklet port.
-
#set_spitfp_baudrate_config(enable_dynamic_baudrate, minimum_dynamic_baudrate) ⇒ Object
The SPITF protocol can be used with a dynamic baudrate.
-
#write_bricklet_plugin(port, offset, chunk) ⇒ Object
Writes 32 bytes of firmware to the bricklet attached at the given port.
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) ⇒ BrickIMU
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#are_leds_on ⇒ Object
Returns true if the orientation and direction LEDs of the IMU Brick are on, false otherwise.
310 311 312 313 314 |
# File 'lib/tinkerforge/brick_imu.rb', line 310 def are_leds_on check_validity send_request FUNCTION_ARE_LEDS_ON, [], '', 9, '?' end |
#disable_status_led ⇒ Object
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)
677 678 679 680 681 |
# File 'lib/tinkerforge/brick_imu.rb', line 677 def disable_status_led check_validity send_request FUNCTION_DISABLE_STATUS_LED, [], '', 8, '' end |
#enable_status_led ⇒ Object
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)
663 664 665 666 667 |
# File 'lib/tinkerforge/brick_imu.rb', line 663 def enable_status_led check_validity send_request FUNCTION_ENABLE_STATUS_LED, [], '', 8, '' end |
#get_acceleration ⇒ Object
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.
189 190 191 192 193 |
# File 'lib/tinkerforge/brick_imu.rb', line 189 def get_acceleration check_validity send_request FUNCTION_GET_ACCELERATION, [], '', 14, 's s s' end |
#get_acceleration_period ⇒ Object
Returns the period as set by BrickIMU#set_acceleration_period.
436 437 438 439 440 |
# File 'lib/tinkerforge/brick_imu.rb', line 436 def get_acceleration_period check_validity send_request FUNCTION_GET_ACCELERATION_PERIOD, [], '', 12, 'L' end |
#get_acceleration_range ⇒ Object
Not implemented yet.
324 325 326 327 328 |
# File 'lib/tinkerforge/brick_imu.rb', line 324 def get_acceleration_range check_validity send_request FUNCTION_GET_ACCELERATION_RANGE, [], '', 9, 'C' end |
#get_all_data ⇒ Object
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.
226 227 228 229 230 |
# File 'lib/tinkerforge/brick_imu.rb', line 226 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 ⇒ Object
Returns the period as set by BrickIMU#set_all_data_period.
481 482 483 484 485 |
# File 'lib/tinkerforge/brick_imu.rb', line 481 def get_all_data_period check_validity send_request FUNCTION_GET_ALL_DATA_PERIOD, [], '', 12, 'L' end |
#get_angular_velocity ⇒ Object
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.
214 215 216 217 218 |
# File 'lib/tinkerforge/brick_imu.rb', line 214 def get_angular_velocity check_validity send_request FUNCTION_GET_ANGULAR_VELOCITY, [], '', 14, 's s s' end |
#get_angular_velocity_period ⇒ Object
Returns the period as set by BrickIMU#set_angular_velocity_period.
466 467 468 469 470 |
# File 'lib/tinkerforge/brick_imu.rb', line 466 def get_angular_velocity_period check_validity send_request FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, [], '', 12, 'L' end |
#get_calibration(typ) ⇒ Object
Returns the calibration for a given type as set by BrickIMU#set_calibration.
421 422 423 424 425 |
# File 'lib/tinkerforge/brick_imu.rb', line 421 def get_calibration(typ) check_validity send_request FUNCTION_GET_CALIBRATION, [typ], 'C', 28, 's10' end |
#get_chip_temperature ⇒ Object
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.
709 710 711 712 713 |
# File 'lib/tinkerforge/brick_imu.rb', line 709 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end |
#get_convergence_speed ⇒ Object
Returns the convergence speed as set by BrickIMU#set_convergence_speed.
376 377 378 379 380 |
# File 'lib/tinkerforge/brick_imu.rb', line 376 def get_convergence_speed check_validity send_request FUNCTION_GET_CONVERGENCE_SPEED, [], '', 10, 'S' end |
#get_identity ⇒ Object
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|
757 758 759 |
# File 'lib/tinkerforge/brick_imu.rb', line 757 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_imu_temperature ⇒ Object
Returns the temperature of the IMU Brick.
288 289 290 291 292 |
# File 'lib/tinkerforge/brick_imu.rb', line 288 def get_imu_temperature check_validity send_request FUNCTION_GET_IMU_TEMPERATURE, [], '', 10, 's' end |
#get_magnetic_field ⇒ Object
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.
201 202 203 204 205 |
# File 'lib/tinkerforge/brick_imu.rb', line 201 def get_magnetic_field check_validity send_request FUNCTION_GET_MAGNETIC_FIELD, [], '', 14, 's s s' end |
#get_magnetic_field_period ⇒ Object
Returns the period as set by BrickIMU#set_magnetic_field_period.
451 452 453 454 455 |
# File 'lib/tinkerforge/brick_imu.rb', line 451 def get_magnetic_field_period check_validity send_request FUNCTION_GET_MAGNETIC_FIELD_PERIOD, [], '', 12, 'L' end |
#get_magnetometer_range ⇒ Object
Not implemented yet.
338 339 340 341 342 |
# File 'lib/tinkerforge/brick_imu.rb', line 338 def get_magnetometer_range check_validity send_request FUNCTION_GET_MAGNETOMETER_RANGE, [], '', 9, 'C' end |
#get_orientation ⇒ Object
Returns the current orientation (roll, pitch, yaw) of the IMU Brick as Euler angles. 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_ORIENTATION callback and set the period with BrickIMU#set_orientation_period.
244 245 246 247 248 |
# File 'lib/tinkerforge/brick_imu.rb', line 244 def get_orientation check_validity send_request FUNCTION_GET_ORIENTATION, [], '', 14, 's s s' end |
#get_orientation_period ⇒ Object
Returns the period as set by BrickIMU#set_orientation_period.
496 497 498 499 500 |
# File 'lib/tinkerforge/brick_imu.rb', line 496 def get_orientation_period check_validity send_request FUNCTION_GET_ORIENTATION_PERIOD, [], '', 12, '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.
697 698 699 700 701 |
# File 'lib/tinkerforge/brick_imu.rb', line 697 def get_protocol1_bricklet_name(port) check_validity send_request FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 52, 'C C3 Z40' end |
#get_quaternion ⇒ Object
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_QUATERNION callback and set the period with BrickIMU#set_quaternion_period.
281 282 283 284 285 |
# File 'lib/tinkerforge/brick_imu.rb', line 281 def get_quaternion check_validity send_request FUNCTION_GET_QUATERNION, [], '', 24, 'e e e e' end |
#get_quaternion_period ⇒ Object
Returns the period as set by BrickIMU#set_quaternion_period.
511 512 513 514 515 |
# File 'lib/tinkerforge/brick_imu.rb', line 511 def get_quaternion_period check_validity send_request FUNCTION_GET_QUATERNION_PERIOD, [], '', 12, 'L' end |
#get_send_timeout_count(communication_method) ⇒ Object
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)
600 601 602 603 604 |
# File 'lib/tinkerforge/brick_imu.rb', line 600 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) ⇒ Object
Returns the baudrate for a given Bricklet port, see BrickIMU#set_spitfp_baudrate.
- .. versionadded
-
2.3.3$nbsp;(Firmware)
630 631 632 633 634 |
# File 'lib/tinkerforge/brick_imu.rb', line 630 def get_spitfp_baudrate(bricklet_port) check_validity send_request FUNCTION_GET_SPITFP_BAUDRATE, [bricklet_port], 'k', 12, 'L' end |
#get_spitfp_baudrate_config ⇒ Object
Returns the baudrate config, see BrickIMU#set_spitfp_baudrate_config.
- .. versionadded
-
2.3.5$nbsp;(Firmware)
586 587 588 589 590 |
# File 'lib/tinkerforge/brick_imu.rb', line 586 def get_spitfp_baudrate_config check_validity send_request FUNCTION_GET_SPITFP_BAUDRATE_CONFIG, [], '', 13, '? L' end |
#get_spitfp_error_count(bricklet_port) ⇒ Object
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)
649 650 651 652 653 |
# File 'lib/tinkerforge/brick_imu.rb', line 649 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 ⇒ Object
Returns true if the orientation calculation of the IMU Brick is on, false otherwise.
- .. versionadded
-
2.0.2$nbsp;(Firmware)
551 552 553 554 555 |
# File 'lib/tinkerforge/brick_imu.rb', line 551 def is_orientation_calculation_on check_validity send_request FUNCTION_IS_ORIENTATION_CALCULATION_ON, [], '', 9, '?' end |
#is_status_led_enabled ⇒ Object
Returns true if the status LED is enabled, false otherwise.
- .. versionadded
-
2.3.1$nbsp;(Firmware)
686 687 688 689 690 |
# File 'lib/tinkerforge/brick_imu.rb', line 686 def is_status_led_enabled check_validity send_request FUNCTION_IS_STATUS_LED_ENABLED, [], '', 9, '?' end |
#leds_off ⇒ Object
Turns the orientation and direction LEDs of the IMU Brick off.
302 303 304 305 306 |
# File 'lib/tinkerforge/brick_imu.rb', line 302 def leds_off check_validity send_request FUNCTION_LEDS_OFF, [], '', 8, '' end |
#leds_on ⇒ Object
Turns the orientation and direction LEDs of the IMU Brick on.
295 296 297 298 299 |
# File 'lib/tinkerforge/brick_imu.rb', line 295 def leds_on check_validity send_request FUNCTION_LEDS_ON, [], '', 8, '' end |
#orientation_calculation_off ⇒ Object
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)
541 542 543 544 545 |
# File 'lib/tinkerforge/brick_imu.rb', line 541 def orientation_calculation_off check_validity send_request FUNCTION_ORIENTATION_CALCULATION_OFF, [], '', 8, '' end |
#orientation_calculation_on ⇒ Object
Turns the orientation calculation of the IMU Brick on.
As default the calculation is on.
- .. versionadded
-
2.0.2$nbsp;(Firmware)
522 523 524 525 526 |
# File 'lib/tinkerforge/brick_imu.rb', line 522 def orientation_calculation_on check_validity send_request FUNCTION_ORIENTATION_CALCULATION_ON, [], '', 8, '' end |
#read_bricklet_plugin(port, offset) ⇒ Object
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.
743 744 745 746 747 |
# File 'lib/tinkerforge/brick_imu.rb', line 743 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) ⇒ Object
Registers a callback with ID id
to the block block
.
762 763 764 765 |
# File 'lib/tinkerforge/brick_imu.rb', line 762 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#reset ⇒ Object
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!
721 722 723 724 725 |
# File 'lib/tinkerforge/brick_imu.rb', line 721 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end |
#set_acceleration_period(period) ⇒ Object
Sets the period with which the CALLBACK_ACCELERATION callback is triggered periodically. A value of 0 turns the callback off.
429 430 431 432 433 |
# File 'lib/tinkerforge/brick_imu.rb', line 429 def set_acceleration_period(period) check_validity send_request FUNCTION_SET_ACCELERATION_PERIOD, [period], 'L', 8, '' end |
#set_acceleration_range(range) ⇒ Object
Not implemented yet.
317 318 319 320 321 |
# File 'lib/tinkerforge/brick_imu.rb', line 317 def set_acceleration_range(range) check_validity send_request FUNCTION_SET_ACCELERATION_RANGE, [range], 'C', 8, '' end |
#set_all_data_period(period) ⇒ Object
Sets the period with which the CALLBACK_ALL_DATA callback is triggered periodically. A value of 0 turns the callback off.
474 475 476 477 478 |
# File 'lib/tinkerforge/brick_imu.rb', line 474 def set_all_data_period(period) check_validity send_request FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 8, '' end |
#set_angular_velocity_period(period) ⇒ Object
Sets the period with which the CALLBACK_ANGULAR_VELOCITY callback is triggered periodically. A value of 0 turns the callback off.
459 460 461 462 463 |
# File 'lib/tinkerforge/brick_imu.rb', line 459 def set_angular_velocity_period(period) check_validity send_request FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, [period], 'L', 8, '' 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.
414 415 416 417 418 |
# File 'lib/tinkerforge/brick_imu.rb', line 414 def set_calibration(typ, data) check_validity send_request FUNCTION_SET_CALIBRATION, [typ, data], 'C s10', 8, '' end |
#set_convergence_speed(speed) ⇒ Object
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.
369 370 371 372 373 |
# File 'lib/tinkerforge/brick_imu.rb', line 369 def set_convergence_speed(speed) check_validity send_request FUNCTION_SET_CONVERGENCE_SPEED, [speed], 'S', 8, '' end |
#set_magnetic_field_period(period) ⇒ Object
Sets the period with which the CALLBACK_MAGNETIC_FIELD callback is triggered periodically. A value of 0 turns the callback off.
444 445 446 447 448 |
# File 'lib/tinkerforge/brick_imu.rb', line 444 def set_magnetic_field_period(period) check_validity send_request FUNCTION_SET_MAGNETIC_FIELD_PERIOD, [period], 'L', 8, '' end |
#set_magnetometer_range(range) ⇒ Object
Not implemented yet.
331 332 333 334 335 |
# File 'lib/tinkerforge/brick_imu.rb', line 331 def set_magnetometer_range(range) check_validity send_request FUNCTION_SET_MAGNETOMETER_RANGE, [range], 'C', 8, '' end |
#set_orientation_period(period) ⇒ Object
Sets the period with which the CALLBACK_ORIENTATION callback is triggered periodically. A value of 0 turns the callback off.
489 490 491 492 493 |
# File 'lib/tinkerforge/brick_imu.rb', line 489 def set_orientation_period(period) check_validity send_request FUNCTION_SET_ORIENTATION_PERIOD, [period], 'L', 8, '' end |
#set_quaternion_period(period) ⇒ Object
Sets the period with which the CALLBACK_QUATERNION callback is triggered periodically. A value of 0 turns the callback off.
504 505 506 507 508 |
# File 'lib/tinkerforge/brick_imu.rb', line 504 def set_quaternion_period(period) check_validity send_request FUNCTION_SET_QUATERNION_PERIOD, [period], 'L', 8, '' end |
#set_spitfp_baudrate(bricklet_port, baudrate) ⇒ Object
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)
621 622 623 624 625 |
# File 'lib/tinkerforge/brick_imu.rb', line 621 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) ⇒ Object
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)
577 578 579 580 581 |
# File 'lib/tinkerforge/brick_imu.rb', line 577 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) ⇒ Object
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.
732 733 734 735 736 |
# File 'lib/tinkerforge/brick_imu.rb', line 732 def write_bricklet_plugin(port, offset, chunk) check_validity send_request FUNCTION_WRITE_BRICKLET_PLUGIN, [port, offset, chunk], 'k C C32', 8, '' end |