tinkerforge 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/lib/tinkerforge.rb +5 -0
  2. data/lib/tinkerforge/brick_dc.rb +359 -0
  3. data/lib/tinkerforge/brick_imu.rb +512 -0
  4. data/lib/tinkerforge/brick_master.rb +1120 -0
  5. data/lib/tinkerforge/brick_servo.rb +475 -0
  6. data/lib/tinkerforge/brick_stepper.rb +556 -0
  7. data/lib/tinkerforge/bricklet_ambient_light.rb +246 -0
  8. data/lib/tinkerforge/bricklet_analog_in.rb +273 -0
  9. data/lib/tinkerforge/bricklet_analog_out.rb +90 -0
  10. data/lib/tinkerforge/bricklet_barometer.rb +313 -0
  11. data/lib/tinkerforge/bricklet_current12.rb +274 -0
  12. data/lib/tinkerforge/bricklet_current25.rb +274 -0
  13. data/lib/tinkerforge/bricklet_distance_ir.rb +274 -0
  14. data/lib/tinkerforge/bricklet_dual_relay.rb +127 -0
  15. data/lib/tinkerforge/bricklet_gps.rb +301 -0
  16. data/lib/tinkerforge/bricklet_humidity.rb +245 -0
  17. data/lib/tinkerforge/bricklet_industrial_digital_in_4.rb +165 -0
  18. data/lib/tinkerforge/bricklet_industrial_digital_out_4.rb +177 -0
  19. data/lib/tinkerforge/bricklet_industrial_quad_relay.rb +177 -0
  20. data/lib/tinkerforge/bricklet_io16.rb +237 -0
  21. data/lib/tinkerforge/bricklet_io4.rb +236 -0
  22. data/lib/tinkerforge/bricklet_joystick.rb +274 -0
  23. data/lib/tinkerforge/bricklet_lcd_16x2.rb +175 -0
  24. data/lib/tinkerforge/bricklet_lcd_20x4.rb +231 -0
  25. data/lib/tinkerforge/bricklet_linear_poti.rb +241 -0
  26. data/lib/tinkerforge/bricklet_piezo_buzzer.rb +84 -0
  27. data/lib/tinkerforge/bricklet_ptc.rb +277 -0
  28. data/lib/tinkerforge/bricklet_rotary_poti.rb +241 -0
  29. data/lib/tinkerforge/bricklet_temperature.rb +188 -0
  30. data/lib/tinkerforge/bricklet_temperature_ir.rb +275 -0
  31. data/lib/tinkerforge/bricklet_voltage.rb +241 -0
  32. data/lib/tinkerforge/bricklet_voltage_current.rb +386 -0
  33. data/lib/tinkerforge/ip_connection.rb +1027 -0
  34. data/lib/tinkerforge/version.rb +4 -0
  35. metadata +98 -0
@@ -0,0 +1,5 @@
1
+
2
+ require 'tinkerforge/version'
3
+
4
+ module Tinkerforge
5
+ end
@@ -0,0 +1,359 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
6
+ # #
7
+ # If you have a bugfix for this file and want to commit it, #
8
+ # please fix the bug in the generator. You can find a link #
9
+ # to the generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for controlling DC motors
14
+ class BrickDC < Device
15
+ DEVICE_IDENTIFIER = 11 # :nodoc:
16
+
17
+ # This callback is triggered when the input voltage drops below the value set by
18
+ # BrickDC#set_minimum_voltage. The parameter is the current voltage given
19
+ # in mV.
20
+ CALLBACK_UNDER_VOLTAGE = 21
21
+
22
+ # This callback is triggered if either the current consumption
23
+ # is too high (above 5A) or the temperature of the driver chip is too high
24
+ # (above 175°C). These two possibilities are essentially the same, since the
25
+ # temperature will reach this threshold immediately if the motor consumes too
26
+ # much current. In case of a voltage below 3.3V (external or stack) this
27
+ # callback is triggered as well.
28
+ #
29
+ # If this callback is triggered, the driver chip gets disabled at the same time.
30
+ # That means, BrickDC#enable has to be called to drive the motor again.
31
+ #
32
+ # .. note::
33
+ # This callback only works in Drive/Brake mode (see BrickDC#set_drive_mode). In
34
+ # Drive/Coast mode it is unfortunately impossible to reliably read the
35
+ # overcurrent/overtemperature signal from the driver chip.
36
+ CALLBACK_EMERGENCY_SHUTDOWN = 22
37
+
38
+ # This callback is triggered whenever a set velocity is reached. For example:
39
+ # If a velocity of 0 is present, acceleration is set to 5000 and velocity
40
+ # to 10000, CALLBACK_VELOCITY_REACHED will be triggered after about 2 seconds, when
41
+ # the set velocity is actually reached.
42
+ #
43
+ # .. note::
44
+ # Since we can't get any feedback from the DC motor, this only works if the
45
+ # acceleration (see BrickDC#set_acceleration) is set smaller or equal to the
46
+ # maximum acceleration of the motor. Otherwise the motor will lag behind the
47
+ # control value and the callback will be triggered too early.
48
+ CALLBACK_VELOCITY_REACHED = 23
49
+
50
+ # This callback is triggered with the period that is set by
51
+ # BrickDC#set_current_velocity_period. The parameter is the *current* velocity
52
+ # used by the motor.
53
+ #
54
+ # CALLBACK_CURRENT_VELOCITY is only triggered after the set period if there is
55
+ # a change in the velocity.
56
+ CALLBACK_CURRENT_VELOCITY = 24
57
+
58
+ FUNCTION_SET_VELOCITY = 1 # :nodoc:
59
+ FUNCTION_GET_VELOCITY = 2 # :nodoc:
60
+ FUNCTION_GET_CURRENT_VELOCITY = 3 # :nodoc:
61
+ FUNCTION_SET_ACCELERATION = 4 # :nodoc:
62
+ FUNCTION_GET_ACCELERATION = 5 # :nodoc:
63
+ FUNCTION_SET_PWM_FREQUENCY = 6 # :nodoc:
64
+ FUNCTION_GET_PWM_FREQUENCY = 7 # :nodoc:
65
+ FUNCTION_FULL_BRAKE = 8 # :nodoc:
66
+ FUNCTION_GET_STACK_INPUT_VOLTAGE = 9 # :nodoc:
67
+ FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE = 10 # :nodoc:
68
+ FUNCTION_GET_CURRENT_CONSUMPTION = 11 # :nodoc:
69
+ FUNCTION_ENABLE = 12 # :nodoc:
70
+ FUNCTION_DISABLE = 13 # :nodoc:
71
+ FUNCTION_IS_ENABLED = 14 # :nodoc:
72
+ FUNCTION_SET_MINIMUM_VOLTAGE = 15 # :nodoc:
73
+ FUNCTION_GET_MINIMUM_VOLTAGE = 16 # :nodoc:
74
+ FUNCTION_SET_DRIVE_MODE = 17 # :nodoc:
75
+ FUNCTION_GET_DRIVE_MODE = 18 # :nodoc:
76
+ FUNCTION_SET_CURRENT_VELOCITY_PERIOD = 19 # :nodoc:
77
+ FUNCTION_GET_CURRENT_VELOCITY_PERIOD = 20 # :nodoc:
78
+ FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
79
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
80
+ FUNCTION_RESET = 243 # :nodoc:
81
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
82
+
83
+ DRIVE_MODE_DRIVE_BRAKE = 0 # :nodoc:
84
+ DRIVE_MODE_DRIVE_COAST = 1 # :nodoc:
85
+
86
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
87
+ # the IP Connection <tt>ipcon</tt>.
88
+ def initialize(uid, ipcon)
89
+ super uid, ipcon
90
+
91
+ @api_version = [2, 0, 0]
92
+
93
+ @response_expected[FUNCTION_SET_VELOCITY] = RESPONSE_EXPECTED_FALSE
94
+ @response_expected[FUNCTION_GET_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
95
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
96
+ @response_expected[FUNCTION_SET_ACCELERATION] = RESPONSE_EXPECTED_FALSE
97
+ @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
98
+ @response_expected[FUNCTION_SET_PWM_FREQUENCY] = RESPONSE_EXPECTED_FALSE
99
+ @response_expected[FUNCTION_GET_PWM_FREQUENCY] = RESPONSE_EXPECTED_ALWAYS_TRUE
100
+ @response_expected[FUNCTION_FULL_BRAKE] = RESPONSE_EXPECTED_FALSE
101
+ @response_expected[FUNCTION_GET_STACK_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
102
+ @response_expected[FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_GET_CURRENT_CONSUMPTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
104
+ @response_expected[FUNCTION_ENABLE] = RESPONSE_EXPECTED_FALSE
105
+ @response_expected[FUNCTION_DISABLE] = RESPONSE_EXPECTED_FALSE
106
+ @response_expected[FUNCTION_IS_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
107
+ @response_expected[FUNCTION_SET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_TRUE
108
+ @response_expected[FUNCTION_GET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
109
+ @response_expected[FUNCTION_SET_DRIVE_MODE] = RESPONSE_EXPECTED_FALSE
110
+ @response_expected[FUNCTION_GET_DRIVE_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
111
+ @response_expected[FUNCTION_SET_CURRENT_VELOCITY_PERIOD] = RESPONSE_EXPECTED_TRUE
112
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
113
+ @response_expected[CALLBACK_UNDER_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
114
+ @response_expected[CALLBACK_EMERGENCY_SHUTDOWN] = RESPONSE_EXPECTED_ALWAYS_FALSE
115
+ @response_expected[CALLBACK_VELOCITY_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
116
+ @response_expected[CALLBACK_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
117
+ @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
118
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
119
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
120
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
121
+
122
+ @callback_formats[CALLBACK_UNDER_VOLTAGE] = 'S'
123
+ @callback_formats[CALLBACK_EMERGENCY_SHUTDOWN] = ''
124
+ @callback_formats[CALLBACK_VELOCITY_REACHED] = 's'
125
+ @callback_formats[CALLBACK_CURRENT_VELOCITY] = 's'
126
+ end
127
+
128
+ # Sets the velocity of the motor. Whereas -32767 is full speed backward,
129
+ # 0 is stop and 32767 is full speed forward. Depending on the
130
+ # acceleration (see BrickDC#set_acceleration), the motor is not immediately
131
+ # brought to the velocity but smoothly accelerated.
132
+ #
133
+ # The velocity describes the duty cycle of the PWM with which the motor is
134
+ # controlled, e.g. a velocity of 3277 sets a PWM with a 10% duty cycle.
135
+ # You can not only control the duty cycle of the PWM but also the frequency,
136
+ # see BrickDC#set_pwm_frequency.
137
+ #
138
+ # The default velocity is 0.
139
+ def set_velocity(velocity)
140
+ send_request(FUNCTION_SET_VELOCITY, [velocity], 's', 0, '')
141
+ end
142
+
143
+ # Returns the velocity as set by BrickDC#set_velocity.
144
+ def get_velocity
145
+ send_request(FUNCTION_GET_VELOCITY, [], '', 2, 's')
146
+ end
147
+
148
+ # Returns the *current* velocity of the motor. This value is different
149
+ # from BrickDC#get_velocity whenever the motor is currently accelerating
150
+ # to a goal set by BrickDC#set_velocity.
151
+ def get_current_velocity
152
+ send_request(FUNCTION_GET_CURRENT_VELOCITY, [], '', 2, 's')
153
+ end
154
+
155
+ # Sets the acceleration of the motor. It is given in *velocity/s*. An
156
+ # acceleration of 10000 means, that every second the velocity is increased
157
+ # by 10000 (or about 30% duty cycle).
158
+ #
159
+ # For example: If the current velocity is 0 and you want to accelerate to a
160
+ # velocity of 16000 (about 50% duty cycle) in 10 seconds, you should set
161
+ # an acceleration of 1600.
162
+ #
163
+ # If acceleration is set to 0, there is no speed ramping, i.e. a new velocity
164
+ # is immediately given to the motor.
165
+ #
166
+ # The default acceleration is 10000.
167
+ def set_acceleration(acceleration)
168
+ send_request(FUNCTION_SET_ACCELERATION, [acceleration], 'S', 0, '')
169
+ end
170
+
171
+ # Returns the acceleration as set by BrickDC#set_acceleration.
172
+ def get_acceleration
173
+ send_request(FUNCTION_GET_ACCELERATION, [], '', 2, 'S')
174
+ end
175
+
176
+ # Sets the frequency (in Hz) of the PWM with which the motor is driven.
177
+ # The possible range of the frequency is 1-20000Hz. Often a high frequency
178
+ # is less noisy and the motor runs smoother. However, with a low frequency
179
+ # there are less switches and therefore fewer switching losses. Also with
180
+ # most motors lower frequencies enable higher torque.
181
+ #
182
+ # If you have no idea what all this means, just ignore this function and use
183
+ # the default frequency, it will very likely work fine.
184
+ #
185
+ # The default frequency is 15 kHz.
186
+ def set_pwm_frequency(frequency)
187
+ send_request(FUNCTION_SET_PWM_FREQUENCY, [frequency], 'S', 0, '')
188
+ end
189
+
190
+ # Returns the PWM frequency (in Hz) as set by BrickDC#set_pwm_frequency.
191
+ def get_pwm_frequency
192
+ send_request(FUNCTION_GET_PWM_FREQUENCY, [], '', 2, 'S')
193
+ end
194
+
195
+ # Executes an active full brake.
196
+ #
197
+ # .. warning::
198
+ # This function is for emergency purposes,
199
+ # where an immediate brake is necessary. Depending on the current velocity and
200
+ # the strength of the motor, a full brake can be quite violent.
201
+ #
202
+ # Call BrickDC#set_velocity with 0 if you just want to stop the motor.
203
+ def full_brake
204
+ send_request(FUNCTION_FULL_BRAKE, [], '', 0, '')
205
+ end
206
+
207
+ # Returns the stack input voltage in mV. The stack input voltage is the
208
+ # voltage that is supplied via the stack, i.e. it is given by a
209
+ # Step-Down or Step-Up Power Supply.
210
+ def get_stack_input_voltage
211
+ send_request(FUNCTION_GET_STACK_INPUT_VOLTAGE, [], '', 2, 'S')
212
+ end
213
+
214
+ # Returns the external input voltage in mV. The external input voltage is
215
+ # given via the black power input connector on the DC Brick.
216
+ #
217
+ # If there is an external input voltage and a stack input voltage, the motor
218
+ # will be driven by the external input voltage. If there is only a stack
219
+ # voltage present, the motor will be driven by this voltage.
220
+ #
221
+ # .. warning::
222
+ # This means, if you have a high stack voltage and a low external voltage,
223
+ # the motor will be driven with the low external voltage. If you then remove
224
+ # the external connection, it will immediately be driven by the high
225
+ # stack voltage.
226
+ def get_external_input_voltage
227
+ send_request(FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE, [], '', 2, 'S')
228
+ end
229
+
230
+ # Returns the current consumption of the motor in mA.
231
+ def get_current_consumption
232
+ send_request(FUNCTION_GET_CURRENT_CONSUMPTION, [], '', 2, 'S')
233
+ end
234
+
235
+ # Enables the driver chip. The driver parameters can be configured (velocity,
236
+ # acceleration, etc) before it is enabled.
237
+ def enable
238
+ send_request(FUNCTION_ENABLE, [], '', 0, '')
239
+ end
240
+
241
+ # Disables the driver chip. The configurations are kept (velocity,
242
+ # acceleration, etc) but the motor is not driven until it is enabled again.
243
+ def disable
244
+ send_request(FUNCTION_DISABLE, [], '', 0, '')
245
+ end
246
+
247
+ # Returns *true* if the driver chip is enabled, *false* otherwise.
248
+ def is_enabled
249
+ send_request(FUNCTION_IS_ENABLED, [], '', 1, '?')
250
+ end
251
+
252
+ # Sets the minimum voltage in mV, below which the CALLBACK_UNDER_VOLTAGE callback
253
+ # is triggered. The minimum possible value that works with the DC Brick is 5V.
254
+ # You can use this function to detect the discharge of a battery that is used
255
+ # to drive the motor. If you have a fixed power supply, you likely do not need
256
+ # this functionality.
257
+ #
258
+ # The default value is 5V.
259
+ def set_minimum_voltage(voltage)
260
+ send_request(FUNCTION_SET_MINIMUM_VOLTAGE, [voltage], 'S', 0, '')
261
+ end
262
+
263
+ # Returns the minimum voltage as set by BrickDC#set_minimum_voltage
264
+ def get_minimum_voltage
265
+ send_request(FUNCTION_GET_MINIMUM_VOLTAGE, [], '', 2, 'S')
266
+ end
267
+
268
+ # Sets the drive mode. Possible modes are:
269
+ #
270
+ # * 0 = Drive/Brake
271
+ # * 1 = Drive/Coast
272
+ #
273
+ # These modes are different kinds of motor controls.
274
+ #
275
+ # In Drive/Brake mode, the motor is always either driving or braking. There
276
+ # is no freewheeling. Advantages are: A more linear correlation between
277
+ # PWM and velocity, more exact accelerations and the possibility to drive
278
+ # with slower velocities.
279
+ #
280
+ # In Drive/Coast mode, the motor is always either driving or freewheeling.
281
+ # Advantages are: Less current consumption and less demands on the motor and
282
+ # driver chip.
283
+ #
284
+ # The default value is 0 = Drive/Brake.
285
+ def set_drive_mode(mode)
286
+ send_request(FUNCTION_SET_DRIVE_MODE, [mode], 'C', 0, '')
287
+ end
288
+
289
+ # Returns the drive mode, as set by BrickDC#set_drive_mode.
290
+ def get_drive_mode
291
+ send_request(FUNCTION_GET_DRIVE_MODE, [], '', 1, 'C')
292
+ end
293
+
294
+ # Sets a period in ms with which the CALLBACK_CURRENT_VELOCITY callback is triggered.
295
+ # A period of 0 turns the callback off.
296
+ #
297
+ # The default value is 0.
298
+ def set_current_velocity_period(period)
299
+ send_request(FUNCTION_SET_CURRENT_VELOCITY_PERIOD, [period], 'S', 0, '')
300
+ end
301
+
302
+ # Returns the period as set by BrickDC#set_current_velocity_period.
303
+ def get_current_velocity_period
304
+ send_request(FUNCTION_GET_CURRENT_VELOCITY_PERIOD, [], '', 2, 'S')
305
+ end
306
+
307
+ # Returns the firmware and protocol version and the name of the Bricklet for a given port.
308
+ #
309
+ # This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet plugins.
310
+ #
311
+ # .. versionadded:: 2.0.0~(Firmware)
312
+ def get_protocol1_bricklet_name(port)
313
+ send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
314
+ end
315
+
316
+ # Returns the temperature in °C/10 as measured inside the microcontroller. The
317
+ # value returned is not the ambient temperature!
318
+ #
319
+ # The temperature is only proportional to the real temperature and it has an
320
+ # accuracy of +-15%. Practically it is only useful as an indicator for
321
+ # temperature changes.
322
+ #
323
+ # .. versionadded:: 1.1.3~(Firmware)
324
+ def get_chip_temperature
325
+ send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
326
+ end
327
+
328
+ # Calling this function will reset the Brick. Calling this function
329
+ # on a Brick inside of a stack will reset the whole stack.
330
+ #
331
+ # After a reset you have to create new device objects,
332
+ # calling functions on the existing ones will result in
333
+ # undefined behavior!
334
+ #
335
+ # .. versionadded:: 1.1.3~(Firmware)
336
+ def reset
337
+ send_request(FUNCTION_RESET, [], '', 0, '')
338
+ end
339
+
340
+ # Returns the UID, the UID where the Brick is connected to,
341
+ # the position, the hardware and firmware version as well as the
342
+ # device identifier.
343
+ #
344
+ # The position can be '0'-'8' (stack position).
345
+ #
346
+ # The device identifiers can be found :ref:`here <device_identifier>`.
347
+ #
348
+ # .. versionadded:: 2.0.0~(Firmware)
349
+ def get_identity
350
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
351
+ end
352
+
353
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
354
+ def register_callback(id, &block)
355
+ callback = block
356
+ @registered_callbacks[id] = callback
357
+ end
358
+ end
359
+ end
@@ -0,0 +1,512 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+ #############################################################
3
+ # This file was automatically generated on 2013-05-16. #
4
+ # #
5
+ # Bindings Version 2.0.7 #
6
+ # #
7
+ # If you have a bugfix for this file and want to commit it, #
8
+ # please fix the bug in the generator. You can find a link #
9
+ # to the generator git on tinkerforge.com #
10
+ #############################################################
11
+
12
+ module Tinkerforge
13
+ # Device for sensing acceleration, magnetic field and angular velocity
14
+ class BrickIMU < Device
15
+ DEVICE_IDENTIFIER = 16 # :nodoc:
16
+
17
+ # This callback is triggered periodically with the period that is set by
18
+ # BrickIMU#set_acceleration_period. The parameters are the acceleration
19
+ # for the x, y and z axis.
20
+ CALLBACK_ACCELERATION = 31
21
+
22
+ # This callback is triggered periodically with the period that is set by
23
+ # BrickIMU#set_magnetic_field_period. The parameters are the magnetic field
24
+ # for the x, y and z axis.
25
+ CALLBACK_MAGNETIC_FIELD = 32
26
+
27
+ # This callback is triggered periodically with the period that is set by
28
+ # BrickIMU#set_angular_velocity_period. The parameters are the angular velocity
29
+ # for the x, y and z axis.
30
+ CALLBACK_ANGULAR_VELOCITY = 33
31
+
32
+ # This callback is triggered periodically with the period that is set by
33
+ # BrickIMU#set_all_data_period. The parameters are the acceleration,
34
+ # the magnetic field and the angular velocity for the x, y and z axis as
35
+ # well as the temperature of the IMU Brick.
36
+ CALLBACK_ALL_DATA = 34
37
+
38
+ # This callback is triggered periodically with the period that is set by
39
+ # BrickIMU#set_orientation_period. The parameters are the orientation
40
+ # (roll, pitch and yaw) of the IMU Brick in Euler angles. See
41
+ # BrickIMU#get_orientation for details.
42
+ CALLBACK_ORIENTATION = 35
43
+
44
+ # This callback is triggered periodically with the period that is set by
45
+ # BrickIMU#set_quaternion_period. The parameters are the orientation
46
+ # (x, y, z, w) of the IMU Brick in quaternions. See BrickIMU#get_quaternion
47
+ # for details.
48
+ CALLBACK_QUATERNION = 36
49
+
50
+ FUNCTION_GET_ACCELERATION = 1 # :nodoc:
51
+ FUNCTION_GET_MAGNETIC_FIELD = 2 # :nodoc:
52
+ FUNCTION_GET_ANGULAR_VELOCITY = 3 # :nodoc:
53
+ FUNCTION_GET_ALL_DATA = 4 # :nodoc:
54
+ FUNCTION_GET_ORIENTATION = 5 # :nodoc:
55
+ FUNCTION_GET_QUATERNION = 6 # :nodoc:
56
+ FUNCTION_GET_IMU_TEMPERATURE = 7 # :nodoc:
57
+ FUNCTION_LEDS_ON = 8 # :nodoc:
58
+ FUNCTION_LEDS_OFF = 9 # :nodoc:
59
+ FUNCTION_ARE_LEDS_ON = 10 # :nodoc:
60
+ FUNCTION_SET_ACCELERATION_RANGE = 11 # :nodoc:
61
+ FUNCTION_GET_ACCELERATION_RANGE = 12 # :nodoc:
62
+ FUNCTION_SET_MAGNETOMETER_RANGE = 13 # :nodoc:
63
+ FUNCTION_GET_MAGNETOMETER_RANGE = 14 # :nodoc:
64
+ FUNCTION_SET_CONVERGENCE_SPEED = 15 # :nodoc:
65
+ FUNCTION_GET_CONVERGENCE_SPEED = 16 # :nodoc:
66
+ FUNCTION_SET_CALIBRATION = 17 # :nodoc:
67
+ FUNCTION_GET_CALIBRATION = 18 # :nodoc:
68
+ FUNCTION_SET_ACCELERATION_PERIOD = 19 # :nodoc:
69
+ FUNCTION_GET_ACCELERATION_PERIOD = 20 # :nodoc:
70
+ FUNCTION_SET_MAGNETIC_FIELD_PERIOD = 21 # :nodoc:
71
+ FUNCTION_GET_MAGNETIC_FIELD_PERIOD = 22 # :nodoc:
72
+ FUNCTION_SET_ANGULAR_VELOCITY_PERIOD = 23 # :nodoc:
73
+ FUNCTION_GET_ANGULAR_VELOCITY_PERIOD = 24 # :nodoc:
74
+ FUNCTION_SET_ALL_DATA_PERIOD = 25 # :nodoc:
75
+ FUNCTION_GET_ALL_DATA_PERIOD = 26 # :nodoc:
76
+ FUNCTION_SET_ORIENTATION_PERIOD = 27 # :nodoc:
77
+ FUNCTION_GET_ORIENTATION_PERIOD = 28 # :nodoc:
78
+ FUNCTION_SET_QUATERNION_PERIOD = 29 # :nodoc:
79
+ FUNCTION_GET_QUATERNION_PERIOD = 30 # :nodoc:
80
+ FUNCTION_ORIENTATION_CALCULATION_ON = 37 # :nodoc:
81
+ FUNCTION_ORIENTATION_CALCULATION_OFF = 38 # :nodoc:
82
+ FUNCTION_IS_ORIENTATION_CALCULATION_ON = 39 # :nodoc:
83
+ FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
84
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
85
+ FUNCTION_RESET = 243 # :nodoc:
86
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
87
+
88
+ CALIBRATION_TYPE_ACCELEROMETER_GAIN = 0 # :nodoc:
89
+ CALIBRATION_TYPE_ACCELEROMETER_BIAS = 1 # :nodoc:
90
+ CALIBRATION_TYPE_MAGNETOMETER_GAIN = 2 # :nodoc:
91
+ CALIBRATION_TYPE_MAGNETOMETER_BIAS = 3 # :nodoc:
92
+ CALIBRATION_TYPE_GYROSCOPE_GAIN = 4 # :nodoc:
93
+ CALIBRATION_TYPE_GYROSCOPE_BIAS = 5 # :nodoc:
94
+
95
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
96
+ # the IP Connection <tt>ipcon</tt>.
97
+ def initialize(uid, ipcon)
98
+ super uid, ipcon
99
+
100
+ @api_version = [2, 0, 1]
101
+
102
+ @response_expected[FUNCTION_GET_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
103
+ @response_expected[FUNCTION_GET_MAGNETIC_FIELD] = RESPONSE_EXPECTED_ALWAYS_TRUE
104
+ @response_expected[FUNCTION_GET_ANGULAR_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
105
+ @response_expected[FUNCTION_GET_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_TRUE
106
+ @response_expected[FUNCTION_GET_ORIENTATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
107
+ @response_expected[FUNCTION_GET_QUATERNION] = RESPONSE_EXPECTED_ALWAYS_TRUE
108
+ @response_expected[FUNCTION_GET_IMU_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
109
+ @response_expected[FUNCTION_LEDS_ON] = RESPONSE_EXPECTED_FALSE
110
+ @response_expected[FUNCTION_LEDS_OFF] = RESPONSE_EXPECTED_FALSE
111
+ @response_expected[FUNCTION_ARE_LEDS_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
112
+ @response_expected[FUNCTION_SET_ACCELERATION_RANGE] = RESPONSE_EXPECTED_FALSE
113
+ @response_expected[FUNCTION_GET_ACCELERATION_RANGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
114
+ @response_expected[FUNCTION_SET_MAGNETOMETER_RANGE] = RESPONSE_EXPECTED_FALSE
115
+ @response_expected[FUNCTION_GET_MAGNETOMETER_RANGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
116
+ @response_expected[FUNCTION_SET_CONVERGENCE_SPEED] = RESPONSE_EXPECTED_FALSE
117
+ @response_expected[FUNCTION_GET_CONVERGENCE_SPEED] = RESPONSE_EXPECTED_ALWAYS_TRUE
118
+ @response_expected[FUNCTION_SET_CALIBRATION] = RESPONSE_EXPECTED_FALSE
119
+ @response_expected[FUNCTION_GET_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
120
+ @response_expected[FUNCTION_SET_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_TRUE
121
+ @response_expected[FUNCTION_GET_ACCELERATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
122
+ @response_expected[FUNCTION_SET_MAGNETIC_FIELD_PERIOD] = RESPONSE_EXPECTED_TRUE
123
+ @response_expected[FUNCTION_GET_MAGNETIC_FIELD_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
124
+ @response_expected[FUNCTION_SET_ANGULAR_VELOCITY_PERIOD] = RESPONSE_EXPECTED_TRUE
125
+ @response_expected[FUNCTION_GET_ANGULAR_VELOCITY_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
126
+ @response_expected[FUNCTION_SET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_TRUE
127
+ @response_expected[FUNCTION_GET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
128
+ @response_expected[FUNCTION_SET_ORIENTATION_PERIOD] = RESPONSE_EXPECTED_TRUE
129
+ @response_expected[FUNCTION_GET_ORIENTATION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
130
+ @response_expected[FUNCTION_SET_QUATERNION_PERIOD] = RESPONSE_EXPECTED_TRUE
131
+ @response_expected[FUNCTION_GET_QUATERNION_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
132
+ @response_expected[CALLBACK_ACCELERATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
133
+ @response_expected[CALLBACK_MAGNETIC_FIELD] = RESPONSE_EXPECTED_ALWAYS_FALSE
134
+ @response_expected[CALLBACK_ANGULAR_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_FALSE
135
+ @response_expected[CALLBACK_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_FALSE
136
+ @response_expected[CALLBACK_ORIENTATION] = RESPONSE_EXPECTED_ALWAYS_FALSE
137
+ @response_expected[CALLBACK_QUATERNION] = RESPONSE_EXPECTED_ALWAYS_FALSE
138
+ @response_expected[FUNCTION_ORIENTATION_CALCULATION_ON] = RESPONSE_EXPECTED_FALSE
139
+ @response_expected[FUNCTION_ORIENTATION_CALCULATION_OFF] = RESPONSE_EXPECTED_FALSE
140
+ @response_expected[FUNCTION_IS_ORIENTATION_CALCULATION_ON] = RESPONSE_EXPECTED_ALWAYS_TRUE
141
+ @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
142
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
143
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
144
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
145
+
146
+ @callback_formats[CALLBACK_ACCELERATION] = 's s s'
147
+ @callback_formats[CALLBACK_MAGNETIC_FIELD] = 's s s'
148
+ @callback_formats[CALLBACK_ANGULAR_VELOCITY] = 's s s'
149
+ @callback_formats[CALLBACK_ALL_DATA] = 's s s s s s s s s s'
150
+ @callback_formats[CALLBACK_ORIENTATION] = 's s s'
151
+ @callback_formats[CALLBACK_QUATERNION] = 'e e e e'
152
+ end
153
+
154
+ # Returns the calibrated acceleration from the accelerometer for the
155
+ # x, y and z axis in mG (G/1000, 1G = 9.80605m/s²).
156
+ #
157
+ # If you want to get the acceleration periodically, it is recommended
158
+ # to use the callback CALLBACK_ACCELERATION and set the period with
159
+ # BrickIMU#set_acceleration_period.
160
+ def get_acceleration
161
+ send_request(FUNCTION_GET_ACCELERATION, [], '', 6, 's s s')
162
+ end
163
+
164
+ # Returns the calibrated magnetic field from the magnetometer for the
165
+ # x, y and z axis in mG (Milligauss or Nanotesla).
166
+ #
167
+ # If you want to get the magnetic field periodically, it is recommended
168
+ # to use the callback CALLBACK_MAGNETIC_FIELD and set the period with
169
+ # BrickIMU#set_magnetic_field_period.
170
+ def get_magnetic_field
171
+ send_request(FUNCTION_GET_MAGNETIC_FIELD, [], '', 6, 's s s')
172
+ end
173
+
174
+ # Returns the calibrated angular velocity from the gyroscope for the
175
+ # x, y and z axis in °/17.5s (you have to divide by 17.5 to
176
+ # get the value in °/s).
177
+ #
178
+ # If you want to get the angular velocity periodically, it is recommended
179
+ # to use the callback CALLBACK_ANGULAR_VELOCITY and set the period with
180
+ # BrickIMU#set_angular_velocity_period.
181
+ def get_angular_velocity
182
+ send_request(FUNCTION_GET_ANGULAR_VELOCITY, [], '', 6, 's s s')
183
+ end
184
+
185
+ # Returns the data from BrickIMU#get_acceleration, BrickIMU#get_magnetic_field
186
+ # and BrickIMU#get_angular_velocity as well as the temperature of the IMU Brick.
187
+ #
188
+ # The temperature is given in °C/100.
189
+ #
190
+ # If you want to get the data periodically, it is recommended
191
+ # to use the callback CALLBACK_ALL_DATA and set the period with
192
+ # BrickIMU#set_all_data_period.
193
+ def get_all_data
194
+ send_request(FUNCTION_GET_ALL_DATA, [], '', 20, 's s s s s s s s s s')
195
+ end
196
+
197
+ # Returns the current orientation (roll, pitch, yaw) of the IMU Brick as Euler
198
+ # angles in one-hundredth degree. Note that Euler angles always experience a
199
+ # `gimbal lock <http://en.wikipedia.org/wiki/Gimbal_lock>`__.
200
+ #
201
+ # We recommend that you use quaternions instead.
202
+ #
203
+ # The order to sequence in which the orientation values should be applied is
204
+ # roll, yaw, pitch.
205
+ #
206
+ # If you want to get the orientation periodically, it is recommended
207
+ # to use the callback CALLBACK_ORIENTATION and set the period with
208
+ # BrickIMU#set_orientation_period.
209
+ def get_orientation
210
+ send_request(FUNCTION_GET_ORIENTATION, [], '', 6, 's s s')
211
+ end
212
+
213
+ # Returns the current orientation (x, y, z, w) of the IMU as
214
+ # `quaternions <http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__.
215
+ #
216
+ # You can go from quaternions to Euler angles with the following formula::
217
+ #
218
+ # roll = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z)
219
+ # pitch = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z)
220
+ # yaw = asin(2*x*y + 2*z*w)
221
+ #
222
+ # This process is not reversible, because of the
223
+ # `gimbal lock <http://en.wikipedia.org/wiki/Gimbal_lock>`__.
224
+ #
225
+ # Converting the quaternions to an OpenGL transformation matrix is
226
+ # possible with the following formula::
227
+ #
228
+ # matrix = [[1 - 2*(y*y + z*z), 2*(x*y - w*z), 2*(x*z + w*y), 0],
229
+ # [ 2*(x*y + w*z), 1 - 2*(x*x + z*z), 2*(y*z - w*x), 0],
230
+ # [ 2*(x*z - w*y), 2*(y*z + w*x), 1 - 2*(x*x + y*y), 0],
231
+ # [ 0, 0, 0, 1]]
232
+ #
233
+ # If you want to get the quaternions periodically, it is recommended
234
+ # to use the callback CALLBACK_QUATERNION and set the period with
235
+ # BrickIMU#set_quaternion_period.
236
+ def get_quaternion
237
+ send_request(FUNCTION_GET_QUATERNION, [], '', 16, 'e e e e')
238
+ end
239
+
240
+ # Returns the temperature of the IMU Brick. The temperature is given in
241
+ # °C/100.
242
+ def get_imu_temperature
243
+ send_request(FUNCTION_GET_IMU_TEMPERATURE, [], '', 2, 's')
244
+ end
245
+
246
+ # Turns the orientation and direction LEDs of the IMU Brick on.
247
+ def leds_on
248
+ send_request(FUNCTION_LEDS_ON, [], '', 0, '')
249
+ end
250
+
251
+ # Turns the orientation and direction LEDs of the IMU Brick off.
252
+ def leds_off
253
+ send_request(FUNCTION_LEDS_OFF, [], '', 0, '')
254
+ end
255
+
256
+ # Returns *true* if the orientation and direction LEDs of the IMU Brick
257
+ # are on, *false* otherwise.
258
+ def are_leds_on
259
+ send_request(FUNCTION_ARE_LEDS_ON, [], '', 1, '?')
260
+ end
261
+
262
+ # Not implemented yet.
263
+ def set_acceleration_range(range)
264
+ send_request(FUNCTION_SET_ACCELERATION_RANGE, [range], 'C', 0, '')
265
+ end
266
+
267
+ # Not implemented yet.
268
+ def get_acceleration_range
269
+ send_request(FUNCTION_GET_ACCELERATION_RANGE, [], '', 1, 'C')
270
+ end
271
+
272
+ # Not implemented yet.
273
+ def set_magnetometer_range(range)
274
+ send_request(FUNCTION_SET_MAGNETOMETER_RANGE, [range], 'C', 0, '')
275
+ end
276
+
277
+ # Not implemented yet.
278
+ def get_magnetometer_range
279
+ send_request(FUNCTION_GET_MAGNETOMETER_RANGE, [], '', 1, 'C')
280
+ end
281
+
282
+ # Sets the convergence speed of the IMU Brick in °/s. The convergence speed
283
+ # determines how the different sensor measurements are fused.
284
+ #
285
+ # If the orientation of the IMU Brick is off by 10° and the convergence speed is
286
+ # set to 20°/s, it will take 0.5s until the orientation is corrected. However,
287
+ # if the correct orientation is reached and the convergence speed is too high,
288
+ # the orientation will fluctuate with the fluctuations of the accelerometer and
289
+ # the magnetometer.
290
+ #
291
+ # If you set the convergence speed to 0, practically only the gyroscope is used
292
+ # to calculate the orientation. This gives very smooth movements, but errors of the
293
+ # gyroscope will not be corrected. If you set the convergence speed to something
294
+ # above 500, practically only the magnetometer and the accelerometer are used to
295
+ # calculate the orientation. In this case the movements are abrupt and the values
296
+ # will fluctuate, but there won't be any errors that accumulate over time.
297
+ #
298
+ # In an application with high angular velocities, we recommend a high convergence
299
+ # speed, so the errors of the gyroscope can be corrected fast. In applications with
300
+ # only slow movements we recommend a low convergence speed. You can change the
301
+ # convergence speed on the fly. So it is possible (and recommended) to increase
302
+ # the convergence speed before an abrupt movement and decrease it afterwards
303
+ # again.
304
+ #
305
+ # You might want to play around with the convergence speed in the Brick Viewer to
306
+ # get a feeling for a good value for your application.
307
+ #
308
+ # The default value is 30.
309
+ def set_convergence_speed(speed)
310
+ send_request(FUNCTION_SET_CONVERGENCE_SPEED, [speed], 'S', 0, '')
311
+ end
312
+
313
+ # Returns the convergence speed as set by BrickIMU#set_convergence_speed.
314
+ def get_convergence_speed
315
+ send_request(FUNCTION_GET_CONVERGENCE_SPEED, [], '', 2, 'S')
316
+ end
317
+
318
+ # There are several different types that can be calibrated:
319
+ #
320
+ # "Type", "Description", "Values"
321
+ #
322
+ # "0", "Accelerometer Gain", "[mul x, mul y, mul z, div x, div y, div z, 0, 0, 0, 0]"
323
+ # "1", "Accelerometer Bias", "[bias x, bias y, bias z, 0, 0, 0, 0, 0, 0, 0]"
324
+ # "2", "Magnetometer Gain", "[mul x, mul y, mul z, div x, div y, div z, 0, 0, 0, 0]"
325
+ # "3", "Magnetometer Bias", "[bias x, bias y, bias z, 0, 0, 0, 0, 0, 0, 0]"
326
+ # "4", "Gyroscope Gain", "[mul x, mul y, mul z, div x, div y, div z, 0, 0, 0, 0]"
327
+ # "5", "Gyroscope Bias", "[bias xl, bias yl, bias zl, temp l, bias xh, bias yh, bias zh, temp h, 0, 0]"
328
+ #
329
+ # The calibration via gain and bias is done with the following formula::
330
+ #
331
+ # new_value = (bias + orig_value) * gain_mul / gain_div
332
+ #
333
+ # If you really want to write your own calibration software, please keep
334
+ # in mind that you first have to undo the old calibration (set bias to 0 and
335
+ # gain to 1/1) and that you have to average over several thousand values
336
+ # to obtain a usable result in the end.
337
+ #
338
+ # The gyroscope bias is highly dependent on the temperature, so you have to
339
+ # calibrate the bias two times with different temperatures. The values xl, yl, zl
340
+ # and temp l are the bias for x, y, z and the corresponding temperature for a
341
+ # low temperature. The values xh, yh, zh and temp h are the same for a high
342
+ # temperatures. The temperature difference should be at least 5°C. If you have
343
+ # a temperature where the IMU Brick is mostly used, you should use this
344
+ # temperature for one of the sampling points.
345
+ #
346
+ # .. note::
347
+ # We highly recommend that you use the Brick Viewer to calibrate your
348
+ # IMU Brick.
349
+ def set_calibration(typ, data)
350
+ send_request(FUNCTION_SET_CALIBRATION, [typ, data], 'C s10', 0, '')
351
+ end
352
+
353
+ # Returns the calibration for a given type as set by BrickIMU#set_calibration.
354
+ def get_calibration(typ)
355
+ send_request(FUNCTION_GET_CALIBRATION, [typ], 'C', 20, 's10')
356
+ end
357
+
358
+ # Sets the period in ms with which the CALLBACK_ACCELERATION callback is triggered
359
+ # periodically. A value of 0 turns the callback off.
360
+ #
361
+ # The default value is 0.
362
+ def set_acceleration_period(period)
363
+ send_request(FUNCTION_SET_ACCELERATION_PERIOD, [period], 'L', 0, '')
364
+ end
365
+
366
+ # Returns the period as set by BrickIMU#set_acceleration_period.
367
+ def get_acceleration_period
368
+ send_request(FUNCTION_GET_ACCELERATION_PERIOD, [], '', 4, 'L')
369
+ end
370
+
371
+ # Sets the period in ms with which the CALLBACK_MAGNETIC_FIELD callback is triggered
372
+ # periodically. A value of 0 turns the callback off.
373
+ def set_magnetic_field_period(period)
374
+ send_request(FUNCTION_SET_MAGNETIC_FIELD_PERIOD, [period], 'L', 0, '')
375
+ end
376
+
377
+ # Returns the period as set by BrickIMU#set_magnetic_field_period.
378
+ def get_magnetic_field_period
379
+ send_request(FUNCTION_GET_MAGNETIC_FIELD_PERIOD, [], '', 4, 'L')
380
+ end
381
+
382
+ # Sets the period in ms with which the CALLBACK_ANGULAR_VELOCITY callback is triggered
383
+ # periodically. A value of 0 turns the callback off.
384
+ def set_angular_velocity_period(period)
385
+ send_request(FUNCTION_SET_ANGULAR_VELOCITY_PERIOD, [period], 'L', 0, '')
386
+ end
387
+
388
+ # Returns the period as set by BrickIMU#set_angular_velocity_period.
389
+ def get_angular_velocity_period
390
+ send_request(FUNCTION_GET_ANGULAR_VELOCITY_PERIOD, [], '', 4, 'L')
391
+ end
392
+
393
+ # Sets the period in ms with which the CALLBACK_ALL_DATA callback is triggered
394
+ # periodically. A value of 0 turns the callback off.
395
+ def set_all_data_period(period)
396
+ send_request(FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 0, '')
397
+ end
398
+
399
+ # Returns the period as set by BrickIMU#set_all_data_period.
400
+ def get_all_data_period
401
+ send_request(FUNCTION_GET_ALL_DATA_PERIOD, [], '', 4, 'L')
402
+ end
403
+
404
+ # Sets the period in ms with which the CALLBACK_ORIENTATION callback is triggered
405
+ # periodically. A value of 0 turns the callback off.
406
+ def set_orientation_period(period)
407
+ send_request(FUNCTION_SET_ORIENTATION_PERIOD, [period], 'L', 0, '')
408
+ end
409
+
410
+ # Returns the period as set by BrickIMU#set_orientation_period.
411
+ def get_orientation_period
412
+ send_request(FUNCTION_GET_ORIENTATION_PERIOD, [], '', 4, 'L')
413
+ end
414
+
415
+ # Sets the period in ms with which the CALLBACK_QUATERNION callback is triggered
416
+ # periodically. A value of 0 turns the callback off.
417
+ def set_quaternion_period(period)
418
+ send_request(FUNCTION_SET_QUATERNION_PERIOD, [period], 'L', 0, '')
419
+ end
420
+
421
+ # Returns the period as set by BrickIMU#set_quaternion_period.
422
+ def get_quaternion_period
423
+ send_request(FUNCTION_GET_QUATERNION_PERIOD, [], '', 4, 'L')
424
+ end
425
+
426
+ # Turns the orientation calculation of the IMU Brick on.
427
+ #
428
+ # As default the calculation is on.
429
+ #
430
+ # .. versionadded:: 2.0.2~(Firmware)
431
+ def orientation_calculation_on
432
+ send_request(FUNCTION_ORIENTATION_CALCULATION_ON, [], '', 0, '')
433
+ end
434
+
435
+ # Turns the orientation calculation of the IMU Brick off.
436
+ #
437
+ # If the calculation is off, BrickIMU#get_orientation will return
438
+ # the last calculated value until the calculation is turned on again.
439
+ #
440
+ # The trigonometric functions that are needed to calculate the orientation
441
+ # are very expensive. We recommend to turn the orientation calculation
442
+ # off if the orientation is not needed, to free calculation time for the
443
+ # sensor fusion algorithm.
444
+ #
445
+ # As default the calculation is on.
446
+ #
447
+ # .. versionadded:: 2.0.2~(Firmware)
448
+ def orientation_calculation_off
449
+ send_request(FUNCTION_ORIENTATION_CALCULATION_OFF, [], '', 0, '')
450
+ end
451
+
452
+ # Returns *true* if the orientation calculation of the IMU Brick
453
+ # is on, *false* otherwise.
454
+ #
455
+ # .. versionadded:: 2.0.2~(Firmware)
456
+ def is_orientation_calculation_on
457
+ send_request(FUNCTION_IS_ORIENTATION_CALCULATION_ON, [], '', 1, '?')
458
+ end
459
+
460
+ # Returns the firmware and protocol version and the name of the Bricklet for a given port.
461
+ #
462
+ # This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet plugins.
463
+ #
464
+ # .. versionadded:: 2.0.0~(Firmware)
465
+ def get_protocol1_bricklet_name(port)
466
+ send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
467
+ end
468
+
469
+ # Returns the temperature in °C/10 as measured inside the microcontroller. The
470
+ # value returned is not the ambient temperature!
471
+ #
472
+ # The temperature is only proportional to the real temperature and it has an
473
+ # accuracy of +-15%. Practically it is only useful as an indicator for
474
+ # temperature changes.
475
+ #
476
+ # .. versionadded:: 1.0.7~(Firmware)
477
+ def get_chip_temperature
478
+ send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
479
+ end
480
+
481
+ # Calling this function will reset the Brick. Calling this function
482
+ # on a Brick inside of a stack will reset the whole stack.
483
+ #
484
+ # After a reset you have to create new device objects,
485
+ # calling functions on the existing ones will result in
486
+ # undefined behavior!
487
+ #
488
+ # .. versionadded:: 1.0.7~(Firmware)
489
+ def reset
490
+ send_request(FUNCTION_RESET, [], '', 0, '')
491
+ end
492
+
493
+ # Returns the UID, the UID where the Brick is connected to,
494
+ # the position, the hardware and firmware version as well as the
495
+ # device identifier.
496
+ #
497
+ # The position can be '0'-'8' (stack position).
498
+ #
499
+ # The device identifiers can be found :ref:`here <device_identifier>`.
500
+ #
501
+ # .. versionadded:: 2.0.0~(Firmware)
502
+ def get_identity
503
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
504
+ end
505
+
506
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
507
+ def register_callback(id, &block)
508
+ callback = block
509
+ @registered_callbacks[id] = callback
510
+ end
511
+ end
512
+ end