PyTmcStepper 0.14.0__tar.gz → 0.16.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/PKG-INFO +3 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/pyproject.toml +3 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/PyTmcStepper.egg-info/PKG-INFO +3 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/PyTmcStepper.egg-info/SOURCES.txt +3 -0
- pytmcstepper-0.16.0/src/tmc_driver/_tmc_stepperdriver.py +210 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/_tmc_xxxx.py +6 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/__init__.py +15 -0
- pytmcstepper-0.16.0/src/tmc_driver/com/_tmc_com_spi_circuitpython.py +113 -0
- pytmcstepper-0.16.0/src/tmc_driver/com/_tmc_com_uart_circuitpython.py +127 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/enable_control/_tmc_ec.py +4 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/_tmc_mc.py +12 -2
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/platform_utils.py +4 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/_tmc220x_reg.py +8 -5
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/_tmc224x_reg.py +6 -3
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/_tmc5160_reg.py +6 -3
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/_tmc_shared_regs.py +1 -1
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_220x.py +1 -7
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_2240.py +0 -13
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_5160.py +0 -13
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/__init__.py +27 -12
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +1 -0
- pytmcstepper-0.16.0/src/tmc_driver/tmc_gpio/_tmc_gpio_board_circuitpython.py +124 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_logger/__init__.py +2 -1
- pytmcstepper-0.16.0/tests/test_tmc2209.py +107 -0
- pytmcstepper-0.16.0/tests/test_tmc2240.py +148 -0
- pytmcstepper-0.16.0/tests/test_tmc_com_spi.py +32 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_math.py +4 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_modules.py +15 -1
- pytmcstepper-0.14.0/src/tmc_driver/_tmc_stepperdriver.py +0 -294
- pytmcstepper-0.14.0/tests/test_tmc2209.py +0 -44
- pytmcstepper-0.14.0/tests/test_tmc2240.py +0 -44
- pytmcstepper-0.14.0/tests/test_tmc_com_spi.py +0 -27
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/LICENSE +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/README.md +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/setup.cfg +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/PyTmcStepper.egg-info/requires.txt +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/__init__.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/_tmc_exceptions.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/_tmc_math.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/_tmc_stallguard.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/_tmc_validation.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_spi_base.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_spi_micropython.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_uart_base.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/com/_tmc_com_uart_micropython.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/enable_control/__init__.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/__init__.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/__init__.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/reg/_tmc_reg.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_2208.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_2209.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_logger/_tmc_logger_base.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_com_uart.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_ec_pin.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_move.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_set_current.py +0 -0
- {pytmcstepper-0.14.0 → pytmcstepper-0.16.0}/tests/test_tmc_stallguard.py +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.0
|
|
4
4
|
Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
|
|
5
5
|
Author-email: Christian Köhlke <christian@koehlke.de>
|
|
6
6
|
License-Expression: GPL-3.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/Chr157i4n/PyTmcStepper
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/Chr157i4n/PyTmcStepper/issues
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
|
+
Classifier: Programming Language :: Python :: Implementation :: MicroPython
|
|
10
12
|
Classifier: Operating System :: POSIX :: Linux
|
|
11
13
|
Classifier: Development Status :: 4 - Beta
|
|
12
14
|
Classifier: Intended Audience :: Developers
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "PyTmcStepper"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.16.0"
|
|
8
8
|
authors = [{ name = "Christian Köhlke", email = "christian@koehlke.de" }]
|
|
9
9
|
description = "This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi"
|
|
10
10
|
readme = "README.md"
|
|
@@ -12,6 +12,8 @@ license = "GPL-3.0"
|
|
|
12
12
|
requires-python = ">=3.10"
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
16
|
+
"Programming Language :: Python :: Implementation :: MicroPython",
|
|
15
17
|
"Operating System :: POSIX :: Linux",
|
|
16
18
|
"Development Status :: 4 - Beta",
|
|
17
19
|
"Intended Audience :: Developers",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.0
|
|
4
4
|
Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
|
|
5
5
|
Author-email: Christian Köhlke <christian@koehlke.de>
|
|
6
6
|
License-Expression: GPL-3.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/Chr157i4n/PyTmcStepper
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/Chr157i4n/PyTmcStepper/issues
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
|
+
Classifier: Programming Language :: Python :: Implementation :: MicroPython
|
|
10
12
|
Classifier: Operating System :: POSIX :: Linux
|
|
11
13
|
Classifier: Development Status :: 4 - Beta
|
|
12
14
|
Classifier: Intended Audience :: Developers
|
|
@@ -23,10 +23,12 @@ src/tmc_driver/com/__init__.py
|
|
|
23
23
|
src/tmc_driver/com/_tmc_com.py
|
|
24
24
|
src/tmc_driver/com/_tmc_com_spi.py
|
|
25
25
|
src/tmc_driver/com/_tmc_com_spi_base.py
|
|
26
|
+
src/tmc_driver/com/_tmc_com_spi_circuitpython.py
|
|
26
27
|
src/tmc_driver/com/_tmc_com_spi_ftdi.py
|
|
27
28
|
src/tmc_driver/com/_tmc_com_spi_micropython.py
|
|
28
29
|
src/tmc_driver/com/_tmc_com_uart.py
|
|
29
30
|
src/tmc_driver/com/_tmc_com_uart_base.py
|
|
31
|
+
src/tmc_driver/com/_tmc_com_uart_circuitpython.py
|
|
30
32
|
src/tmc_driver/com/_tmc_com_uart_micropython.py
|
|
31
33
|
src/tmc_driver/enable_control/__init__.py
|
|
32
34
|
src/tmc_driver/enable_control/_tmc_ec.py
|
|
@@ -48,6 +50,7 @@ src/tmc_driver/reg/_tmc_reg.py
|
|
|
48
50
|
src/tmc_driver/reg/_tmc_shared_regs.py
|
|
49
51
|
src/tmc_driver/tmc_gpio/__init__.py
|
|
50
52
|
src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py
|
|
53
|
+
src/tmc_driver/tmc_gpio/_tmc_gpio_board_circuitpython.py
|
|
51
54
|
src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py
|
|
52
55
|
src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py
|
|
53
56
|
src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# pylint: disable=too-many-arguments
|
|
2
|
+
# pylint: disable=too-many-public-methods
|
|
3
|
+
# pylint: disable=too-many-branches
|
|
4
|
+
# pylint: disable=too-many-positional-arguments
|
|
5
|
+
# pylint: disable=import-outside-toplevel
|
|
6
|
+
# pylint: disable=bare-except
|
|
7
|
+
# pylint: disable=unused-import
|
|
8
|
+
# pylint: disable=wildcard-import
|
|
9
|
+
# pylint: disable=unused-wildcard-import
|
|
10
|
+
"""TmcStepperDriver module
|
|
11
|
+
|
|
12
|
+
this module has the function to move the motor via STEP/DIR pins
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from typing import TYPE_CHECKING
|
|
17
|
+
except ImportError:
|
|
18
|
+
TYPE_CHECKING = False
|
|
19
|
+
from .tmc_gpio import Board
|
|
20
|
+
from . import tmc_gpio
|
|
21
|
+
from .motion_control._tmc_mc import (
|
|
22
|
+
TmcMotionControl,
|
|
23
|
+
MovementAbsRel,
|
|
24
|
+
MovementPhase,
|
|
25
|
+
StopMode,
|
|
26
|
+
Direction,
|
|
27
|
+
)
|
|
28
|
+
from .enable_control._tmc_ec import TmcEnableControl
|
|
29
|
+
from .enable_control._tmc_ec_pin import TmcEnableControlPin
|
|
30
|
+
from .motion_control._tmc_mc_step_dir import TmcMotionControlStepDir
|
|
31
|
+
from .motion_control._tmc_mc_step_pwm_dir import TmcMotionControlStepPwmDir
|
|
32
|
+
from .tmc_logger import *
|
|
33
|
+
from . import _tmc_math as tmc_math
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TmcStepperDriver:
|
|
37
|
+
"""TmcStepperDriver
|
|
38
|
+
|
|
39
|
+
this class has two different functions:
|
|
40
|
+
1. change setting in the TMC-driver via UART
|
|
41
|
+
2. move the motor via STEP/DIR pins
|
|
42
|
+
|
|
43
|
+
Attributes forwarded to tmc_mc (motion control):
|
|
44
|
+
current_pos, current_pos_fullstep, mres, steps_per_rev, fullsteps_per_rev,
|
|
45
|
+
movement_abs_rel, movement_phase, speed, max_speed, max_speed_fullstep,
|
|
46
|
+
acceleration, acceleration_fullstep
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# Attributes that are automatically forwarded to tmc_mc submodule
|
|
50
|
+
_MC_FORWARDED_ATTRS = {
|
|
51
|
+
"current_pos",
|
|
52
|
+
"current_pos_fullstep",
|
|
53
|
+
"mres",
|
|
54
|
+
"steps_per_rev",
|
|
55
|
+
"fullsteps_per_rev",
|
|
56
|
+
"movement_abs_rel",
|
|
57
|
+
"movement_phase",
|
|
58
|
+
"speed",
|
|
59
|
+
"max_speed",
|
|
60
|
+
"max_speed_fullstep",
|
|
61
|
+
"acceleration",
|
|
62
|
+
"acceleration_fullstep",
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if TYPE_CHECKING:
|
|
66
|
+
# Type hints for IDE/type checkers - these attributes are forwarded via __getattr__
|
|
67
|
+
current_pos: int
|
|
68
|
+
current_pos_fullstep: int
|
|
69
|
+
mres: int
|
|
70
|
+
steps_per_rev: int
|
|
71
|
+
fullsteps_per_rev: int
|
|
72
|
+
movement_abs_rel: MovementAbsRel
|
|
73
|
+
movement_phase: MovementPhase
|
|
74
|
+
speed: float
|
|
75
|
+
max_speed: int
|
|
76
|
+
max_speed_fullstep: int
|
|
77
|
+
acceleration: int
|
|
78
|
+
acceleration_fullstep: int
|
|
79
|
+
|
|
80
|
+
# Constructor/Destructor
|
|
81
|
+
# ----------------------------
|
|
82
|
+
def __init__(
|
|
83
|
+
self,
|
|
84
|
+
tmc_ec: TmcEnableControl,
|
|
85
|
+
tmc_mc: TmcMotionControl,
|
|
86
|
+
gpio_mode=None,
|
|
87
|
+
loglevel: Loglevel = Loglevel.INFO,
|
|
88
|
+
logprefix: str | None = None,
|
|
89
|
+
log_handlers: list | None = None,
|
|
90
|
+
log_formatter: logging.Formatter | None = None,
|
|
91
|
+
):
|
|
92
|
+
"""constructor
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
tmc_ec (TmcEnableControl): TMC Enable Control object
|
|
96
|
+
tmc_mc (TmcMotionControl): TMC Motion Control object
|
|
97
|
+
gpio_mode (enum, optional): gpio mode. Defaults to None.
|
|
98
|
+
loglevel (enum, optional): loglevel. Defaults to None.
|
|
99
|
+
logprefix (str, optional): log prefix (name of the logger).
|
|
100
|
+
Defaults to None (standard TMC prefix).
|
|
101
|
+
log_handlers (list, optional): list of logging handlers.
|
|
102
|
+
Defaults to None (log to console).
|
|
103
|
+
log_formatter (logging.Formatter, optional): formatter for the log messages.
|
|
104
|
+
Defaults to None (messages are logged in the format
|
|
105
|
+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s').
|
|
106
|
+
"""
|
|
107
|
+
self.BOARD: Board = tmc_gpio.BOARD
|
|
108
|
+
self.tmc_ec = tmc_ec
|
|
109
|
+
self.tmc_mc = tmc_mc
|
|
110
|
+
self.tmc_logger: TmcLogger
|
|
111
|
+
|
|
112
|
+
if logprefix is None:
|
|
113
|
+
logprefix = "StepperDriver"
|
|
114
|
+
self.tmc_logger = TmcLogger(loglevel, logprefix, log_handlers, log_formatter)
|
|
115
|
+
|
|
116
|
+
self.tmc_logger.log("Init", Loglevel.INFO)
|
|
117
|
+
|
|
118
|
+
tmc_gpio.tmc_gpio.init(gpio_mode)
|
|
119
|
+
|
|
120
|
+
if self.tmc_mc is not None:
|
|
121
|
+
self.tmc_mc.init(self.tmc_logger)
|
|
122
|
+
|
|
123
|
+
if self.tmc_ec is not None:
|
|
124
|
+
self.tmc_ec.init(self.tmc_logger)
|
|
125
|
+
|
|
126
|
+
def __del__(self):
|
|
127
|
+
self.deinit()
|
|
128
|
+
|
|
129
|
+
def deinit(self):
|
|
130
|
+
"""destructor"""
|
|
131
|
+
if hasattr(self, "tmc_ec") and self.tmc_ec is not None:
|
|
132
|
+
self.tmc_ec.deinit()
|
|
133
|
+
self.tmc_ec = None
|
|
134
|
+
if hasattr(self, "tmc_mc") and self.tmc_mc is not None:
|
|
135
|
+
self.tmc_mc.deinit()
|
|
136
|
+
self.tmc_mc = None
|
|
137
|
+
if hasattr(self, "tmc_logger") and self.tmc_logger is not None:
|
|
138
|
+
self.tmc_logger.deinit()
|
|
139
|
+
del self.tmc_logger
|
|
140
|
+
|
|
141
|
+
# Attribute Forwarding
|
|
142
|
+
# ----------------------------
|
|
143
|
+
def __getattr__(self, name):
|
|
144
|
+
"""Forward attribute access to tmc_mc submodule dynamically"""
|
|
145
|
+
if name in self._MC_FORWARDED_ATTRS:
|
|
146
|
+
if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
|
|
147
|
+
raise AttributeError(
|
|
148
|
+
f"Cannot access '{name}': TmcMotionControl is not set"
|
|
149
|
+
)
|
|
150
|
+
return getattr(self.tmc_mc, name)
|
|
151
|
+
|
|
152
|
+
raise AttributeError(
|
|
153
|
+
f"'{type(self).__name__}' object has no attribute '{name}'"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
def __setattr__(self, name, value):
|
|
157
|
+
"""Forward attribute setting to tmc_mc submodule dynamically"""
|
|
158
|
+
# Forward to tmc_mc if it's a forwarded attribute and tmc_mc exists
|
|
159
|
+
if name in self._MC_FORWARDED_ATTRS:
|
|
160
|
+
# Only forward if tmc_mc is already initialized (not during __init__)
|
|
161
|
+
if hasattr(self, "tmc_mc") and self.tmc_mc is not None:
|
|
162
|
+
setattr(self.tmc_mc, name, value)
|
|
163
|
+
return
|
|
164
|
+
# During __init__, tmc_mc doesn't exist yet, so fall through
|
|
165
|
+
|
|
166
|
+
# Normal attribute assignment (self.tmc_mc, self.tmc_ec, etc.)
|
|
167
|
+
super().__setattr__(name, value)
|
|
168
|
+
|
|
169
|
+
# TmcEnableControl Wrapper
|
|
170
|
+
# ----------------------------
|
|
171
|
+
def set_motor_enabled(self, en: bool):
|
|
172
|
+
"""enable control wrapper"""
|
|
173
|
+
if self.tmc_ec is not None:
|
|
174
|
+
self.tmc_ec.set_motor_enabled(en)
|
|
175
|
+
|
|
176
|
+
# TmcMotionControl Wrapper
|
|
177
|
+
# ----------------------------
|
|
178
|
+
def run_to_position_steps(
|
|
179
|
+
self, steps, movement_abs_rel: MovementAbsRel | None = None
|
|
180
|
+
) -> StopMode:
|
|
181
|
+
"""motioncontrol wrapper"""
|
|
182
|
+
if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
|
|
183
|
+
raise AttributeError("TmcMotionControl is not set")
|
|
184
|
+
return self.tmc_mc.run_to_position_steps(steps, movement_abs_rel)
|
|
185
|
+
|
|
186
|
+
def run_to_position_fullsteps(
|
|
187
|
+
self, steps, movement_abs_rel: MovementAbsRel | None = None
|
|
188
|
+
) -> StopMode:
|
|
189
|
+
"""motioncontrol wrapper"""
|
|
190
|
+
return self.run_to_position_steps(steps * self.mres, movement_abs_rel)
|
|
191
|
+
|
|
192
|
+
def run_to_position_revolutions(
|
|
193
|
+
self, revs, movement_abs_rel: MovementAbsRel | None = None
|
|
194
|
+
) -> StopMode:
|
|
195
|
+
"""motioncontrol wrapper"""
|
|
196
|
+
return self.run_to_position_steps(revs * self.steps_per_rev, movement_abs_rel)
|
|
197
|
+
|
|
198
|
+
def reset_position(self):
|
|
199
|
+
"""resets the current position to 0"""
|
|
200
|
+
self.current_pos_fullstep = 0
|
|
201
|
+
|
|
202
|
+
# Test Methods
|
|
203
|
+
# ----------------------------
|
|
204
|
+
def test_step(self):
|
|
205
|
+
"""test method"""
|
|
206
|
+
if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
|
|
207
|
+
raise AttributeError("TmcMotionControl is not set")
|
|
208
|
+
for _ in range(100):
|
|
209
|
+
self.tmc_mc.set_direction(Direction.CW)
|
|
210
|
+
self.tmc_mc.make_a_step()
|
|
@@ -271,13 +271,18 @@ class TmcXXXX(TmcStepperDriver):
|
|
|
271
271
|
)
|
|
272
272
|
return self.tmc_mc.mres
|
|
273
273
|
|
|
274
|
-
@abstractmethod
|
|
275
274
|
def set_microstepping_resolution(self, mres: int):
|
|
276
275
|
"""sets the current native microstep resolution (1,2,4,8,16,32,64,128,256)
|
|
277
276
|
|
|
278
277
|
Args:
|
|
279
278
|
mres (int): µstep resolution; has to be a power of 2 or 1 for fullstep
|
|
280
279
|
"""
|
|
280
|
+
if self.tmc_mc is not None:
|
|
281
|
+
self.tmc_mc.mres = mres
|
|
282
|
+
|
|
283
|
+
self.chopconf.read()
|
|
284
|
+
self.chopconf.mres_ms = mres
|
|
285
|
+
self.chopconf.write_check()
|
|
281
286
|
|
|
282
287
|
@abstractmethod
|
|
283
288
|
def set_current_peak(
|
|
@@ -6,6 +6,8 @@ Provides UART and SPI communication implementations for different platforms:
|
|
|
6
6
|
- TmcComSpi: Standard SPI communication (CPython with spidev)
|
|
7
7
|
- TmcComUartMicroPython: UART for MicroPython
|
|
8
8
|
- TmcComSpiMicroPython: SPI for MicroPython
|
|
9
|
+
- TmcComUartCircuitPython: UART for CircuitPython
|
|
10
|
+
- TmcComSpiCircuitPython: SPI for CircuitPython
|
|
9
11
|
- TmcComSpiFtdi: SPI via FTDI USB devices
|
|
10
12
|
|
|
11
13
|
Example:
|
|
@@ -25,12 +27,15 @@ try:
|
|
|
25
27
|
from ._tmc_com_spi import TmcComSpi
|
|
26
28
|
from ._tmc_com_uart_micropython import TmcComUartMicroPython
|
|
27
29
|
from ._tmc_com_spi_micropython import TmcComSpiMicroPython
|
|
30
|
+
from ._tmc_com_uart_circuitpython import TmcComUartCircuitPython
|
|
31
|
+
from ._tmc_com_spi_circuitpython import TmcComSpiCircuitPython
|
|
28
32
|
from ._tmc_com_spi_ftdi import TmcComSpiFtdi
|
|
29
33
|
except ImportError:
|
|
30
34
|
pass
|
|
31
35
|
|
|
32
36
|
|
|
33
37
|
def __getattr__(name):
|
|
38
|
+
# pylint: disable=too-many-return-statements
|
|
34
39
|
"""Lazy import of communication classes to avoid circular imports"""
|
|
35
40
|
if name == "TmcComUart":
|
|
36
41
|
from ._tmc_com_uart import TmcComUart
|
|
@@ -48,6 +53,14 @@ def __getattr__(name):
|
|
|
48
53
|
from ._tmc_com_spi_micropython import TmcComSpiMicroPython
|
|
49
54
|
|
|
50
55
|
return TmcComSpiMicroPython
|
|
56
|
+
if name == "TmcComUartCircuitPython":
|
|
57
|
+
from ._tmc_com_uart_circuitpython import TmcComUartCircuitPython
|
|
58
|
+
|
|
59
|
+
return TmcComUartCircuitPython
|
|
60
|
+
if name == "TmcComSpiCircuitPython":
|
|
61
|
+
from ._tmc_com_spi_circuitpython import TmcComSpiCircuitPython
|
|
62
|
+
|
|
63
|
+
return TmcComSpiCircuitPython
|
|
51
64
|
if name == "TmcComSpiFtdi":
|
|
52
65
|
from ._tmc_com_spi_ftdi import TmcComSpiFtdi
|
|
53
66
|
|
|
@@ -60,5 +73,7 @@ __all__ = [
|
|
|
60
73
|
"TmcComSpi",
|
|
61
74
|
"TmcComUartMicroPython",
|
|
62
75
|
"TmcComSpiMicroPython",
|
|
76
|
+
"TmcComUartCircuitPython",
|
|
77
|
+
"TmcComSpiCircuitPython",
|
|
63
78
|
"TmcComSpiFtdi",
|
|
64
79
|
]
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
# pylint: disable=too-many-arguments
|
|
3
|
+
# pylint: disable=too-many-positional-arguments
|
|
4
|
+
"""
|
|
5
|
+
TmcComSpiCircuitPython - SPI communication for CircuitPython
|
|
6
|
+
|
|
7
|
+
Uses the busio.SPI interface available on CircuitPython boards.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import busio # pylint: disable=import-error
|
|
11
|
+
import digitalio # pylint: disable=import-error
|
|
12
|
+
from ._tmc_com_spi_base import TmcComSpiBase
|
|
13
|
+
from .._tmc_exceptions import TmcComException
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TmcComSpiCircuitPython(TmcComSpiBase):
|
|
17
|
+
"""SPI Communication class for CircuitPython
|
|
18
|
+
|
|
19
|
+
Example usage:
|
|
20
|
+
import board
|
|
21
|
+
from tmc_driver.com import TmcComSpiCircuitPython
|
|
22
|
+
|
|
23
|
+
spi_com = TmcComSpiCircuitPython(
|
|
24
|
+
cs=board.D17,
|
|
25
|
+
clock=board.SCK,
|
|
26
|
+
mosi=board.MOSI,
|
|
27
|
+
miso=board.MISO,
|
|
28
|
+
baudrate=1000000
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
TMC2240/TMC5160 uses SPI Mode 3: CPOL=1, CPHA=1
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
cs,
|
|
37
|
+
clock,
|
|
38
|
+
mosi,
|
|
39
|
+
miso,
|
|
40
|
+
baudrate=1000000,
|
|
41
|
+
):
|
|
42
|
+
"""Initialize SPI communication
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
cs: Chip select board pin (e.g., board.D17)
|
|
46
|
+
clock: SPI clock board pin (e.g., board.SCK)
|
|
47
|
+
mosi: MOSI board pin (e.g., board.MOSI)
|
|
48
|
+
miso: MISO board pin (e.g., board.MISO)
|
|
49
|
+
baudrate: SPI clock frequency in Hz (default 1MHz)
|
|
50
|
+
"""
|
|
51
|
+
super().__init__()
|
|
52
|
+
|
|
53
|
+
self._cs_pin = cs
|
|
54
|
+
self._clock_pin = clock
|
|
55
|
+
self._mosi_pin = mosi
|
|
56
|
+
self._miso_pin = miso
|
|
57
|
+
self._baudrate = baudrate
|
|
58
|
+
|
|
59
|
+
self._spi = None
|
|
60
|
+
self._cs = None
|
|
61
|
+
|
|
62
|
+
def init(self):
|
|
63
|
+
"""Initialize SPI hardware"""
|
|
64
|
+
# Create SPI bus
|
|
65
|
+
self._spi = busio.SPI(
|
|
66
|
+
clock=self._clock_pin, MOSI=self._mosi_pin, MISO=self._miso_pin
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Setup CS pin (active low)
|
|
70
|
+
self._cs = digitalio.DigitalInOut(self._cs_pin)
|
|
71
|
+
self._cs.direction = digitalio.Direction.OUTPUT
|
|
72
|
+
self._cs.value = True # CS high (inactive)
|
|
73
|
+
|
|
74
|
+
def deinit(self):
|
|
75
|
+
"""Deinitialize SPI hardware"""
|
|
76
|
+
if self._spi is not None:
|
|
77
|
+
self._spi.deinit()
|
|
78
|
+
self._spi = None
|
|
79
|
+
if self._cs is not None:
|
|
80
|
+
self._cs.deinit()
|
|
81
|
+
self._cs = None
|
|
82
|
+
|
|
83
|
+
def _spi_transfer(self, data):
|
|
84
|
+
"""Perform SPI transfer
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
data: List of bytes to send
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
List of received bytes
|
|
91
|
+
"""
|
|
92
|
+
if self._spi is None or self._cs is None:
|
|
93
|
+
raise TmcComException("SPI not initialized")
|
|
94
|
+
|
|
95
|
+
tx_data = bytes(data)
|
|
96
|
+
rx_data = bytearray(len(data))
|
|
97
|
+
|
|
98
|
+
# Lock the SPI bus and perform transfer
|
|
99
|
+
while not self._spi.try_lock():
|
|
100
|
+
pass
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
# Configure SPI for TMC (Mode 3: CPOL=1, CPHA=1)
|
|
104
|
+
self._spi.configure(baudrate=self._baudrate, polarity=1, phase=1, bits=8)
|
|
105
|
+
|
|
106
|
+
# Perform transfer with CS control
|
|
107
|
+
self._cs.value = False # CS low (active)
|
|
108
|
+
self._spi.write_readinto(tx_data, rx_data)
|
|
109
|
+
self._cs.value = True # CS high (inactive)
|
|
110
|
+
finally:
|
|
111
|
+
self._spi.unlock()
|
|
112
|
+
|
|
113
|
+
return list(rx_data)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
# pylint: disable=too-many-arguments
|
|
3
|
+
# pylint: disable=too-many-positional-arguments
|
|
4
|
+
# pylint: disable=too-few-public-methods
|
|
5
|
+
"""
|
|
6
|
+
TmcComUartCircuitPython - UART communication for CircuitPython
|
|
7
|
+
|
|
8
|
+
Uses the busio.UART interface for single-wire UART communication.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import time
|
|
12
|
+
import busio # pylint: disable=import-error
|
|
13
|
+
from ._tmc_com_uart_base import TmcComUartBase
|
|
14
|
+
from .._tmc_exceptions import TmcComException
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TmcComUartCircuitPython(TmcComUartBase):
|
|
18
|
+
"""UART Communication class for CircuitPython
|
|
19
|
+
|
|
20
|
+
Example usage:
|
|
21
|
+
import board
|
|
22
|
+
from tmc_driver.com import TmcComUartCircuitPython
|
|
23
|
+
|
|
24
|
+
uart_com = TmcComUartCircuitPython(
|
|
25
|
+
tx=board.TX,
|
|
26
|
+
rx=board.RX,
|
|
27
|
+
baudrate=115200
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
For single-wire UART, connect TX to the TMC UART pin through a 1k resistor.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, tx, rx, baudrate=115200, timeout=1.0):
|
|
34
|
+
"""Initialize UART communication
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
tx: TX board pin (e.g., board.TX or board.GP0)
|
|
38
|
+
rx: RX board pin (e.g., board.RX or board.GP1)
|
|
39
|
+
baudrate: UART baudrate (default 115200)
|
|
40
|
+
timeout: Read timeout in seconds (default 1.0)
|
|
41
|
+
"""
|
|
42
|
+
super().__init__()
|
|
43
|
+
|
|
44
|
+
self._tx_pin = tx
|
|
45
|
+
self._rx_pin = rx
|
|
46
|
+
self._baudrate = baudrate
|
|
47
|
+
self._timeout = timeout
|
|
48
|
+
|
|
49
|
+
self._uart = None
|
|
50
|
+
|
|
51
|
+
def init(self):
|
|
52
|
+
"""Initialize UART hardware"""
|
|
53
|
+
self._uart = busio.UART(
|
|
54
|
+
tx=self._tx_pin,
|
|
55
|
+
rx=self._rx_pin,
|
|
56
|
+
baudrate=self._baudrate,
|
|
57
|
+
timeout=self._timeout,
|
|
58
|
+
)
|
|
59
|
+
# Create a fake serial object for compatibility with base class
|
|
60
|
+
self.ser = _FakeSerial(self._uart)
|
|
61
|
+
|
|
62
|
+
def deinit(self):
|
|
63
|
+
"""Deinitialize UART hardware"""
|
|
64
|
+
if self._uart is not None:
|
|
65
|
+
self._uart.deinit()
|
|
66
|
+
self._uart = None
|
|
67
|
+
self.ser = None
|
|
68
|
+
|
|
69
|
+
def _uart_write(self, data):
|
|
70
|
+
"""Write data to UART
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
data: Bytes to write
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Number of bytes written
|
|
77
|
+
"""
|
|
78
|
+
if self._uart is None:
|
|
79
|
+
raise TmcComException("UART not initialized")
|
|
80
|
+
|
|
81
|
+
data_bytes = bytes(data)
|
|
82
|
+
self._uart.write(data_bytes)
|
|
83
|
+
|
|
84
|
+
time.sleep(0.01) # Small delay to ensure data is sent
|
|
85
|
+
|
|
86
|
+
return len(data_bytes)
|
|
87
|
+
|
|
88
|
+
def _uart_read(self, length):
|
|
89
|
+
"""Read data from UART
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
length: Number of bytes to read
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Bytes read or empty bytes if timeout
|
|
96
|
+
"""
|
|
97
|
+
if self._uart is None:
|
|
98
|
+
raise TmcComException("UART not initialized")
|
|
99
|
+
|
|
100
|
+
# Wait a bit for data to arrive
|
|
101
|
+
time.sleep(0.01) # 10ms in seconds (CircuitPython uses seconds)
|
|
102
|
+
|
|
103
|
+
result = self._uart.read(length)
|
|
104
|
+
if result is None:
|
|
105
|
+
return bytes()
|
|
106
|
+
return bytes(result)
|
|
107
|
+
|
|
108
|
+
def _uart_flush(self):
|
|
109
|
+
"""Flush UART receive buffer"""
|
|
110
|
+
if self._uart is None:
|
|
111
|
+
raise TmcComException("UART not initialized")
|
|
112
|
+
|
|
113
|
+
# Reset input buffer
|
|
114
|
+
self._uart.reset_input_buffer()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class _FakeSerial:
|
|
118
|
+
"""Fake serial object for compatibility with base class"""
|
|
119
|
+
|
|
120
|
+
def __init__(self, uart):
|
|
121
|
+
"""Constructor for fake serial object"""
|
|
122
|
+
self._uart = uart
|
|
123
|
+
self.is_open = True
|
|
124
|
+
|
|
125
|
+
def close(self):
|
|
126
|
+
"""Close the fake serial port"""
|
|
127
|
+
self.is_open = False
|
|
@@ -48,7 +48,10 @@ class TmcEnableControl:
|
|
|
48
48
|
|
|
49
49
|
def deinit(self):
|
|
50
50
|
"""destructor"""
|
|
51
|
-
|
|
51
|
+
# Only disable motor if callback is still available
|
|
52
|
+
# During garbage collection, parent object may already be destroyed
|
|
53
|
+
if self._get_register_callback is not None:
|
|
54
|
+
self.set_motor_enabled(False)
|
|
52
55
|
|
|
53
56
|
@abstractmethod
|
|
54
57
|
def set_motor_enabled(self, en):
|
|
@@ -55,6 +55,16 @@ class TmcMotionControl:
|
|
|
55
55
|
"""_current_pos setter"""
|
|
56
56
|
self._current_pos = current_pos
|
|
57
57
|
|
|
58
|
+
@property
|
|
59
|
+
def current_pos_fullstep(self) -> int:
|
|
60
|
+
"""_current_pos as fullstep property"""
|
|
61
|
+
return self.current_pos // self.mres
|
|
62
|
+
|
|
63
|
+
@current_pos_fullstep.setter
|
|
64
|
+
def current_pos_fullstep(self, current_pos: int):
|
|
65
|
+
"""_current_pos as fullstep setter"""
|
|
66
|
+
self.current_pos = current_pos * self.mres
|
|
67
|
+
|
|
58
68
|
@property
|
|
59
69
|
def mres(self):
|
|
60
70
|
"""_mres property"""
|
|
@@ -130,7 +140,7 @@ class TmcMotionControl:
|
|
|
130
140
|
@property
|
|
131
141
|
def max_speed_fullstep(self):
|
|
132
142
|
"""_max_speed_fullstep property"""
|
|
133
|
-
return self.max_speed
|
|
143
|
+
return self.max_speed // self.mres
|
|
134
144
|
|
|
135
145
|
@max_speed_fullstep.setter
|
|
136
146
|
def max_speed_fullstep(self, max_speed_fullstep: int):
|
|
@@ -155,7 +165,7 @@ class TmcMotionControl:
|
|
|
155
165
|
@property
|
|
156
166
|
def acceleration_fullstep(self):
|
|
157
167
|
"""_acceleration_fullstep property"""
|
|
158
|
-
return self._acceleration
|
|
168
|
+
return self._acceleration // self.mres
|
|
159
169
|
|
|
160
170
|
@acceleration_fullstep.setter
|
|
161
171
|
def acceleration_fullstep(self, acceleration_fullstep: int):
|
|
@@ -4,10 +4,13 @@ import sys
|
|
|
4
4
|
import time
|
|
5
5
|
|
|
6
6
|
MICROPYTHON = sys.implementation.name == "micropython"
|
|
7
|
+
CIRCUITPYTHON = sys.implementation.name == "circuitpython"
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def get_time_us():
|
|
10
|
-
"""Get current time in microseconds, compatible with
|
|
11
|
+
"""Get current time in microseconds, compatible with CPython, MicroPython and CircuitPython"""
|
|
11
12
|
if MICROPYTHON:
|
|
12
13
|
return time.ticks_us() # pylint: disable=no-member
|
|
14
|
+
if CIRCUITPYTHON:
|
|
15
|
+
return time.monotonic_ns() // 1000 # pylint: disable=no-member
|
|
13
16
|
return time.time_ns() // 1000
|
|
@@ -55,12 +55,12 @@ class GStat(shared.GStat):
|
|
|
55
55
|
def check(self):
|
|
56
56
|
"""check if the driver is ok"""
|
|
57
57
|
self.read()
|
|
58
|
-
if self.reset:
|
|
59
|
-
raise TmcDriverException("TMC220X: reset detected")
|
|
60
58
|
if self.uv_cp:
|
|
61
59
|
raise TmcDriverException("TMC220X: undervoltage detected")
|
|
62
60
|
if self.drv_err:
|
|
63
61
|
raise TmcDriverException("TMC220X: driver error detected")
|
|
62
|
+
if self.reset:
|
|
63
|
+
raise TmcDriverException("TMC220X: reset detected")
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
class IfCnt(shared.IfCnt):
|
|
@@ -192,9 +192,12 @@ class ChopConf(shared.ChopConf):
|
|
|
192
192
|
@mres_ms.setter
|
|
193
193
|
def mres_ms(self, mres: int):
|
|
194
194
|
"""set µstep resolution"""
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
mres_to_bit = {1: 8, 2: 7, 4: 6, 8: 5, 16: 4, 32: 3, 64: 2, 128: 1, 256: 0}
|
|
196
|
+
if mres not in mres_to_bit:
|
|
197
|
+
raise ValueError(
|
|
198
|
+
f"Invalid mres value: {mres}. Must be power of 2 from 1 to 256"
|
|
199
|
+
)
|
|
200
|
+
self.mres = mres_to_bit[mres]
|
|
198
201
|
|
|
199
202
|
|
|
200
203
|
class PwmConf(shared.PwmConf):
|