Class: Tinkerforge::BrickletPerformanceDC

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

Overview

Drives one brushed DC motor with up to 36V and 10A

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

2156
DEVICE_DISPLAY_NAME =

:nodoc:

'Performance DC Bricklet'
CALLBACK_EMERGENCY_SHUTDOWN =

This callback is triggered if either the current consumption is too high or the temperature of the driver chip is too high (above 150°C) or the user defined thermal shutdown is triggered (see BrickletPerformanceDC#set_thermal_shutdown). n case of a voltage below 6V (input voltage) this callback is triggered as well.

If this callback is triggered, the driver chip gets disabled at the same time. That means, BrickletPerformanceDC#set_enabled has to be called to drive the motor again.

35
CALLBACK_VELOCITY_REACHED =

This callback is triggered whenever a set velocity is reached. For example: If a velocity of 0 is present, acceleration is set to 5000 and velocity to 10000, the CALLBACK_VELOCITY_REACHED callback will be triggered after about 2 seconds, when the set velocity is actually reached.

.. note

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

36
CALLBACK_CURRENT_VELOCITY =

This callback is triggered with the period that is set by BrickletPerformanceDC#set_current_velocity_callback_configuration. The parameter is the current velocity used by the motor.

The CALLBACK_CURRENT_VELOCITY callback is only triggered after the set period if there is a change in the velocity.

37
CALLBACK_GPIO_STATE =

This callback is triggered by GPIO changes if it is activated through BrickletPerformanceDC#set_gpio_action.

.. versionadded

2.0.1$nbsp;(Plugin)

38
FUNCTION_SET_ENABLED =

:nodoc:

1
FUNCTION_GET_ENABLED =

:nodoc:

2
FUNCTION_SET_VELOCITY =

:nodoc:

3
FUNCTION_GET_VELOCITY =

:nodoc:

4
FUNCTION_GET_CURRENT_VELOCITY =

:nodoc:

5
FUNCTION_SET_MOTION =

:nodoc:

6
FUNCTION_GET_MOTION =

:nodoc:

7
FUNCTION_FULL_BRAKE =

:nodoc:

8
FUNCTION_SET_DRIVE_MODE =

:nodoc:

9
FUNCTION_GET_DRIVE_MODE =

:nodoc:

10
FUNCTION_SET_PWM_FREQUENCY =

:nodoc:

11
FUNCTION_GET_PWM_FREQUENCY =

:nodoc:

12
FUNCTION_GET_POWER_STATISTICS =

:nodoc:

13
FUNCTION_SET_THERMAL_SHUTDOWN =

:nodoc:

14
FUNCTION_GET_THERMAL_SHUTDOWN =

:nodoc:

15
FUNCTION_SET_GPIO_CONFIGURATION =

:nodoc:

16
FUNCTION_GET_GPIO_CONFIGURATION =

:nodoc:

17
FUNCTION_SET_GPIO_ACTION =

:nodoc:

18
FUNCTION_GET_GPIO_ACTION =

:nodoc:

19
FUNCTION_GET_GPIO_STATE =

:nodoc:

20
FUNCTION_SET_ERROR_LED_CONFIG =

:nodoc:

21
FUNCTION_GET_ERROR_LED_CONFIG =

:nodoc:

22
FUNCTION_SET_CW_LED_CONFIG =

:nodoc:

23
FUNCTION_GET_CW_LED_CONFIG =

:nodoc:

24
FUNCTION_SET_CCW_LED_CONFIG =

:nodoc:

25
FUNCTION_GET_CCW_LED_CONFIG =

:nodoc:

26
FUNCTION_SET_GPIO_LED_CONFIG =

:nodoc:

27
FUNCTION_GET_GPIO_LED_CONFIG =

:nodoc:

28
FUNCTION_SET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION =

:nodoc:

29
FUNCTION_GET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION =

:nodoc:

30
FUNCTION_SET_VELOCITY_REACHED_CALLBACK_CONFIGURATION =

:nodoc:

31
FUNCTION_GET_VELOCITY_REACHED_CALLBACK_CONFIGURATION =

:nodoc:

32
FUNCTION_SET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION =

:nodoc:

33
FUNCTION_GET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION =

:nodoc:

34
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
DRIVE_MODE_DRIVE_BRAKE =

:nodoc:

0
DRIVE_MODE_DRIVE_COAST =

:nodoc:

1
GPIO_ACTION_NONE =

:nodoc:

0
GPIO_ACTION_NORMAL_STOP_RISING_EDGE =

:nodoc:

1
GPIO_ACTION_NORMAL_STOP_FALLING_EDGE =

:nodoc:

2
GPIO_ACTION_FULL_BRAKE_RISING_EDGE =

:nodoc:

4
GPIO_ACTION_FULL_BRAKE_FALLING_EDGE =

:nodoc:

8
GPIO_ACTION_CALLBACK_RISING_EDGE =

:nodoc:

16
GPIO_ACTION_CALLBACK_FALLING_EDGE =

:nodoc:

32
ERROR_LED_CONFIG_OFF =

:nodoc:

0
ERROR_LED_CONFIG_ON =

:nodoc:

1
ERROR_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
ERROR_LED_CONFIG_SHOW_ERROR =

:nodoc:

3
CW_LED_CONFIG_OFF =

:nodoc:

0
CW_LED_CONFIG_ON =

:nodoc:

1
CW_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
CW_LED_CONFIG_SHOW_CW_AS_FORWARD =

:nodoc:

3
CW_LED_CONFIG_SHOW_CW_AS_BACKWARD =

:nodoc:

4
CCW_LED_CONFIG_OFF =

:nodoc:

0
CCW_LED_CONFIG_ON =

:nodoc:

1
CCW_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD =

:nodoc:

3
CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD =

:nodoc:

4
GPIO_LED_CONFIG_OFF =

:nodoc:

0
GPIO_LED_CONFIG_ON =

:nodoc:

1
GPIO_LED_CONFIG_SHOW_HEARTBEAT =

:nodoc:

2
GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH =

:nodoc:

3
GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW =

:nodoc:

4
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) ⇒ BrickletPerformanceDC

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



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 148

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

  @api_version = [2, 0, 1]

  @response_expected[FUNCTION_SET_ENABLED] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_VELOCITY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MOTION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MOTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_FULL_BRAKE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SET_DRIVE_MODE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_DRIVE_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_PWM_FREQUENCY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_PWM_FREQUENCY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_POWER_STATISTICS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_THERMAL_SHUTDOWN] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_THERMAL_SHUTDOWN] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_GPIO_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_GPIO_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_GPIO_ACTION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_GPIO_ACTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_GPIO_STATE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_ERROR_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CW_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CW_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CCW_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CCW_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_GPIO_LED_CONFIG] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_GPIO_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_VELOCITY_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_VELOCITY_REACHED_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_CURRENT_VELOCITY_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_EMERGENCY_SHUTDOWN] = [8, '']
  @callback_formats[CALLBACK_VELOCITY_REACHED] = [10, 's']
  @callback_formats[CALLBACK_CURRENT_VELOCITY] = [10, 's']
  @callback_formats[CALLBACK_GPIO_STATE] = [9, '?2']

  @ipcon.add_device self
end

Instance Method Details

#full_brakeObject

Executes an active full brake.

.. warning

This function is for emergency purposes, where an immediate brake is necessary. Depending on the current velocity and the strength of the motor, a full brake can be quite violent.

Call BrickletPerformanceDC#set_velocity with 0 if you just want to stop the motor.



285
286
287
288
289
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 285

def full_brake
  check_validity

  send_request FUNCTION_FULL_BRAKE, [], '', 8, ''
end

#get_bootloader_modeObject

Returns the current bootloader mode, see BrickletPerformanceDC#set_bootloader_mode.



567
568
569
570
571
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 567

def get_bootloader_mode
  check_validity

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

#get_ccw_led_configObject

Returns the LED configuration as set by BrickletPerformanceDC#set_ccw_led_config



458
459
460
461
462
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 458

def get_ccw_led_config
  check_validity

  send_request FUNCTION_GET_CCW_LED_CONFIG, [], '', 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.



625
626
627
628
629
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 625

def get_chip_temperature
  check_validity

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

#get_current_velocityObject

Returns the current velocity of the motor. This value is different from BrickletPerformanceDC#get_velocity whenever the motor is currently accelerating to a goal set by BrickletPerformanceDC#set_velocity.



248
249
250
251
252
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 248

def get_current_velocity
  check_validity

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

#get_current_velocity_callback_configurationObject

Returns the callback configuration as set by BrickletPerformanceDC#set_current_velocity_callback_configuration.



528
529
530
531
532
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 528

def get_current_velocity_callback_configuration
  check_validity

  send_request FUNCTION_GET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION, [], '', 13, 'L ?'
end

#get_cw_led_configObject

Returns the LED configuration as set by BrickletPerformanceDC#set_cw_led_config



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

def get_cw_led_config
  check_validity

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

#get_drive_modeObject

Returns the drive mode, as set by BrickletPerformanceDC#set_drive_mode.



313
314
315
316
317
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 313

def get_drive_mode
  check_validity

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

#get_emergency_shutdown_callback_configurationObject

Returns the callback configuration as set by BrickletPerformanceDC#set_emergency_shutdown_callback_configuration.



490
491
492
493
494
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 490

def get_emergency_shutdown_callback_configuration
  check_validity

  send_request FUNCTION_GET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION, [], '', 9, '?'
end

#get_enabledObject

Returns true if the driver chip is enabled, false otherwise.



217
218
219
220
221
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 217

def get_enabled
  check_validity

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

#get_error_led_configObject

Returns the LED configuration as set by BrickletPerformanceDC#set_error_led_config



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

def get_error_led_config
  check_validity

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

#get_gpio_action(channel) ⇒ Object

Returns the GPIO action for a channel as set by BrickletPerformanceDC#set_gpio_action.



399
400
401
402
403
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 399

def get_gpio_action(channel)
  check_validity

  send_request FUNCTION_GET_GPIO_ACTION, [channel], 'C', 12, 'L'
end

#get_gpio_configuration(channel) ⇒ Object

Returns the GPIO configuration for a channel as set by BrickletPerformanceDC#set_gpio_configuration.



377
378
379
380
381
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 377

def get_gpio_configuration(channel)
  check_validity

  send_request FUNCTION_GET_GPIO_CONFIGURATION, [channel], 'C', 12, 'S S'
end

#get_gpio_led_config(channel) ⇒ Object

Returns the LED configuration as set by BrickletPerformanceDC#set_gpio_led_config



475
476
477
478
479
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 475

def get_gpio_led_config(channel)
  check_validity

  send_request FUNCTION_GET_GPIO_LED_CONFIG, [channel], 'C', 9, 'C'
end

#get_gpio_stateObject

Returns the GPIO state for both channels. True if the state is “high“ and false if the state is “low“.



407
408
409
410
411
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 407

def get_gpio_state
  check_validity

  send_request FUNCTION_GET_GPIO_STATE, [], '', 9, '?2'
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|



672
673
674
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 672

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

#get_motionObject

Returns the acceleration/deceleration as set by BrickletPerformanceDC#set_motion.



271
272
273
274
275
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 271

def get_motion
  check_validity

  send_request FUNCTION_GET_MOTION, [], '', 12, 'S S'
end

#get_power_statisticsObject

Returns input voltage, current usage and temperature of the driver.



341
342
343
344
345
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 341

def get_power_statistics
  check_validity

  send_request FUNCTION_GET_POWER_STATISTICS, [], '', 14, 'S S s'
end

#get_pwm_frequencyObject

Returns the PWM frequency as set by BrickletPerformanceDC#set_pwm_frequency.



334
335
336
337
338
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 334

def get_pwm_frequency
  check_validity

  send_request FUNCTION_GET_PWM_FREQUENCY, [], '', 10, 'S'
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.



545
546
547
548
549
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 545

def get_spitfp_error_count
  check_validity

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

#get_status_led_configObject

Returns the configuration as set by BrickletPerformanceDC#set_status_led_config



613
614
615
616
617
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 613

def get_status_led_config
  check_validity

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

#get_thermal_shutdownObject

Returns the thermal shutdown temperature as set by BrickletPerformanceDC#set_thermal_shutdown.



361
362
363
364
365
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 361

def get_thermal_shutdown
  check_validity

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

#get_velocityObject

Returns the velocity as set by BrickletPerformanceDC#set_velocity.



239
240
241
242
243
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 239

def get_velocity
  check_validity

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

#get_velocity_reached_callback_configurationObject

Returns the callback configuration as set by BrickletPerformanceDC#set_velocity_reached_callback_configuration.



505
506
507
508
509
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 505

def get_velocity_reached_callback_configuration
  check_validity

  send_request FUNCTION_GET_VELOCITY_REACHED_CALLBACK_CONFIGURATION, [], '', 9, '?'
end

#read_uidObject

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



656
657
658
659
660
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 656

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.



677
678
679
680
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 677

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!



637
638
639
640
641
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 637

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.



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

def set_bootloader_mode(mode)
  check_validity

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

#set_ccw_led_config(config) ⇒ Object

Configures the CCW LED to be either turned off, turned on, blink in heartbeat mode or if the motor turn counter-clockwise.



451
452
453
454
455
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 451

def set_ccw_led_config(config)
  check_validity

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

#set_current_velocity_callback_configuration(period, value_has_to_change) ⇒ Object

The period is the period with which the CALLBACK_CURRENT_VELOCITY callback is triggered periodically. A value of 0 turns the callback off.

If the ‘value has to change`-parameter is set to true, the callback is only triggered after the value has changed. If the value didn’t change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.



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

def set_current_velocity_callback_configuration(period, value_has_to_change)
  check_validity

  send_request FUNCTION_SET_CURRENT_VELOCITY_CALLBACK_CONFIGURATION, [period, value_has_to_change], 'L ?', 8, ''
end

#set_cw_led_config(config) ⇒ Object

Configures the CW LED to be either turned off, turned on, blink in heartbeat mode or if the motor turn clockwise.



436
437
438
439
440
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 436

def set_cw_led_config(config)
  check_validity

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

#set_drive_mode(mode) ⇒ Object

Sets the drive mode. Possible modes are:

  • 0 = Drive/Brake

  • 1 = Drive/Coast

These modes are different kinds of motor controls.

In Drive/Brake mode, the motor is always either driving or braking. There is no freewheeling. Advantages are: A more linear correlation between PWM and velocity, more exact accelerations and the possibility to drive with slower velocities.

In Drive/Coast mode, the motor is always either driving or freewheeling. Advantages are: Less current consumption and less demands on the motor and driver chip.



306
307
308
309
310
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 306

def set_drive_mode(mode)
  check_validity

  send_request FUNCTION_SET_DRIVE_MODE, [mode], 'C', 8, ''
end

#set_emergency_shutdown_callback_configuration(enabled) ⇒ Object

Enable/Disable CALLBACK_EMERGENCY_SHUTDOWN callback.



482
483
484
485
486
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 482

def set_emergency_shutdown_callback_configuration(enabled)
  check_validity

  send_request FUNCTION_SET_EMERGENCY_SHUTDOWN_CALLBACK_CONFIGURATION, [enabled], '?', 8, ''
end

#set_enabled(enabled) ⇒ Object

Enables/Disables the driver chip. The driver parameters can be configured (velocity, acceleration, etc) before it is enabled.



210
211
212
213
214
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 210

def set_enabled(enabled)
  check_validity

  send_request FUNCTION_SET_ENABLED, [enabled], '?', 8, ''
end

#set_error_led_config(config) ⇒ Object

Configures the error LED to be either turned off, turned on, blink in heartbeat mode or show an error.

If the LED is configured to show errors it has three different states:

  • Off: No error present.

  • 1s interval blinking: Input voltage too low (below 6V).

  • 250ms interval blinking: Overtemperature or overcurrent.



421
422
423
424
425
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 421

def set_error_led_config(config)
  check_validity

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

#set_gpio_action(channel, action) ⇒ Object

Sets the GPIO action for the given channel.

The action can be a normal stop, a full brake or a callback. Each for a rising edge or falling edge. The actions are a bitmask they can be used at the same time. You can for example trigger a full brake and a callback at the same time or for rising and falling edge.

The deceleration speed for the normal stop can be configured with BrickletPerformanceDC#set_gpio_configuration.



392
393
394
395
396
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 392

def set_gpio_action(channel, action)
  check_validity

  send_request FUNCTION_SET_GPIO_ACTION, [channel, action], 'C L', 8, ''
end

#set_gpio_configuration(channel, debounce, stop_deceleration) ⇒ Object

Sets the GPIO configuration for the given channel. You can configure a debounce and the deceleration that is used if the action is configured as “normal stop“. See BrickletPerformanceDC#set_gpio_action.



370
371
372
373
374
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 370

def set_gpio_configuration(channel, debounce, stop_deceleration)
  check_validity

  send_request FUNCTION_SET_GPIO_CONFIGURATION, [channel, debounce, stop_deceleration], 'C S S', 8, ''
end

#set_gpio_led_config(channel, config) ⇒ Object

Configures the GPIO LED to be either turned off, turned on, blink in heartbeat mode or the GPIO state.

The GPIO LED can be configured for both channels.



468
469
470
471
472
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 468

def set_gpio_led_config(channel, config)
  check_validity

  send_request FUNCTION_SET_GPIO_LED_CONFIG, [channel, config], 'C C', 8, ''
end

#set_motion(acceleration, deceleration) ⇒ Object

Sets the acceleration and deceleration of the motor. It is given in velocity/s. An acceleration of 10000 means, that every second the velocity is increased by 10000 (or about 30% duty cycle).

For example: If the current velocity is 0 and you want to accelerate to a velocity of 16000 (about 50% duty cycle) in 10 seconds, you should set an acceleration of 1600.

If acceleration and deceleration is set to 0, there is no speed ramping, i.e. a new velocity is immediately given to the motor.



264
265
266
267
268
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 264

def set_motion(acceleration, deceleration)
  check_validity

  send_request FUNCTION_SET_MOTION, [acceleration, deceleration], 'S S', 8, ''
end

#set_pwm_frequency(frequency) ⇒ Object

Sets the frequency of the PWM with which the motor is driven. Often a high frequency is less noisy and the motor runs smoother. However, with a low frequency there are less switches and therefore fewer switching losses. Also with most motors lower frequencies enable higher torque.

If you have no idea what all this means, just ignore this function and use the default frequency, it will very likely work fine.



327
328
329
330
331
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 327

def set_pwm_frequency(frequency)
  check_validity

  send_request FUNCTION_SET_PWM_FREQUENCY, [frequency], 'S', 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.



606
607
608
609
610
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 606

def set_status_led_config(config)
  check_validity

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

#set_thermal_shutdown(temperature) ⇒ Object

Sets a temperature threshold that is used for thermal shutdown.

Additionally to this user defined threshold the driver chip will shut down at a temperature of 150°C.

If a thermal shutdown is triggered the driver is disabled and has to be explicitly re-enabled with BrickletPerformanceDC#set_enabled.



354
355
356
357
358
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 354

def set_thermal_shutdown(temperature)
  check_validity

  send_request FUNCTION_SET_THERMAL_SHUTDOWN, [temperature], 'C', 8, ''
end

#set_velocity(velocity) ⇒ Object

Sets the velocity of the motor. Whereas -32767 is full speed backward, 0 is stop and 32767 is full speed forward. Depending on the acceleration (see BrickletPerformanceDC#set_motion), the motor is not immediately brought to the velocity but smoothly accelerated.

The velocity describes the duty cycle of the PWM with which the motor is controlled, e.g. a velocity of 3277 sets a PWM with a 10% duty cycle. You can not only control the duty cycle of the PWM but also the frequency, see BrickletPerformanceDC#set_pwm_frequency.



232
233
234
235
236
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 232

def set_velocity(velocity)
  check_validity

  send_request FUNCTION_SET_VELOCITY, [velocity], 's', 8, ''
end

#set_velocity_reached_callback_configuration(enabled) ⇒ Object

Enable/Disable CALLBACK_VELOCITY_REACHED callback.



497
498
499
500
501
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 497

def set_velocity_reached_callback_configuration(enabled)
  check_validity

  send_request FUNCTION_SET_VELOCITY_REACHED_CALLBACK_CONFIGURATION, [enabled], '?', 8, ''
end

#set_write_firmware_pointer(pointer) ⇒ Object

Sets the firmware pointer for BrickletPerformanceDC#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.



579
580
581
582
583
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 579

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 BrickletPerformanceDC#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.



593
594
595
596
597
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 593

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.



648
649
650
651
652
# File 'lib/tinkerforge/bricklet_performance_dc.rb', line 648

def write_uid(uid)
  check_validity

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