Class: Tinkerforge::BrickStepper

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

Overview

Drives one bipolar stepper motor with up to 38V and 2.5A per phase

Constant Summary collapse

DEVICE_IDENTIFIER =

:nodoc:

15
DEVICE_DISPLAY_NAME =

:nodoc:

'Stepper Brick'
CALLBACK_UNDER_VOLTAGE =

This callback is triggered when the input voltage drops below the value set by BrickStepper#set_minimum_voltage. The parameter is the current voltage given in mV.

31
CALLBACK_POSITION_REACHED =

This callback is triggered when a position set by BrickStepper#set_steps or BrickStepper#set_target_position is reached.

.. note

Since we can’t get any feedback from the stepper motor, this only works if the acceleration (see BrickStepper#set_speed_ramping) 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.

32
CALLBACK_ALL_DATA =

This callback is triggered periodically with the period that is set by BrickStepper#set_all_data_period. The parameters are: the current velocity, the current position, the remaining steps, the stack voltage, the external voltage and the current consumption of the stepper motor.

40
CALLBACK_NEW_STATE =

This callback is triggered whenever the Stepper Brick enters a new state. It returns the new state as well as the previous state.

41
FUNCTION_SET_MAX_VELOCITY =

:nodoc:

1
FUNCTION_GET_MAX_VELOCITY =

:nodoc:

2
FUNCTION_GET_CURRENT_VELOCITY =

:nodoc:

3
FUNCTION_SET_SPEED_RAMPING =

:nodoc:

4
FUNCTION_GET_SPEED_RAMPING =

:nodoc:

5
FUNCTION_FULL_BRAKE =

:nodoc:

6
FUNCTION_SET_CURRENT_POSITION =

:nodoc:

7
FUNCTION_GET_CURRENT_POSITION =

:nodoc:

8
FUNCTION_SET_TARGET_POSITION =

:nodoc:

9
FUNCTION_GET_TARGET_POSITION =

:nodoc:

10
FUNCTION_SET_STEPS =

:nodoc:

11
FUNCTION_GET_STEPS =

:nodoc:

12
FUNCTION_GET_REMAINING_STEPS =

:nodoc:

13
FUNCTION_SET_STEP_MODE =

:nodoc:

14
FUNCTION_GET_STEP_MODE =

:nodoc:

15
FUNCTION_DRIVE_FORWARD =

:nodoc:

16
FUNCTION_DRIVE_BACKWARD =

:nodoc:

17
FUNCTION_STOP =

:nodoc:

18
FUNCTION_GET_STACK_INPUT_VOLTAGE =

:nodoc:

19
FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE =

:nodoc:

20
FUNCTION_GET_CURRENT_CONSUMPTION =

:nodoc:

21
FUNCTION_SET_MOTOR_CURRENT =

:nodoc:

22
FUNCTION_GET_MOTOR_CURRENT =

:nodoc:

23
FUNCTION_ENABLE =

:nodoc:

24
FUNCTION_DISABLE =

:nodoc:

25
FUNCTION_IS_ENABLED =

:nodoc:

26
FUNCTION_SET_DECAY =

:nodoc:

27
FUNCTION_GET_DECAY =

:nodoc:

28
FUNCTION_SET_MINIMUM_VOLTAGE =

:nodoc:

29
FUNCTION_GET_MINIMUM_VOLTAGE =

:nodoc:

30
FUNCTION_SET_SYNC_RECT =

:nodoc:

33
FUNCTION_IS_SYNC_RECT =

:nodoc:

34
FUNCTION_SET_TIME_BASE =

:nodoc:

35
FUNCTION_GET_TIME_BASE =

:nodoc:

36
FUNCTION_GET_ALL_DATA =

:nodoc:

37
FUNCTION_SET_ALL_DATA_PERIOD =

:nodoc:

38
FUNCTION_GET_ALL_DATA_PERIOD =

:nodoc:

39
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_GET_IDENTITY =

:nodoc:

255
STEP_MODE_FULL_STEP =

:nodoc:

1
STEP_MODE_HALF_STEP =

:nodoc:

2
STEP_MODE_QUARTER_STEP =

:nodoc:

4
STEP_MODE_EIGHTH_STEP =

:nodoc:

8
STATE_STOP =

:nodoc:

1
STATE_ACCELERATION =

:nodoc:

2
STATE_RUN =

:nodoc:

3
STATE_DEACCELERATION =

:nodoc:

4
STATE_DIRECTION_CHANGE_TO_FORWARD =

:nodoc:

5
STATE_DIRECTION_CHANGE_TO_BACKWARD =

:nodoc:

6

Constants inherited from Device

Device::RESPONSE_EXPECTED_ALWAYS_FALSE, 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, #registered_callbacks, #uid

Instance Method Summary collapse

Methods inherited from Device

#dequeue_response, #enqueue_response, #get_api_version, #get_response_expected, #send_request, #set_response_expected, #set_response_expected_all

Constructor Details

#initialize(uid, ipcon) ⇒ BrickStepper

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



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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/tinkerforge/brick_stepper.rb', line 101

def initialize(uid, ipcon)
  super uid, ipcon

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_SET_MAX_VELOCITY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MAX_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CURRENT_VELOCITY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_SPEED_RAMPING] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_SPEED_RAMPING] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_FULL_BRAKE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SET_CURRENT_POSITION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_CURRENT_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_TARGET_POSITION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_TARGET_POSITION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_STEPS] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STEPS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_REMAINING_STEPS] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_STEP_MODE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STEP_MODE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_DRIVE_FORWARD] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_DRIVE_BACKWARD] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_STOP] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_STACK_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CURRENT_CONSUMPTION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MOTOR_CURRENT] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_MOTOR_CURRENT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_ENABLE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_DISABLE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_IS_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_DECAY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_DECAY] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_MINIMUM_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[CALLBACK_UNDER_VOLTAGE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_POSITION_REACHED] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_SET_SYNC_RECT] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_IS_SYNC_RECT] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_TIME_BASE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_TIME_BASE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_SET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_TRUE
  @response_expected[FUNCTION_GET_ALL_DATA_PERIOD] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[CALLBACK_ALL_DATA] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[CALLBACK_NEW_STATE] = RESPONSE_EXPECTED_ALWAYS_FALSE
  @response_expected[FUNCTION_ENABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_DISABLE_STATUS_LED] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_IS_STATUS_LED_ENABLED] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_PROTOCOL1_BRICKLET_NAME] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_GET_CHIP_TEMPERATURE] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_RESET] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_UNDER_VOLTAGE] = 'S'
  @callback_formats[CALLBACK_POSITION_REACHED] = 'l'
  @callback_formats[CALLBACK_ALL_DATA] = 'S l l S S S'
  @callback_formats[CALLBACK_NEW_STATE] = 'C C'
end

Instance Method Details

#disableObject

Disables the driver chip. The configurations are kept (maximum velocity, acceleration, etc) but the motor is not driven until it is enabled again.



361
362
363
# File 'lib/tinkerforge/brick_stepper.rb', line 361

def disable
  send_request(FUNCTION_DISABLE, [], '', 0, '')
end

#disable_status_ledObject

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)



504
505
506
# File 'lib/tinkerforge/brick_stepper.rb', line 504

def disable_status_led
  send_request(FUNCTION_DISABLE_STATUS_LED, [], '', 0, '')
end

#drive_backwardObject

Drives the stepper motor backward until BrickStepper#drive_forward or BrickStepper#stop is triggered. The velocity, acceleration and deacceleration as set by BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping will be used.



299
300
301
# File 'lib/tinkerforge/brick_stepper.rb', line 299

def drive_backward
  send_request(FUNCTION_DRIVE_BACKWARD, [], '', 0, '')
end

#drive_forwardObject

Drives the stepper motor forward until BrickStepper#drive_backward or BrickStepper#stop is called. The velocity, acceleration and deacceleration as set by BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping will be used.



292
293
294
# File 'lib/tinkerforge/brick_stepper.rb', line 292

def drive_forward
  send_request(FUNCTION_DRIVE_FORWARD, [], '', 0, '')
end

#enableObject

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



355
356
357
# File 'lib/tinkerforge/brick_stepper.rb', line 355

def enable
  send_request(FUNCTION_ENABLE, [], '', 0, '')
end

#enable_status_ledObject

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)



492
493
494
# File 'lib/tinkerforge/brick_stepper.rb', line 492

def enable_status_led
  send_request(FUNCTION_ENABLE_STATUS_LED, [], '', 0, '')
end

#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 BrickStepper#stop if you just want to stop the motor.



210
211
212
# File 'lib/tinkerforge/brick_stepper.rb', line 210

def full_brake
  send_request(FUNCTION_FULL_BRAKE, [], '', 0, '')
end

#get_all_dataObject

Returns the following parameters: The current velocity, the current position, the remaining steps, the stack voltage, the external voltage and the current consumption of the stepper motor.

There is also a callback for this function, see CALLBACK_ALL_DATA.



469
470
471
# File 'lib/tinkerforge/brick_stepper.rb', line 469

def get_all_data
  send_request(FUNCTION_GET_ALL_DATA, [], '', 16, 'S l l S S S')
end

#get_all_data_periodObject

Returns the period as set by BrickStepper#set_all_data_period.



480
481
482
# File 'lib/tinkerforge/brick_stepper.rb', line 480

def get_all_data_period
  send_request(FUNCTION_GET_ALL_DATA_PERIOD, [], '', 4, 'L')
end

#get_chip_temperatureObject

Returns the temperature in °C/10 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.



530
531
532
# File 'lib/tinkerforge/brick_stepper.rb', line 530

def get_chip_temperature
  send_request(FUNCTION_GET_CHIP_TEMPERATURE, [], '', 2, 's')
end

#get_current_consumptionObject

Returns the current consumption of the motor in mA.



333
334
335
# File 'lib/tinkerforge/brick_stepper.rb', line 333

def get_current_consumption
  send_request(FUNCTION_GET_CURRENT_CONSUMPTION, [], '', 2, 'S')
end

#get_current_positionObject

Returns the current position of the stepper motor in steps. On startup the position is 0. The steps are counted with all possible driving functions (BrickStepper#set_target_position, BrickStepper#set_steps, BrickStepper#drive_forward or BrickStepper#drive_backward). It also is possible to reset the steps to 0 or set them to any other desired value with BrickStepper#set_current_position.



226
227
228
# File 'lib/tinkerforge/brick_stepper.rb', line 226

def get_current_position
  send_request(FUNCTION_GET_CURRENT_POSITION, [], '', 4, 'l')
end

#get_current_velocityObject

Returns the current velocity of the stepper motor in steps per second.



176
177
178
# File 'lib/tinkerforge/brick_stepper.rb', line 176

def get_current_velocity
  send_request(FUNCTION_GET_CURRENT_VELOCITY, [], '', 2, 'S')
end

#get_decayObject

Returns the decay mode as set by BrickStepper#set_decay.



402
403
404
# File 'lib/tinkerforge/brick_stepper.rb', line 402

def get_decay
  send_request(FUNCTION_GET_DECAY, [], '', 2, 'S')
end

#get_external_input_voltageObject

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

If there is an external input voltage and a stack input voltage, the motor will be driven by the external input voltage. If there is only a stack voltage present, the motor will be driven by this voltage.

.. warning

This means, if you have a high stack voltage and a low external voltage, the motor 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



328
329
330
# File 'lib/tinkerforge/brick_stepper.rb', line 328

def get_external_input_voltage
  send_request(FUNCTION_GET_EXTERNAL_INPUT_VOLTAGE, [], '', 2, 'S')
end

#get_identityObject

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 can be ‘0’-‘8’ (stack position).

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



552
553
554
# File 'lib/tinkerforge/brick_stepper.rb', line 552

def get_identity
  send_request(FUNCTION_GET_IDENTITY, [], '', 25, 'Z8 Z8 k C3 C3 S')
end

#get_max_velocityObject

Returns the velocity as set by BrickStepper#set_max_velocity.



171
172
173
# File 'lib/tinkerforge/brick_stepper.rb', line 171

def get_max_velocity
  send_request(FUNCTION_GET_MAX_VELOCITY, [], '', 2, 'S')
end

#get_minimum_voltageObject

Returns the minimum voltage as set by BrickStepper#set_minimum_voltage.



418
419
420
# File 'lib/tinkerforge/brick_stepper.rb', line 418

def get_minimum_voltage
  send_request(FUNCTION_GET_MINIMUM_VOLTAGE, [], '', 2, 'S')
end

#get_motor_currentObject

Returns the current as set by BrickStepper#set_motor_current.



349
350
351
# File 'lib/tinkerforge/brick_stepper.rb', line 349

def get_motor_current
  send_request(FUNCTION_GET_MOTOR_CURRENT, [], '', 2, '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.



520
521
522
# File 'lib/tinkerforge/brick_stepper.rb', line 520

def get_protocol1_bricklet_name(port)
  send_request(FUNCTION_GET_PROTOCOL1_BRICKLET_NAME, [port], 'k', 44, 'C C3 Z40')
end

#get_remaining_stepsObject

Returns the remaining steps of the last call of BrickStepper#set_steps. For example, if BrickStepper#set_steps is called with 2000 and BrickStepper#get_remaining_steps is called after the motor has run for 500 steps, it will return 1500.



265
266
267
# File 'lib/tinkerforge/brick_stepper.rb', line 265

def get_remaining_steps
  send_request(FUNCTION_GET_REMAINING_STEPS, [], '', 4, 'l')
end

#get_speed_rampingObject

Returns the acceleration and deacceleration as set by BrickStepper#set_speed_ramping.



198
199
200
# File 'lib/tinkerforge/brick_stepper.rb', line 198

def get_speed_ramping
  send_request(FUNCTION_GET_SPEED_RAMPING, [], '', 4, 'S S')
end

#get_stack_input_voltageObject

Returns the stack input voltage in mV. 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.



312
313
314
# File 'lib/tinkerforge/brick_stepper.rb', line 312

def get_stack_input_voltage
  send_request(FUNCTION_GET_STACK_INPUT_VOLTAGE, [], '', 2, 'S')
end

#get_step_modeObject

Returns the step mode as set by BrickStepper#set_step_mode.



285
286
287
# File 'lib/tinkerforge/brick_stepper.rb', line 285

def get_step_mode
  send_request(FUNCTION_GET_STEP_MODE, [], '', 1, 'C')
end

#get_stepsObject

Returns the last steps as set by BrickStepper#set_steps.



257
258
259
# File 'lib/tinkerforge/brick_stepper.rb', line 257

def get_steps
  send_request(FUNCTION_GET_STEPS, [], '', 4, 'l')
end

#get_target_positionObject

Returns the last target position as set by BrickStepper#set_target_position.



244
245
246
# File 'lib/tinkerforge/brick_stepper.rb', line 244

def get_target_position
  send_request(FUNCTION_GET_TARGET_POSITION, [], '', 4, 'l')
end

#get_time_baseObject

Returns the time base as set by BrickStepper#set_time_base.



460
461
462
# File 'lib/tinkerforge/brick_stepper.rb', line 460

def get_time_base
  send_request(FUNCTION_GET_TIME_BASE, [], '', 4, 'L')
end

#is_enabledObject

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



366
367
368
# File 'lib/tinkerforge/brick_stepper.rb', line 366

def is_enabled
  send_request(FUNCTION_IS_ENABLED, [], '', 1, '?')
end

#is_status_led_enabledObject

Returns true if the status LED is enabled, false otherwise.

.. versionadded

2.3.1$nbsp;(Firmware)



511
512
513
# File 'lib/tinkerforge/brick_stepper.rb', line 511

def is_status_led_enabled
  send_request(FUNCTION_IS_STATUS_LED_ENABLED, [], '', 1, '?')
end

#is_sync_rectObject

Returns true if synchronous rectification is enabled, false otherwise.



443
444
445
# File 'lib/tinkerforge/brick_stepper.rb', line 443

def is_sync_rect
  send_request(FUNCTION_IS_SYNC_RECT, [], '', 1, '?')
end

#register_callback(id, &block) ⇒ Object

Registers a callback with ID id to the block block.



557
558
559
560
# File 'lib/tinkerforge/brick_stepper.rb', line 557

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

#resetObject

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!



540
541
542
# File 'lib/tinkerforge/brick_stepper.rb', line 540

def reset
  send_request(FUNCTION_RESET, [], '', 0, '')
end

#set_all_data_period(period) ⇒ Object

Sets the period in ms with which the CALLBACK_ALL_DATA callback is triggered periodically. A value of 0 turns the callback off.



475
476
477
# File 'lib/tinkerforge/brick_stepper.rb', line 475

def set_all_data_period(period)
  send_request(FUNCTION_SET_ALL_DATA_PERIOD, [period], 'L', 0, '')
end

#set_current_position(position) ⇒ Object

Sets the current steps of the internal step counter. This can be used to set the current position to 0 when some kind of starting position is reached (e.g. when a CNC machine reaches a corner).



217
218
219
# File 'lib/tinkerforge/brick_stepper.rb', line 217

def set_current_position(position)
  send_request(FUNCTION_SET_CURRENT_POSITION, [position], 'l', 0, '')
end

#set_decay(decay) ⇒ Object

Sets the decay mode of the stepper motor. The possible value range is between 0 and 65535. A value of 0 sets the fast decay mode, a value of 65535 sets the slow decay mode and a value in between sets the mixed decay mode.

Changing the decay mode is only possible if synchronous rectification is enabled (see BrickStepper#set_sync_rect).

For a good explanation of the different decay modes see ‘this <ebldc.com/?p=86/>`__ blog post by Avayan.

A good decay mode is unfortunately different for every motor. The best way to work out a good decay mode for your stepper motor, if you can’t measure the current with an oscilloscope, is to listen to the sound of the motor. If the value is too low, you often hear a high pitched sound and if it is too high you can often hear a humming sound.

Generally, fast decay mode (small value) will be noisier but also allow higher motor speeds.

The default value is 10000.

.. note

There is unfortunately no formula to calculate a perfect decay mode for a given stepper motor. If you have problems with loud noises or the maximum motor speed is too slow, you should try to tinker with the decay value



397
398
399
# File 'lib/tinkerforge/brick_stepper.rb', line 397

def set_decay(decay)
  send_request(FUNCTION_SET_DECAY, [decay], 'S', 0, '')
end

#set_max_velocity(velocity) ⇒ Object

Sets the maximum velocity of the stepper motor in steps per second. This function does not start the motor, it merely sets the maximum velocity the stepper motor is accelerated to. To get the motor running use either BrickStepper#set_target_position, BrickStepper#set_steps, BrickStepper#drive_forward or BrickStepper#drive_backward.



166
167
168
# File 'lib/tinkerforge/brick_stepper.rb', line 166

def set_max_velocity(velocity)
  send_request(FUNCTION_SET_MAX_VELOCITY, [velocity], 'S', 0, '')
end

#set_minimum_voltage(voltage) ⇒ Object

Sets the minimum voltage in mV, below which the CALLBACK_UNDER_VOLTAGE callback is triggered. The minimum possible value that works with the Stepper Brick is 8V. 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.

The default value is 8V.



413
414
415
# File 'lib/tinkerforge/brick_stepper.rb', line 413

def set_minimum_voltage(voltage)
  send_request(FUNCTION_SET_MINIMUM_VOLTAGE, [voltage], 'S', 0, '')
end

#set_motor_current(current) ⇒ Object

Sets the current in mA with which the motor will be driven. The minimum value is 100mA, the maximum value 2291mA and the default value is 800mA.

.. warning

Do not set this value above the specifications of your stepper motor. Otherwise it may damage your motor.



344
345
346
# File 'lib/tinkerforge/brick_stepper.rb', line 344

def set_motor_current(current)
  send_request(FUNCTION_SET_MOTOR_CURRENT, [current], 'S', 0, '')
end

#set_speed_ramping(acceleration, deacceleration) ⇒ Object

Sets the acceleration and deacceleration of the stepper motor. The values are given in steps/s². An acceleration of 1000 means, that every second the velocity is increased by 1000 steps/s.

For example: If the current velocity is 0 and you want to accelerate to a velocity of 8000 steps/s in 10 seconds, you should set an acceleration of 800 steps/s².

An acceleration/deacceleration of 0 means instantaneous acceleration/deacceleration (not recommended)

The default value is 1000 for both



192
193
194
# File 'lib/tinkerforge/brick_stepper.rb', line 192

def set_speed_ramping(acceleration, deacceleration)
  send_request(FUNCTION_SET_SPEED_RAMPING, [acceleration, deacceleration], 'S S', 0, '')
end

#set_step_mode(mode) ⇒ Object

Sets the step mode of the stepper motor. Possible values are:

  • Full Step = 1

  • Half Step = 2

  • Quarter Step = 4

  • Eighth Step = 8

A higher value will increase the resolution and decrease the torque of the stepper motor.

The default value is 8 (Eighth Step).



280
281
282
# File 'lib/tinkerforge/brick_stepper.rb', line 280

def set_step_mode(mode)
  send_request(FUNCTION_SET_STEP_MODE, [mode], 'C', 0, '')
end

#set_steps(steps) ⇒ Object

Sets the number of steps the stepper motor should run. Positive values will drive the motor forward and negative values backward. The velocity, acceleration and deacceleration as set by BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping will be used.



252
253
254
# File 'lib/tinkerforge/brick_stepper.rb', line 252

def set_steps(steps)
  send_request(FUNCTION_SET_STEPS, [steps], 'l', 0, '')
end

#set_sync_rect(sync_rect) ⇒ Object

Turns synchronous rectification on or off (true or false).

With synchronous rectification on, the decay can be changed (see BrickStepper#set_decay). Without synchronous rectification fast decay is used.

For an explanation of synchronous rectification see ‘here <en.wikipedia.org/wiki/Active_rectification>`__.

.. warning

If you want to use high speeds (> 10000 steps/s) for a large stepper motor with a large inductivity we strongly suggest that you disable synchronous rectification. Otherwise the Brick may not be able to cope with the load and overheat.

The default value is false.



438
439
440
# File 'lib/tinkerforge/brick_stepper.rb', line 438

def set_sync_rect(sync_rect)
  send_request(FUNCTION_SET_SYNC_RECT, [sync_rect], '?', 0, '')
end

#set_target_position(position) ⇒ Object

Sets the target position of the stepper motor in steps. For example, if the current position of the motor is 500 and BrickStepper#set_target_position is called with 1000, the stepper motor will drive 500 steps forward. It will use the velocity, acceleration and deacceleration as set by BrickStepper#set_max_velocity and BrickStepper#set_speed_ramping.

A call of BrickStepper#set_target_position with the parameter x is equivalent to a call of BrickStepper#set_steps with the parameter (x - BrickStepper#get_current_position).



239
240
241
# File 'lib/tinkerforge/brick_stepper.rb', line 239

def set_target_position(position)
  send_request(FUNCTION_SET_TARGET_POSITION, [position], 'l', 0, '')
end

#set_time_base(time_base) ⇒ Object

Sets the time base of the velocity and the acceleration of the stepper brick (in seconds).

For example, if you want to make one step every 1.5 seconds, you can set the time base to 15 and the velocity to 10. Now the velocity is 10steps/15s = 1steps/1.5s.

The default value is 1.



455
456
457
# File 'lib/tinkerforge/brick_stepper.rb', line 455

def set_time_base(time_base)
  send_request(FUNCTION_SET_TIME_BASE, [time_base], 'L', 0, '')
end

#stopObject

Stops the stepper motor with the deacceleration as set by BrickStepper#set_speed_ramping.



305
306
307
# File 'lib/tinkerforge/brick_stepper.rb', line 305

def stop
  send_request(FUNCTION_STOP, [], '', 0, '')
end