PyTmcStepper 0.15.0__py3-none-any.whl
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.15.0.dist-info/METADATA +338 -0
- pytmcstepper-0.15.0.dist-info/RECORD +56 -0
- pytmcstepper-0.15.0.dist-info/WHEEL +5 -0
- pytmcstepper-0.15.0.dist-info/licenses/LICENSE +683 -0
- pytmcstepper-0.15.0.dist-info/top_level.txt +1 -0
- tmc_driver/__init__.py +96 -0
- tmc_driver/_tmc_exceptions.py +21 -0
- tmc_driver/_tmc_math.py +122 -0
- tmc_driver/_tmc_stallguard.py +340 -0
- tmc_driver/_tmc_stepperdriver.py +210 -0
- tmc_driver/_tmc_validation.py +29 -0
- tmc_driver/_tmc_xxxx.py +489 -0
- tmc_driver/com/__init__.py +64 -0
- tmc_driver/com/_tmc_com.py +148 -0
- tmc_driver/com/_tmc_com_spi.py +81 -0
- tmc_driver/com/_tmc_com_spi_base.py +159 -0
- tmc_driver/com/_tmc_com_spi_ftdi.py +48 -0
- tmc_driver/com/_tmc_com_spi_micropython.py +99 -0
- tmc_driver/com/_tmc_com_uart.py +113 -0
- tmc_driver/com/_tmc_com_uart_base.py +386 -0
- tmc_driver/com/_tmc_com_uart_micropython.py +115 -0
- tmc_driver/enable_control/__init__.py +55 -0
- tmc_driver/enable_control/_tmc_ec.py +59 -0
- tmc_driver/enable_control/_tmc_ec_pin.py +48 -0
- tmc_driver/enable_control/_tmc_ec_toff.py +30 -0
- tmc_driver/motion_control/__init__.py +111 -0
- tmc_driver/motion_control/_tmc_mc.py +280 -0
- tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +218 -0
- tmc_driver/motion_control/_tmc_mc_step_dir.py +415 -0
- tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +78 -0
- tmc_driver/motion_control/_tmc_mc_step_reg.py +36 -0
- tmc_driver/motion_control/_tmc_mc_vactual.py +221 -0
- tmc_driver/platform_utils.py +13 -0
- tmc_driver/reg/__init__.py +0 -0
- tmc_driver/reg/_tmc2209_reg.py +55 -0
- tmc_driver/reg/_tmc220x_reg.py +261 -0
- tmc_driver/reg/_tmc224x_reg.py +414 -0
- tmc_driver/reg/_tmc5160_reg.py +526 -0
- tmc_driver/reg/_tmc_reg.py +202 -0
- tmc_driver/reg/_tmc_shared_regs.py +314 -0
- tmc_driver/tmc_2208.py +17 -0
- tmc_driver/tmc_2209.py +75 -0
- tmc_driver/tmc_220x.py +383 -0
- tmc_driver/tmc_2240.py +340 -0
- tmc_driver/tmc_5160.py +344 -0
- tmc_driver/tmc_gpio/__init__.py +101 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +106 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +162 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +135 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +108 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +87 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +182 -0
- tmc_driver/tmc_logger/__init__.py +15 -0
- tmc_driver/tmc_logger/_tmc_logger_base.py +111 -0
- tmc_driver/tmc_logger/_tmc_logger_cpython.py +155 -0
- tmc_driver/tmc_logger/_tmc_logger_micropython.py +52 -0
|
@@ -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()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TMC validation module
|
|
3
|
+
|
|
4
|
+
This module provides validation functions for TMC driver components.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from ._tmc_exceptions import TmcDriverException
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def validate_submodule(
|
|
11
|
+
module, supported_types: tuple, driver_name: str, module_name: str = "module"
|
|
12
|
+
):
|
|
13
|
+
"""Validate that a module is of a supported type.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
module: The module instance to validate
|
|
17
|
+
supported_types: Tuple of supported base classes
|
|
18
|
+
driver_name: Name of the driver (for error messages)
|
|
19
|
+
module_name: Name of the module being validated (for error messages)
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
TmcDriverException: If the module type is not supported
|
|
23
|
+
"""
|
|
24
|
+
if module is not None and not isinstance(module, supported_types):
|
|
25
|
+
supported_names = ", ".join(cls.__name__ for cls in supported_types)
|
|
26
|
+
raise TmcDriverException(
|
|
27
|
+
f"{driver_name} does not support {type(module).__name__} as {module_name}. "
|
|
28
|
+
f"Supported types: {supported_names}"
|
|
29
|
+
)
|