async def move(ax: TMCM_1161,
               mode: str,
               to: int,
               at: int,
               id: str = '',
               verbose: bool = False):
    """
    Parameters:
        ax: TMCM_1161 instance
        mode: absolute or ralative
        to: int: target position
        at: int: speed
        id: str: idintifier to print in terminal
    return:
        int: actual position of motor
    """
    old_position = ax.getActualPosition()
    if verbose:
        print(f'{id} was at {old_position}')
    if mode == 'abs':
        ax.moveTo(to, at)
    elif mode == 'rel':
        ax.moveBy(to, at)
    else:
        print('unknown mode')
        return
    while not ax.positionReached():
        if verbose:
            print(id, ax.getActualPosition())
        await asyncio.sleep(0.001)
    await asyncio.sleep(0.001)
    pos = ax.getActualPosition()
    if verbose:
        print(id, pos)
    return pos
async def main(reset=True):
    # connect to motor and set initial values
    connectionManager = ConnectionManager(argList='--port 1')
    x = TMCM_1161(connectionManager.connect())
    initialize(x)
    # stop motors before setActualPosition (data sheet p76/110, table 15)
    if reset:
        x.stop()
        x.setActualPosition(0)

    # Move motor to initial value
    print('moving to initial position')
    set_speed(x, 1600, 1000, 3, 7)
    await move(x, 'abs', 51200, 1000, 'x')
    x.stop()
    report(x)  # print info in case of an error

    print('Start measurement')
    # increase pulse division to 6 for a smoother movement during measurement
    set_speed(x, 2047, 2047, 5, 8)
    result = []

    now = time.time()
    x.connection.clearDigitalOutput(
        0)  # sets digital output to high in my case
    x.connection.clearDigitalOutput(
        1)  # sets digital output to high in my case

    for i in range(100):
        val = await move(x, 'rel', -1024, 2047, 'x')
        ans = get_all_inputs(x)
        result.append((val, ans))
        print(i, val, ans)

    x.connection.setDigitalOutput(0)  # clears digital output in my case
    x.connection.setDigitalOutput(1)

    total = time.time() - now
    print(f'Finished measurement in {total:.2f}s')

    report(x)
    x.stop()

    # Plotting
    X = [i[0] for i in result]
    A = [i[1][0] for i in result]
    T = [i[1][1] for i in result]
    V = [i[1][2] for i in result]

    fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
    ax1.plot(X, A)
    ax2.plot(X, T)
    ax3.plot(X, V)

    ax2.set_xlabel('Motor Position')
    ax1.set_ylabel('AIN_0 [0/4095]')
    ax2.set_ylabel('Temperature [°C]')
    ax3.set_ylabel('Voltage [1/10V]')
    plt.show()
from PyTrinamicMicro.platforms.motionpy1.connections.rs485_tmcl_interface import rs485_tmcl_interface
from PyTrinamic.modules.TMCM1161.TMCM_1161 import TMCM_1161
import logging

MODULE_ID = 1
GP_BANK = 0
AP_AXIS = 0

logger = logging.getLogger(__name__)
logger.info("Test module TMCM1161 parameters via RS485")

logger.info("Initializing interface.")
interface = rs485_tmcl_interface(module_id=MODULE_ID)

logger.info("Initializing module.")
module = TMCM_1161(interface)

logger.info("Testing global parameter access.")

logger.info("Getting global parameter ({}, {}) ...".format(
    "timer_0", module.GPs.timer_0))
logger.info("{}".format(module.getGlobalParameter(module.GPs.timer_0,
                                                  GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
    "timer_1", module.GPs.timer_0))
logger.info("{}".format(module.getGlobalParameter(module.GPs.timer_1,
                                                  GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
    "timer_2", module.GPs.timer_0))
logger.info("{}".format(module.getGlobalParameter(module.GPs.timer_2,
                                                  GP_BANK)))
Exemple #4
0
Created on 22.05.2019

@author: LH
'''

import PyTrinamic
from PyTrinamic.connections.ConnectionManager import ConnectionManager
from PyTrinamic.modules.TMCM1161.TMCM_1161 import TMCM_1161
import time

PyTrinamic.showInfo()

connectionManager = ConnectionManager()
myInterface = connectionManager.connect()
Module_1161 = TMCM_1161(myInterface)

DEFAULT_MOTOR = 0

print("Preparing parameters")
Module_1161.setMaxAcceleration(1000)

print("Rotating")
Module_1161.rotate(500)

time.sleep(2)

print("Stopping")
Module_1161.stop()

time.sleep(1)
Exemple #5
0
'''
Rotate the motor with TMCM1161 using RS485 interface.

Created on 05.10.2020

@author: LK
'''

from PyTrinamic.modules.TMCM1161.TMCM_1161 import TMCM_1161
from PyTrinamicMicro.platforms.motionpy.connections.rs485_tmcl_interface import rs485_tmcl_interface
import time

con = rs485_tmcl_interface()
module = TMCM_1161(con)

module.rotate(0, 1000)
time.sleep(5)
module.stop(0)

con.close()