Class: Tinkerforge::BrickletServoV2

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

Overview

Drives up to 10 RC Servos

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

2157
DEVICE_DISPLAY_NAME =

:nodoc:

'Servo Bricklet 2.0'
CALLBACK_POSITION_REACHED =

This callback is triggered when a position set by BrickletServoV2#set_position is reached. If the new position matches the current position then the callback is not triggered, because the servo didn’t move. The parameters are the servo and the position that is reached.

You can enable this callback with BrickletServoV2#set_position_reached_callback_configuration.

.. note

Since we can’t get any feedback from the servo, this only works if the velocity (see BrickletServoV2#set_motion_configuration) is set smaller or equal to the maximum velocity of the servo. Otherwise the servo will lag behind the control value and the callback will be triggered too early.

27
FUNCTION_GET_STATUS =

:nodoc:

1
FUNCTION_SET_ENABLE =

:nodoc:

2
FUNCTION_GET_ENABLED =

:nodoc:

3
FUNCTION_SET_POSITION =

:nodoc:

4
FUNCTION_GET_POSITION =

:nodoc:

5
FUNCTION_GET_CURRENT_POSITION =

:nodoc:

6
FUNCTION_GET_CURRENT_VELOCITY =

:nodoc:

7
FUNCTION_SET_MOTION_CONFIGURATION =

:nodoc:

8
FUNCTION_GET_MOTION_CONFIGURATION =

:nodoc:

9
FUNCTION_SET_PULSE_WIDTH =

:nodoc:

10
FUNCTION_GET_PULSE_WIDTH =

:nodoc:

11
FUNCTION_SET_DEGREE =

:nodoc:

12
FUNCTION_GET_DEGREE =

:nodoc:

13
FUNCTION_SET_PERIOD =

:nodoc:

14
FUNCTION_GET_PERIOD =

:nodoc:

15
FUNCTION_GET_SERVO_CURRENT =

:nodoc:

16
FUNCTION_SET_SERVO_CURRENT_CONFIGURATION =

:nodoc:

17
FUNCTION_GET_SERVO_CURRENT_CONFIGURATION =

:nodoc:

18
FUNCTION_SET_INPUT_VOLTAGE_CONFIGURATION =

:nodoc:

19
FUNCTION_GET_INPUT_VOLTAGE_CONFIGURATION =

:nodoc:

20
FUNCTION_GET_OVERALL_CURRENT =

:nodoc:

21
FUNCTION_GET_INPUT_VOLTAGE =

:nodoc:

22
FUNCTION_SET_CURRENT_CALIBRATION =

:nodoc:

23
FUNCTION_GET_CURRENT_CALIBRATION =

:nodoc:

24
FUNCTION_SET_POSITION_REACHED_CALLBACK_CONFIGURATION =

:nodoc:

25
FUNCTION_GET_POSITION_REACHED_CALLBACK_CONFIGURATION =

:nodoc:

26
FUNCTION_GET_SPITFP_ERROR_COUNT =

:nodoc:

234
FUNCTION_SET_BOOTLOADER_MODE =

:nodoc:

235
FUNCTION_GET_BOOTLOADER_MODE =

:nodoc:

236
FUNCTION_SET_WRITE_FIRMWARE_POINTER =

:nodoc:

237
FUNCTION_WRITE_FIRMWARE =

:nodoc:

238
FUNCTION_SET_STATUS_LED_CONFIG =

:nodoc:

239
FUNCTION_GET_STATUS_LED_CONFIG =

:nodoc:

240
FUNCTION_GET_CHIP_TEMPERATURE =

:nodoc:

242
FUNCTION_RESET =

:nodoc:

243
FUNCTION_WRITE_UID =

:nodoc:

248
FUNCTION_READ_UID =

:nodoc:

249
FUNCTION_GET_IDENTITY =

:nodoc:

255
BOOTLOADER_MODE_BOOTLOADER =

:nodoc:

0
BOOTLOADER_MODE_FIRMWARE =

:nodoc:

1
BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT =

:nodoc:

2
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT =

:nodoc:

3
BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT =

:nodoc:

4
BOOTLOADER_STATUS_OK =

:nodoc:

0
BOOTLOADER_STATUS_INVALID_MODE =

:nodoc:

1
BOOTLOADER_STATUS_NO_CHANGE =

:nodoc:

2
BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT =

:nodoc:

3
BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT =

:nodoc:

4
BOOTLOADER_STATUS_CRC_MISMATCH =

:nodoc:

5
STATUS_LED_CONFIG_OFF =

:nodoc:

0
STATUS_LED_CONFIG_ON =

:nodoc:

1
STATUS_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
STATUS_LED_CONFIG_SHOW_STATUS =

:nodoc:

3

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

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

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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 91

def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_GET_STATUS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ENABLE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_POSITION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CURRENT_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MOTION_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MOTION_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_PULSE_WIDTH] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_PULSE_WIDTH] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DEGREE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_DEGREE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_PERIOD] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_SERVO_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_SERVO_CURRENT_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SERVO_CURRENT_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_INPUT_VOLTAGE_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_INPUT_VOLTAGE_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_OVERALL_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CURRENT_CALIBRATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CURRENT_CALIBRATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_POSITION_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_POSITION_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_SPITFP_ERROR_COUNT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_BOOTLOADER_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_WRITE_FIRMWARE_POINTER] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_WRITE_FIRMWARE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_WRITE_UID] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_READ_UID] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_POSITION_REACHED] = [12, 'S s']

  @ipcon.add_device self
end

Instance Method Details

#get_bootloader_modeObject

Returns the current bootloader mode, see BrickletServoV2#set_bootloader_mode.



450
451
452
453
454
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 450

def get_bootloader_mode
  check_validity

  send_request FUNCTION_GET_BOOTLOADER_MODE, [], '', 9, 'C'
end

#get_chip_temperatureObject

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 bad accuracy. Practically it is only useful as an indicator for temperature changes.



508
509
510
511
512
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 508

def get_chip_temperature
  check_validity

  send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's'
end

#get_current_calibrationObject

Returns the current calibration as set by BrickletServoV2#set_current_calibration.



396
397
398
399
400
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 396

def get_current_calibration
  check_validity

  send_request FUNCTION_GET_CURRENT_CALIBRATION, [], '', 28, 's10'
end

#get_current_position(servo_channel) ⇒ Object

Returns the current position of the specified servo channel. This may not be the value of BrickletServoV2#set_position if the servo is currently approaching a position goal.



197
198
199
200
201
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 197

def get_current_position(servo_channel)
  check_validity

  send_request FUNCTION_GET_CURRENT_POSITION, [servo_channel], 'S', 10, 's'
end

#get_current_velocity(servo_channel) ⇒ Object

Returns the current velocity of the specified servo channel. This may not be the velocity specified by BrickletServoV2#set_motion_configuration. if the servo is currently approaching a velocity goal.



206
207
208
209
210
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 206

def get_current_velocity(servo_channel)
  check_validity

  send_request FUNCTION_GET_CURRENT_VELOCITY, [servo_channel], 'S', 10, 'S'
end

#get_degree(servo_channel) ⇒ Object

Returns the minimum and maximum degree for the specified servo channel as set by BrickletServoV2#set_degree.



301
302
303
304
305
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 301

def get_degree(servo_channel)
  check_validity

  send_request FUNCTION_GET_DEGREE, [servo_channel], 'S', 12, 's s'
end

#get_enabled(servo_channel) ⇒ Object

Returns true if the specified servo channel is enabled, false otherwise.



167
168
169
170
171
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 167

def get_enabled(servo_channel)
  check_validity

  send_request FUNCTION_GET_ENABLED, [servo_channel], 'S', 9, '?'
end

#get_identityObject

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

The position can be ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an :ref:‘Isolator Bricklet <isolator_bricklet>` is always at position ’z’.

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



555
556
557
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 555

def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end

#get_input_voltageObject

Returns the input voltage in mV. The input voltage is given via the black power input connector on the Servo Brick.



380
381
382
383
384
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 380

def get_input_voltage
  check_validity

  send_request FUNCTION_GET_INPUT_VOLTAGE, [], '', 10, 'S'
end

#get_input_voltage_configurationObject

Returns the input voltage configuration as set by BrickletServoV2#set_input_voltage_configuration.



365
366
367
368
369
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 365

def get_input_voltage_configuration
  check_validity

  send_request FUNCTION_GET_INPUT_VOLTAGE_CONFIGURATION, [], '', 9, 'C'
end

#get_motion_configuration(servo_channel) ⇒ Object

Returns the motion configuration as set by BrickletServoV2#set_motion_configuration.



226
227
228
229
230
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 226

def get_motion_configuration(servo_channel)
  check_validity

  send_request FUNCTION_GET_MOTION_CONFIGURATION, [servo_channel], 'S', 20, 'L L L'
end

#get_overall_currentObject

Returns the current consumption of all servos together in mA.



372
373
374
375
376
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 372

def get_overall_current
  check_validity

  send_request FUNCTION_GET_OVERALL_CURRENT, [], '', 10, 'S'
end

#get_period(servo_channel) ⇒ Object

Returns the period for the specified servo channel as set by BrickletServoV2#set_period.



329
330
331
332
333
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 329

def get_period(servo_channel)
  check_validity

  send_request FUNCTION_GET_PERIOD, [servo_channel], 'S', 12, 'L'
end

#get_position(servo_channel) ⇒ Object

Returns the position of the specified servo channel as set by BrickletServoV2#set_position.



188
189
190
191
192
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 188

def get_position(servo_channel)
  check_validity

  send_request FUNCTION_GET_POSITION, [servo_channel], 'S', 10, 's'
end

#get_position_reached_callback_configuration(servo_channel) ⇒ Object

Returns the callback configuration as set by BrickletServoV2#set_position_reached_callback_configuration.



411
412
413
414
415
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 411

def get_position_reached_callback_configuration(servo_channel)
  check_validity

  send_request FUNCTION_GET_POSITION_REACHED_CALLBACK_CONFIGURATION, [servo_channel], 'S', 9, '?'
end

#get_pulse_width(servo_channel) ⇒ Object

Returns the minimum and maximum pulse width for the specified servo channel as set by BrickletServoV2#set_pulse_width.



257
258
259
260
261
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 257

def get_pulse_width(servo_channel)
  check_validity

  send_request FUNCTION_GET_PULSE_WIDTH, [servo_channel], 'S', 16, 'L L'
end

#get_servo_current(servo_channel) ⇒ Object

Returns the current consumption of the specified servo channel in mA.



336
337
338
339
340
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 336

def get_servo_current(servo_channel)
  check_validity

  send_request FUNCTION_GET_SERVO_CURRENT, [servo_channel], 'S', 10, 'S'
end

#get_servo_current_configuration(servo_channel) ⇒ Object

Returns the servo current configuration for the specified servo channel as set by BrickletServoV2#set_servo_current_configuration.



351
352
353
354
355
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 351

def get_servo_current_configuration(servo_channel)
  check_validity

  send_request FUNCTION_GET_SERVO_CURRENT_CONFIGURATION, [servo_channel], 'S', 9, 'C'
end

#get_spitfp_error_countObject

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 Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.



428
429
430
431
432
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 428

def get_spitfp_error_count
  check_validity

  send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [], '', 24, 'L L L L'
end

#get_statusObject

Returns the status information of the Servo Bricklet 2.0.

The status includes

  • for each channel if it is enabled or disabled,

  • for each channel the current position,

  • for each channel the current velocity,

  • for each channel the current usage and

  • the input voltage.

Please note that the position and the velocity is a snapshot of the current position and velocity of the servo in motion.



152
153
154
155
156
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 152

def get_status
  check_validity

  send_request FUNCTION_GET_STATUS, [], '', 72, '?10 s10 s10 S10 S'
end

#get_status_led_configObject

Returns the configuration as set by BrickletServoV2#set_status_led_config



496
497
498
499
500
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 496

def get_status_led_config
  check_validity

  send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C'
end

#read_uidObject

Returns the current UID as an integer. Encode as Base58 to get the usual string version.



539
540
541
542
543
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 539

def read_uid
  check_validity

  send_request FUNCTION_READ_UID, [], '', 12, 'L'
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



560
561
562
563
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 560

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

#resetObject

Calling this function will reset the Bricklet. All configurations will be lost.

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



520
521
522
523
524
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 520

def reset
  check_validity

  send_request FUNCTION_RESET, [], '', 8, ''
end

#set_bootloader_mode(mode) ⇒ Object

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

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



443
444
445
446
447
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 443

def set_bootloader_mode(mode)
  check_validity

  send_request FUNCTION_SET_BOOTLOADER_MODE, [mode], 'C', 9, 'C'
end

#set_current_calibration(offset) ⇒ Object

Sets an offset value (in mA) for each channel.

Note: On delivery the Servo Bricklet 2.0 is already calibrated.



389
390
391
392
393
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 389

def set_current_calibration(offset)
  check_validity

  send_request FUNCTION_SET_CURRENT_CALIBRATION, [offset], 's10', 8, ''
end

#set_degree(servo_channel, min, max) ⇒ Object

Sets the minimum and maximum degree for the specified servo channel (by default given as °/100).

This only specifies the abstract values between which the minimum and maximum pulse width is scaled. For example: If you specify a pulse width of 1000µs to 2000µs and a degree range of -90° to 90°, a call of BrickletServoV2#set_position with 0 will result in a pulse width of 1500µs (-90° = 1000µs, 90° = 2000µs, etc.).

Possible usage:

  • The datasheet of your servo specifies a range of 200° with the middle position at 110°. In this case you can set the minimum to -9000 and the maximum to 11000.

  • You measure a range of 220° on your servo and you don’t have or need a middle position. In this case you can set the minimum to 0 and the maximum to 22000.

  • You have a linear servo with a drive length of 20cm, In this case you could set the minimum to 0 and the maximum to 20000. Now you can set the Position with BrickletServoV2#set_position with a resolution of cm/100. Also the velocity will have a resolution of cm/100s and the acceleration will have a resolution of cm/100s².

  • You don’t care about units and just want the highest possible resolution. In this case you should set the minimum to -32767 and the maximum to 32767.

  • You have a brushless motor with a maximum speed of 10000 rpm and want to control it with a RC brushless motor controller. In this case you can set the minimum to 0 and the maximum to 10000. BrickletServoV2#set_position now controls the rpm.

Both values have a possible range from -32767 to 32767 (signed 16-bit integer). The minimum must be smaller than the maximum.

The default values are -9000 and 9000 for the minimum and maximum degree.



293
294
295
296
297
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 293

def set_degree(servo_channel, min, max)
  check_validity

  send_request FUNCTION_SET_DEGREE, [servo_channel, min, max], 'S s s', 8, ''
end

#set_enable(servo_channel, enable) ⇒ Object

Enables a servo channel (0 to 9). If a servo is enabled, the configured position, velocity, acceleration, etc. are applied immediately.



160
161
162
163
164
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 160

def set_enable(servo_channel, enable)
  check_validity

  send_request FUNCTION_SET_ENABLE, [servo_channel, enable], 'S ?', 8, ''
end

#set_input_voltage_configuration(averaging_duration) ⇒ Object

Sets the averaging duration of the input voltage measurement for the specified servo channel in ms.



358
359
360
361
362
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 358

def set_input_voltage_configuration(averaging_duration)
  check_validity

  send_request FUNCTION_SET_INPUT_VOLTAGE_CONFIGURATION, [averaging_duration], 'C', 8, ''
end

#set_motion_configuration(servo_channel, velocity, acceleration, deceleration) ⇒ Object

Sets the maximum velocity of the specified servo channel in °/100s as well as the acceleration and deceleration in °/100s²

With a velocity of 0 °/100s the position will be set immediately (no velocity).

With an acc-/deceleration of 0 °/100s² the velocity will be set immediately (no acc-/deceleration).



219
220
221
222
223
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 219

def set_motion_configuration(servo_channel, velocity, acceleration, deceleration)
  check_validity

  send_request FUNCTION_SET_MOTION_CONFIGURATION, [servo_channel, velocity, acceleration, deceleration], 'S L L L', 8, ''
end

#set_period(servo_channel, period) ⇒ Object

Sets the period of the specified servo channel in µs.

Usually, servos are controlled with a ‘PWM <en.wikipedia.org/wiki/Pulse-width_modulation>`__. Different servos expect PWMs with different periods. Most servos run well with a period of about 20ms.

If your servo comes with a datasheet that specifies a period, you should set it accordingly. If you don’t have a datasheet and you have no idea what the correct period is, the default value (19.5ms) will most likely work fine.

The minimum possible period is 1µs and the maximum is 1000000µs.

The default value is 19.5ms (19500µs).



322
323
324
325
326
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 322

def set_period(servo_channel, period)
  check_validity

  send_request FUNCTION_SET_PERIOD, [servo_channel, period], 'S L', 8, ''
end

#set_position(servo_channel, position) ⇒ Object

Sets the position in °/100 for the specified servo channel.

The default range of the position is -9000 to 9000, but it can be specified according to your servo with BrickletServoV2#set_degree.

If you want to control a linear servo or RC brushless motor controller or similar with the Servo Brick, you can also define lengths or speeds with BrickletServoV2#set_degree.



181
182
183
184
185
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 181

def set_position(servo_channel, position)
  check_validity

  send_request FUNCTION_SET_POSITION, [servo_channel, position], 'S s', 8, ''
end

#set_position_reached_callback_configuration(servo_channel, enabled) ⇒ Object

Enable/Disable CALLBACK_POSITION_REACHED callback.



403
404
405
406
407
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 403

def set_position_reached_callback_configuration(servo_channel, enabled)
  check_validity

  send_request FUNCTION_SET_POSITION_REACHED_CALLBACK_CONFIGURATION, [servo_channel, enabled], 'S ?', 8, ''
end

#set_pulse_width(servo_channel, min, max) ⇒ Object

Sets the minimum and maximum pulse width of the specified servo channel in µs.

Usually, servos are controlled with a ‘PWM <en.wikipedia.org/wiki/Pulse-width_modulation>`__, whereby the length of the pulse controls the position of the servo. Every servo has different minimum and maximum pulse widths, these can be specified with this function.

If you have a datasheet for your servo that specifies the minimum and maximum pulse width, you should set the values accordingly. If your servo comes without any datasheet you have to find the values via trial and error.

Both values have a range from 1 to 65535 (unsigned 16-bit integer). The minimum must be smaller than the maximum.

The default values are 1000µs (1ms) and 2000µs (2ms) for minimum and maximum pulse width.



249
250
251
252
253
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 249

def set_pulse_width(servo_channel, min, max)
  check_validity

  send_request FUNCTION_SET_PULSE_WIDTH, [servo_channel, min, max], 'S L L', 8, ''
end

#set_servo_current_configuration(servo_channel, averaging_duration) ⇒ Object

Sets the averaging duration of the current measurement for the specified servo channel in ms.



343
344
345
346
347
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 343

def set_servo_current_configuration(servo_channel, averaging_duration)
  check_validity

  send_request FUNCTION_SET_SERVO_CURRENT_CONFIGURATION, [servo_channel, averaging_duration], 'S C', 8, ''
end

#set_status_led_config(config) ⇒ Object

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.



489
490
491
492
493
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 489

def set_status_led_config(config)
  check_validity

  send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, ''
end

#set_write_firmware_pointer(pointer) ⇒ Object

Sets the firmware pointer for BrickletServoV2#write_firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

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



462
463
464
465
466
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 462

def set_write_firmware_pointer(pointer)
  check_validity

  send_request FUNCTION_SET_WRITE_FIRMWARE_POINTER, [pointer], 'L', 8, ''
end

#write_firmware(data) ⇒ Object

Writes 64 Bytes of firmware at the position as written by BrickletServoV2#set_write_firmware_pointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

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



476
477
478
479
480
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 476

def write_firmware(data)
  check_validity

  send_request FUNCTION_WRITE_FIRMWARE, [data], 'C64', 9, 'C'
end

#write_uid(uid) ⇒ Object

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.



531
532
533
534
535
# File 'lib/tinkerforge/bricklet_servo_v2.rb', line 531

def write_uid(uid)
  check_validity

  send_request FUNCTION_WRITE_UID, [uid], 'L', 8, ''
end