TIC_KNOB
Download Flojoy Studio to try this app
Control a stepper motor's movement through a Polulu TIC driver. The user controls the motor's rotation with the knob position, specified in the node's parameters. Params: default : OrderedPair The default value of the node, by default None knob_value : int Defines the position of the motor (rotational movement). current_limit : int Defines the current limitation that the stepper motor will receive. sleep_time : int Defines the sleep time after moving to each position. speed : int Defines the speed of the motor movement (between 0 and 200000). Returns: out : OrderedPair
Python Code
from time import sleep
from typing import Optional
from flojoy import OrderedPair, flojoy
# Import the TicUSB library to send command to Tic drivers with USB connection
from ticlib import TicUSB
@flojoy(deps={"ticlib": "0.2.2"})
def TIC_KNOB(
default: Optional[OrderedPair] = None,
knob_value: int = 0,
current_limit: int = 30,
sleep_time: int = 2,
speed: int = 200000,
) -> OrderedPair:
"""Control a stepper motor's movement through a Polulu TIC driver.
The user controls the motor's rotation with the knob position, specified in the node's parameters.
Parameters
----------
default : OrderedPair, optional
The default value of the node, by default None
knob_value : int
Defines the position of the motor (rotational movement).
current_limit : int
Defines the current limitation that the stepper motor will receive.
sleep_time : int
Defines the sleep time after moving to each position.
speed : int
Defines the speed of the motor movement (between 0 and 200000).
Returns
-------
OrderedPair
"""
# Converting the knob value into a position
knob_position: int = 2 * knob_value
# Declaration of the stepper driver (You can add serial number to specify the driver)
tic: TicUSB = TicUSB()
# Set the current limit for the driver TIC
tic.set_current_limit(current_limit)
tic.energize() # Turn on the driver
tic.exit_safe_start() # The driver is now ready to receive commands
# Set maximum speed for the motor during first movement.
tic.set_max_speed(speed)
tic.halt_and_set_position(0) # Set initial position to origin
sleep(sleep_time)
# Set target position for the first movement
tic.set_target_position(knob_position)
sleep(sleep_time)
tic.deenergize()
tic.enter_safe_start()
return OrderedPair(x=knob_position, y=speed)
Videos
Control Tinymovr servo motor with Flojoy
Example App
Having problems with this example app? Join our Discord community and we will help you out!
In this example, the STEPPER_DRIVER_TIC_KNOB
node controls a stepper motor movement with a TIC driver. It allows you to control the motor’s rotation with a KNOB button. (From 0 to 100 corresponds to a rotation between 0 and 360 degrees.)
First, the user must define the current limitation, which depends on the motor’s size and model. After that, he can set the speed, the rotation, and the sleep time to create a specific movement for different applications. Then, after clicking the PLAY button, the motor will start moving.
After updating the knob position, click on PLAY again to initiate a new movement.
To create a repetitive movement, use the LOOP
and GOTO
nodes.