PyTmcStepper 0.7.6__tar.gz → 0.7.8__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.7.6/src/PyTmcStepper.egg-info → pytmcstepper-0.7.8}/PKG-INFO +1 -1
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/setup.cfg +1 -1
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8/src/PyTmcStepper.egg-info}/PKG-INFO +1 -1
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/_tmc_gpio_board.py +21 -11
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/_tmc_logger.py +12 -3
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/_tmc_stallguard.py +16 -3
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/_tmc_stepperdriver.py +15 -12
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/com/_tmc_com.py +8 -10
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/com/_tmc_com_spi.py +9 -6
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/com/_tmc_com_uart.py +6 -3
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/enable_control/_tmc_ec.py +3 -1
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/enable_control/_tmc_ec_pin.py +6 -2
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/enable_control/_tmc_ec_toff.py +7 -4
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/_tmc_mc.py +31 -24
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +21 -16
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +6 -3
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +6 -4
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/reg/_tmc220x_reg.py +1 -1
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/reg/_tmc_reg.py +3 -7
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/tmc_2209.py +8 -6
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/tmc_220x.py +8 -6
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/tmc_2240.py +14 -10
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/LICENSE +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/README.md +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/pyproject.toml +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/PyTmcStepper.egg-info/SOURCES.txt +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/PyTmcStepper.egg-info/requires.txt +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/__init__.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/_tmc_exceptions.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/_tmc_math.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/com/__init__.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/enable_control/__init__.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/__init__.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/reg/__init__.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/reg/_tmc224x_reg.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/tmc_2208.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc2209.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc2240.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc_com_spi.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc_com_uart.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc_ec_pin.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc_math.py +0 -0
- {pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/tests/test_tmc_move.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.8
|
|
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
|
Home-page: https://github.com/Chr157i4n/PyTmcStepper
|
|
6
6
|
Author: Christian Köhlke
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = PyTmcStepper
|
|
3
|
-
version = 0.7.
|
|
3
|
+
version = 0.7.8
|
|
4
4
|
author = Christian Köhlke
|
|
5
5
|
author_email = christian@koehlke.de
|
|
6
6
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.8
|
|
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
|
Home-page: https://github.com/Chr157i4n/PyTmcStepper
|
|
6
6
|
Author: Christian Köhlke
|
|
@@ -117,7 +117,9 @@ class BaseGPIOWrapper:
|
|
|
117
117
|
class BaseRPiGPIOWrapper(BaseGPIOWrapper):
|
|
118
118
|
"""RPI.GPIO base wrapper"""
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
def __init__(self):
|
|
121
|
+
"""constructor"""
|
|
122
|
+
self._gpios_pwm = [None] * 200
|
|
121
123
|
|
|
122
124
|
def init(self, gpio_mode=None):
|
|
123
125
|
"""initialize GPIO library"""
|
|
@@ -185,6 +187,7 @@ class MockGPIOWrapper(BaseRPiGPIOWrapper):
|
|
|
185
187
|
|
|
186
188
|
def __init__(self):
|
|
187
189
|
"""constructor, imports Mock.GPIO"""
|
|
190
|
+
super().__init__()
|
|
188
191
|
self.GPIO = import_module('Mock.GPIO')
|
|
189
192
|
dependencies_logger.log("using Mock.GPIO for GPIO mocking", Loglevel.INFO)
|
|
190
193
|
|
|
@@ -193,6 +196,7 @@ class RPiGPIOWrapper(BaseRPiGPIOWrapper):
|
|
|
193
196
|
|
|
194
197
|
def __init__(self):
|
|
195
198
|
"""constructor, imports RPi.GPIO"""
|
|
199
|
+
super().__init__()
|
|
196
200
|
self.GPIO = import_module('RPi.GPIO')
|
|
197
201
|
dependencies_logger.log("using RPi.GPIO for GPIO control", Loglevel.INFO)
|
|
198
202
|
|
|
@@ -201,6 +205,7 @@ class JetsonGPIOWrapper(BaseRPiGPIOWrapper):
|
|
|
201
205
|
|
|
202
206
|
def __init__(self):
|
|
203
207
|
"""constructor, imports Jetson.GPIO"""
|
|
208
|
+
super().__init__()
|
|
204
209
|
self.GPIO = import_module('Jetson.GPIO')
|
|
205
210
|
dependencies_logger.log("using Jetson.GPIO for GPIO control", Loglevel.INFO)
|
|
206
211
|
|
|
@@ -209,17 +214,17 @@ class OPiGPIOWrapper(BaseRPiGPIOWrapper):
|
|
|
209
214
|
|
|
210
215
|
def __init__(self):
|
|
211
216
|
"""constructor, imports OPi.GPIO"""
|
|
217
|
+
super().__init__()
|
|
212
218
|
self.GPIO = import_module('OPi.GPIO')
|
|
213
219
|
dependencies_logger.log("using OPi.GPIO for GPIO control", Loglevel.INFO)
|
|
214
220
|
|
|
215
221
|
class GpiozeroWrapper(BaseGPIOWrapper):
|
|
216
222
|
"""gpiozero GPIO wrapper"""
|
|
217
223
|
|
|
218
|
-
_gpios = [None] * 200
|
|
219
|
-
_gpios_pwm = [None] * 200
|
|
220
|
-
|
|
221
224
|
def __init__(self):
|
|
222
225
|
"""constructor, imports gpiozero"""
|
|
226
|
+
self._gpios = [None] * 200
|
|
227
|
+
self._gpios_pwm = [None] * 200
|
|
223
228
|
self.gpiozero = import_module('gpiozero')
|
|
224
229
|
dependencies_logger.log("using gpiozero for GPIO control", Loglevel.INFO)
|
|
225
230
|
|
|
@@ -234,16 +239,20 @@ class GpiozeroWrapper(BaseGPIOWrapper):
|
|
|
234
239
|
def gpio_setup(self, pin:int, mode:GpioMode, initial:Gpio=Gpio.LOW, pull_up_down:GpioPUD=GpioPUD.PUD_OFF):
|
|
235
240
|
"""setup GPIO pin"""
|
|
236
241
|
if mode == GpioMode.OUT:
|
|
237
|
-
self._gpios[pin]
|
|
242
|
+
if self._gpios[pin] is None or self._gpios[pin].closed:
|
|
243
|
+
self._gpios[pin] = self.gpiozero.DigitalOutputDevice(pin, initial_value =bool(initial))
|
|
238
244
|
else:
|
|
239
|
-
self._gpios[pin]
|
|
245
|
+
if self._gpios[pin] is None or self._gpios[pin].closed:
|
|
246
|
+
self._gpios[pin] = self.gpiozero.DigitalInputDevice(pin)
|
|
240
247
|
|
|
241
248
|
def gpio_cleanup(self, pin:int):
|
|
242
249
|
"""cleanup GPIO pin"""
|
|
243
250
|
if self._gpios[pin] is not None:
|
|
244
251
|
self._gpios[pin].close()
|
|
252
|
+
self._gpios[pin] = None
|
|
245
253
|
if self._gpios_pwm[pin] is not None:
|
|
246
254
|
self._gpios_pwm[pin].close()
|
|
255
|
+
self._gpios_pwm[pin] = None
|
|
247
256
|
|
|
248
257
|
def gpio_input(self, pin:int) -> int:
|
|
249
258
|
"""read GPIO pin"""
|
|
@@ -314,7 +323,9 @@ class peripheryWrapper(BaseGPIOWrapper):
|
|
|
314
323
|
|
|
315
324
|
def gpio_cleanup(self, pin:int):
|
|
316
325
|
"""cleanup GPIO pin"""
|
|
317
|
-
self._gpios[pin]
|
|
326
|
+
if self._gpios[pin] is not None:
|
|
327
|
+
self._gpios[pin].close()
|
|
328
|
+
self._gpios[pin] = None
|
|
318
329
|
|
|
319
330
|
def gpio_input(self, pin:int) -> int:
|
|
320
331
|
"""read GPIO pin"""
|
|
@@ -327,7 +338,7 @@ class peripheryWrapper(BaseGPIOWrapper):
|
|
|
327
338
|
|
|
328
339
|
board_mapping = {
|
|
329
340
|
"raspberry pi 5": (GpiozeroWrapper, Board.RASPBERRY_PI5, "gpiozero", "https://gpiozero.readthedocs.io/en/stable/installing.html"),
|
|
330
|
-
"raspberry": (
|
|
341
|
+
"raspberry": (RPiGPIOWrapper, Board.RASPBERRY_PI, "RPi.GPIO", "https://sourceforge.net/p/raspberry-gpio-python/wiki/install"),
|
|
331
342
|
"jetson": (JetsonGPIOWrapper, Board.NVIDIA_JETSON, "jetson-gpio", "https://github.com/NVIDIA/jetson-gpio"),
|
|
332
343
|
"luckfox": (peripheryWrapper, Board.LUCKFOX_PICO, "periphery", "https://github.com/vsergeev/python-periphery"),
|
|
333
344
|
"orange": (OPiGPIOWrapper, Board.ORANGE_PI, "OPi.GPIO", "https://github.com/rm-hull/OPi.GPIO")
|
|
@@ -365,16 +376,15 @@ def handle_import_error(err, board_name, module_name, install_link):
|
|
|
365
376
|
Loglevel.ERROR)
|
|
366
377
|
raise err
|
|
367
378
|
|
|
368
|
-
def initialize_gpio():
|
|
379
|
+
def initialize_gpio(force_lib:Board = None) -> tuple[BaseGPIOWrapper, Board]:
|
|
369
380
|
"""initialize GPIO"""
|
|
370
381
|
model = get_board_model_name()
|
|
371
382
|
dependencies_logger.log(f"Board model: {model}", Loglevel.INFO)
|
|
372
383
|
if model == "mock":
|
|
373
384
|
return MockGPIOWrapper(), Board.UNKNOWN
|
|
374
385
|
|
|
375
|
-
|
|
376
386
|
for key, (wrapper_class, board_enum, module_name, install_link) in board_mapping.items():
|
|
377
|
-
if key in model:
|
|
387
|
+
if (key in model and force_lib is None) or (force_lib == module_name):
|
|
378
388
|
try:
|
|
379
389
|
return wrapper_class(), board_enum
|
|
380
390
|
except ModuleNotFoundError as err:
|
|
@@ -27,9 +27,6 @@ class TmcLogger:
|
|
|
27
27
|
log messages from the Tmc2209 lib
|
|
28
28
|
"""
|
|
29
29
|
|
|
30
|
-
_loglevel: Loglevel = Loglevel.INFO
|
|
31
|
-
|
|
32
|
-
|
|
33
30
|
@property
|
|
34
31
|
def loglevel(self):
|
|
35
32
|
"""get the loglevel"""
|
|
@@ -55,6 +52,8 @@ class TmcLogger:
|
|
|
55
52
|
handlers (list): list of logging handlers, see logging.handlers (default: None)
|
|
56
53
|
formatter (logging.Formatter): formatter for the log messages (default: None)
|
|
57
54
|
"""
|
|
55
|
+
self._loglevel: Loglevel = Loglevel.INFO
|
|
56
|
+
|
|
58
57
|
if logprefix is None:
|
|
59
58
|
logprefix = "TMC2209"
|
|
60
59
|
|
|
@@ -80,6 +79,16 @@ class TmcLogger:
|
|
|
80
79
|
self.logger.propagate = True
|
|
81
80
|
|
|
82
81
|
|
|
82
|
+
def __del__(self):
|
|
83
|
+
"""destructor"""
|
|
84
|
+
self.deinit()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def deinit(self):
|
|
88
|
+
"""destructor"""
|
|
89
|
+
self.remove_all_handlers()
|
|
90
|
+
|
|
91
|
+
|
|
83
92
|
def set_logprefix(self, logprefix: str):
|
|
84
93
|
"""set the logprefix.
|
|
85
94
|
|
|
@@ -29,12 +29,25 @@ class StallGuard():
|
|
|
29
29
|
This class is used to control the stallguard feature of the TMC stepper driver.
|
|
30
30
|
The drivers class needs to inherit from this class to use the stallguard feature (mixin).
|
|
31
31
|
"""
|
|
32
|
-
tmc_com:TmcCom = None
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
def __init__(self):
|
|
34
|
+
"""initialize StallGuard instance variables"""
|
|
35
|
+
self._pin_stallguard:int = None
|
|
36
|
+
self._sg_callback:types.FunctionType = None
|
|
36
37
|
|
|
37
38
|
|
|
39
|
+
def __del__(self):
|
|
40
|
+
self.deinit()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def deinit(self):
|
|
44
|
+
"""destructor"""
|
|
45
|
+
if self._deinit_finished is False:
|
|
46
|
+
if self._pin_stallguard is not None:
|
|
47
|
+
tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
|
|
48
|
+
tmc_gpio.gpio_cleanup(self._pin_stallguard)
|
|
49
|
+
self._pin_stallguard = None
|
|
50
|
+
|
|
38
51
|
|
|
39
52
|
def set_stallguard_callback(self, pin_stallguard, threshold, callback,
|
|
40
53
|
min_speed = 100):
|
|
@@ -30,15 +30,6 @@ class TmcStepperDriver:
|
|
|
30
30
|
2. move the motor via STEP/DIR pins
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
|
-
BOARD:Board = BOARD
|
|
34
|
-
tmc_mc:TmcMotionControl = None
|
|
35
|
-
tmc_ec:TmcEnableControl = None
|
|
36
|
-
tmc_logger:TmcLogger = None
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_deinit_finished:bool = False
|
|
40
|
-
|
|
41
|
-
|
|
42
33
|
|
|
43
34
|
# Constructor/Destructor
|
|
44
35
|
# ----------------------------
|
|
@@ -69,6 +60,13 @@ class TmcStepperDriver:
|
|
|
69
60
|
Defaults to None (messages are logged in the format
|
|
70
61
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s').
|
|
71
62
|
"""
|
|
63
|
+
self.BOARD:Board = BOARD
|
|
64
|
+
self.tmc_mc:TmcMotionControl = None
|
|
65
|
+
self.tmc_ec:TmcEnableControl = None
|
|
66
|
+
self.tmc_logger:TmcLogger = None
|
|
67
|
+
|
|
68
|
+
self._deinit_finished:bool = False
|
|
69
|
+
|
|
72
70
|
if logprefix is None:
|
|
73
71
|
logprefix = "StepperDriver"
|
|
74
72
|
self.tmc_logger = TmcLogger(loglevel, logprefix, log_handlers, log_formatter)
|
|
@@ -94,6 +92,11 @@ class TmcStepperDriver:
|
|
|
94
92
|
|
|
95
93
|
|
|
96
94
|
def __del__(self):
|
|
95
|
+
self.deinit()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def deinit(self):
|
|
97
100
|
"""destructor"""
|
|
98
101
|
if self._deinit_finished is False:
|
|
99
102
|
self.tmc_logger.log("Deinit", Loglevel.INFO)
|
|
@@ -105,11 +108,11 @@ class TmcStepperDriver:
|
|
|
105
108
|
else:
|
|
106
109
|
self.tmc_logger.log("Deinit already finished", Loglevel.INFO)
|
|
107
110
|
if self.tmc_ec is not None:
|
|
108
|
-
|
|
111
|
+
self.tmc_ec.deinit()
|
|
109
112
|
if self.tmc_mc is not None:
|
|
110
|
-
|
|
113
|
+
self.tmc_mc.deinit()
|
|
111
114
|
if self.tmc_logger is not None:
|
|
112
|
-
|
|
115
|
+
self.tmc_logger.deinit()
|
|
113
116
|
|
|
114
117
|
|
|
115
118
|
# TmcEnableControl Wrapper
|
|
@@ -36,15 +36,6 @@ def compute_crc8_atm(datagram, initial_value=0):
|
|
|
36
36
|
class TmcCom:
|
|
37
37
|
"""TmcCom
|
|
38
38
|
"""
|
|
39
|
-
_tmc_logger:TmcLogger = None
|
|
40
|
-
_tmc_registers = None
|
|
41
|
-
|
|
42
|
-
mtr_id:int = 0
|
|
43
|
-
r_frame:List[int]
|
|
44
|
-
w_frame:List[int]
|
|
45
|
-
communication_pause:int = 0
|
|
46
|
-
error_handler_running:bool = False
|
|
47
|
-
|
|
48
39
|
@property
|
|
49
40
|
def tmc_logger(self):
|
|
50
41
|
"""get the tmc_logger"""
|
|
@@ -69,7 +60,7 @@ class TmcCom:
|
|
|
69
60
|
|
|
70
61
|
def __init__(self,
|
|
71
62
|
mtr_id:int = 0,
|
|
72
|
-
tmc_logger = None
|
|
63
|
+
tmc_logger:TmcLogger = None
|
|
73
64
|
):
|
|
74
65
|
"""constructor
|
|
75
66
|
|
|
@@ -79,6 +70,13 @@ class TmcCom:
|
|
|
79
70
|
"""
|
|
80
71
|
self._tmc_logger = tmc_logger
|
|
81
72
|
self.mtr_id = mtr_id
|
|
73
|
+
self._tmc_registers = None
|
|
74
|
+
|
|
75
|
+
self.mtr_id:int = 0
|
|
76
|
+
# self.r_frame:List[int]
|
|
77
|
+
# self.w_frame:List[int]
|
|
78
|
+
self.communication_pause:int = 0
|
|
79
|
+
self.error_handler_running:bool = False
|
|
82
80
|
|
|
83
81
|
|
|
84
82
|
# def init(self):
|
|
@@ -37,16 +37,13 @@ class TmcComSpi(TmcCom):
|
|
|
37
37
|
like the current or the microsteppingmode
|
|
38
38
|
"""
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
_spi_bus: int
|
|
42
|
-
_spi_dev: int
|
|
43
|
-
_spi_speed: int
|
|
40
|
+
|
|
44
41
|
|
|
45
42
|
|
|
46
43
|
|
|
47
44
|
def __init__(self,
|
|
48
|
-
spi_bus,
|
|
49
|
-
spi_dev,
|
|
45
|
+
spi_bus:int,
|
|
46
|
+
spi_dev:int,
|
|
50
47
|
spi_speed:int = 8000000,
|
|
51
48
|
mtr_id:int = 0,
|
|
52
49
|
tmc_logger = None
|
|
@@ -59,6 +56,8 @@ class TmcComSpi(TmcCom):
|
|
|
59
56
|
"""
|
|
60
57
|
super().__init__(mtr_id, tmc_logger)
|
|
61
58
|
|
|
59
|
+
self.spi = spidev.SpiDev()
|
|
60
|
+
|
|
62
61
|
self._spi_bus = spi_bus
|
|
63
62
|
self._spi_dev = spi_dev
|
|
64
63
|
self._spi_speed = spi_speed
|
|
@@ -85,6 +84,10 @@ class TmcComSpi(TmcCom):
|
|
|
85
84
|
|
|
86
85
|
|
|
87
86
|
def __del__(self):
|
|
87
|
+
self.deinit()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def deinit(self):
|
|
88
91
|
"""destructor"""
|
|
89
92
|
|
|
90
93
|
|
|
@@ -21,9 +21,6 @@ class TmcComUart(TmcCom):
|
|
|
21
21
|
like the current or the microsteppingmode
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
ser:serial.Serial = serial.Serial()
|
|
25
|
-
|
|
26
|
-
|
|
27
24
|
def __init__(self,
|
|
28
25
|
serialport:str ,
|
|
29
26
|
baudrate:int = 115200,
|
|
@@ -40,6 +37,8 @@ class TmcComUart(TmcCom):
|
|
|
40
37
|
"""
|
|
41
38
|
super().__init__(mtr_id, tmc_logger)
|
|
42
39
|
|
|
40
|
+
self.ser = serial.Serial()
|
|
41
|
+
|
|
43
42
|
if serialport is None:
|
|
44
43
|
return
|
|
45
44
|
|
|
@@ -86,6 +85,10 @@ class TmcComUart(TmcCom):
|
|
|
86
85
|
|
|
87
86
|
|
|
88
87
|
def __del__(self):
|
|
88
|
+
self.deinit()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def deinit(self):
|
|
89
92
|
"""destructor"""
|
|
90
93
|
if self.ser is not None and isinstance(self.ser, serial.Serial):
|
|
91
94
|
self.ser.close()
|
|
@@ -8,8 +8,10 @@ from .._tmc_logger import TmcLogger
|
|
|
8
8
|
class TmcEnableControl():
|
|
9
9
|
"""Enable Control base class"""
|
|
10
10
|
|
|
11
|
-
_tmc_logger:TmcLogger
|
|
12
11
|
|
|
12
|
+
def __init__(self):
|
|
13
|
+
"""constructor"""
|
|
14
|
+
self._tmc_logger:TmcLogger = None
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
def init(self, tmc_logger: TmcLogger):
|
|
@@ -10,8 +10,6 @@ from .._tmc_logger import TmcLogger, Loglevel
|
|
|
10
10
|
class TmcEnableControlPin(TmcEnableControl):
|
|
11
11
|
"""Enable Control base class"""
|
|
12
12
|
|
|
13
|
-
_pin_en:int = None
|
|
14
|
-
|
|
15
13
|
|
|
16
14
|
@property
|
|
17
15
|
def pin_en(self):
|
|
@@ -21,6 +19,7 @@ class TmcEnableControlPin(TmcEnableControl):
|
|
|
21
19
|
|
|
22
20
|
def __init__(self, pin_en:int = None):
|
|
23
21
|
"""constructor"""
|
|
22
|
+
super().__init__()
|
|
24
23
|
self._pin_en = pin_en
|
|
25
24
|
|
|
26
25
|
|
|
@@ -32,9 +31,14 @@ class TmcEnableControlPin(TmcEnableControl):
|
|
|
32
31
|
|
|
33
32
|
|
|
34
33
|
def __del__(self):
|
|
34
|
+
self.deinit()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def deinit(self):
|
|
35
38
|
"""destructor"""
|
|
36
39
|
if self._pin_en is not None:
|
|
37
40
|
tmc_gpio.gpio_cleanup(self._pin_en)
|
|
41
|
+
self._pin_en = None
|
|
38
42
|
|
|
39
43
|
|
|
40
44
|
def set_motor_enabled(self, en):
|
|
@@ -10,10 +10,6 @@ from .._tmc_logger import Loglevel
|
|
|
10
10
|
class TmcEnableControlToff(TmcEnableControl):
|
|
11
11
|
"""Enable Control base class"""
|
|
12
12
|
|
|
13
|
-
_tmc_com:TmcCom = None
|
|
14
|
-
|
|
15
|
-
_default_toff = 3
|
|
16
|
-
|
|
17
13
|
|
|
18
14
|
@property
|
|
19
15
|
def tmc_com(self):
|
|
@@ -26,6 +22,13 @@ class TmcEnableControlToff(TmcEnableControl):
|
|
|
26
22
|
self._tmc_com = tmc_com
|
|
27
23
|
|
|
28
24
|
|
|
25
|
+
def __init__(self):
|
|
26
|
+
"""constructor"""
|
|
27
|
+
super().__init__()
|
|
28
|
+
self._tmc_com:TmcCom = None
|
|
29
|
+
self._default_toff = 3
|
|
30
|
+
|
|
31
|
+
|
|
29
32
|
def set_motor_enabled(self, en):
|
|
30
33
|
"""enables or disables the motor current output
|
|
31
34
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#pylint: disable=too-many-instance-attributes
|
|
2
|
+
#pylint: disable=unnecessary-pass
|
|
2
3
|
"""
|
|
3
4
|
Motion Control base module
|
|
4
5
|
"""
|
|
@@ -38,30 +39,6 @@ class StopMode(Enum):
|
|
|
38
39
|
class TmcMotionControl():
|
|
39
40
|
"""Motion Control base class"""
|
|
40
41
|
|
|
41
|
-
_tmc_logger:TmcLogger
|
|
42
|
-
|
|
43
|
-
_direction:Direction = Direction.CW
|
|
44
|
-
|
|
45
|
-
_stop:StopMode = StopMode.NO
|
|
46
|
-
|
|
47
|
-
_current_pos:int = 0 # current position of stepper in steps
|
|
48
|
-
_target_pos:int = 0 # the target position in steps
|
|
49
|
-
|
|
50
|
-
_speed:int = 0 # the current speed in steps per second
|
|
51
|
-
|
|
52
|
-
_max_speed:int = 1 # the maximum speed in steps per second
|
|
53
|
-
_max_speed_homing:int = 200 # the maximum speed in steps per second for homing
|
|
54
|
-
_acceleration:int = 1 # the acceleration in steps per second per second
|
|
55
|
-
_acceleration_homing:int = 10000 # the acceleration in steps per second per second for homing
|
|
56
|
-
|
|
57
|
-
_mres:int = 2 # microstepping resolution
|
|
58
|
-
_steps_per_rev:int = 400 # microsteps per revolution
|
|
59
|
-
_fullsteps_per_rev:int = 200 # fullsteps per revolution
|
|
60
|
-
|
|
61
|
-
_movement_abs_rel:MovementAbsRel = MovementAbsRel.ABSOLUTE
|
|
62
|
-
_movement_phase:MovementPhase = MovementPhase.STANDSTILL
|
|
63
|
-
|
|
64
|
-
|
|
65
42
|
@property
|
|
66
43
|
def current_pos(self):
|
|
67
44
|
"""_current_pos property"""
|
|
@@ -170,6 +147,31 @@ class TmcMotionControl():
|
|
|
170
147
|
self.acceleration = acceleration_fullstep * self.mres
|
|
171
148
|
|
|
172
149
|
|
|
150
|
+
def __init__(self):
|
|
151
|
+
"""constructor"""
|
|
152
|
+
self._tmc_logger:TmcLogger
|
|
153
|
+
|
|
154
|
+
self._direction:Direction = Direction.CW
|
|
155
|
+
|
|
156
|
+
self._stop:StopMode = StopMode.NO
|
|
157
|
+
|
|
158
|
+
self._current_pos:int = 0 # current position of stepper in steps
|
|
159
|
+
self._target_pos:int = 0 # the target position in steps
|
|
160
|
+
|
|
161
|
+
self._speed:int = 0 # the current speed in steps per second
|
|
162
|
+
|
|
163
|
+
self._max_speed:int = 1 # the maximum speed in steps per second
|
|
164
|
+
self._max_speed_homing:int = 200 # the maximum speed in steps per second for homing
|
|
165
|
+
self._acceleration:int = 1 # the acceleration in steps per second per second
|
|
166
|
+
self._acceleration_homing:int = 10000 # the acceleration in steps per second per second for homing
|
|
167
|
+
|
|
168
|
+
self._mres:int = 2 # microstepping resolution
|
|
169
|
+
self._steps_per_rev:int = 400 # microsteps per revolution
|
|
170
|
+
self._fullsteps_per_rev:int = 200 # fullsteps per revolution
|
|
171
|
+
|
|
172
|
+
self._movement_abs_rel:MovementAbsRel = MovementAbsRel.ABSOLUTE
|
|
173
|
+
self._movement_phase:MovementPhase = MovementPhase.STANDSTILL
|
|
174
|
+
|
|
173
175
|
|
|
174
176
|
def init(self, tmc_logger:TmcLogger):
|
|
175
177
|
"""init: called by the Tmc class"""
|
|
@@ -178,6 +180,11 @@ class TmcMotionControl():
|
|
|
178
180
|
self.acceleration_fullstep = 100
|
|
179
181
|
|
|
180
182
|
|
|
183
|
+
def deinit(self):
|
|
184
|
+
"""destructor"""
|
|
185
|
+
pass
|
|
186
|
+
|
|
187
|
+
|
|
181
188
|
def make_a_step(self):
|
|
182
189
|
"""make a Step"""
|
|
183
190
|
raise NotImplementedError
|
|
@@ -18,20 +18,6 @@ from .. import _tmc_math as tmc_math
|
|
|
18
18
|
class TmcMotionControlStepDir(TmcMotionControl):
|
|
19
19
|
"""STEP/DIR Motion Control class"""
|
|
20
20
|
|
|
21
|
-
_pin_step:int = None
|
|
22
|
-
_pin_dir:int = None
|
|
23
|
-
|
|
24
|
-
_movement_thread:threading.Thread = None
|
|
25
|
-
|
|
26
|
-
_sqrt_twoa:float = 1.0 # Precomputed sqrt(2*_acceleration)
|
|
27
|
-
_step_interval:int = 0 # the current interval between two steps
|
|
28
|
-
_min_pulse_width:int = 1 # minimum allowed pulse with in microseconds
|
|
29
|
-
_last_step_time:int = 0 # The last step time in microseconds
|
|
30
|
-
_n:int = 0 # step counter
|
|
31
|
-
_c0:int = 0 # Initial step size in microseconds
|
|
32
|
-
_cn:int = 0 # Last step size in microseconds
|
|
33
|
-
_cmin:int = 0 # Min step size in microseconds based on maxSpeed
|
|
34
|
-
|
|
35
21
|
|
|
36
22
|
@property
|
|
37
23
|
def max_speed(self):
|
|
@@ -119,9 +105,21 @@ class TmcMotionControlStepDir(TmcMotionControl):
|
|
|
119
105
|
|
|
120
106
|
def __init__(self, pin_step:int, pin_dir:int):
|
|
121
107
|
"""constructor"""
|
|
108
|
+
super().__init__()
|
|
122
109
|
self._pin_step = pin_step
|
|
123
110
|
self._pin_dir = pin_dir
|
|
124
111
|
|
|
112
|
+
self._movement_thread:threading.Thread = None
|
|
113
|
+
|
|
114
|
+
self._sqrt_twoa:float = 1.0 # Precomputed sqrt(2*_acceleration)
|
|
115
|
+
self._step_interval:int = 0 # the current interval between two steps
|
|
116
|
+
self._min_pulse_width:int = 1 # minimum allowed pulse with in microseconds
|
|
117
|
+
self._last_step_time:int = 0 # The last step time in microseconds
|
|
118
|
+
self._n:int = 0 # step counter
|
|
119
|
+
self._c0:int = 0 # Initial step size in microseconds
|
|
120
|
+
self._cn:int = 0 # Last step size in microseconds
|
|
121
|
+
self._cmin:int = 0 # Min step size in microseconds based on maxSpeed
|
|
122
|
+
|
|
125
123
|
|
|
126
124
|
def init(self, tmc_logger:TmcLogger):
|
|
127
125
|
"""init: called by the Tmc class"""
|
|
@@ -129,16 +127,23 @@ class TmcMotionControlStepDir(TmcMotionControl):
|
|
|
129
127
|
self._tmc_logger.log(f"STEP Pin: {self._pin_step}", Loglevel.DEBUG)
|
|
130
128
|
tmc_gpio.gpio_setup(self._pin_step, GpioMode.OUT, initial=Gpio.LOW)
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
if self._pin_dir is not None:
|
|
131
|
+
self._tmc_logger.log(f"DIR Pin: {self._pin_dir}", Loglevel.DEBUG)
|
|
132
|
+
tmc_gpio.gpio_setup(self._pin_dir, GpioMode.OUT, initial=self._direction.value)
|
|
134
133
|
|
|
135
134
|
|
|
136
135
|
def __del__(self):
|
|
136
|
+
self.deinit()
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def deinit(self):
|
|
137
140
|
"""destructor"""
|
|
138
141
|
if self._pin_step is not None:
|
|
139
142
|
tmc_gpio.gpio_cleanup(self._pin_step)
|
|
143
|
+
self._pin_step = None
|
|
140
144
|
if self._pin_dir is not None:
|
|
141
145
|
tmc_gpio.gpio_cleanup(self._pin_dir)
|
|
146
|
+
self._pin_dir = None
|
|
142
147
|
|
|
143
148
|
|
|
144
149
|
def make_a_step(self):
|
|
@@ -13,8 +13,6 @@ from .._tmc_gpio_board import tmc_gpio, Gpio, GpioMode
|
|
|
13
13
|
class TmcMotionControlStepReg(TmcMotionControlStepDir):
|
|
14
14
|
"""STEP/REG Motion Control class"""
|
|
15
15
|
|
|
16
|
-
_tmc_com:TmcCom = None
|
|
17
|
-
|
|
18
16
|
|
|
19
17
|
@property
|
|
20
18
|
def tmc_com(self):
|
|
@@ -30,7 +28,7 @@ class TmcMotionControlStepReg(TmcMotionControlStepDir):
|
|
|
30
28
|
def __init__(self, pin_step:int):
|
|
31
29
|
"""constructor"""
|
|
32
30
|
super().__init__(pin_step, None)
|
|
33
|
-
|
|
31
|
+
self._tmc_com:TmcCom = None
|
|
34
32
|
|
|
35
33
|
|
|
36
34
|
def init(self, tmc_logger:TmcLogger):
|
|
@@ -44,9 +42,14 @@ class TmcMotionControlStepReg(TmcMotionControlStepDir):
|
|
|
44
42
|
|
|
45
43
|
|
|
46
44
|
def __del__(self):
|
|
45
|
+
self.deinit()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def deinit(self):
|
|
47
49
|
"""destructor"""
|
|
48
50
|
if self._pin_step is not None:
|
|
49
51
|
tmc_gpio.gpio_cleanup(self._pin_step)
|
|
52
|
+
self._pin_step = None
|
|
50
53
|
|
|
51
54
|
|
|
52
55
|
def set_direction(self, direction:Direction):
|
|
@@ -17,10 +17,6 @@ from .. import _tmc_math as tmc_math
|
|
|
17
17
|
class TmcMotionControlVActual(TmcMotionControl):
|
|
18
18
|
"""VActual Motion Control class"""
|
|
19
19
|
|
|
20
|
-
_tmc_com:TmcCom = None
|
|
21
|
-
|
|
22
|
-
_starttime:int = 0
|
|
23
|
-
|
|
24
20
|
|
|
25
21
|
@property
|
|
26
22
|
def tmc_com(self):
|
|
@@ -33,6 +29,12 @@ class TmcMotionControlVActual(TmcMotionControl):
|
|
|
33
29
|
self._tmc_com = tmc_com
|
|
34
30
|
|
|
35
31
|
|
|
32
|
+
def __init__(self):
|
|
33
|
+
"""constructor"""
|
|
34
|
+
super().__init__()
|
|
35
|
+
self._tmc_com:TmcCom = None
|
|
36
|
+
self._starttime:int = 0
|
|
37
|
+
|
|
36
38
|
|
|
37
39
|
def make_a_step(self):
|
|
38
40
|
"""method that makes on step
|
|
@@ -12,13 +12,6 @@ from ..com._tmc_com import TmcCom
|
|
|
12
12
|
class TmcReg():
|
|
13
13
|
"""Register class"""
|
|
14
14
|
|
|
15
|
-
_addr: hex
|
|
16
|
-
_name: str
|
|
17
|
-
_tmc_com: TmcCom
|
|
18
|
-
_reg_map: typing.List
|
|
19
|
-
_data_int: int
|
|
20
|
-
_flags: typing.Dict
|
|
21
|
-
|
|
22
15
|
|
|
23
16
|
@property
|
|
24
17
|
def addr(self) -> hex:
|
|
@@ -48,6 +41,9 @@ class TmcReg():
|
|
|
48
41
|
|
|
49
42
|
def __init__(self, address:hex, name:str, tmc_com:TmcCom, reg_map:typing.List):
|
|
50
43
|
"""Constructor"""
|
|
44
|
+
self._data_int: int
|
|
45
|
+
self._flags: typing.Dict
|
|
46
|
+
|
|
51
47
|
self._addr = address
|
|
52
48
|
self._name = name
|
|
53
49
|
self._tmc_com = tmc_com
|
|
@@ -49,6 +49,7 @@ class Tmc2209(Tmc220x, StallGuard):
|
|
|
49
49
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s').
|
|
50
50
|
"""
|
|
51
51
|
super().__init__(tmc_ec, tmc_mc, tmc_com, driver_address, gpio_mode, loglevel, logprefix, log_handlers, log_formatter)
|
|
52
|
+
StallGuard.__init__(self)
|
|
52
53
|
|
|
53
54
|
if tmc_com is not None:
|
|
54
55
|
|
|
@@ -75,13 +76,14 @@ class Tmc2209(Tmc220x, StallGuard):
|
|
|
75
76
|
|
|
76
77
|
|
|
77
78
|
def __del__(self):
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if self._pin_stallguard is not None:
|
|
81
|
-
tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
|
|
82
|
-
tmc_gpio.gpio_cleanup(self._pin_stallguard)
|
|
79
|
+
self.deinit()
|
|
80
|
+
|
|
83
81
|
|
|
84
|
-
|
|
82
|
+
|
|
83
|
+
def deinit(self):
|
|
84
|
+
"""destructor"""
|
|
85
|
+
super().deinit()
|
|
86
|
+
StallGuard.deinit(self)
|
|
85
87
|
|
|
86
88
|
|
|
87
89
|
|
|
@@ -42,9 +42,6 @@ class Tmc220x(TmcStepperDriver):
|
|
|
42
42
|
2. move the motor via STEP/DIR pins
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
tmc_com:TmcComUart = None
|
|
46
|
-
|
|
47
|
-
|
|
48
45
|
|
|
49
46
|
# Constructor/Destructor
|
|
50
47
|
# ----------------------------
|
|
@@ -76,6 +73,8 @@ class Tmc220x(TmcStepperDriver):
|
|
|
76
73
|
Defaults to None (messages are logged in the format
|
|
77
74
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s').
|
|
78
75
|
"""
|
|
76
|
+
self.tmc_com:TmcComUart = None
|
|
77
|
+
|
|
79
78
|
if logprefix is None:
|
|
80
79
|
logprefix = f"TMC2209 {driver_address}"
|
|
81
80
|
|
|
@@ -141,12 +140,15 @@ class Tmc220x(TmcStepperDriver):
|
|
|
141
140
|
self.tmc_logger.log("TMC220x Init finished", Loglevel.INFO)
|
|
142
141
|
|
|
143
142
|
|
|
144
|
-
|
|
145
143
|
def __del__(self):
|
|
144
|
+
self.deinit()
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def deinit(self):
|
|
146
148
|
"""destructor"""
|
|
147
149
|
if self.tmc_com is not None:
|
|
148
|
-
|
|
149
|
-
super().
|
|
150
|
+
self.tmc_com.deinit()
|
|
151
|
+
super().deinit()
|
|
150
152
|
|
|
151
153
|
|
|
152
154
|
|
|
@@ -44,13 +44,6 @@ class Tmc2240(TmcStepperDriver, StallGuard):
|
|
|
44
44
|
2. move the motor via STEP/DIR pins
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
|
-
tmc_com:TmcComSpi = None
|
|
48
|
-
|
|
49
|
-
_pin_stallguard:int = None
|
|
50
|
-
_sg_callback:types.FunctionType = None
|
|
51
|
-
_sg_threshold:int = 100 # threshold for stallguard
|
|
52
|
-
|
|
53
|
-
|
|
54
47
|
|
|
55
48
|
# Constructor/Destructor
|
|
56
49
|
# ----------------------------
|
|
@@ -82,9 +75,16 @@ class Tmc2240(TmcStepperDriver, StallGuard):
|
|
|
82
75
|
Defaults to None (messages are logged in the format
|
|
83
76
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s').
|
|
84
77
|
"""
|
|
78
|
+
self.tmc_com:TmcComSpi = None
|
|
79
|
+
self._pin_stallguard:int = None
|
|
80
|
+
self._sg_callback:types.FunctionType = None
|
|
81
|
+
self._sg_threshold:int = 100 # threshold for stallguard
|
|
82
|
+
|
|
83
|
+
if logprefix is None:
|
|
84
|
+
logprefix = f"TMC2240 {driver_address}"
|
|
85
|
+
|
|
85
86
|
super().__init__(tmc_ec, tmc_mc, gpio_mode, loglevel, logprefix, log_handlers, log_formatter)
|
|
86
87
|
|
|
87
|
-
self.tmc_logger.set_logprefix(f"TMC2240 {driver_address}")
|
|
88
88
|
|
|
89
89
|
if tmc_com is not None:
|
|
90
90
|
self.tmc_com = tmc_com
|
|
@@ -154,10 +154,14 @@ class Tmc2240(TmcStepperDriver, StallGuard):
|
|
|
154
154
|
|
|
155
155
|
|
|
156
156
|
def __del__(self):
|
|
157
|
+
self.deinit()
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def deinit(self):
|
|
157
161
|
"""destructor"""
|
|
158
162
|
if self.tmc_com is not None:
|
|
159
|
-
|
|
160
|
-
super().
|
|
163
|
+
self.tmc_com.deinit()
|
|
164
|
+
super().deinit()
|
|
161
165
|
|
|
162
166
|
|
|
163
167
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytmcstepper-0.7.6 → pytmcstepper-0.7.8}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|