tinkerforge 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,556 @@
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 stepper motors
14
+ class BrickStepper < Device
15
+ DEVICE_IDENTIFIER = 15 # :nodoc:
16
+
17
+ # This callback is triggered when the input voltage drops below the value set by
18
+ # BrickStepper#set_minimum_voltage. The parameter is the current voltage given
19
+ # in mV.
20
+ CALLBACK_UNDER_VOLTAGE = 31
21
+
22
+ # This callback is triggered when a position set by BrickStepper#set_steps or
23
+ # BrickStepper#set_target_position is reached.
24
+ #
25
+ # .. note::
26
+ # Since we can't get any feedback from the stepper motor, this only works if the
27
+ # acceleration (see BrickStepper#set_speed_ramping) is set smaller or equal to the
28
+ # maximum acceleration of the motor. Otherwise the motor will lag behind the
29
+ # control value and the callback will be triggered too early.
30
+ CALLBACK_POSITION_REACHED = 32
31
+
32
+ # This callback is triggered periodically with the period that is set by
33
+ # BrickStepper#set_all_data_period. The parameters are: the current velocity,
34
+ # the current position, the remaining steps, the stack voltage, the external
35
+ # voltage and the current consumption of the stepper motor.
36
+ #
37
+ # .. versionadded:: 1.1.6~(Firmware)
38
+ CALLBACK_ALL_DATA = 40
39
+
40
+ # This callback is triggered whenever the Stepper Brick enters a new state.
41
+ # It returns the new state as well as the previous state.
42
+ #
43
+ # Possible states are:
44
+ #
45
+ # * Stop = 1
46
+ # * Acceleration = 2
47
+ # * Run = 3
48
+ # * Deacceleration = 4
49
+ # * Direction change to forward = 5
50
+ # * Direction change to backward = 6
51
+ #
52
+ # .. versionadded:: 1.1.6~(Firmware)
53
+ CALLBACK_NEW_STATE = 41
54
+
55
+ FUNCTION_SET_MAX_VELOCITY = 1 # :nodoc:
56
+ FUNCTION_GET_MAX_VELOCITY = 2 # :nodoc:
57
+ FUNCTION_GET_CURRENT_VELOCITY = 3 # :nodoc:
58
+ FUNCTION_SET_SPEED_RAMPING = 4 # :nodoc:
59
+ FUNCTION_GET_SPEED_RAMPING = 5 # :nodoc:
60
+ FUNCTION_FULL_BRAKE = 6 # :nodoc:
61
+ FUNCTION_SET_CURRENT_POSITION = 7 # :nodoc:
62
+ FUNCTION_GET_CURRENT_POSITION = 8 # :nodoc:
63
+ FUNCTION_SET_TARGET_POSITION = 9 # :nodoc:
64
+ FUNCTION_GET_TARGET_POSITION = 10 # :nodoc:
65
+ FUNCTION_SET_STEPS = 11 # :nodoc:
66
+ FUNCTION_GET_STEPS = 12 # :nodoc:
67
+ FUNCTION_GET_REMAINING_STEPS = 13 # :nodoc:
68
+ FUNCTION_SET_STEP_MODE = 14 # :nodoc:
69
+ FUNCTION_GET_STEP_MODE = 15 # :nodoc:
70
+ FUNCTION_DRIVE_FORWARD = 16 # :nodoc:
71
+ FUNCTION_DRIVE_BACKWARD = 17 # :nodoc:
72
+ FUNCTION_STOP = 18 # :nodoc:
73
+ FUNCTION_GET_STACK_INPUT_VOLTAGE = 19 # :nodoc:
74
+ FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE = 20 # :nodoc:
75
+ FUNCTION_GET_CURRENT_CONSUMPTION = 21 # :nodoc:
76
+ FUNCTION_SET_MOTOR_CURRENT = 22 # :nodoc:
77
+ FUNCTION_GET_MOTOR_CURRENT = 23 # :nodoc:
78
+ FUNCTION_ENABLE = 24 # :nodoc:
79
+ FUNCTION_DISABLE = 25 # :nodoc:
80
+ FUNCTION_IS_ENABLED = 26 # :nodoc:
81
+ FUNCTION_SET_DECAY = 27 # :nodoc:
82
+ FUNCTION_GET_DECAY = 28 # :nodoc:
83
+ FUNCTION_SET_MINIMUM_VOLTAGE = 29 # :nodoc:
84
+ FUNCTION_GET_MINIMUM_VOLTAGE = 30 # :nodoc:
85
+ FUNCTION_SET_SYNC_RECT = 33 # :nodoc:
86
+ FUNCTION_IS_SYNC_RECT = 34 # :nodoc:
87
+ FUNCTION_SET_TIME_BASE = 35 # :nodoc:
88
+ FUNCTION_GET_TIME_BASE = 36 # :nodoc:
89
+ FUNCTION_GET_ALL_DATA = 37 # :nodoc:
90
+ FUNCTION_SET_ALL_DATA_PERIOD = 38 # :nodoc:
91
+ FUNCTION_GET_ALL_DATA_PERIOD = 39 # :nodoc:
92
+ FUNCTION_GET_PROTOCOL1_BRICKLET_NAME = 241 # :nodoc:
93
+ FUNCTION_GET_CHIP_TEMPERATURE = 242 # :nodoc:
94
+ FUNCTION_RESET = 243 # :nodoc:
95
+ FUNCTION_GET_IDENTITY = 255 # :nodoc:
96
+
97
+ STEP_MODE_FULL_STEP = 1 # :nodoc:
98
+ STEP_MODE_HALF_STEP = 2 # :nodoc:
99
+ STEP_MODE_QUARTER_STEP = 4 # :nodoc:
100
+ STEP_MODE_EIGHTH_STEP = 8 # :nodoc:
101
+ STATE_STOP = 1 # :nodoc:
102
+ STATE_ACCELERATION = 2 # :nodoc:
103
+ STATE_RUN = 3 # :nodoc:
104
+ STATE_DEACCELERATION = 4 # :nodoc:
105
+ STATE_DIRECTION_CHANGE_TO_FORWARD = 5 # :nodoc:
106
+ STATE_DIRECTION_CHANGE_TO_BACKWARD = 6 # :nodoc:
107
+
108
+ # Creates an object with the unique device ID <tt>uid</tt> and adds it to
109
+ # the IP Connection <tt>ipcon</tt>.
110
+ def initialize(uid, ipcon)
111
+ super uid, ipcon
112
+
113
+ @api_version = [2, 0, 0]
114
+
115
+ @response_expected[FUNCTION_SET_MAX_VELOCITY] = RESPONSE_EXPECTED_FALSE
116
+ @response_expected[FUNCTION_GET_MAX_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
117
+ @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
118
+ @response_expected[FUNCTION_SET_SPEED_RAMPING] = RESPONSE_EXPECTED_FALSE
119
+ @response_expected[FUNCTION_GET_SPEED_RAMPING] = RESPONSE_EXPECTED_ALWAYS_TRUE
120
+ @response_expected[FUNCTION_FULL_BRAKE] = RESPONSE_EXPECTED_FALSE
121
+ @response_expected[FUNCTION_SET_CURRENT_POSITION] = RESPONSE_EXPECTED_FALSE
122
+ @response_expected[FUNCTION_GET_CURRENT_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
123
+ @response_expected[FUNCTION_SET_TARGET_POSITION] = RESPONSE_EXPECTED_FALSE
124
+ @response_expected[FUNCTION_GET_TARGET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
125
+ @response_expected[FUNCTION_SET_STEPS] = RESPONSE_EXPECTED_FALSE
126
+ @response_expected[FUNCTION_GET_STEPS] = RESPONSE_EXPECTED_ALWAYS_TRUE
127
+ @response_expected[FUNCTION_GET_REMAINING_STEPS] = RESPONSE_EXPECTED_ALWAYS_TRUE
128
+ @response_expected[FUNCTION_SET_STEP_MODE] = RESPONSE_EXPECTED_FALSE
129
+ @response_expected[FUNCTION_GET_STEP_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
130
+ @response_expected[FUNCTION_DRIVE_FORWARD] = RESPONSE_EXPECTED_FALSE
131
+ @response_expected[FUNCTION_DRIVE_BACKWARD] = RESPONSE_EXPECTED_FALSE
132
+ @response_expected[FUNCTION_STOP] = RESPONSE_EXPECTED_FALSE
133
+ @response_expected[FUNCTION_GET_STACK_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
134
+ @response_expected[FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
135
+ @response_expected[FUNCTION_GET_CURRENT_CONSUMPTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
136
+ @response_expected[FUNCTION_SET_MOTOR_CURRENT] = RESPONSE_EXPECTED_FALSE
137
+ @response_expected[FUNCTION_GET_MOTOR_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
138
+ @response_expected[FUNCTION_ENABLE] = RESPONSE_EXPECTED_FALSE
139
+ @response_expected[FUNCTION_DISABLE] = RESPONSE_EXPECTED_FALSE
140
+ @response_expected[FUNCTION_IS_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
141
+ @response_expected[FUNCTION_SET_DECAY] = RESPONSE_EXPECTED_FALSE
142
+ @response_expected[FUNCTION_GET_DECAY] = RESPONSE_EXPECTED_ALWAYS_TRUE
143
+ @response_expected[FUNCTION_SET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_TRUE
144
+ @response_expected[FUNCTION_GET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
145
+ @response_expected[CALLBACK_UNDER_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
146
+ @response_expected[CALLBACK_POSITION_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
147
+ @response_expected[FUNCTION_SET_SYNC_RECT] = RESPONSE_EXPECTED_FALSE
148
+ @response_expected[FUNCTION_IS_SYNC_RECT] = RESPONSE_EXPECTED_ALWAYS_TRUE
149
+ @response_expected[FUNCTION_SET_TIME_BASE] = RESPONSE_EXPECTED_FALSE
150
+ @response_expected[FUNCTION_GET_TIME_BASE] = RESPONSE_EXPECTED_ALWAYS_TRUE
151
+ @response_expected[FUNCTION_GET_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_TRUE
152
+ @response_expected[FUNCTION_SET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_TRUE
153
+ @response_expected[FUNCTION_GET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
154
+ @response_expected[CALLBACK_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_FALSE
155
+ @response_expected[CALLBACK_NEW_STATE] = RESPONSE_EXPECTED_ALWAYS_FALSE
156
+ @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
157
+ @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
158
+ @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
159
+ @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
160
+
161
+ @callback_formats[CALLBACK_UNDER_VOLTAGE] = 'S'
162
+ @callback_formats[CALLBACK_POSITION_REACHED] = 'l'
163
+ @callback_formats[CALLBACK_ALL_DATA] = 'S l l S S S'
164
+ @callback_formats[CALLBACK_NEW_STATE] = 'C C'
165
+ end
166
+
167
+ # Sets the maximum velocity of the stepper motor in steps per second.
168
+ # This function does *not* start the motor, it merely sets the maximum
169
+ # velocity the stepper motor is accelerated to. To get the motor running use
170
+ # either BrickStepper#set_target_position, BrickStepper#set_steps, BrickStepper#drive_forward or
171
+ # BrickStepper#drive_backward.
172
+ def set_max_velocity(velocity)
173
+ send_request(FUNCTION_SET_MAX_VELOCITY, [velocity], 'S', 0, '')
174
+ end
175
+
176
+ # Returns the velocity as set by BrickStepper#set_max_velocity.
177
+ def get_max_velocity
178
+ send_request(FUNCTION_GET_MAX_VELOCITY, [], '', 2, 'S')
179
+ end
180
+
181
+ # Returns the *current* velocity of the stepper motor in steps per second.
182
+ def get_current_velocity
183
+ send_request(FUNCTION_GET_CURRENT_VELOCITY, [], '', 2, 'S')
184
+ end
185
+
186
+ # Sets the acceleration and deacceleration of the stepper motor. The values
187
+ # are given in *steps/s²*. An acceleration of 1000 means, that
188
+ # every second the velocity is increased by 1000 *steps/s*.
189
+ #
190
+ # For example: If the current velocity is 0 and you want to accelerate to a
191
+ # velocity of 8000 *steps/s* in 10 seconds, you should set an acceleration
192
+ # of 800 *steps/s²*.
193
+ #
194
+ # An acceleration/deacceleration of 0 means instantaneous
195
+ # acceleration/deacceleration (not recommended)
196
+ #
197
+ # The default value is 1000 for both
198
+ def set_speed_ramping(acceleration, deacceleration)
199
+ send_request(FUNCTION_SET_SPEED_RAMPING, [acceleration, deacceleration], 'S S', 0, '')
200
+ end
201
+
202
+ # Returns the acceleration and deacceleration as set by
203
+ # BrickStepper#set_speed_ramping.
204
+ def get_speed_ramping
205
+ send_request(FUNCTION_GET_SPEED_RAMPING, [], '', 4, 'S S')
206
+ end
207
+
208
+ # Executes an active full brake.
209
+ #
210
+ # .. warning::
211
+ # This function is for emergency purposes,
212
+ # where an immediate brake is necessary. Depending on the current velocity and
213
+ # the strength of the motor, a full brake can be quite violent.
214
+ #
215
+ # Call BrickStepper#stop if you just want to stop the motor.
216
+ def full_brake
217
+ send_request(FUNCTION_FULL_BRAKE, [], '', 0, '')
218
+ end
219
+
220
+ # Sets the current steps of the internal step counter. This can be used to
221
+ # set the current position to 0 when some kind of starting position
222
+ # is reached (e.g. when a CNC machine reaches a corner).
223
+ def set_current_position(position)
224
+ send_request(FUNCTION_SET_CURRENT_POSITION, [position], 'l', 0, '')
225
+ end
226
+
227
+ # Returns the current position of the stepper motor in steps. On startup
228
+ # the position is 0. The steps are counted with all possible driving
229
+ # functions (BrickStepper#set_target_position, BrickStepper#set_steps, BrickStepper#drive_forward or
230
+ # BrickStepper#drive_backward). It also is possible to reset the steps to 0 or
231
+ # set them to any other desired value with BrickStepper#set_current_position.
232
+ def get_current_position
233
+ send_request(FUNCTION_GET_CURRENT_POSITION, [], '', 4, 'l')
234
+ end
235
+
236
+ # Sets the target position of the stepper motor in steps. For example,
237
+ # if the current position of the motor is 500 and BrickStepper#set_target_position is
238
+ # called with 1000, the stepper motor will drive 500 steps forward. It will
239
+ # use the velocity, acceleration and deacceleration as set by
240
+ # BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping.
241
+ #
242
+ # A call of BrickStepper#set_target_position with the parameter *x* is equivalent to
243
+ # a call of BrickStepper#set_steps with the parameter
244
+ # (*x* - BrickStepper#get_current_position).
245
+ def set_target_position(position)
246
+ send_request(FUNCTION_SET_TARGET_POSITION, [position], 'l', 0, '')
247
+ end
248
+
249
+ # Returns the last target position as set by BrickStepper#set_target_position.
250
+ def get_target_position
251
+ send_request(FUNCTION_GET_TARGET_POSITION, [], '', 4, 'l')
252
+ end
253
+
254
+ # Sets the number of steps the stepper motor should run. Positive values
255
+ # will drive the motor forward and negative values backward.
256
+ # The velocity, acceleration and deacceleration as set by
257
+ # BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping will be used.
258
+ def set_steps(steps)
259
+ send_request(FUNCTION_SET_STEPS, [steps], 'l', 0, '')
260
+ end
261
+
262
+ # Returns the last steps as set by BrickStepper#set_steps.
263
+ def get_steps
264
+ send_request(FUNCTION_GET_STEPS, [], '', 4, 'l')
265
+ end
266
+
267
+ # Returns the remaining steps of the last call of BrickStepper#set_steps.
268
+ # For example, if BrickStepper#set_steps is called with 2000 and
269
+ # BrickStepper#get_remaining_steps is called after the motor has run for 500 steps,
270
+ # it will return 1500.
271
+ def get_remaining_steps
272
+ send_request(FUNCTION_GET_REMAINING_STEPS, [], '', 4, 'l')
273
+ end
274
+
275
+ # Sets the step mode of the stepper motor. Possible values are:
276
+ #
277
+ # * Full Step = 1
278
+ # * Half Step = 2
279
+ # * Quarter Step = 4
280
+ # * Eighth Step = 8
281
+ #
282
+ # A higher value will increase the resolution and
283
+ # decrease the torque of the stepper motor.
284
+ #
285
+ # The default value is 8 (Eighth Step).
286
+ def set_step_mode(mode)
287
+ send_request(FUNCTION_SET_STEP_MODE, [mode], 'C', 0, '')
288
+ end
289
+
290
+ # Returns the step mode as set by BrickStepper#set_step_mode.
291
+ def get_step_mode
292
+ send_request(FUNCTION_GET_STEP_MODE, [], '', 1, 'C')
293
+ end
294
+
295
+ # Drives the stepper motor forward until BrickStepper#drive_backward or
296
+ # BrickStepper#stop is called. The velocity, acceleration and deacceleration as
297
+ # set by BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping will be used.
298
+ def drive_forward
299
+ send_request(FUNCTION_DRIVE_FORWARD, [], '', 0, '')
300
+ end
301
+
302
+ # Drives the stepper motor backward until BrickStepper#drive_forward or
303
+ # BrickStepper#stop is triggered. The velocity, acceleration and deacceleration as
304
+ # set by BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping will be used.
305
+ def drive_backward
306
+ send_request(FUNCTION_DRIVE_BACKWARD, [], '', 0, '')
307
+ end
308
+
309
+ # Stops the stepper motor with the deacceleration as set by
310
+ # BrickStepper#set_speed_ramping.
311
+ def stop
312
+ send_request(FUNCTION_STOP, [], '', 0, '')
313
+ end
314
+
315
+ # Returns the stack input voltage in mV. The stack input voltage is the
316
+ # voltage that is supplied via the stack, i.e. it is given by a
317
+ # Step-Down or Step-Up Power Supply.
318
+ def get_stack_input_voltage
319
+ send_request(FUNCTION_GET_STACK_INPUT_VOLTAGE, [], '', 2, 'S')
320
+ end
321
+
322
+ # Returns the external input voltage in mV. The external input voltage is
323
+ # given via the black power input connector on the Stepper Brick.
324
+ #
325
+ # If there is an external input voltage and a stack input voltage, the motor
326
+ # will be driven by the external input voltage. If there is only a stack
327
+ # voltage present, the motor will be driven by this voltage.
328
+ #
329
+ # .. warning::
330
+ # This means, if you have a high stack voltage and a low external voltage,
331
+ # the motor will be driven with the low external voltage. If you then remove
332
+ # the external connection, it will immediately be driven by the high
333
+ # stack voltage
334
+ def get_external_input_voltage
335
+ send_request(FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE, [], '', 2, 'S')
336
+ end
337
+
338
+ # Returns the current consumption of the motor in mA.
339
+ def get_current_consumption
340
+ send_request(FUNCTION_GET_CURRENT_CONSUMPTION, [], '', 2, 'S')
341
+ end
342
+
343
+ # Sets the current in mA with which the motor will be driven.
344
+ # The minimum value is 100mA, the maximum value 2291mA and the
345
+ # default value is 800mA.
346
+ #
347
+ # .. warning::
348
+ # Do not set this value above the specifications of your stepper motor.
349
+ # Otherwise it may damage your motor.
350
+ def set_motor_current(current)
351
+ send_request(FUNCTION_SET_MOTOR_CURRENT, [current], 'S', 0, '')
352
+ end
353
+
354
+ # Returns the current as set by BrickStepper#set_motor_current.
355
+ def get_motor_current
356
+ send_request(FUNCTION_GET_MOTOR_CURRENT, [], '', 2, 'S')
357
+ end
358
+
359
+ # Enables the driver chip. The driver parameters can be configured (maximum velocity,
360
+ # acceleration, etc) before it is enabled.
361
+ def enable
362
+ send_request(FUNCTION_ENABLE, [], '', 0, '')
363
+ end
364
+
365
+ # Disables the driver chip. The configurations are kept (maximum velocity,
366
+ # acceleration, etc) but the motor is not driven until it is enabled again.
367
+ def disable
368
+ send_request(FUNCTION_DISABLE, [], '', 0, '')
369
+ end
370
+
371
+ # Returns *true* if the driver chip is enabled, *false* otherwise.
372
+ def is_enabled
373
+ send_request(FUNCTION_IS_ENABLED, [], '', 1, '?')
374
+ end
375
+
376
+ # Sets the decay mode of the stepper motor. The possible value range is
377
+ # between 0 and 65535. A value of 0 sets the fast decay mode, a value of
378
+ # 65535 sets the slow decay mode and a value in between sets the mixed
379
+ # decay mode.
380
+ #
381
+ # Changing the decay mode is only possible if synchronous rectification
382
+ # is enabled (see BrickStepper#set_sync_rect).
383
+ #
384
+ # For a good explanation of the different decay modes see
385
+ # `this <http://ebldc.com/?p=86/>`__ blog post by Avayan.
386
+ #
387
+ # A good decay mode is unfortunately different for every motor. The best
388
+ # way to work out a good decay mode for your stepper motor, if you can't
389
+ # measure the current with an oscilloscope, is to listen to the sound of
390
+ # the motor. If the value is too low, you often hear a high pitched
391
+ # sound and if it is too high you can often hear a humming sound.
392
+ #
393
+ # Generally, fast decay mode (small value) will be noisier but also
394
+ # allow higher motor speeds.
395
+ #
396
+ # The default value is 10000.
397
+ #
398
+ # .. note::
399
+ # There is unfortunately no formula to calculate a perfect decay
400
+ # mode for a given stepper motor. If you have problems with loud noises
401
+ # or the maximum motor speed is too slow, you should try to tinker with
402
+ # the decay value
403
+ def set_decay(decay)
404
+ send_request(FUNCTION_SET_DECAY, [decay], 'S', 0, '')
405
+ end
406
+
407
+ # Returns the decay mode as set by BrickStepper#set_decay.
408
+ def get_decay
409
+ send_request(FUNCTION_GET_DECAY, [], '', 2, 'S')
410
+ end
411
+
412
+ # Sets the minimum voltage in mV, below which the CALLBACK_UNDER_VOLTAGE callback
413
+ # is triggered. The minimum possible value that works with the Stepper Brick is 8V.
414
+ # You can use this function to detect the discharge of a battery that is used
415
+ # to drive the stepper motor. If you have a fixed power supply, you likely do
416
+ # not need this functionality.
417
+ #
418
+ # The default value is 8V.
419
+ def set_minimum_voltage(voltage)
420
+ send_request(FUNCTION_SET_MINIMUM_VOLTAGE, [voltage], 'S', 0, '')
421
+ end
422
+
423
+ # Returns the minimum voltage as set by BrickStepper#set_minimum_voltage.
424
+ def get_minimum_voltage
425
+ send_request(FUNCTION_GET_MINIMUM_VOLTAGE, [], '', 2, 'S')
426
+ end
427
+
428
+ # Turns synchronous rectification on or off (*true* or *false*).
429
+ #
430
+ # With synchronous rectification on, the decay can be changed
431
+ # (see BrickStepper#set_decay). Without synchronous rectification fast
432
+ # decay is used.
433
+ #
434
+ # For an explanation of synchronous rectification see
435
+ # `here <http://en.wikipedia.org/wiki/Active_rectification>`__.
436
+ #
437
+ # .. warning::
438
+ # If you want to use high speeds (> 10000 steps/s) for a large
439
+ # stepper motor with a large inductivity we strongly
440
+ # suggest that you disable synchronous rectification. Otherwise the
441
+ # Brick may not be able to cope with the load and overheat.
442
+ #
443
+ # The default value is *false*.
444
+ #
445
+ # .. versionadded:: 1.1.4~(Firmware)
446
+ def set_sync_rect(sync_rect)
447
+ send_request(FUNCTION_SET_SYNC_RECT, [sync_rect], '?', 0, '')
448
+ end
449
+
450
+ # Returns *true* if synchronous rectification is enabled, *false* otherwise.
451
+ #
452
+ # .. versionadded:: 1.1.4~(Firmware)
453
+ def is_sync_rect
454
+ send_request(FUNCTION_IS_SYNC_RECT, [], '', 1, '?')
455
+ end
456
+
457
+ # Sets the time base of the velocity and the acceleration of the stepper brick
458
+ # (in seconds).
459
+ #
460
+ # For example, if you want to make one step every 1.5 seconds, you can set
461
+ # the time base to 15 and the velocity to 10. Now the velocity is
462
+ # 10steps/15s = 1steps/1.5s.
463
+ #
464
+ # The default value is 1.
465
+ #
466
+ # .. versionadded:: 1.1.6~(Firmware)
467
+ def set_time_base(time_base)
468
+ send_request(FUNCTION_SET_TIME_BASE, [time_base], 'L', 0, '')
469
+ end
470
+
471
+ # Returns the time base as set by BrickStepper#set_time_base.
472
+ #
473
+ # .. versionadded:: 1.1.6~(Firmware)
474
+ def get_time_base
475
+ send_request(FUNCTION_GET_TIME_BASE, [], '', 4, 'L')
476
+ end
477
+
478
+ # Returns the following parameters: The current velocity,
479
+ # the current position, the remaining steps, the stack voltage, the external
480
+ # voltage and the current consumption of the stepper motor.
481
+ #
482
+ # There is also a callback for this function, see CALLBACK_ALL_DATA.
483
+ #
484
+ # .. versionadded:: 1.1.6~(Firmware)
485
+ def get_all_data
486
+ send_request(FUNCTION_GET_ALL_DATA, [], '', 16, 'S l l S S S')
487
+ end
488
+
489
+ # Sets the period in ms with which the CALLBACK_ALL_DATA callback is triggered
490
+ # periodically. A value of 0 turns the callback off.
491
+ #
492
+ # .. versionadded:: 1.1.6~(Firmware)
493
+ def set_all_data_period(period)
494
+ send_request(FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 0, '')
495
+ end
496
+
497
+ # Returns the period as set by BrickStepper#set_all_data_period.
498
+ #
499
+ # .. versionadded:: 1.1.6~(Firmware)
500
+ def get_all_data_period
501
+ send_request(FUNCTION_GET_ALL_DATA_PERIOD, [], '', 4, 'L')
502
+ end
503
+
504
+ # Returns the firmware and protocol version and the name of the Bricklet for a given port.
505
+ #
506
+ # This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet plugins.
507
+ #
508
+ # .. versionadded:: 2.0.0~(Firmware)
509
+ def get_protocol1_bricklet_name(port)
510
+ send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
511
+ end
512
+
513
+ # Returns the temperature in °C/10 as measured inside the microcontroller. The
514
+ # value returned is not the ambient temperature!
515
+ #
516
+ # The temperature is only proportional to the real temperature and it has an
517
+ # accuracy of +-15%. Practically it is only useful as an indicator for
518
+ # temperature changes.
519
+ #
520
+ # .. versionadded:: 1.1.4~(Firmware)
521
+ def get_chip_temperature
522
+ send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
523
+ end
524
+
525
+ # Calling this function will reset the Brick. Calling this function
526
+ # on a Brick inside of a stack will reset the whole stack.
527
+ #
528
+ # After a reset you have to create new device objects,
529
+ # calling functions on the existing ones will result in
530
+ # undefined behavior!
531
+ #
532
+ # .. versionadded:: 1.1.4~(Firmware)
533
+ def reset
534
+ send_request(FUNCTION_RESET, [], '', 0, '')
535
+ end
536
+
537
+ # Returns the UID, the UID where the Brick is connected to,
538
+ # the position, the hardware and firmware version as well as the
539
+ # device identifier.
540
+ #
541
+ # The position can be '0'-'8' (stack position).
542
+ #
543
+ # The device identifiers can be found :ref:`here <device_identifier>`.
544
+ #
545
+ # .. versionadded:: 2.0.0~(Firmware)
546
+ def get_identity
547
+ send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
548
+ end
549
+
550
+ # Registers a callback with ID <tt>id</tt> to the block <tt>block</tt>.
551
+ def register_callback(id, &block)
552
+ callback = block
553
+ @registered_callbacks[id] = callback
554
+ end
555
+ end
556
+ end