Skip to content

TINYMOVR_SET_VELOCITY

Direct a tinymovr BLDC driver to a set velocity.Input ----- velocity : Scalar Servo velocity (10k ticks/sec [1, 15]).Params:Returns:out : TextblobTraceback error (if any)
Python Code
from flojoy import flojoy, DataContainer, Scalar, TextBlob
import time, can, traceback
from typing import Optional

from tinymovr.tee import init_tee, destroy_tee
from tinymovr.config import get_bus_config, create_device


@flojoy(deps={"tinymovr": "1.6.2"})
def TINYMOVR_SET_VELOCITY(default: Scalar) -> TextBlob:
    """Direct a tinymovr BLDC driver to a set velocity.

    Input
    -----
    velocity : Scalar
        Servo velocity (10k ticks/sec [1, 15]).

    Returns
    -------
    Textblob
        Traceback error (if any)
    """

    tb = ""
    bitrate = 1000000
    params = get_bus_config(["canine", "slcan_disco"])
    params["bitrate"] = bitrate
    velocity_multiplier = 10000
    MAX_v = 15
    MIN_v = 1

    velocity = sorted((MIN_v, default.c, MAX_v))[1]

    try:
        # Connect to servo over CAN network
        # TODO: Consider saving Avlos tm Python object in HW device context manager
        # Reference: https://github.com/tinymovr/avlos
        with can.Bus(**params) as bus:
            init_tee(bus)
            tm = create_device(node_id=1)
            tm.controller.velocity_mode()
            tm.controller.velocity.setpoint = velocity * velocity_multiplier
            destroy_tee()
    except:
        tb = traceback.format_exc()

    return TextBlob(text_blob=tb)

Find this Flojoy Block on GitHub

Example

Having problem with this example app? Join our Discord community and we will help you out!
React Flow mini map