TMCM-Lib – Trinamic Motion Control Module Library for Python
This project aims to offer a clean high-level interface to the TMCM stepper motor controllers by
Trinamic with TMCL firmware.
It currently only supports the module TMCM-3110 but others should be fairly easy to integrate.
Features
- Object-oriented design
- Documented public elements via type hints and docstrings
- Signaling errors via exceptions
- Blocking and non-blocking moving
- Expressing currents, velocities, and accelerations in physical units
- Reverting of motor direction per motor
- Setting, getting, and moving to coordinates
- Sending heartbeat messages automatically
Installing
pip install TMCM-Lib
Importing
import tmcm_lib
Examples
Configuring
from tmcm_lib import Port, Module
port = Port('COM1')
module = Module.construct(port)
module.switch_limit_pullup_enabled = True
module.switch_limit_activity = True
motor = module.motors[0]
motor.current_moving = 1_000
motor.current_standby = 100
motor.microstep_resolution = 256
motor.velocity_moving = 800
motor.acceleration_moving = 400
motor.switch_limit_left.enabled = True
motor.switch_limit_right.enabled = True
Identifying
print(module.model_number)
print(module.firmware_version)
Moving (Blocking)
Blocking moving waits while the motor is moving.
motor.move_by(512_000)
motor.move_to(0)
motor.move_right()
Moving (Non-blocking)
Non-blocking moving returns immediately after starting the moving.
motor.move_by(512_000, False)
motor.wait_while_moving()
motor.move_to(0, False)
while motor.moving :
...
motor.move_right(False)
...
motor.stop()
Motor union
A motor union is a set of motors that move simultaneously.
Motors can move synchronously (i.e. they stop at the same time) or asynchronously.
from tmcl_lib import MotorUnion
motor_union = MotorUnion(module, [0, 1])
motor_union.move_to((512_000, 256_000))