PyTmcStepper 0.12.0__tar.gz → 0.14.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.
Files changed (75) hide show
  1. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/PKG-INFO +2 -2
  2. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/README.md +1 -1
  3. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/pyproject.toml +1 -1
  4. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/PyTmcStepper.egg-info/PKG-INFO +2 -2
  5. pytmcstepper-0.14.0/src/tmc_driver/__init__.py +96 -0
  6. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/_tmc_math.py +2 -0
  7. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/_tmc_stallguard.py +21 -12
  8. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/_tmc_stepperdriver.py +30 -29
  9. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/_tmc_xxxx.py +21 -9
  10. pytmcstepper-0.14.0/src/tmc_driver/com/__init__.py +64 -0
  11. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com.py +1 -1
  12. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_spi_base.py +4 -5
  13. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_uart_base.py +386 -341
  14. pytmcstepper-0.14.0/src/tmc_driver/enable_control/__init__.py +55 -0
  15. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/enable_control/_tmc_ec_pin.py +2 -2
  16. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -12
  17. pytmcstepper-0.14.0/src/tmc_driver/motion_control/__init__.py +111 -0
  18. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +48 -24
  19. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +2 -2
  20. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +1 -24
  21. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -12
  22. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +7 -20
  23. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/reg/_tmc220x_reg.py +2 -1
  24. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/reg/_tmc224x_reg.py +1 -0
  25. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/reg/_tmc5160_reg.py +21 -20
  26. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/reg/_tmc_reg.py +34 -2
  27. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_220x.py +1 -9
  28. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_2240.py +10 -21
  29. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_5160.py +50 -21
  30. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -2
  31. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +43 -18
  32. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +11 -4
  33. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +21 -5
  34. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py +2 -0
  35. pytmcstepper-0.12.0/src/tmc_driver/com/__init__.py +0 -0
  36. pytmcstepper-0.12.0/src/tmc_driver/enable_control/__init__.py +0 -0
  37. pytmcstepper-0.12.0/src/tmc_driver/motion_control/__init__.py +0 -0
  38. pytmcstepper-0.12.0/src/tmc_driver/reg/__init__.py +0 -0
  39. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/LICENSE +0 -0
  40. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/setup.cfg +0 -0
  41. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/PyTmcStepper.egg-info/SOURCES.txt +0 -0
  42. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  43. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  44. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  45. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/_tmc_exceptions.py +0 -0
  46. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/_tmc_validation.py +0 -0
  47. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
  48. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
  49. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_spi_micropython.py +0 -0
  50. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
  51. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/com/_tmc_com_uart_micropython.py +0 -0
  52. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  53. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  54. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/platform_utils.py +0 -0
  55. {pytmcstepper-0.12.0/src/tmc_driver → pytmcstepper-0.14.0/src/tmc_driver/reg}/__init__.py +0 -0
  56. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  57. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/reg/_tmc_shared_regs.py +0 -0
  58. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_2208.py +0 -0
  59. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_2209.py +0 -0
  60. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/__init__.py +0 -0
  61. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +0 -0
  62. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
  63. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_logger/__init__.py +0 -0
  64. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_logger/_tmc_logger_base.py +0 -0
  65. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py +0 -0
  66. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc2209.py +0 -0
  67. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc2240.py +0 -0
  68. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_com_spi.py +0 -0
  69. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_com_uart.py +0 -0
  70. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_ec_pin.py +0 -0
  71. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_math.py +0 -0
  72. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_modules.py +0 -0
  73. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_move.py +0 -0
  74. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_set_current.py +0 -0
  75. {pytmcstepper-0.12.0 → pytmcstepper-0.14.0}/tests/test_tmc_stallguard.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.12.0
3
+ Version: 0.14.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
@@ -283,7 +283,7 @@ from tmc_driver.tmc_2209 import *
283
283
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
284
284
 
285
285
  tmc.set_direction_reg(False)
286
- tmc.set_current(300)
286
+ tmc.set_current_rms(300)
287
287
  tmc.set_interpolation(True)
288
288
  tmc.set_spreadcycle(False)
289
289
  tmc.set_microstepping_resolution(2)
@@ -253,7 +253,7 @@ from tmc_driver.tmc_2209 import *
253
253
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
254
254
 
255
255
  tmc.set_direction_reg(False)
256
- tmc.set_current(300)
256
+ tmc.set_current_rms(300)
257
257
  tmc.set_interpolation(True)
258
258
  tmc.set_spreadcycle(False)
259
259
  tmc.set_microstepping_resolution(2)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyTmcStepper"
7
- version = "0.12.0"
7
+ version = "0.14.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"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.12.0
3
+ Version: 0.14.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
@@ -283,7 +283,7 @@ from tmc_driver.tmc_2209 import *
283
283
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
284
284
 
285
285
  tmc.set_direction_reg(False)
286
- tmc.set_current(300)
286
+ tmc.set_current_rms(300)
287
287
  tmc.set_interpolation(True)
288
288
  tmc.set_spreadcycle(False)
289
289
  tmc.set_microstepping_resolution(2)
@@ -0,0 +1,96 @@
1
+ """
2
+ PyTmcStepper - Python library for Trinamic TMC stepper motor drivers
3
+
4
+ This package provides a high-level interface for controlling TMC stepper motor drivers
5
+ via UART or SPI communication on various platforms including Raspberry Pi, Jetson, and MicroPython.
6
+
7
+ Main Components:
8
+ - Driver Classes: Tmc2208, Tmc2209, Tmc2240, Tmc5160
9
+ - Communication: TmcCom and subclasses for UART/SPI
10
+ - Motion Control: Various strategies for motor movement
11
+ - Enable Control: Motor enable/disable functionality
12
+ - GPIO Abstraction: Platform-independent GPIO access
13
+ - Logging: Configurable logging support
14
+
15
+ Example:
16
+ >>> from tmc_driver import Tmc2209, Loglevel
17
+ >>> from tmc_driver.com import TmcComUart
18
+ >>> from tmc_driver.motion_control import TmcMotionControlStepDir
19
+ >>> from tmc_driver.enable_control import TmcEnableControlPin
20
+ >>>
21
+ >>> tmc = Tmc2209(
22
+ ... TmcEnableControlPin(21),
23
+ ... TmcMotionControlStepDir(16, 20),
24
+ ... TmcComUart("/dev/serial0"),
25
+ ... loglevel=Loglevel.INFO
26
+ ... )
27
+ """
28
+
29
+ # Driver classes
30
+ from .tmc_2208 import Tmc2208
31
+ from .tmc_2209 import Tmc2209
32
+ from .tmc_2240 import Tmc2240
33
+ from .tmc_5160 import Tmc5160
34
+
35
+ # Exceptions
36
+ from ._tmc_exceptions import (
37
+ TmcException,
38
+ TmcDriverException,
39
+ TmcComException,
40
+ TmcMotionControlException,
41
+ TmcEnableControlException,
42
+ )
43
+
44
+ # Logger
45
+ from .tmc_logger import TmcLogger, Loglevel
46
+
47
+ # GPIO
48
+ from . import tmc_gpio
49
+ from .tmc_gpio import Board
50
+
51
+ # Enable Control
52
+ from .enable_control._tmc_ec_pin import TmcEnableControlPin
53
+ from .enable_control._tmc_ec_toff import TmcEnableControlToff
54
+
55
+ # Motion Control
56
+ from .motion_control._tmc_mc import StopMode, MovementAbsRel, MovementPhase, Direction
57
+ from .motion_control._tmc_mc_step_dir import TmcMotionControlStepDir
58
+ from .motion_control._tmc_mc_step_pwm_dir import TmcMotionControlStepPwmDir
59
+ from .motion_control._tmc_mc_step_reg import TmcMotionControlStepReg
60
+ from .motion_control._tmc_mc_vactual import TmcMotionControlVActual
61
+ from .motion_control._tmc_mc_int_ramp_generator import TmcMotionControlIntRampGenerator
62
+
63
+ __all__ = [
64
+ # Driver classes
65
+ "Tmc2208",
66
+ "Tmc2209",
67
+ "Tmc2240",
68
+ "Tmc5160",
69
+ # Exceptions
70
+ "TmcException",
71
+ "TmcDriverException",
72
+ "TmcComException",
73
+ "TmcMotionControlException",
74
+ "TmcEnableControlException",
75
+ # Logger
76
+ "TmcLogger",
77
+ "Loglevel",
78
+ # GPIO
79
+ "tmc_gpio",
80
+ "Board",
81
+ # Enable Control
82
+ "TmcEnableControlPin",
83
+ "TmcEnableControlToff",
84
+ # Motion Control
85
+ "StopMode",
86
+ "MovementAbsRel",
87
+ "MovementPhase",
88
+ "Direction",
89
+ "TmcMotionControlStepDir",
90
+ "TmcMotionControlStepPwmDir",
91
+ "TmcMotionControlStepReg",
92
+ "TmcMotionControlVActual",
93
+ "TmcMotionControlIntRampGenerator",
94
+ ]
95
+
96
+ __version__ = "0.5.0"
@@ -81,6 +81,8 @@ def steps_to_tstep(steps: int, mres: int) -> int:
81
81
  Returns:
82
82
  tstep (int): time per step
83
83
  """
84
+ if steps == 0:
85
+ return 0
84
86
  return int(round(12000000 / (steps * 256 / mres)))
85
87
 
86
88
 
@@ -81,10 +81,7 @@ class StallGuard:
81
81
 
82
82
  def deinit(self):
83
83
  """destructor"""
84
- if (
85
- getattr(self, "_pin_stallguard", None) is not None
86
- and self._pin_stallguard is not None
87
- ):
84
+ if hasattr(self, "_pin_stallguard") and self._pin_stallguard is not None:
88
85
  tmc_gpio.tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
89
86
  tmc_gpio.tmc_gpio.gpio_cleanup(self._pin_stallguard)
90
87
  self._pin_stallguard = None
@@ -110,10 +107,8 @@ class StallGuard:
110
107
  Loglevel.INFO,
111
108
  )
112
109
 
113
- self._set_stallguard_threshold(threshold)
114
- self._set_coolstep_threshold(
115
- tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution())
116
- )
110
+ self.stallguard_setup(threshold, min_speed)
111
+
117
112
  self._sg_callback = callback
118
113
  self._pin_stallguard = pin_stallguard
119
114
 
@@ -194,6 +189,24 @@ class StallGuard:
194
189
  raise TmcMotionControlException("tmc_mc is None; cannot reset current pos")
195
190
  self.tmc_mc.current_pos = 0
196
191
 
192
+ def stallguard_setup(
193
+ self,
194
+ threshold: int,
195
+ min_speed: int,
196
+ ):
197
+ """internal setup for stallguard
198
+ Args:
199
+ threshold (int): value for SGTHRS
200
+ min_speed (int): min speed [steps/s] for StallGuard
201
+ """
202
+ self.tmc_logger.log(f"Stallguard threshold: {threshold}", Loglevel.DEBUG)
203
+
204
+ self.set_spreadcycle(False)
205
+ self._set_stallguard_threshold(threshold)
206
+ self._set_coolstep_threshold(
207
+ tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution())
208
+ )
209
+
197
210
  def do_homing(
198
211
  self,
199
212
  diag_pin: int,
@@ -223,8 +236,6 @@ class StallGuard:
223
236
  if self.tmc_mc is None:
224
237
  raise TmcMotionControlException("tmc_mc is None; cannot do homing")
225
238
 
226
- self.tmc_logger.log(f"Stallguard threshold: {threshold}", Loglevel.DEBUG)
227
-
228
239
  if max_speed is None:
229
240
  max_speed = self.tmc_mc.max_speed_homing
230
241
  if cb_success is _CB_SENTINEL:
@@ -233,8 +244,6 @@ class StallGuard:
233
244
  self.tmc_logger.log("---", Loglevel.INFO)
234
245
  self.tmc_logger.log("homing", Loglevel.INFO)
235
246
 
236
- self.set_spreadcycle(False)
237
-
238
247
  self.set_stallguard_callback(
239
248
  diag_pin,
240
249
  threshold,
@@ -12,7 +12,7 @@
12
12
  this module has the function to move the motor via STEP/DIR pins
13
13
  """
14
14
 
15
- from .tmc_gpio import Gpio, GpioMode, Board
15
+ from .tmc_gpio import Board
16
16
  from . import tmc_gpio
17
17
  from .motion_control._tmc_mc import (
18
18
  TmcMotionControl,
@@ -91,16 +91,13 @@ class TmcStepperDriver:
91
91
 
92
92
  def deinit(self):
93
93
  """destructor"""
94
- if getattr(self, "tmc_ec", None) is not None and self.tmc_ec is not None:
94
+ if hasattr(self, "tmc_ec") and self.tmc_ec is not None:
95
95
  self.tmc_ec.deinit()
96
96
  self.tmc_ec = None
97
- if getattr(self, "tmc_mc", None) is not None and self.tmc_mc is not None:
97
+ if hasattr(self, "tmc_mc") and self.tmc_mc is not None:
98
98
  self.tmc_mc.deinit()
99
99
  self.tmc_mc = None
100
- if (
101
- getattr(self, "tmc_logger", None) is not None
102
- and self.tmc_logger is not None
103
- ):
100
+ if hasattr(self, "tmc_logger") and self.tmc_logger is not None:
104
101
  self.tmc_logger.deinit()
105
102
  del self.tmc_logger
106
103
 
@@ -116,14 +113,14 @@ class TmcStepperDriver:
116
113
  @property
117
114
  def current_pos(self) -> int:
118
115
  """_current_pos property"""
119
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
116
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
120
117
  raise AttributeError("TmcMotionControl is not set")
121
118
  return self.tmc_mc.current_pos
122
119
 
123
120
  @current_pos.setter
124
121
  def current_pos(self, current_pos: int):
125
122
  """_current_pos setter"""
126
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
123
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
127
124
  raise AttributeError("TmcMotionControl is not set")
128
125
  self.tmc_mc.current_pos = current_pos
129
126
 
@@ -140,77 +137,77 @@ class TmcStepperDriver:
140
137
  @property
141
138
  def mres(self) -> int:
142
139
  """_mres property"""
143
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
140
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
144
141
  raise AttributeError("TmcMotionControl is not set")
145
142
  return self.tmc_mc.mres
146
143
 
147
144
  @mres.setter
148
145
  def mres(self, mres: int):
149
146
  """_mres setter"""
150
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
147
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
151
148
  raise AttributeError("TmcMotionControl is not set")
152
149
  self.tmc_mc.mres = mres
153
150
 
154
151
  @property
155
152
  def steps_per_rev(self) -> int:
156
153
  """_steps_per_rev property"""
157
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
154
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
158
155
  raise AttributeError("TmcMotionControl is not set")
159
156
  return self.tmc_mc.steps_per_rev
160
157
 
161
158
  @property
162
159
  def fullsteps_per_rev(self) -> int:
163
160
  """_fullsteps_per_rev property"""
164
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
161
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
165
162
  raise AttributeError("TmcMotionControl is not set")
166
163
  return self.tmc_mc.fullsteps_per_rev
167
164
 
168
165
  @fullsteps_per_rev.setter
169
166
  def fullsteps_per_rev(self, fullsteps_per_rev: int):
170
167
  """_fullsteps_per_rev setter"""
171
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
168
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
172
169
  raise AttributeError("TmcMotionControl is not set")
173
170
  self.tmc_mc.fullsteps_per_rev = fullsteps_per_rev
174
171
 
175
172
  @property
176
173
  def movement_abs_rel(self) -> MovementAbsRel:
177
174
  """_movement_abs_rel property"""
178
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
175
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
179
176
  raise AttributeError("TmcMotionControl is not set")
180
177
  return self.tmc_mc.movement_abs_rel
181
178
 
182
179
  @movement_abs_rel.setter
183
180
  def movement_abs_rel(self, movement_abs_rel: MovementAbsRel):
184
181
  """_movement_abs_rel setter"""
185
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
182
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
186
183
  raise AttributeError("TmcMotionControl is not set")
187
184
  self.tmc_mc.movement_abs_rel = movement_abs_rel
188
185
 
189
186
  @property
190
187
  def movement_phase(self) -> MovementPhase:
191
188
  """_movement_phase property"""
192
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
189
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
193
190
  raise AttributeError("TmcMotionControl is not set")
194
191
  return self.tmc_mc.movement_phase
195
192
 
196
193
  @property
197
194
  def speed(self) -> float:
198
195
  """_speed property"""
199
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
196
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
200
197
  raise AttributeError("TmcMotionControl is not set")
201
198
  return self.tmc_mc.speed
202
199
 
203
200
  @speed.setter
204
201
  def speed(self, speed: int):
205
202
  """_speed setter"""
206
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
203
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
207
204
  raise AttributeError("TmcMotionControl is not set")
208
205
  self.tmc_mc.speed = speed
209
206
 
210
207
  @property
211
208
  def max_speed(self) -> int:
212
209
  """_max_speed property"""
213
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
210
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
214
211
  raise AttributeError("TmcMotionControl is not set")
215
212
  return self.tmc_mc.max_speed
216
213
 
@@ -223,42 +220,42 @@ class TmcStepperDriver:
223
220
  @property
224
221
  def max_speed_fullstep(self) -> int:
225
222
  """_max_speed_fullstep property"""
226
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
223
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
227
224
  raise AttributeError("TmcMotionControl is not set")
228
225
  return self.tmc_mc.max_speed_fullstep
229
226
 
230
227
  @max_speed_fullstep.setter
231
228
  def max_speed_fullstep(self, max_speed_fullstep: int):
232
229
  """_max_speed_fullstep setter"""
233
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
230
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
234
231
  raise AttributeError("TmcMotionControl is not set")
235
232
  self.tmc_mc.max_speed_fullstep = max_speed_fullstep
236
233
 
237
234
  @property
238
235
  def acceleration(self) -> int:
239
236
  """_acceleration property"""
240
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
237
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
241
238
  raise AttributeError("TmcMotionControl is not set")
242
239
  return self.tmc_mc.acceleration
243
240
 
244
241
  @acceleration.setter
245
242
  def acceleration(self, acceleration: int):
246
243
  """_acceleration setter"""
247
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
244
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
248
245
  raise AttributeError("TmcMotionControl is not set")
249
246
  self.tmc_mc.acceleration = acceleration
250
247
 
251
248
  @property
252
249
  def acceleration_fullstep(self) -> int:
253
250
  """_acceleration_fullstep property"""
254
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
251
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
255
252
  raise AttributeError("TmcMotionControl is not set")
256
253
  return self.tmc_mc.acceleration_fullstep
257
254
 
258
255
  @acceleration_fullstep.setter
259
256
  def acceleration_fullstep(self, acceleration_fullstep: int):
260
257
  """_acceleration_fullstep setter"""
261
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
258
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
262
259
  raise AttributeError("TmcMotionControl is not set")
263
260
  self.tmc_mc.acceleration_fullstep = acceleration_fullstep
264
261
 
@@ -266,7 +263,7 @@ class TmcStepperDriver:
266
263
  self, steps, movement_abs_rel: MovementAbsRel | None = None
267
264
  ) -> StopMode:
268
265
  """motioncontrol wrapper"""
269
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
266
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
270
267
  raise AttributeError("TmcMotionControl is not set")
271
268
  return self.tmc_mc.run_to_position_steps(steps, movement_abs_rel)
272
269
 
@@ -282,11 +279,15 @@ class TmcStepperDriver:
282
279
  """motioncontrol wrapper"""
283
280
  return self.run_to_position_steps(revs * self.steps_per_rev, movement_abs_rel)
284
281
 
285
- # StepperDriver methods
282
+ def reset_position(self):
283
+ """resets the current position to 0"""
284
+ self.current_pos_fullstep = 0
285
+
286
+ # Test Methods
286
287
  # ----------------------------
287
288
  def test_step(self):
288
289
  """test method"""
289
- if getattr(self, "tmc_mc", None) is None or self.tmc_mc is None:
290
+ if not hasattr(self, "tmc_mc") or self.tmc_mc is None:
290
291
  raise AttributeError("TmcMotionControl is not set")
291
292
  for _ in range(100):
292
293
  self.tmc_mc.set_direction(Direction.CW)
@@ -1,5 +1,6 @@
1
1
  # pylint: disable=wildcard-import
2
2
  # pylint: disable=unused-wildcard-import
3
+ # pylint: disable=unused-import
3
4
  # pylint: disable=too-many-arguments
4
5
  # pylint: disable=too-many-positional-arguments
5
6
  # pylint: disable=too-many-public-methods
@@ -13,6 +14,7 @@ this module has two different functions:
13
14
 
14
15
  import time
15
16
  from abc import abstractmethod
17
+ from .tmc_gpio import Gpio
16
18
  from ._tmc_stepperdriver import *
17
19
  from .tmc_logger import Loglevel
18
20
  from .enable_control._tmc_ec import TmcEnableControl
@@ -21,7 +23,13 @@ from .com._tmc_com import TmcCom
21
23
  from .reg._tmc_reg import TmcReg
22
24
  from .reg import _tmc_shared_regs as tmc_shared_regs
23
25
  from ._tmc_validation import validate_submodule
24
- from ._tmc_exceptions import TmcDriverException, TmcComException
26
+ from ._tmc_exceptions import (
27
+ TmcException,
28
+ TmcComException,
29
+ TmcMotionControlException,
30
+ TmcEnableControlException,
31
+ TmcDriverException,
32
+ )
25
33
 
26
34
 
27
35
  class TmcXXXX(TmcStepperDriver):
@@ -37,6 +45,7 @@ class TmcXXXX(TmcStepperDriver):
37
45
  gconf: tmc_shared_regs.GConf
38
46
  chopconf: tmc_shared_regs.ChopConf
39
47
  mscnt: tmc_shared_regs.MsCnt
48
+ tpwmthrs: tmc_shared_regs.TPwmThrs
40
49
 
41
50
  # Constructor/Destructor
42
51
  # ----------------------------
@@ -91,14 +100,8 @@ class TmcXXXX(TmcStepperDriver):
91
100
  if self.tmc_com is not None:
92
101
  self.tmc_com.tmc_logger = self.tmc_logger
93
102
  self.tmc_com.driver_address = driver_address
94
-
95
103
  self.tmc_com.init()
96
104
 
97
- if self.tmc_mc is not None:
98
- setattr(self.tmc_mc, "tmc_com", self.tmc_com)
99
- if self.tmc_ec is not None:
100
- setattr(self.tmc_ec, "tmc_com", self.tmc_com)
101
-
102
105
  # Register callback for submodules to access registers
103
106
  self.tmc_com.set_get_register_callback(self._get_register)
104
107
  if self.tmc_mc is not None:
@@ -106,7 +109,7 @@ class TmcXXXX(TmcStepperDriver):
106
109
  if self.tmc_ec is not None:
107
110
  self.tmc_ec.set_get_register_callback(self._get_register)
108
111
 
109
- if getattr(self, "tmc_mc", None) is not None:
112
+ if hasattr(self, "tmc_mc") and self.tmc_mc is not None:
110
113
  self.max_speed_fullstep = 100
111
114
  self.acceleration_fullstep = 100
112
115
 
@@ -380,6 +383,15 @@ class TmcXXXX(TmcStepperDriver):
380
383
 
381
384
  return reg, data, flags
382
385
 
386
+ def set_hybrid_threshold_speed(self, speed: int):
387
+ """sets the hybrid threshold speed
388
+
389
+ Args:
390
+ speed (int): speed in steps per second
391
+ """
392
+ tstep = tmc_math.steps_to_tstep(speed, self.get_microstepping_resolution())
393
+ self.tpwmthrs.modify("tpwmthrs", tstep)
394
+
383
395
  # Test Methods
384
396
  # ----------------------------
385
397
  def test_pin(self, pin, ioin_reg_field_name: str) -> bool:
@@ -469,4 +481,4 @@ class TmcXXXX(TmcStepperDriver):
469
481
  self.tmc_logger.log("---")
470
482
  self.tmc_logger.log("TEST COM")
471
483
 
472
- return self.tmc_com.test_com()
484
+ return self.tmc_com.test_com(self.ioin)
@@ -0,0 +1,64 @@
1
+ # pylint: disable=import-outside-toplevel
2
+ """Communication module for TMC stepper drivers
3
+
4
+ Provides UART and SPI communication implementations for different platforms:
5
+ - TmcComUart: Standard UART communication (CPython with pyserial)
6
+ - TmcComSpi: Standard SPI communication (CPython with spidev)
7
+ - TmcComUartMicroPython: UART for MicroPython
8
+ - TmcComSpiMicroPython: SPI for MicroPython
9
+ - TmcComSpiFtdi: SPI via FTDI USB devices
10
+
11
+ Example:
12
+ >>> from tmc_driver.com import TmcComUart
13
+ >>> tmc_com = TmcComUart("/dev/serial0")
14
+
15
+ Note: Base classes (TmcCom, TmcComUartBase, TmcComSpiBase) can be imported
16
+ directly from their respective files if needed for type hints or subclassing.
17
+ """
18
+
19
+ try:
20
+ from typing import TYPE_CHECKING
21
+
22
+ if TYPE_CHECKING:
23
+ # Import for type checkers/IDE only - not executed at runtime
24
+ from ._tmc_com_uart import TmcComUart
25
+ from ._tmc_com_spi import TmcComSpi
26
+ from ._tmc_com_uart_micropython import TmcComUartMicroPython
27
+ from ._tmc_com_spi_micropython import TmcComSpiMicroPython
28
+ from ._tmc_com_spi_ftdi import TmcComSpiFtdi
29
+ except ImportError:
30
+ pass
31
+
32
+
33
+ def __getattr__(name):
34
+ """Lazy import of communication classes to avoid circular imports"""
35
+ if name == "TmcComUart":
36
+ from ._tmc_com_uart import TmcComUart
37
+
38
+ return TmcComUart
39
+ if name == "TmcComSpi":
40
+ from ._tmc_com_spi import TmcComSpi
41
+
42
+ return TmcComSpi
43
+ if name == "TmcComUartMicroPython":
44
+ from ._tmc_com_uart_micropython import TmcComUartMicroPython
45
+
46
+ return TmcComUartMicroPython
47
+ if name == "TmcComSpiMicroPython":
48
+ from ._tmc_com_spi_micropython import TmcComSpiMicroPython
49
+
50
+ return TmcComSpiMicroPython
51
+ if name == "TmcComSpiFtdi":
52
+ from ._tmc_com_spi_ftdi import TmcComSpiFtdi
53
+
54
+ return TmcComSpiFtdi
55
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
56
+
57
+
58
+ __all__ = [
59
+ "TmcComUart",
60
+ "TmcComSpi",
61
+ "TmcComUartMicroPython",
62
+ "TmcComSpiMicroPython",
63
+ "TmcComSpiFtdi",
64
+ ]
@@ -144,5 +144,5 @@ class TmcCom:
144
144
  """this function clear the communication buffers of the Raspberry Pi"""
145
145
 
146
146
  @abstractmethod
147
- def test_com(self):
147
+ def test_com(self, ioin) -> bool:
148
148
  """test com connection"""
@@ -138,16 +138,15 @@ class TmcComSpiBase(TmcCom):
138
138
  def flush_com_buffer(self):
139
139
  """this function clear the communication buffers of the Raspberry Pi"""
140
140
 
141
- def test_com(self):
141
+ def test_com(self, ioin: tmc_shared_reg.Ioin):
142
142
  """test com connection
143
143
 
144
+ Args:
145
+ ioin: IOIN register instance
146
+
144
147
  Returns:
145
148
  bool: True if communication is OK, False otherwise
146
-
147
- Raises:
148
- TmcComException: if TMC register IOIN not available
149
149
  """
150
- ioin: tmc_shared_reg.Ioin = self.get_register("ioin") # type: ignore
151
150
  data, flags = ioin.read()
152
151
  del flags # unused
153
152