PyTmcStepper 0.9.1__tar.gz → 0.9.2__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.9.1 → pytmcstepper-0.9.2}/PKG-INFO +1 -1
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/pyproject.toml +5 -12
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/PyTmcStepper.egg-info/PKG-INFO +1 -1
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/PyTmcStepper.egg-info/SOURCES.txt +3 -1
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/_tmc_exceptions.py +5 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/_tmc_logger.py +28 -30
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/_tmc_math.py +8 -8
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/_tmc_stallguard.py +47 -43
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/_tmc_stepperdriver.py +66 -63
- pytmcstepper-0.9.2/src/tmc_driver/_tmc_validation.py +29 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com.py +31 -41
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_spi.py +25 -25
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_spi_base.py +30 -43
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +5 -15
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_spi_micropython.py +24 -21
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_uart.py +17 -15
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_uart_base.py +99 -74
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/_tmc_com_uart_micropython.py +16 -22
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/enable_control/_tmc_ec.py +2 -6
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/enable_control/_tmc_ec_pin.py +1 -7
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/enable_control/_tmc_ec_toff.py +1 -4
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/motion_control/_tmc_mc.py +45 -39
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +96 -69
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +12 -15
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +5 -11
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +56 -46
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/reg/_tmc2209_reg.py +23 -19
- pytmcstepper-0.9.2/src/tmc_driver/reg/_tmc220x_reg.py +287 -0
- pytmcstepper-0.9.2/src/tmc_driver/reg/_tmc224x_reg.py +464 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/reg/_tmc_reg.py +10 -15
- pytmcstepper-0.9.2/src/tmc_driver/tmc_2208.py +10 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_2209.py +113 -97
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_220x.py +135 -195
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_2240.py +688 -705
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/__init__.py +31 -11
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +25 -11
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +33 -17
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +33 -18
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +2 -2
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +21 -14
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +34 -24
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/tests/test_tmc2209.py +3 -1
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/tests/test_tmc2240.py +3 -1
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/tests/test_tmc_com_spi.py +7 -5
- pytmcstepper-0.9.2/tests/test_tmc_com_uart.py +44 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/tests/test_tmc_ec_pin.py +2 -3
- pytmcstepper-0.9.2/tests/test_tmc_math.py +64 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/tests/test_tmc_modules.py +6 -4
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/tests/test_tmc_move.py +19 -10
- pytmcstepper-0.9.2/tests/test_tmc_set_current.py +140 -0
- pytmcstepper-0.9.1/src/tmc_driver/reg/_tmc220x_reg.py +0 -239
- pytmcstepper-0.9.1/src/tmc_driver/reg/_tmc224x_reg.py +0 -366
- pytmcstepper-0.9.1/src/tmc_driver/tmc_2208.py +0 -12
- pytmcstepper-0.9.1/tests/test_tmc_com_uart.py +0 -27
- pytmcstepper-0.9.1/tests/test_tmc_math.py +0 -51
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/LICENSE +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/README.md +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/setup.cfg +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/PyTmcStepper.egg-info/requires.txt +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/__init__.py +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/com/__init__.py +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/enable_control/__init__.py +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/motion_control/__init__.py +0 -0
- {pytmcstepper-0.9.1 → pytmcstepper-0.9.2}/src/tmc_driver/reg/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
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
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = [
|
|
3
|
-
"setuptools>=42",
|
|
4
|
-
"wheel"
|
|
5
|
-
]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
6
3
|
build-backend = "setuptools.build_meta"
|
|
7
4
|
|
|
8
5
|
[project]
|
|
9
6
|
name = "PyTmcStepper"
|
|
10
|
-
version = "0.9.
|
|
11
|
-
authors = [
|
|
12
|
-
{ name = "Christian Köhlke", email = "christian@koehlke.de" }
|
|
13
|
-
]
|
|
7
|
+
version = "0.9.2"
|
|
8
|
+
authors = [{ name = "Christian Köhlke", email = "christian@koehlke.de" }]
|
|
14
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"
|
|
15
10
|
readme = "README.md"
|
|
16
11
|
license = "GPL-3.0"
|
|
@@ -23,9 +18,7 @@ classifiers = [
|
|
|
23
18
|
"Natural Language :: English",
|
|
24
19
|
"Topic :: System :: Hardware :: Hardware Drivers",
|
|
25
20
|
]
|
|
26
|
-
dependencies = [
|
|
27
|
-
"pyserial",
|
|
28
|
-
]
|
|
21
|
+
dependencies = ["pyserial"]
|
|
29
22
|
|
|
30
23
|
[project.urls]
|
|
31
24
|
Homepage = "https://github.com/Chr157i4n/PyTmcStepper"
|
|
@@ -49,4 +42,4 @@ ignored-modules = "machine"
|
|
|
49
42
|
unsafe-load-any-extension = true
|
|
50
43
|
|
|
51
44
|
[tool.pylint.format]
|
|
52
|
-
max-line-length = 160
|
|
45
|
+
max-line-length = 160
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
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
|
|
@@ -12,6 +12,7 @@ src/tmc_driver/_tmc_logger.py
|
|
|
12
12
|
src/tmc_driver/_tmc_math.py
|
|
13
13
|
src/tmc_driver/_tmc_stallguard.py
|
|
14
14
|
src/tmc_driver/_tmc_stepperdriver.py
|
|
15
|
+
src/tmc_driver/_tmc_validation.py
|
|
15
16
|
src/tmc_driver/tmc_2208.py
|
|
16
17
|
src/tmc_driver/tmc_2209.py
|
|
17
18
|
src/tmc_driver/tmc_220x.py
|
|
@@ -54,4 +55,5 @@ tests/test_tmc_com_uart.py
|
|
|
54
55
|
tests/test_tmc_ec_pin.py
|
|
55
56
|
tests/test_tmc_math.py
|
|
56
57
|
tests/test_tmc_modules.py
|
|
57
|
-
tests/test_tmc_move.py
|
|
58
|
+
tests/test_tmc_move.py
|
|
59
|
+
tests/test_tmc_set_current.py
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"""Exceptions module"""
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
class TmcException(Exception):
|
|
4
5
|
"""Base class for all TMC exceptions"""
|
|
5
6
|
|
|
7
|
+
|
|
6
8
|
class TmcDriverException(TmcException):
|
|
7
9
|
"""Base class for all TMC driver exceptions"""
|
|
8
10
|
|
|
11
|
+
|
|
9
12
|
class TmcComException(TmcException):
|
|
10
13
|
"""Base class for all TMC communication exceptions"""
|
|
11
14
|
|
|
15
|
+
|
|
12
16
|
class TmcMotionControlException(TmcException):
|
|
13
17
|
"""Base class for all TMC motion control exceptions"""
|
|
14
18
|
|
|
19
|
+
|
|
15
20
|
class TmcEnableControlException(TmcException):
|
|
16
21
|
"""Base class for all TMC enable control exceptions"""
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#pylint: disable=protected-access
|
|
2
|
-
#pylint: skip-file
|
|
1
|
+
# pylint: disable=protected-access
|
|
2
|
+
# pylint: skip-file
|
|
3
3
|
"""
|
|
4
4
|
Tmc2209 stepper driver logger module
|
|
5
5
|
"""
|
|
@@ -14,26 +14,26 @@ if not MICROPYTHON:
|
|
|
14
14
|
import logging
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
17
|
class Loglevel(IntEnum):
|
|
21
18
|
"""loglevel"""
|
|
22
|
-
ALL = 1 # all messages will be logged
|
|
23
|
-
MOVEMENT = 5 # error, warning, info, debug and movement messages will be logged
|
|
24
|
-
DEBUG = 10 # error, warning, info and debug messages will be logged
|
|
25
|
-
INFO = 20 # error, warning and info messages will be logged
|
|
26
|
-
WARNING = 30 # error and warning messages will be logged
|
|
27
|
-
ERROR = 40 # only error messages will be logged
|
|
28
|
-
NONE = -1 # no messages will be logged
|
|
29
19
|
|
|
20
|
+
ALL = 1 # all messages will be logged
|
|
21
|
+
MOVEMENT = 5 # error, warning, info, debug and movement messages will be logged
|
|
22
|
+
DEBUG = 10 # error, warning, info and debug messages will be logged
|
|
23
|
+
INFO = 20 # error, warning and info messages will be logged
|
|
24
|
+
WARNING = 30 # error and warning messages will be logged
|
|
25
|
+
ERROR = 40 # only error messages will be logged
|
|
26
|
+
NONE = -1 # no messages will be logged
|
|
30
27
|
|
|
31
28
|
|
|
32
29
|
if MICROPYTHON:
|
|
30
|
+
|
|
33
31
|
class TmcLogger:
|
|
34
32
|
"""minimal logger for MicroPython"""
|
|
35
33
|
|
|
36
|
-
def __init__(
|
|
34
|
+
def __init__(
|
|
35
|
+
self, loglevel=None, logprefix=None, handlers=None, formatter=None
|
|
36
|
+
):
|
|
37
37
|
self._loglevel = Loglevel.NONE
|
|
38
38
|
|
|
39
39
|
@property
|
|
@@ -68,7 +68,9 @@ if MICROPYTHON:
|
|
|
68
68
|
def log(self, message, loglevel=None):
|
|
69
69
|
if loglevel is None or self.loglevel is None or loglevel >= self._loglevel:
|
|
70
70
|
print(message)
|
|
71
|
+
|
|
71
72
|
else:
|
|
73
|
+
|
|
72
74
|
class TmcLogger:
|
|
73
75
|
"""Tmc2209_logger
|
|
74
76
|
|
|
@@ -87,12 +89,13 @@ else:
|
|
|
87
89
|
self._loglevel = loglevel
|
|
88
90
|
self.logger.setLevel(int(loglevel))
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
def __init__(
|
|
93
|
+
self,
|
|
94
|
+
loglevel: Loglevel = Loglevel.INFO,
|
|
95
|
+
logprefix: str = "TMC2209",
|
|
96
|
+
handlers: list | None = None,
|
|
97
|
+
formatter: logging.Formatter | None = None,
|
|
98
|
+
):
|
|
96
99
|
"""constructor
|
|
97
100
|
|
|
98
101
|
Args:
|
|
@@ -114,7 +117,9 @@ else:
|
|
|
114
117
|
|
|
115
118
|
self.loglevel = loglevel
|
|
116
119
|
if formatter is None:
|
|
117
|
-
formatter = logging.Formatter(
|
|
120
|
+
formatter = logging.Formatter(
|
|
121
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
122
|
+
)
|
|
118
123
|
self.formatter = formatter
|
|
119
124
|
|
|
120
125
|
if handlers is None:
|
|
@@ -127,17 +132,14 @@ else:
|
|
|
127
132
|
|
|
128
133
|
self.logger.propagate = True
|
|
129
134
|
|
|
130
|
-
|
|
131
135
|
def __del__(self):
|
|
132
136
|
"""destructor"""
|
|
133
137
|
self.deinit()
|
|
134
138
|
|
|
135
|
-
|
|
136
139
|
def deinit(self):
|
|
137
140
|
"""destructor"""
|
|
138
141
|
self.remove_all_handlers()
|
|
139
142
|
|
|
140
|
-
|
|
141
143
|
def set_logprefix(self, logprefix: str):
|
|
142
144
|
"""set the logprefix.
|
|
143
145
|
|
|
@@ -146,7 +148,6 @@ else:
|
|
|
146
148
|
"""
|
|
147
149
|
self.logger.name = logprefix
|
|
148
150
|
|
|
149
|
-
|
|
150
151
|
def add_handler(self, handler, formatter=None):
|
|
151
152
|
"""add a handler to the logger
|
|
152
153
|
|
|
@@ -160,7 +161,6 @@ else:
|
|
|
160
161
|
handler.setFormatter(formatter)
|
|
161
162
|
self.logger.addHandler(handler)
|
|
162
163
|
|
|
163
|
-
|
|
164
164
|
def remove_handler(self, handler):
|
|
165
165
|
"""remove a handler from the logger
|
|
166
166
|
|
|
@@ -169,13 +169,11 @@ else:
|
|
|
169
169
|
"""
|
|
170
170
|
self.logger.removeHandler(handler)
|
|
171
171
|
|
|
172
|
-
|
|
173
172
|
def remove_all_handlers(self):
|
|
174
173
|
"""remove all handlers from the logger"""
|
|
175
174
|
for handler in self.logger.handlers:
|
|
176
175
|
self.logger.removeHandler(handler)
|
|
177
176
|
|
|
178
|
-
|
|
179
177
|
def set_formatter(self, formatter, handlers=None):
|
|
180
178
|
"""set a new formatter for the log messages
|
|
181
179
|
|
|
@@ -191,9 +189,10 @@ else:
|
|
|
191
189
|
for handler in handlers:
|
|
192
190
|
handler.setFormatter(formatter)
|
|
193
191
|
|
|
194
|
-
|
|
195
192
|
@staticmethod
|
|
196
|
-
def _add_logging_level(
|
|
193
|
+
def _add_logging_level(
|
|
194
|
+
level_name: str, level_num: int, method_name: str | None = None
|
|
195
|
+
):
|
|
197
196
|
if not method_name:
|
|
198
197
|
method_name = level_name.lower()
|
|
199
198
|
|
|
@@ -209,7 +208,6 @@ else:
|
|
|
209
208
|
setattr(logging.getLoggerClass(), method_name, logForLevel)
|
|
210
209
|
setattr(logging, method_name, logToRoot)
|
|
211
210
|
|
|
212
|
-
|
|
213
211
|
def log(self, message, loglevel: Loglevel = Loglevel.INFO):
|
|
214
212
|
"""logs a message
|
|
215
213
|
|
|
@@ -3,8 +3,7 @@ TMC2209_Raspberry_Pi math library
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
def rps_to_vactual(rps, steps_per_rev:int, fclk:int = 12000000) -> int:
|
|
6
|
+
def rps_to_vactual(rps, steps_per_rev: int, fclk: int = 12000000) -> int:
|
|
8
7
|
"""converts rps -> vactual
|
|
9
8
|
|
|
10
9
|
Args:
|
|
@@ -18,7 +17,7 @@ def rps_to_vactual(rps, steps_per_rev:int, fclk:int = 12000000) -> int:
|
|
|
18
17
|
return int(round(rps / (fclk / 16777216) * steps_per_rev))
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
def vactual_to_rps(vactual:int, steps_per_rev:int, fclk:int = 12000000) -> float:
|
|
20
|
+
def vactual_to_rps(vactual: int, steps_per_rev: int, fclk: int = 12000000) -> float:
|
|
22
21
|
"""converts vactual -> rps
|
|
23
22
|
|
|
24
23
|
Args:
|
|
@@ -32,7 +31,7 @@ def vactual_to_rps(vactual:int, steps_per_rev:int, fclk:int = 12000000) -> float
|
|
|
32
31
|
return vactual * (fclk / 16777216) / steps_per_rev
|
|
33
32
|
|
|
34
33
|
|
|
35
|
-
def rps_to_steps(rps:float, steps_per_rev:int) -> int:
|
|
34
|
+
def rps_to_steps(rps: float, steps_per_rev: int) -> int:
|
|
36
35
|
"""converts rps -> steps/second
|
|
37
36
|
|
|
38
37
|
Args:
|
|
@@ -44,7 +43,8 @@ def rps_to_steps(rps:float, steps_per_rev:int) -> int:
|
|
|
44
43
|
"""
|
|
45
44
|
return int(round(rps * steps_per_rev))
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
|
|
47
|
+
def steps_to_rps(steps: int, steps_per_rev: int) -> float:
|
|
48
48
|
"""converts steps/second -> rps
|
|
49
49
|
|
|
50
50
|
Args:
|
|
@@ -57,7 +57,7 @@ def steps_to_rps(steps:int, steps_per_rev:int) -> float:
|
|
|
57
57
|
return steps / steps_per_rev
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def rps_to_tstep(rps:float, steps_per_rev:int, mres:int) -> int:
|
|
60
|
+
def rps_to_tstep(rps: float, steps_per_rev: int, mres: int) -> int:
|
|
61
61
|
"""converts rps -> tstep
|
|
62
62
|
|
|
63
63
|
Args:
|
|
@@ -71,7 +71,7 @@ def rps_to_tstep(rps:float, steps_per_rev:int, mres:int) -> int:
|
|
|
71
71
|
return int(round(12000000 / (rps_to_steps(rps, steps_per_rev) * 256 / mres)))
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
def steps_to_tstep(steps:int, mres:int) -> int:
|
|
74
|
+
def steps_to_tstep(steps: int, mres: int) -> int:
|
|
75
75
|
"""converts steps/second -> tstep
|
|
76
76
|
|
|
77
77
|
Args:
|
|
@@ -84,7 +84,7 @@ def steps_to_tstep(steps:int, mres:int) -> int:
|
|
|
84
84
|
return int(round(12000000 / (steps * 256 / mres)))
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
def constrain(val:int, min_val:int, max_val:int) -> int:
|
|
87
|
+
def constrain(val: int, min_val: int, max_val: int) -> int:
|
|
88
88
|
"""constrains a value between a min and a max
|
|
89
89
|
|
|
90
90
|
Args:
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
#pylint: disable=too-many-arguments
|
|
2
|
-
#pylint: disable=too-many-public-methods
|
|
3
|
-
#pylint: disable=too-many-branches
|
|
4
|
-
#pylint: disable=too-many-instance-attributes
|
|
5
|
-
#pylint: disable=too-many-positional-arguments
|
|
6
|
-
#pylint: disable=bare-except
|
|
7
|
-
#pylint: disable=no-member
|
|
8
|
-
#pylint: disable=unused-import
|
|
9
|
-
#pylint: disable=wildcard-import
|
|
10
|
-
#pylint: disable=unused-wildcard-import
|
|
11
|
-
"""StallGuard mixin
|
|
12
|
-
"""
|
|
1
|
+
# pylint: disable=too-many-arguments
|
|
2
|
+
# pylint: disable=too-many-public-methods
|
|
3
|
+
# pylint: disable=too-many-branches
|
|
4
|
+
# pylint: disable=too-many-instance-attributes
|
|
5
|
+
# pylint: disable=too-many-positional-arguments
|
|
6
|
+
# pylint: disable=bare-except
|
|
7
|
+
# pylint: disable=no-member
|
|
8
|
+
# pylint: disable=unused-import
|
|
9
|
+
# pylint: disable=wildcard-import
|
|
10
|
+
# pylint: disable=unused-wildcard-import
|
|
11
|
+
"""StallGuard mixin"""
|
|
13
12
|
|
|
14
13
|
import types
|
|
15
14
|
from ._tmc_stepperdriver import *
|
|
@@ -21,10 +20,7 @@ from .reg._tmc224x_reg import *
|
|
|
21
20
|
from . import _tmc_math as tmc_math
|
|
22
21
|
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class StallGuard():
|
|
23
|
+
class StallGuard:
|
|
28
24
|
"""StallGuard
|
|
29
25
|
|
|
30
26
|
This class is used to control the stallguard feature of the TMC stepper driver.
|
|
@@ -33,14 +29,12 @@ class StallGuard():
|
|
|
33
29
|
|
|
34
30
|
def __init__(self):
|
|
35
31
|
"""initialize StallGuard instance variables"""
|
|
36
|
-
self._pin_stallguard:int|None = None
|
|
37
|
-
self._sg_callback:types.FunctionType|None = None
|
|
38
|
-
|
|
32
|
+
self._pin_stallguard: int | None = None
|
|
33
|
+
self._sg_callback: types.FunctionType | None = None
|
|
39
34
|
|
|
40
35
|
def __del__(self):
|
|
41
36
|
self.deinit()
|
|
42
37
|
|
|
43
|
-
|
|
44
38
|
def deinit(self):
|
|
45
39
|
"""destructor"""
|
|
46
40
|
if self._deinit_finished is False:
|
|
@@ -49,9 +43,9 @@ class StallGuard():
|
|
|
49
43
|
tmc_gpio.tmc_gpio.gpio_cleanup(self._pin_stallguard)
|
|
50
44
|
self._pin_stallguard = None
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
def set_stallguard_callback(
|
|
47
|
+
self, pin_stallguard, threshold, callback, min_speed=100
|
|
48
|
+
):
|
|
55
49
|
"""set a function to call back, when the driver detects a stall
|
|
56
50
|
via stallguard
|
|
57
51
|
high value on the diag pin can also mean a driver error
|
|
@@ -62,20 +56,29 @@ class StallGuard():
|
|
|
62
56
|
callback (func): will be called on StallGuard trigger
|
|
63
57
|
min_speed (int): min speed [steps/s] for StallGuard (Default value = 100)
|
|
64
58
|
"""
|
|
65
|
-
self.tmc_logger.log(
|
|
66
|
-
|
|
59
|
+
self.tmc_logger.log(
|
|
60
|
+
f"setup stallguard callback on GPIO {pin_stallguard}", Loglevel.INFO
|
|
61
|
+
)
|
|
62
|
+
self.tmc_logger.log(
|
|
63
|
+
f"StallGuard Threshold: {threshold} | minimum Speed: {min_speed}",
|
|
64
|
+
Loglevel.INFO,
|
|
65
|
+
)
|
|
67
66
|
|
|
68
67
|
self._set_stallguard_threshold(threshold)
|
|
69
|
-
self._set_coolstep_threshold(
|
|
68
|
+
self._set_coolstep_threshold(
|
|
69
|
+
tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution())
|
|
70
|
+
)
|
|
70
71
|
self._sg_callback = callback
|
|
71
72
|
self._pin_stallguard = pin_stallguard
|
|
72
73
|
|
|
73
|
-
tmc_gpio.tmc_gpio.gpio_setup(
|
|
74
|
+
tmc_gpio.tmc_gpio.gpio_setup(
|
|
75
|
+
self._pin_stallguard, GpioMode.IN, pull_up_down=GpioPUD.PUD_DOWN
|
|
76
|
+
)
|
|
74
77
|
# first remove existing events
|
|
75
78
|
tmc_gpio.tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
|
|
76
|
-
tmc_gpio.tmc_gpio.gpio_add_event_detect(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
tmc_gpio.tmc_gpio.gpio_add_event_detect(
|
|
80
|
+
self._pin_stallguard, self.stallguard_callback
|
|
81
|
+
)
|
|
79
82
|
|
|
80
83
|
def stallguard_callback(self, gpio_pin):
|
|
81
84
|
"""the callback function for StallGuard.
|
|
@@ -91,9 +94,14 @@ class StallGuard():
|
|
|
91
94
|
return
|
|
92
95
|
self._sg_callback()
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
def enable_coolstep(
|
|
98
|
+
self,
|
|
99
|
+
semin_sg: int = 150,
|
|
100
|
+
semax_sg: int = 200,
|
|
101
|
+
seup: int = 1,
|
|
102
|
+
sedn: int = 3,
|
|
103
|
+
min_speed: int = 100,
|
|
104
|
+
):
|
|
97
105
|
"""enables coolstep and sets the parameters for coolstep
|
|
98
106
|
The values for semin etc. can be tested with the test_stallguard_threshold function
|
|
99
107
|
|
|
@@ -106,16 +114,16 @@ class StallGuard():
|
|
|
106
114
|
semax_sg = semax_sg - semin_sg
|
|
107
115
|
|
|
108
116
|
self.coolconf.read()
|
|
109
|
-
self.coolconf.semin = round(max(0, min(semin_sg/32, 15)))
|
|
110
|
-
self.coolconf.semax = round(max(0, min(semax_sg/32, 15)))
|
|
111
|
-
self.coolconf.seimin = 1
|
|
117
|
+
self.coolconf.semin = round(max(0, min(semin_sg / 32, 15)))
|
|
118
|
+
self.coolconf.semax = round(max(0, min(semax_sg / 32, 15)))
|
|
119
|
+
self.coolconf.seimin = 1 # scale down to until 1/4 of IRun (7 - 31)
|
|
112
120
|
self.coolconf.seup = seup
|
|
113
121
|
self.coolconf.sedn = sedn
|
|
114
122
|
self.coolconf.write_check()
|
|
115
123
|
|
|
116
|
-
self._set_coolstep_threshold(
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
self._set_coolstep_threshold(
|
|
125
|
+
tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution())
|
|
126
|
+
)
|
|
119
127
|
|
|
120
128
|
def get_stallguard_result(self):
|
|
121
129
|
"""return the current stallguard result
|
|
@@ -128,8 +136,6 @@ class StallGuard():
|
|
|
128
136
|
self.sgresult.read()
|
|
129
137
|
return self.sgresult.sgresult
|
|
130
138
|
|
|
131
|
-
|
|
132
|
-
|
|
133
139
|
def _set_stallguard_threshold(self, threshold):
|
|
134
140
|
"""sets the register bit "SGTHRS" to to a given value
|
|
135
141
|
this is needed for the stallguard interrupt callback
|
|
@@ -141,8 +147,6 @@ class StallGuard():
|
|
|
141
147
|
"""
|
|
142
148
|
self.sgthrs.modify("sgthrs", threshold)
|
|
143
149
|
|
|
144
|
-
|
|
145
|
-
|
|
146
150
|
def _set_coolstep_threshold(self, threshold):
|
|
147
151
|
"""This is the lower threshold velocity for switching
|
|
148
152
|
on smart energy CoolStep and StallGuard to DIAG output. (unsigned)
|