예제 #1
0
@author: LK
'''

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(
예제 #2
0
from PyTrinamicMicro.platforms.motionpy1.modules.linear_distance import linear_distance
from PyTrinamic.modules.TMCM1240.TMCM_1240 import TMCM_1240
from PyTrinamicMicro.platforms.motionpy1.modules.hc_sr04_multi import hc_sr04_multi
from PyTrinamicMicro.platforms.motionpy1.modules.MCP23S08 import MCP23S08
from PyTrinamicMicro.platforms.motionpy1.connections.rs485_tmcl_interface import rs485_tmcl_interface

module = TMCM_1240(rs485_tmcl_interface())
module.setMaxAcceleration(0, 100000)

lin = linear_distance(
    sensor = hc_sr04_multi(avg_window=100),
    sensor_index = 1,
    module = module
)

lin.homing_direct(velocity=100000)

print(lin.bounds)
예제 #3
0
    if (request_command != TMCL.COMMANDS["GET_FIRMWARE_VERSION"]):
        reply.calculate_checksum()
    return reply


logger.info("Initializing interfaces ...")
host = usb_vcp_tmcl_interface()
modules = [{
    "module": uart_tmcl_interface()
}, {
    "module": can_tmcl_interface(),
    "request_callback": request_callback,
    "reply_callback": reply_callback
}, {
    "module": rs232_tmcl_interface()
}, {
    "module": rs485_tmcl_interface()
}]
bridge = TMCL_Bridge(host, modules)
logger.info("Interfaces initialized.")

while (not (bridge.process())):
    pass

logger.info("Closing interfaces ...")
host.close()
module.close()
logger.info("Interfaces closed.")

logger.info("Bridge stopped.")
'''
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.motionpy1.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()
예제 #5
0
'''
Rotate the motor with TMCM3214 using RS485 interface.

Created on 19.04.2021

@author: LK
'''

from PyTrinamic.modules.TMCM3214.TMCM_3214 import TMCM_3214
from PyTrinamicMicro.platforms.motionpy1.connections.rs485_tmcl_interface import rs485_tmcl_interface
from pyb import Pin
import time

con = rs485_tmcl_interface(data_rate=9600)
module = TMCM_3214(con)

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

con.close()
def reply_callback(reply):
    if (request_command != TMCL.COMMANDS["GET_FIRMWARE_VERSION"]):
        reply.calculate_checksum()
    return reply


logger.info("Initializing interfaces ...")
host = uart_tmcl_interface()
modules = [{
    "module": can_tmcl_interface(debug=True),
    "request_callback": request_callback,
    "reply_callback": reply_callback
}, {
    "module": rs232_tmcl_interface(debug=True)
}, {
    "module": rs485_tmcl_interface(debug=True)
}]
bridge = TMCL_Bridge(host, modules)
logger.info("Interfaces initialized.")

while (not (bridge.process())):
    pass

logger.info("Closing interfaces ...")
host.close()
module.close()
logger.info("Interfaces closed.")

logger.info("Bridge stopped.")
def real(ticks, prescaler, freq):
    return ((ticks * (prescaler + 1)) / freq)


min_ticks = 0
max_ticks = 0
avg_ticks = 0
std_dev_ticks = 0
n = 0
timer = Timer(2)

logger = logging.getLogger(__name__)
logger.info("Latency test RS485")

logger.info("Initializing interface.")
interface = rs485_tmcl_interface(data_rate=DATA_RATE)

logger.info("Performing test.")
while (n < N_SAMPLES):
    timer.counter(0)
    timer.init(prescaler=0, period=16800000, callback=timeout)
    # send invalid (for all modules) TMCL Request
    reply = interface.send_request(TMCL_Request(MODULE_ID, 1, 2, 3, 4, 5),
                                   host_id=HOST_ID,
                                   module_id=MODULE_ID)
    timer.deinit()
    if (not (tout)):
        counter = timer.counter()
        logger.debug("Measured delta ticks: {}".format(counter))
        # update values
        value = counter
예제 #8
0
from PyTrinamicMicro.platforms.motionpy1.connections.rs485_tmcl_interface import rs485_tmcl_interface
from PyTrinamicMicro import PyTrinamicMicro
import struct
import logging

# Prepare Logger
PyTrinamicMicro.set_logging_console_enabled(False)
logger = logging.getLogger(__name__)
logger.info("TMCL Slave on USB_VCP interface")

# Main program
lin = None
logger.info("Initializing interface ...")
con = usb_vcp_tmcl_interface()
slave = tmcl_slave_motionpy()
module = TMCM_1240(rs485_tmcl_interface(data_rate=115200))
module.setMaxAcceleration(0, 100000)
logger.info("Interface initialized.")

while(not(slave.status.stop)):
    # Handle connection
    if(con.request_available()):
        logger.debug("Request available.")
        request = con.receive_request()
        if(not(slave.filter(request))):
            continue
        logger.debug("Request for this slave detected.")
        reply = slave.handle_request(request)
        con.send_reply(reply)
    # Handle flags
    if(slave.status.lin[0]):
예제 #9
0
Created on 14.10.2020

@author: LK
'''

from PyTrinamicMicro.connections.tmcl_host_interface import tmcl_host_interface
from PyTrinamicMicro.platforms.motionpy1.connections.rs485_tmcl_interface import rs485_tmcl_interface
from PyTrinamicMicro.platforms.motionpy1.connections.uart_tmcl_interface import uart_tmcl_interface
from PyTrinamicMicro.TMCL_Bridge import TMCL_Bridge
import logging

# Prepare Logger
logger = logging.getLogger(__name__)
logger.info("TMCL Bridge from UART to RS485")

logger.info("Initializing interfaces ...")
host = uart_tmcl_interface()
module = rs485_tmcl_interface()
bridge = TMCL_Bridge(host, [{"module": module}])
logger.info("Interfaces initialized.")

while (not (bridge.process())):
    pass

logger.info("Closing interfaces ...")
host.close()
module.close()
logger.info("Interfaces closed.")

logger.info("Bridge stopped.")
예제 #10
0
Test TMCL GET_FIRMWARE_VERSION via several interfaces and module ID 1.

Created on 02.11.2020

@author: LK
'''

from PyTrinamicMicro.platforms.motionpy1.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamicMicro.platforms.motionpy1.connections.rs232_tmcl_interface import rs232_tmcl_interface
from PyTrinamicMicro.platforms.motionpy1.connections.rs485_tmcl_interface import rs485_tmcl_interface
import logging
import re

VERSION_PATTERN = "^\d\d\d\dV\d\d\d$"

logger = logging.getLogger(__name__)
logger.info("Test GET_FIRMWARE_VERSION for CAN, RS232 and RS485 interfaces.")

logger.info("Initializing interfaces.")
interfaces = set()
interfaces.add(can_tmcl_interface())
interfaces.add(rs232_tmcl_interface())
interfaces.add(rs485_tmcl_interface())

for interface in interfaces:
    logger.info("Issuing GET_FIRMWARE_VERSION on interface {}.".format(interface))
    value = interface.getVersionString()
    logger.info("Value: {}.".format(value))
    assert re.match(VERSION_PATTERN, value), "Invalid version string"
    logger.info("Version string valid")