Пример #1
0
@author: LK
'''

from PyTrinamicMicro.platforms.motionpy.connections.rs485_tmcl_interface import rs485_tmcl_interface
from PyTrinamic.modules.TMCM1640.TMCM_1640 import TMCM_1640
import logging

MODULE_ID = 1
GP_BANK = 0
AP_AXIS = 0

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

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

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

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

logger.info("Getting global parameter ({}, {}) ...".format(
    "serialBaudRate", module.GPs.serialBaudRate))
logger.info("{}".format(
    module.getGlobalParameter(module.GPs.serialBaudRate, GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
    "serialAddress", module.GPs.serialAddress))
logger.info("{}".format(
    module.getGlobalParameter(module.GPs.serialAddress, GP_BANK)))
logger.info("Getting global parameter ({}, {}) ...".format(
Пример #2
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.motionpy.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()
Пример #3
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()
Пример #4
0
'''

from PyTrinamicMicro import PyTrinamicMicro
from PyTrinamicMicro.connections.tmcl_host_interface import tmcl_host_interface
from PyTrinamicMicro.platforms.motionpy.connections.rs485_tmcl_interface import rs485_tmcl_interface
from PyTrinamicMicro.platforms.motionpy.connections.usb_vcp_tmcl_interface import usb_vcp_tmcl_interface
from PyTrinamicMicro.TMCL_Bridge import TMCL_Bridge
from PyTrinamic.TMCL import TMCL_Command
import logging

# Prepare Logger
PyTrinamicMicro.set_logging_console_enabled(False)
logger = logging.getLogger(__name__)
logger.info("TMCL Bridge from USB to RS485")

logger.info("Initializing interfaces ...")
host = usb_vcp_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.")
Пример #5
0
def real(ticks, prescaler, freq):
    return ((ticks * freq) / (prescaler + 1))


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.")
ticks = (WORST_CASE_LATENCY * PAYLOAD * pyb.freq()[2] * 2) / 1000
prescaler = int(ticks / 0x3fffffff)
period = int((WORST_CASE_LATENCY * PAYLOAD * pyb.freq()[2] * 2) /
             (1000 * (prescaler + 1)))
while (n < N_SAMPLES):
    timer.counter(0)
    timer.init(prescaler=prescaler, period=period, callback=timeout)
    for i in range(0, PAYLOAD):
        interface.send_request_only(TMCL_Request(MODULE_ID, 1, 2, 3, 4, 5),
                                    host_id=HOST_ID,
                                    module_id=MODULE_ID)
    try:
        for i in range(0, PAYLOAD):
Пример #6
0
from PyTrinamicMicro.platforms.motionpy.modules.linear_distance import linear_distance
from PyTrinamic.modules.TMCM1240.TMCM_1240 import TMCM_1240
from PyTrinamicMicro.platforms.motionpy.modules.hc_sr04_multi import hc_sr04_multi
from PyTrinamicMicro.platforms.motionpy.modules.MCP23S08 import MCP23S08
from PyTrinamicMicro.platforms.motionpy.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)
Пример #7
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.")
Пример #8
0
from PyTrinamicMicro.platforms.motionpy.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
def reply_callback(reply):
    if (request_command != TMCL_Command.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.")
Пример #10
0
Created on 02.11.2020

@author: LK
'''

from PyTrinamicMicro.platforms.motionpy.connections.can_tmcl_interface import can_tmcl_interface
from PyTrinamicMicro.platforms.motionpy.connections.rs232_tmcl_interface import rs232_tmcl_interface
from PyTrinamicMicro.platforms.motionpy.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")