Class: Tinkerforge::BrickServo
- Defined in:
- lib/tinkerforge/brick_servo.rb
Overview
Drives up to 7 RC Servos with up to 3A
Constant Summary collapse
- DEVICE_IDENTIFIER =
:nodoc:
14
- DEVICE_DISPLAY_NAME =
:nodoc:
'Servo Brick'
- CALLBACK_UNDER_VOLTAGE =
This callback is triggered when the input voltage drops below the value set by BrickServo#set_minimum_voltage. The parameter is the current voltage.
26
- CALLBACK_POSITION_REACHED =
This callback is triggered when a position set by BrickServo#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 BrickServo#enable_position_reached_callback.
- .. note
-
Since we can’t get any feedback from the servo, this only works if the velocity (see BrickServo#set_velocity) 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
- CALLBACK_VELOCITY_REACHED =
This callback is triggered when a velocity set by BrickServo#set_velocity is reached. The parameters are the servo and the velocity that is reached.
You can enable this callback with BrickServo#enable_velocity_reached_callback.
- .. note
-
Since we can’t get any feedback from the servo, this only works if the acceleration (see BrickServo#set_acceleration) is set smaller or equal to the maximum acceleration of the servo. Otherwise the servo will lag behind the control value and the callback will be triggered too early.
28
- FUNCTION_ENABLE =
:nodoc:
1
- FUNCTION_DISABLE =
:nodoc:
2
- FUNCTION_IS_ENABLED =
:nodoc:
3
- FUNCTION_SET_POSITION =
:nodoc:
4
- FUNCTION_GET_POSITION =
:nodoc:
5
- FUNCTION_GET_CURRENT_POSITION =
:nodoc:
6
- FUNCTION_SET_VELOCITY =
:nodoc:
7
- FUNCTION_GET_VELOCITY =
:nodoc:
8
- FUNCTION_GET_CURRENT_VELOCITY =
:nodoc:
9
- FUNCTION_SET_ACCELERATION =
:nodoc:
10
- FUNCTION_GET_ACCELERATION =
:nodoc:
11
- FUNCTION_SET_OUTPUT_VOLTAGE =
:nodoc:
12
- FUNCTION_GET_OUTPUT_VOLTAGE =
:nodoc:
13
- FUNCTION_SET_PULSE_WIDTH =
:nodoc:
14
- FUNCTION_GET_PULSE_WIDTH =
:nodoc:
15
- FUNCTION_SET_DEGREE =
:nodoc:
16
- FUNCTION_GET_DEGREE =
:nodoc:
17
- FUNCTION_SET_PERIOD =
:nodoc:
18
- FUNCTION_GET_PERIOD =
:nodoc:
19
- FUNCTION_GET_SERVO_CURRENT =
:nodoc:
20
- FUNCTION_GET_OVERALL_CURRENT =
:nodoc:
21
- FUNCTION_GET_STACK_INPUT_VOLTAGE =
:nodoc:
22
- FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE =
:nodoc:
23
- FUNCTION_SET_MINIMUM_VOLTAGE =
:nodoc:
24
- FUNCTION_GET_MINIMUM_VOLTAGE =
:nodoc:
25
- FUNCTION_ENABLE_POSITION_REACHED_CALLBACK =
:nodoc:
29
- FUNCTION_DISABLE_POSITION_REACHED_CALLBACK =
:nodoc:
30
- FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED =
:nodoc:
31
- FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK =
:nodoc:
32
- FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK =
:nodoc:
33
- FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED =
:nodoc:
34
- FUNCTION_SET_SPITFP_BAUDRATE_CONFIG =
:nodoc:
231
- FUNCTION_GET_SPITFP_BAUDRATE_CONFIG =
:nodoc:
232
- FUNCTION_GET_SEND_TIMEOUT_COUNT =
:nodoc:
233
- FUNCTION_SET_SPITFP_BAUDRATE =
:nodoc:
234
- FUNCTION_GET_SPITFP_BAUDRATE =
:nodoc:
235
- FUNCTION_GET_SPITFP_ERROR_COUNT =
:nodoc:
237
- FUNCTION_ENABLE_STATUS_LED =
:nodoc:
238
- FUNCTION_DISABLE_STATUS_LED =
:nodoc:
239
- FUNCTION_IS_STATUS_LED_ENABLED =
:nodoc:
240
- FUNCTION_GET_PROTOCOL1_BRICKLET_NAME =
:nodoc:
241
- FUNCTION_GET_CHIP_TEMPERATURE =
:nodoc:
242
- FUNCTION_RESET =
:nodoc:
243
- FUNCTION_WRITE_BRICKLET_PLUGIN =
:nodoc:
246
- FUNCTION_READ_BRICKLET_PLUGIN =
:nodoc:
247
- FUNCTION_GET_IDENTITY =
:nodoc:
255
- COMMUNICATION_METHOD_NONE =
:nodoc:
0
- COMMUNICATION_METHOD_USB =
:nodoc:
1
- COMMUNICATION_METHOD_SPI_STACK =
:nodoc:
2
- COMMUNICATION_METHOD_CHIBI =
:nodoc:
3
- COMMUNICATION_METHOD_RS485 =
:nodoc:
4
- COMMUNICATION_METHOD_WIFI =
:nodoc:
5
- COMMUNICATION_METHOD_ETHERNET =
:nodoc:
6
- COMMUNICATION_METHOD_WIFI_V2 =
:nodoc:
7
Constants inherited from Device
Device::DEVICE_IDENTIFIER_CHECK_MATCH, Device::DEVICE_IDENTIFIER_CHECK_MISMATCH, Device::DEVICE_IDENTIFIER_CHECK_PENDING, Device::RESPONSE_EXPECTED_ALWAYS_TRUE, Device::RESPONSE_EXPECTED_FALSE, Device::RESPONSE_EXPECTED_INVALID_FUNCTION_ID, Device::RESPONSE_EXPECTED_TRUE
Instance Attribute Summary
Attributes inherited from Device
#callback_formats, #expected_response_function_id, #expected_response_sequence_number, #high_level_callbacks, #registered_callbacks, #replaced, #uid
Instance Method Summary collapse
-
#disable(servo_num) ⇒ Object
Disables a servo (0 to 6).
-
#disable_position_reached_callback ⇒ Object
Disables the CALLBACK_POSITION_REACHED callback.
-
#disable_status_led ⇒ Object
Disables the status LED.
-
#disable_velocity_reached_callback ⇒ Object
Disables the CALLBACK_VELOCITY_REACHED callback.
-
#enable(servo_num) ⇒ Object
Enables a servo (0 to 6).
-
#enable_position_reached_callback ⇒ Object
Enables the CALLBACK_POSITION_REACHED callback.
-
#enable_status_led ⇒ Object
Enables the status LED.
-
#enable_velocity_reached_callback ⇒ Object
Enables the CALLBACK_VELOCITY_REACHED callback.
-
#get_acceleration(servo_num) ⇒ Object
Returns the acceleration for the specified servo as set by BrickServo#set_acceleration.
-
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller.
-
#get_current_position(servo_num) ⇒ Object
Returns the current position of the specified servo.
-
#get_current_velocity(servo_num) ⇒ Object
Returns the current velocity of the specified servo.
-
#get_degree(servo_num) ⇒ Object
Returns the minimum and maximum degree for the specified servo as set by BrickServo#set_degree.
-
#get_external_input_voltage ⇒ Object
Returns the external input voltage.
-
#get_identity ⇒ Object
Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.
-
#get_minimum_voltage ⇒ Object
Returns the minimum voltage as set by BrickServo#set_minimum_voltage.
-
#get_output_voltage ⇒ Object
Returns the output voltage as specified by BrickServo#set_output_voltage.
-
#get_overall_current ⇒ Object
Returns the current consumption of all servos together.
-
#get_period(servo_num) ⇒ Object
Returns the period for the specified servo as set by BrickServo#set_period.
-
#get_position(servo_num) ⇒ Object
Returns the position of the specified servo as set by BrickServo#set_position.
-
#get_protocol1_bricklet_name(port) ⇒ Object
Returns the firmware and protocol version and the name of the Bricklet for a given port.
-
#get_pulse_width(servo_num) ⇒ Object
Returns the minimum and maximum pulse width for the specified servo as set by BrickServo#set_pulse_width.
-
#get_send_timeout_count(communication_method) ⇒ Object
Returns the timeout count for the different communication methods.
-
#get_servo_current(servo_num) ⇒ Object
Returns the current consumption of the specified servo.
-
#get_spitfp_baudrate(bricklet_port) ⇒ Object
Returns the baudrate for a given Bricklet port, see BrickServo#set_spitfp_baudrate.
-
#get_spitfp_baudrate_config ⇒ Object
Returns the baudrate config, see BrickServo#set_spitfp_baudrate_config.
-
#get_spitfp_error_count(bricklet_port) ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
-
#get_stack_input_voltage ⇒ Object
Returns the stack input voltage.
-
#get_velocity(servo_num) ⇒ Object
Returns the velocity of the specified servo as set by BrickServo#set_velocity.
-
#initialize(uid, ipcon) ⇒ BrickServo
constructor
Creates an object with the unique device ID
uid
and adds it to the IP Connectionipcon
. -
#is_enabled(servo_num) ⇒ Object
Returns true if the specified servo is enabled, false otherwise.
-
#is_position_reached_callback_enabled ⇒ Object
Returns true if CALLBACK_POSITION_REACHED callback is enabled, false otherwise.
-
#is_status_led_enabled ⇒ Object
Returns true if the status LED is enabled, false otherwise.
-
#is_velocity_reached_callback_enabled ⇒ Object
Returns true if CALLBACK_VELOCITY_REACHED callback is enabled, false otherwise.
-
#read_bricklet_plugin(port, offset) ⇒ Object
Reads 32 bytes of firmware from the bricklet attached at the given port.
-
#register_callback(id, &block) ⇒ Object
Registers a callback with ID
id
to the blockblock
. -
#reset ⇒ Object
Calling this function will reset the Brick.
-
#set_acceleration(servo_num, acceleration) ⇒ Object
Sets the acceleration of the specified servo.
-
#set_degree(servo_num, min, max) ⇒ Object
Sets the minimum and maximum degree for the specified servo (by default given as °/100).
-
#set_minimum_voltage(voltage) ⇒ Object
Sets the minimum voltage, below which the CALLBACK_UNDER_VOLTAGE callback is triggered.
-
#set_output_voltage(voltage) ⇒ Object
Sets the output voltages with which the servos are driven.
-
#set_period(servo_num, period) ⇒ Object
Sets the period of the specified servo.
-
#set_position(servo_num, position) ⇒ Object
Sets the position for the specified servo.
-
#set_pulse_width(servo_num, min, max) ⇒ Object
Sets the minimum and maximum pulse width of the specified servo.
-
#set_spitfp_baudrate(bricklet_port, baudrate) ⇒ Object
Sets the baudrate for a specific Bricklet port.
-
#set_spitfp_baudrate_config(enable_dynamic_baudrate, minimum_dynamic_baudrate) ⇒ Object
The SPITF protocol can be used with a dynamic baudrate.
-
#set_velocity(servo_num, velocity) ⇒ Object
Sets the maximum velocity of the specified servo.
-
#write_bricklet_plugin(port, offset, chunk) ⇒ Object
Writes 32 bytes of firmware to the bricklet attached at the given port.
Methods inherited from Device
#check_validity, #dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all
Constructor Details
#initialize(uid, ipcon) ⇒ BrickServo
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
Instance Method Details
#disable(servo_num) ⇒ Object
Disables a servo (0 to 6). Disabled servos are not driven at all, i.e. a disabled servo will not hold its position if a load is applied.
177 178 179 180 181 |
# File 'lib/tinkerforge/brick_servo.rb', line 177 def disable(servo_num) check_validity send_request FUNCTION_DISABLE, [servo_num], 'C', 8, '' end |
#disable_position_reached_callback ⇒ Object
Disables the CALLBACK_POSITION_REACHED callback.
- .. versionadded
-
2.0.1$nbsp;(Firmware)
449 450 451 452 453 |
# File 'lib/tinkerforge/brick_servo.rb', line 449 def disable_position_reached_callback check_validity send_request FUNCTION_DISABLE_POSITION_REACHED_CALLBACK, [], '', 8, '' end |
#disable_status_led ⇒ Object
Disables the status LED.
The status LED is the blue LED next to the USB connector. If enabled is is on and it flickers if data is transfered. If disabled it is always off.
The default state is enabled.
- .. versionadded
-
2.3.1$nbsp;(Firmware)
615 616 617 618 619 |
# File 'lib/tinkerforge/brick_servo.rb', line 615 def disable_status_led check_validity send_request FUNCTION_DISABLE_STATUS_LED, [], '', 8, '' end |
#disable_velocity_reached_callback ⇒ Object
Disables the CALLBACK_VELOCITY_REACHED callback.
Default is disabled.
- .. versionadded
-
2.0.1$nbsp;(Firmware)
480 481 482 483 484 |
# File 'lib/tinkerforge/brick_servo.rb', line 480 def disable_velocity_reached_callback check_validity send_request FUNCTION_DISABLE_VELOCITY_REACHED_CALLBACK, [], '', 8, '' end |
#enable(servo_num) ⇒ Object
Enables a servo (0 to 6). If a servo is enabled, the configured position, velocity, acceleration, etc. are applied immediately.
169 170 171 172 173 |
# File 'lib/tinkerforge/brick_servo.rb', line 169 def enable(servo_num) check_validity send_request FUNCTION_ENABLE, [servo_num], 'C', 8, '' end |
#enable_position_reached_callback ⇒ Object
Enables the CALLBACK_POSITION_REACHED callback.
Default is disabled.
- .. versionadded
-
2.0.1$nbsp;(Firmware)
440 441 442 443 444 |
# File 'lib/tinkerforge/brick_servo.rb', line 440 def enable_position_reached_callback check_validity send_request FUNCTION_ENABLE_POSITION_REACHED_CALLBACK, [], '', 8, '' end |
#enable_status_led ⇒ Object
Enables the status LED.
The status LED is the blue LED next to the USB connector. If enabled is is on and it flickers if data is transfered. If disabled it is always off.
The default state is enabled.
- .. versionadded
-
2.3.1$nbsp;(Firmware)
601 602 603 604 605 |
# File 'lib/tinkerforge/brick_servo.rb', line 601 def enable_status_led check_validity send_request FUNCTION_ENABLE_STATUS_LED, [], '', 8, '' end |
#enable_velocity_reached_callback ⇒ Object
Enables the CALLBACK_VELOCITY_REACHED callback.
Default is disabled.
- .. versionadded
-
2.0.1$nbsp;(Firmware)
469 470 471 472 473 |
# File 'lib/tinkerforge/brick_servo.rb', line 469 def enable_velocity_reached_callback check_validity send_request FUNCTION_ENABLE_VELOCITY_REACHED_CALLBACK, [], '', 8, '' end |
#get_acceleration(servo_num) ⇒ Object
Returns the acceleration for the specified servo as set by BrickServo#set_acceleration.
259 260 261 262 263 |
# File 'lib/tinkerforge/brick_servo.rb', line 259 def get_acceleration(servo_num) check_validity send_request FUNCTION_GET_ACCELERATION, [servo_num], 'C', 10, 'S' end |
#get_chip_temperature ⇒ Object
Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!
The temperature is only proportional to the real temperature and it has an accuracy of ±15%. Practically it is only useful as an indicator for temperature changes.
647 648 649 650 651 |
# File 'lib/tinkerforge/brick_servo.rb', line 647 def get_chip_temperature check_validity send_request FUNCTION_GET_CHIP_TEMPERATURE, [], '', 10, 's' end |
#get_current_position(servo_num) ⇒ Object
Returns the current position of the specified servo. This may not be the value of BrickServo#set_position if the servo is currently approaching a position goal.
214 215 216 217 218 |
# File 'lib/tinkerforge/brick_servo.rb', line 214 def get_current_position(servo_num) check_validity send_request FUNCTION_GET_CURRENT_POSITION, [servo_num], 'C', 10, 's' end |
#get_current_velocity(servo_num) ⇒ Object
Returns the current velocity of the specified servo. This may not be the value of BrickServo#set_velocity if the servo is currently approaching a velocity goal.
241 242 243 244 245 |
# File 'lib/tinkerforge/brick_servo.rb', line 241 def get_current_velocity(servo_num) check_validity send_request FUNCTION_GET_CURRENT_VELOCITY, [servo_num], 'C', 10, 'S' end |
#get_degree(servo_num) ⇒ Object
Returns the minimum and maximum degree for the specified servo as set by BrickServo#set_degree.
346 347 348 349 350 |
# File 'lib/tinkerforge/brick_servo.rb', line 346 def get_degree(servo_num) check_validity send_request FUNCTION_GET_DEGREE, [servo_num], 'C', 12, 's s' end |
#get_external_input_voltage ⇒ Object
Returns the external input voltage. The external input voltage is given via the black power input connector on the Servo Brick.
If there is an external input voltage and a stack input voltage, the motors will be driven by the external input voltage. If there is only a stack voltage present, the motors will be driven by this voltage.
- .. warning
-
This means, if you have a high stack voltage and a low external voltage, the motors will be driven with the low external voltage. If you then remove the external connection, it will immediately be driven by the high stack voltage
411 412 413 414 415 |
# File 'lib/tinkerforge/brick_servo.rb', line 411 def get_external_input_voltage check_validity send_request FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE, [], '', 10, 'S' end |
#get_identity ⇒ Object
Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.
The position is the position in the stack from ‘0’ (bottom) to ‘8’ (top).
The device identifier numbers can be found :ref:‘here <device_identifier>`. |device_identifier_constant|
695 696 697 |
# File 'lib/tinkerforge/brick_servo.rb', line 695 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end |
#get_minimum_voltage ⇒ Object
Returns the minimum voltage as set by BrickServo#set_minimum_voltage
429 430 431 432 433 |
# File 'lib/tinkerforge/brick_servo.rb', line 429 def get_minimum_voltage check_validity send_request FUNCTION_GET_MINIMUM_VOLTAGE, [], '', 10, 'S' end |
#get_output_voltage ⇒ Object
Returns the output voltage as specified by BrickServo#set_output_voltage.
278 279 280 281 282 |
# File 'lib/tinkerforge/brick_servo.rb', line 278 def get_output_voltage check_validity send_request FUNCTION_GET_OUTPUT_VOLTAGE, [], '', 10, 'S' end |
#get_overall_current ⇒ Object
Returns the current consumption of all servos together.
384 385 386 387 388 |
# File 'lib/tinkerforge/brick_servo.rb', line 384 def get_overall_current check_validity send_request FUNCTION_GET_OVERALL_CURRENT, [], '', 10, 'S' end |
#get_period(servo_num) ⇒ Object
Returns the period for the specified servo as set by BrickServo#set_period.
370 371 372 373 374 |
# File 'lib/tinkerforge/brick_servo.rb', line 370 def get_period(servo_num) check_validity send_request FUNCTION_GET_PERIOD, [servo_num], 'C', 10, 'S' end |
#get_position(servo_num) ⇒ Object
Returns the position of the specified servo as set by BrickServo#set_position.
205 206 207 208 209 |
# File 'lib/tinkerforge/brick_servo.rb', line 205 def get_position(servo_num) check_validity send_request FUNCTION_GET_POSITION, [servo_num], 'C', 10, 's' end |
#get_protocol1_bricklet_name(port) ⇒ Object
Returns the firmware and protocol version and the name of the Bricklet for a given port.
This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet plugins.
635 636 637 638 639 |
# File 'lib/tinkerforge/brick_servo.rb', line 635 def get_protocol1_bricklet_name(port) check_validity send_request FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 52, 'C C3 Z40' end |
#get_pulse_width(servo_num) ⇒ Object
Returns the minimum and maximum pulse width for the specified servo as set by BrickServo#set_pulse_width.
305 306 307 308 309 |
# File 'lib/tinkerforge/brick_servo.rb', line 305 def get_pulse_width(servo_num) check_validity send_request FUNCTION_GET_PULSE_WIDTH, [servo_num], 'C', 12, 'S S' end |
#get_send_timeout_count(communication_method) ⇒ Object
Returns the timeout count for the different communication methods.
The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.
This function is mostly used for debugging during development, in normal operation the counters should nearly always stay at 0.
- .. versionadded
-
2.3.2$nbsp;(Firmware)
538 539 540 541 542 |
# File 'lib/tinkerforge/brick_servo.rb', line 538 def get_send_timeout_count(communication_method) check_validity send_request FUNCTION_GET_SEND_TIMEOUT_COUNT, [communication_method], 'C', 12, 'L' end |
#get_servo_current(servo_num) ⇒ Object
Returns the current consumption of the specified servo.
377 378 379 380 381 |
# File 'lib/tinkerforge/brick_servo.rb', line 377 def get_servo_current(servo_num) check_validity send_request FUNCTION_GET_SERVO_CURRENT, [servo_num], 'C', 10, 'S' end |
#get_spitfp_baudrate(bricklet_port) ⇒ Object
Returns the baudrate for a given Bricklet port, see BrickServo#set_spitfp_baudrate.
- .. versionadded
-
2.3.2$nbsp;(Firmware)
568 569 570 571 572 |
# File 'lib/tinkerforge/brick_servo.rb', line 568 def get_spitfp_baudrate(bricklet_port) check_validity send_request FUNCTION_GET_SPITFP_BAUDRATE, [bricklet_port], 'k', 12, 'L' end |
#get_spitfp_baudrate_config ⇒ Object
Returns the baudrate config, see BrickServo#set_spitfp_baudrate_config.
- .. versionadded
-
2.3.4$nbsp;(Firmware)
524 525 526 527 528 |
# File 'lib/tinkerforge/brick_servo.rb', line 524 def get_spitfp_baudrate_config check_validity send_request FUNCTION_GET_SPITFP_BAUDRATE_CONFIG, [], '', 13, '? L' end |
#get_spitfp_error_count(bricklet_port) ⇒ Object
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
-
ACK checksum errors,
-
message checksum errors,
-
framing errors and
-
overflow errors.
The errors counts are for errors that occur on the Brick side. All Bricklets have a similar function that returns the errors on the Bricklet side.
- .. versionadded
-
2.3.2$nbsp;(Firmware)
587 588 589 590 591 |
# File 'lib/tinkerforge/brick_servo.rb', line 587 def get_spitfp_error_count(bricklet_port) check_validity send_request FUNCTION_GET_SPITFP_ERROR_COUNT, [bricklet_port], 'k', 24, 'L L L L' end |
#get_stack_input_voltage ⇒ Object
Returns the stack input voltage. The stack input voltage is the voltage that is supplied via the stack, i.e. it is given by a Step-Down or Step-Up Power Supply.
393 394 395 396 397 |
# File 'lib/tinkerforge/brick_servo.rb', line 393 def get_stack_input_voltage check_validity send_request FUNCTION_GET_STACK_INPUT_VOLTAGE, [], '', 10, 'S' end |
#get_velocity(servo_num) ⇒ Object
Returns the velocity of the specified servo as set by BrickServo#set_velocity.
232 233 234 235 236 |
# File 'lib/tinkerforge/brick_servo.rb', line 232 def get_velocity(servo_num) check_validity send_request FUNCTION_GET_VELOCITY, [servo_num], 'C', 10, 'S' end |
#is_enabled(servo_num) ⇒ Object
Returns true if the specified servo is enabled, false otherwise.
184 185 186 187 188 |
# File 'lib/tinkerforge/brick_servo.rb', line 184 def is_enabled(servo_num) check_validity send_request FUNCTION_IS_ENABLED, [servo_num], 'C', 9, '?' end |
#is_position_reached_callback_enabled ⇒ Object
Returns true if CALLBACK_POSITION_REACHED callback is enabled, false otherwise.
- .. versionadded
-
2.0.1$nbsp;(Firmware)
458 459 460 461 462 |
# File 'lib/tinkerforge/brick_servo.rb', line 458 def is_position_reached_callback_enabled check_validity send_request FUNCTION_IS_POSITION_REACHED_CALLBACK_ENABLED, [], '', 9, '?' end |
#is_status_led_enabled ⇒ Object
Returns true if the status LED is enabled, false otherwise.
- .. versionadded
-
2.3.1$nbsp;(Firmware)
624 625 626 627 628 |
# File 'lib/tinkerforge/brick_servo.rb', line 624 def is_status_led_enabled check_validity send_request FUNCTION_IS_STATUS_LED_ENABLED, [], '', 9, '?' end |
#is_velocity_reached_callback_enabled ⇒ Object
Returns true if CALLBACK_VELOCITY_REACHED callback is enabled, false otherwise.
- .. versionadded
-
2.0.1$nbsp;(Firmware)
489 490 491 492 493 |
# File 'lib/tinkerforge/brick_servo.rb', line 489 def is_velocity_reached_callback_enabled check_validity send_request FUNCTION_IS_VELOCITY_REACHED_CALLBACK_ENABLED, [], '', 9, '?' end |
#read_bricklet_plugin(port, offset) ⇒ Object
Reads 32 bytes of firmware from the bricklet attached at the given port. The bytes are read starting at the position offset * 32.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
681 682 683 684 685 |
# File 'lib/tinkerforge/brick_servo.rb', line 681 def read_bricklet_plugin(port, offset) check_validity send_request FUNCTION_READ_BRICKLET_PLUGIN, [port, offset], 'k C', 40, 'C32' end |
#register_callback(id, &block) ⇒ Object
Registers a callback with ID id
to the block block
.
700 701 702 703 |
# File 'lib/tinkerforge/brick_servo.rb', line 700 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end |
#reset ⇒ Object
Calling this function will reset the Brick. Calling this function on a Brick inside of a stack will reset the whole stack.
After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!
659 660 661 662 663 |
# File 'lib/tinkerforge/brick_servo.rb', line 659 def reset check_validity send_request FUNCTION_RESET, [], '', 8, '' end |
#set_acceleration(servo_num, acceleration) ⇒ Object
Sets the acceleration of the specified servo.
The minimum acceleration is 1 and the maximum acceleration is 65535. With a value of 65535 the velocity will be set immediately (no acceleration).
251 252 253 254 255 |
# File 'lib/tinkerforge/brick_servo.rb', line 251 def set_acceleration(servo_num, acceleration) check_validity send_request FUNCTION_SET_ACCELERATION, [servo_num, acceleration], 'C S', 8, '' end |
#set_degree(servo_num, min, max) ⇒ Object
Sets the minimum and maximum degree for the specified servo (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 BrickServo#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 BrickServo#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. BrickServo#set_position now controls the rpm.
The minimum must be smaller than the maximum.
338 339 340 341 342 |
# File 'lib/tinkerforge/brick_servo.rb', line 338 def set_degree(servo_num, min, max) check_validity send_request FUNCTION_SET_DEGREE, [servo_num, min, max], 'C s s', 8, '' end |
#set_minimum_voltage(voltage) ⇒ Object
Sets the minimum voltage, below which the CALLBACK_UNDER_VOLTAGE callback is triggered. The minimum possible value that works with the Servo Brick is 5V. You can use this function to detect the discharge of a battery that is used to drive the stepper motor. If you have a fixed power supply, you likely do not need this functionality.
422 423 424 425 426 |
# File 'lib/tinkerforge/brick_servo.rb', line 422 def set_minimum_voltage(voltage) check_validity send_request FUNCTION_SET_MINIMUM_VOLTAGE, [voltage], 'S', 8, '' end |
#set_output_voltage(voltage) ⇒ Object
Sets the output voltages with which the servos are driven.
- .. note
-
We recommend that you set this value to the maximum voltage that is specified for your servo, most servos achieve their maximum force only with high voltages.
271 272 273 274 275 |
# File 'lib/tinkerforge/brick_servo.rb', line 271 def set_output_voltage(voltage) check_validity send_request FUNCTION_SET_OUTPUT_VOLTAGE, [voltage], 'S', 8, '' end |
#set_period(servo_num, period) ⇒ Object
Sets the period of the specified servo.
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 will most likely work fine.
363 364 365 366 367 |
# File 'lib/tinkerforge/brick_servo.rb', line 363 def set_period(servo_num, period) check_validity send_request FUNCTION_SET_PERIOD, [servo_num, period], 'C S', 8, '' end |
#set_position(servo_num, position) ⇒ Object
Sets the position for the specified servo.
The default range of the position is -9000 to 9000, but it can be specified according to your servo with BrickServo#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 BrickServo#set_degree.
198 199 200 201 202 |
# File 'lib/tinkerforge/brick_servo.rb', line 198 def set_position(servo_num, position) check_validity send_request FUNCTION_SET_POSITION, [servo_num, position], 'C s', 8, '' end |
#set_pulse_width(servo_num, min, max) ⇒ Object
Sets the minimum and maximum pulse width of the specified servo.
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.
The minimum must be smaller than the maximum.
297 298 299 300 301 |
# File 'lib/tinkerforge/brick_servo.rb', line 297 def set_pulse_width(servo_num, min, max) check_validity send_request FUNCTION_SET_PULSE_WIDTH, [servo_num, min, max], 'C S S', 8, '' end |
#set_spitfp_baudrate(bricklet_port, baudrate) ⇒ Object
Sets the baudrate for a specific Bricklet port.
If you want to increase the throughput of Bricklets you can increase the baudrate. If you get a high error count because of high interference (see BrickServo#get_spitfp_error_count) you can decrease the baudrate.
If the dynamic baudrate feature is enabled, the baudrate set by this function corresponds to the maximum baudrate (see BrickServo#set_spitfp_baudrate_config).
Regulatory testing is done with the default baudrate. If CE compatibility or similar is necessary in your applications we recommend to not change the baudrate.
- .. versionadded
-
2.3.2$nbsp;(Firmware)
559 560 561 562 563 |
# File 'lib/tinkerforge/brick_servo.rb', line 559 def set_spitfp_baudrate(bricklet_port, baudrate) check_validity send_request FUNCTION_SET_SPITFP_BAUDRATE, [bricklet_port, baudrate], 'k L', 8, '' end |
#set_spitfp_baudrate_config(enable_dynamic_baudrate, minimum_dynamic_baudrate) ⇒ Object
The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is enabled, the Brick will try to adapt the baudrate for the communication between Bricks and Bricklets according to the amount of data that is transferred.
The baudrate will be increased exponentially if lots of data is sent/received and decreased linearly if little data is sent/received.
This lowers the baudrate in applications where little data is transferred (e.g. a weather station) and increases the robustness. If there is lots of data to transfer (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
In cases where some data has to transferred as fast as possible every few seconds (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn the dynamic baudrate off to get the highest possible performance.
The maximum value of the baudrate can be set per port with the function BrickServo#set_spitfp_baudrate. If the dynamic baudrate is disabled, the baudrate as set by BrickServo#set_spitfp_baudrate will be used statically.
- .. versionadded
-
2.3.4$nbsp;(Firmware)
515 516 517 518 519 |
# File 'lib/tinkerforge/brick_servo.rb', line 515 def set_spitfp_baudrate_config(enable_dynamic_baudrate, minimum_dynamic_baudrate) check_validity send_request FUNCTION_SET_SPITFP_BAUDRATE_CONFIG, [enable_dynamic_baudrate, minimum_dynamic_baudrate], '? L', 8, '' end |
#set_velocity(servo_num, velocity) ⇒ Object
Sets the maximum velocity of the specified servo. The velocity is accelerated according to the value set by BrickServo#set_acceleration.
The minimum velocity is 0 (no movement) and the maximum velocity is 65535. With a value of 65535 the position will be set immediately (no velocity).
225 226 227 228 229 |
# File 'lib/tinkerforge/brick_servo.rb', line 225 def set_velocity(servo_num, velocity) check_validity send_request FUNCTION_SET_VELOCITY, [servo_num, velocity], 'C S', 8, '' end |
#write_bricklet_plugin(port, offset, chunk) ⇒ Object
Writes 32 bytes of firmware to the bricklet attached at the given port. The bytes are written to the position offset * 32.
This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.
670 671 672 673 674 |
# File 'lib/tinkerforge/brick_servo.rb', line 670 def write_bricklet_plugin(port, offset, chunk) check_validity send_request FUNCTION_WRITE_BRICKLET_PLUGIN, [port, offset, chunk], 'k C C32', 8, '' end |