PyTmcStepper 0.18.2__tar.gz → 0.18.4__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.18.2 → pytmcstepper-0.18.4}/PKG-INFO +3 -3
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/README.md +2 -2
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/pyproject.toml +23 -1
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/PyTmcStepper.egg-info/PKG-INFO +3 -3
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/PyTmcStepper.egg-info/SOURCES.txt +7 -1
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/__init__.py +0 -2
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/_tmc_xxxx.py +0 -1
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/enable_control/__init__.py +0 -4
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +2 -2
- pytmcstepper-0.18.4/tests/test_gpiozero.py +118 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc2209.py +38 -2
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc2240.py +6 -2
- pytmcstepper-0.18.4/tests/test_tmc_imports.py +46 -0
- pytmcstepper-0.18.4/tests/test_tmc_move_intramp.py +132 -0
- pytmcstepper-0.18.4/tests/test_tmc_move_steppwmdir.py +93 -0
- pytmcstepper-0.18.4/tests/test_tmc_move_stepreg.py +146 -0
- pytmcstepper-0.18.4/tests/test_tmc_move_vactual.py +120 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_set_current.py +34 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/LICENSE +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/setup.cfg +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/PyTmcStepper.egg-info/requires.txt +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/_tmc_exceptions.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/_tmc_math.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/_tmc_stallguard.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/_tmc_stepperdriver.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/_tmc_validation.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/__init__.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_spi_base.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_spi_circuitpython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_spi_micropython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_uart_base.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_uart_circuitpython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_uart_micropython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/__init__.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/platform_utils.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/__init__.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/_tmc220x_reg.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/_tmc224x_reg.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/_tmc5160_reg.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/_tmc_reg.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/reg/_tmc_shared_regs.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_2208.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_2209.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_220x.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_2240.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_5160.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/__init__.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_circuitpython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_logger/__init__.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_logger/_tmc_logger_base.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_com_spi.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_com_uart.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_ec_pin.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_math.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_modules.py +0 -0
- /pytmcstepper-0.18.2/tests/test_tmc_move.py → /pytmcstepper-0.18.4/tests/test_tmc_move_stepdir.py +0 -0
- {pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/tests/test_tmc_stallguard.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.18.
|
|
3
|
+
Version: 0.18.4
|
|
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
|
|
@@ -37,8 +37,8 @@ Dynamic: license-file
|
|
|
37
37
|
[](https://pypi.org/project/PyTmcStepper)
|
|
38
38
|
[](https://GitHub.com/Chr157i4n/PyTmcStepper/issues/)
|
|
39
39
|
|
|
40
|
-
[](https://github.com/Chr157i4n/PyTmcStepper/actions/workflows/ci.yml)
|
|
41
|
+
[](https://htmlpreview.github.io/?https://github.com/Chr157i4n/PyTmcStepper/blob/python-coverage-comment-action-data/htmlcov/index.html)
|
|
42
42
|
|
|
43
43
|
\
|
|
44
44
|
\
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
[](https://pypi.org/project/PyTmcStepper)
|
|
6
6
|
[](https://GitHub.com/Chr157i4n/PyTmcStepper/issues/)
|
|
7
7
|
|
|
8
|
-
[](https://github.com/Chr157i4n/PyTmcStepper/actions/workflows/ci.yml)
|
|
9
|
+
[](https://htmlpreview.github.io/?https://github.com/Chr157i4n/PyTmcStepper/blob/python-coverage-comment-action-data/htmlcov/index.html)
|
|
10
10
|
|
|
11
11
|
\
|
|
12
12
|
\
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "PyTmcStepper"
|
|
7
|
-
version = "0.18.
|
|
7
|
+
version = "0.18.4"
|
|
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"
|
|
@@ -50,6 +50,28 @@ max-line-length = 160
|
|
|
50
50
|
relative_files = true
|
|
51
51
|
source = ["src"]
|
|
52
52
|
|
|
53
|
+
[tool.coverage.report]
|
|
54
|
+
omit = [
|
|
55
|
+
"tests/*",
|
|
56
|
+
"*_micropython.py",
|
|
57
|
+
"*_circuitpython.py",
|
|
58
|
+
"*_ftdi.py",
|
|
59
|
+
"*_periphery.py",
|
|
60
|
+
]
|
|
61
|
+
exclude_lines = [
|
|
62
|
+
"pragma: no cover",
|
|
63
|
+
"def __repr__",
|
|
64
|
+
"if self.debug:",
|
|
65
|
+
"if settings.DEBUG:",
|
|
66
|
+
"if TYPE_CHECKING:",
|
|
67
|
+
"raise AssertionError",
|
|
68
|
+
"raise NotImplementedError",
|
|
69
|
+
"if 0:",
|
|
70
|
+
"if __name__ == .__main__.:",
|
|
71
|
+
"class .*\\bProtocol\\):",
|
|
72
|
+
"@(abc\\.)?abstractmethod",
|
|
73
|
+
]
|
|
74
|
+
|
|
53
75
|
[tool.semantic_release]
|
|
54
76
|
branch = "main"
|
|
55
77
|
version_toml = ["pyproject.toml:project.version"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyTmcStepper
|
|
3
|
-
Version: 0.18.
|
|
3
|
+
Version: 0.18.4
|
|
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
|
|
@@ -37,8 +37,8 @@ Dynamic: license-file
|
|
|
37
37
|
[](https://pypi.org/project/PyTmcStepper)
|
|
38
38
|
[](https://GitHub.com/Chr157i4n/PyTmcStepper/issues/)
|
|
39
39
|
|
|
40
|
-
[](https://github.com/Chr157i4n/PyTmcStepper/actions/workflows/ci.yml)
|
|
41
|
+
[](https://htmlpreview.github.io/?https://github.com/Chr157i4n/PyTmcStepper/blob/python-coverage-comment-action-data/htmlcov/index.html)
|
|
42
42
|
|
|
43
43
|
\
|
|
44
44
|
\
|
|
@@ -60,13 +60,19 @@ src/tmc_driver/tmc_logger/__init__.py
|
|
|
60
60
|
src/tmc_driver/tmc_logger/_tmc_logger_base.py
|
|
61
61
|
src/tmc_driver/tmc_logger/_tmc_logger_cpython.py
|
|
62
62
|
src/tmc_driver/tmc_logger/_tmc_logger_micropython.py
|
|
63
|
+
tests/test_gpiozero.py
|
|
63
64
|
tests/test_tmc2209.py
|
|
64
65
|
tests/test_tmc2240.py
|
|
65
66
|
tests/test_tmc_com_spi.py
|
|
66
67
|
tests/test_tmc_com_uart.py
|
|
67
68
|
tests/test_tmc_ec_pin.py
|
|
69
|
+
tests/test_tmc_imports.py
|
|
68
70
|
tests/test_tmc_math.py
|
|
69
71
|
tests/test_tmc_modules.py
|
|
70
|
-
tests/
|
|
72
|
+
tests/test_tmc_move_intramp.py
|
|
73
|
+
tests/test_tmc_move_stepdir.py
|
|
74
|
+
tests/test_tmc_move_steppwmdir.py
|
|
75
|
+
tests/test_tmc_move_stepreg.py
|
|
76
|
+
tests/test_tmc_move_vactual.py
|
|
71
77
|
tests/test_tmc_set_current.py
|
|
72
78
|
tests/test_tmc_stallguard.py
|
|
@@ -33,10 +33,6 @@ except ImportError:
|
|
|
33
33
|
|
|
34
34
|
def __getattr__(name):
|
|
35
35
|
"""Lazy import of enable control classes to avoid circular imports"""
|
|
36
|
-
if name == "TmcEnableControl":
|
|
37
|
-
from ._tmc_ec import TmcEnableControl
|
|
38
|
-
|
|
39
|
-
return TmcEnableControl
|
|
40
36
|
if name == "TmcEnableControlPin":
|
|
41
37
|
from ._tmc_ec_pin import TmcEnableControlPin
|
|
42
38
|
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py
RENAMED
|
@@ -122,14 +122,14 @@ class GpiozeroWrapper(BaseGPIOWrapper):
|
|
|
122
122
|
|
|
123
123
|
def gpio_add_event_detect(self, pin: int, callback: types.FunctionType):
|
|
124
124
|
"""add event detect"""
|
|
125
|
-
gpio = self.
|
|
125
|
+
gpio = self._gpios[pin]
|
|
126
126
|
if not isinstance(gpio, DigitalInputDevice):
|
|
127
127
|
raise RuntimeError(f"GPIO pin {pin} not configured as input")
|
|
128
128
|
gpio.when_activated = callback
|
|
129
129
|
|
|
130
130
|
def gpio_remove_event_detect(self, pin: int):
|
|
131
131
|
"""remove event detect"""
|
|
132
|
-
gpio = self.
|
|
132
|
+
gpio = self._gpios[pin]
|
|
133
133
|
if not isinstance(gpio, DigitalInputDevice):
|
|
134
134
|
raise RuntimeError(f"GPIO pin {pin} not configured as input")
|
|
135
135
|
gpio.when_activated = None
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""
|
|
2
|
+
test for Tmc2209 with gpiozero
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import unittest
|
|
7
|
+
from gpiozero.pins.mock import MockFactory, MockPWMPin
|
|
8
|
+
from gpiozero import Device
|
|
9
|
+
|
|
10
|
+
# Konfiguriere MockFactory mit PWM-Unterstützung
|
|
11
|
+
Device.pin_factory = MockFactory(pin_class=MockPWMPin)
|
|
12
|
+
|
|
13
|
+
import src.tmc_driver.tmc_gpio as tmc_driver_gpio
|
|
14
|
+
from src.tmc_driver.tmc_gpio._tmc_gpio_board_gpiozero import GpiozeroWrapper
|
|
15
|
+
|
|
16
|
+
from src.tmc_driver import (
|
|
17
|
+
Tmc2209,
|
|
18
|
+
TmcEnableControlPin,
|
|
19
|
+
TmcMotionControlStepPwmDir,
|
|
20
|
+
MovementAbsRel,
|
|
21
|
+
)
|
|
22
|
+
from src.tmc_driver import tmc_2209
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _FakeTmcCom:
|
|
26
|
+
"""_FakeTmcCom class for testing purposes"""
|
|
27
|
+
|
|
28
|
+
def read_int(self, addr: int, tries: int = 3): # pylint: disable=unused-argument
|
|
29
|
+
"""fake read_int method for testing purposes"""
|
|
30
|
+
value = 0
|
|
31
|
+
return value, None
|
|
32
|
+
|
|
33
|
+
def write_reg(self, addr: int, data: int):
|
|
34
|
+
"""fake write_reg method for testing purposes"""
|
|
35
|
+
# if addr == tmc_5160.XActual.ADDR:
|
|
36
|
+
# current_pos = data
|
|
37
|
+
# if addr == tmc_5160.XTarget.ADDR:
|
|
38
|
+
# current_pos = data
|
|
39
|
+
|
|
40
|
+
def write_reg_check(self, addr: int, data: int):
|
|
41
|
+
"""fake write_reg_check method for testing purposes"""
|
|
42
|
+
self.write_reg(addr, data)
|
|
43
|
+
return True
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
fake_com = _FakeTmcCom()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TestTMCMove(unittest.TestCase):
|
|
50
|
+
"""TestTMCMove with gpiozero"""
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def setUpClass(cls):
|
|
54
|
+
"""setUpClass"""
|
|
55
|
+
|
|
56
|
+
cls.original_tmc_gpio = tmc_driver_gpio.tmc_gpio
|
|
57
|
+
tmc_driver_gpio.tmc_gpio = GpiozeroWrapper()
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def tearDownClass(cls):
|
|
61
|
+
"""tearDownClass"""
|
|
62
|
+
# Setze tmc_gpio auf die ursprüngliche Implementierung zurück
|
|
63
|
+
if cls.original_tmc_gpio is not None:
|
|
64
|
+
tmc_driver_gpio.tmc_gpio = cls.original_tmc_gpio
|
|
65
|
+
|
|
66
|
+
def setUp(self):
|
|
67
|
+
"""setUp"""
|
|
68
|
+
|
|
69
|
+
self.MovementAbsRel = MovementAbsRel
|
|
70
|
+
self.tmc = Tmc2209(TmcEnableControlPin(1), TmcMotionControlStepPwmDir(2, 3))
|
|
71
|
+
self.tmc.gconf = tmc_2209.GConf(fake_com)
|
|
72
|
+
self.tmc.sgthrs = tmc_2209.SgThrs(fake_com)
|
|
73
|
+
self.tmc.tcoolthrs = tmc_2209.TCoolThrs(fake_com)
|
|
74
|
+
|
|
75
|
+
# these values are normally set by reading the driver
|
|
76
|
+
self.tmc.mres = 2
|
|
77
|
+
|
|
78
|
+
self.tmc.acceleration_fullstep = 100000
|
|
79
|
+
self.tmc.max_speed_fullstep = 10000
|
|
80
|
+
self.tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
|
|
81
|
+
|
|
82
|
+
def tearDown(self):
|
|
83
|
+
"""tearDown"""
|
|
84
|
+
del self.tmc
|
|
85
|
+
|
|
86
|
+
def test_run_to_position_steps(self):
|
|
87
|
+
"""test_run_to_position_steps"""
|
|
88
|
+
|
|
89
|
+
self.tmc.run_to_position_steps(400, self.MovementAbsRel.RELATIVE)
|
|
90
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
91
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
92
|
+
|
|
93
|
+
self.tmc.run_to_position_steps(-200, self.MovementAbsRel.RELATIVE)
|
|
94
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
95
|
+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
|
|
96
|
+
|
|
97
|
+
self.tmc.run_to_position_steps(400)
|
|
98
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
99
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
100
|
+
|
|
101
|
+
def test_stallguard_interrupt(self):
|
|
102
|
+
"""test_stallguard_interrupt"""
|
|
103
|
+
self.tmc.set_stallguard_callback(4, 100, lambda: print("Stallguard interrupt"))
|
|
104
|
+
|
|
105
|
+
def test_run_pwm(self):
|
|
106
|
+
"""test_run_to_position_steps_threaded"""
|
|
107
|
+
# continous movement using pwm
|
|
108
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(250)
|
|
109
|
+
time.sleep(0.1)
|
|
110
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(0)
|
|
111
|
+
time.sleep(0.1)
|
|
112
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(-250)
|
|
113
|
+
time.sleep(0.1)
|
|
114
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(0)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
unittest.main()
|
|
@@ -2,15 +2,30 @@
|
|
|
2
2
|
test for Tmc2209
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
import time
|
|
6
5
|
import unittest
|
|
7
|
-
from src.tmc_driver
|
|
6
|
+
from src.tmc_driver import (
|
|
7
|
+
Tmc2209,
|
|
8
|
+
TmcEnableControlPin,
|
|
9
|
+
TmcMotionControlStepDir,
|
|
10
|
+
MovementAbsRel,
|
|
11
|
+
)
|
|
8
12
|
from src.tmc_driver.reg import _tmc220x_reg as tmc220x_reg
|
|
9
13
|
|
|
10
14
|
|
|
11
15
|
faketmccom_return_value = 0
|
|
12
16
|
|
|
13
17
|
|
|
18
|
+
class _FakeIoin:
|
|
19
|
+
"""_FakeIoin class for testing purposes"""
|
|
20
|
+
|
|
21
|
+
pin_state = False
|
|
22
|
+
|
|
23
|
+
def get(self, name: str) -> int:
|
|
24
|
+
"""get pin value"""
|
|
25
|
+
self.pin_state = not self.pin_state
|
|
26
|
+
return self.pin_state
|
|
27
|
+
|
|
28
|
+
|
|
14
29
|
class _FakeTmcCom:
|
|
15
30
|
"""_FakeTmcCom class for testing purposes"""
|
|
16
31
|
|
|
@@ -102,6 +117,27 @@ class TestTMCMove(unittest.TestCase):
|
|
|
102
117
|
|
|
103
118
|
gstat.check() # should not raise
|
|
104
119
|
|
|
120
|
+
def test_pins(self):
|
|
121
|
+
"""test_pins"""
|
|
122
|
+
self.assertEqual(
|
|
123
|
+
self.tmc.tmc_ec.pin_en,
|
|
124
|
+
1,
|
|
125
|
+
f"actual enable pin: {self.tmc.tmc_ec.pin_en}, expected enable pin: 1",
|
|
126
|
+
)
|
|
127
|
+
self.assertEqual(
|
|
128
|
+
self.tmc.tmc_mc.pin_step,
|
|
129
|
+
2,
|
|
130
|
+
f"actual step pin: {self.tmc.tmc_mc.pin_step}, expected step pin: 2",
|
|
131
|
+
)
|
|
132
|
+
self.assertEqual(
|
|
133
|
+
self.tmc.tmc_mc.pin_dir,
|
|
134
|
+
3,
|
|
135
|
+
f"actual dir pin: {self.tmc.tmc_mc.pin_dir}, expected dir pin: 3",
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
self.tmc.ioin = _FakeIoin()
|
|
139
|
+
self.tmc.test_dir_step_en()
|
|
140
|
+
|
|
105
141
|
|
|
106
142
|
if __name__ == "__main__":
|
|
107
143
|
unittest.main()
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
test for Tmc2240
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
import time
|
|
6
5
|
import unittest
|
|
7
|
-
from src.tmc_driver
|
|
6
|
+
from src.tmc_driver import (
|
|
7
|
+
Tmc2240,
|
|
8
|
+
TmcEnableControlPin,
|
|
9
|
+
TmcMotionControlStepDir,
|
|
10
|
+
MovementAbsRel,
|
|
11
|
+
)
|
|
8
12
|
from src.tmc_driver.reg import _tmc224x_reg as tmc224x_reg
|
|
9
13
|
|
|
10
14
|
faketmccom_return_value = 0
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
test for _tmc_ec_pin.py
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestTmcEnableControlPin(unittest.TestCase):
|
|
9
|
+
"""TestTmcEnableControlPin"""
|
|
10
|
+
|
|
11
|
+
def setUp(self):
|
|
12
|
+
"""setUp"""
|
|
13
|
+
|
|
14
|
+
def test_imports(self):
|
|
15
|
+
"""test_enable"""
|
|
16
|
+
from src.tmc_driver import TmcLogger, Loglevel
|
|
17
|
+
from src.tmc_driver import Tmc2208, Tmc2209, Tmc2240, Tmc5160
|
|
18
|
+
from src.tmc_driver import tmc_gpio, Board
|
|
19
|
+
|
|
20
|
+
from src.tmc_driver.com import TmcComUart
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from src.tmc_driver.com import TmcComSpi
|
|
24
|
+
except ImportError:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
from src.tmc_driver.enable_control import (
|
|
28
|
+
TmcEnableControlPin,
|
|
29
|
+
TmcEnableControlToff,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
from src.tmc_driver.motion_control import (
|
|
33
|
+
TmcMotionControlStepDir,
|
|
34
|
+
TmcMotionControlStepPwmDir,
|
|
35
|
+
TmcMotionControlStepReg,
|
|
36
|
+
TmcMotionControlVActual,
|
|
37
|
+
TmcMotionControlIntRampGenerator,
|
|
38
|
+
StopMode,
|
|
39
|
+
MovementAbsRel,
|
|
40
|
+
MovementPhase,
|
|
41
|
+
Direction,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
unittest.main()
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
test for _tmc_move.py
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import unittest
|
|
7
|
+
from src.tmc_driver.tmc_5160 import *
|
|
8
|
+
from src.tmc_driver import tmc_5160
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
current_pos = 100
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _FakeTmcCom:
|
|
15
|
+
"""_FakeTmcCom class for testing purposes"""
|
|
16
|
+
|
|
17
|
+
def read_int(self, addr: int, tries: int = 3):
|
|
18
|
+
"""fake read_int method for testing purposes"""
|
|
19
|
+
value = 0
|
|
20
|
+
if addr == tmc_5160.XActual.ADDR:
|
|
21
|
+
value = current_pos
|
|
22
|
+
if addr == tmc_5160.RampStat.ADDR:
|
|
23
|
+
value = 0xFFFFFFFF # all flags set - pos reached
|
|
24
|
+
return value, None
|
|
25
|
+
|
|
26
|
+
def write_reg(self, addr: int, data: int):
|
|
27
|
+
"""fake write_reg method for testing purposes"""
|
|
28
|
+
global current_pos
|
|
29
|
+
if addr == tmc_5160.XActual.ADDR:
|
|
30
|
+
current_pos = data
|
|
31
|
+
if addr == tmc_5160.XTarget.ADDR:
|
|
32
|
+
current_pos = data
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
fake_com = _FakeTmcCom()
|
|
36
|
+
|
|
37
|
+
reg_dict = {
|
|
38
|
+
"xactual": tmc_5160.XActual(fake_com),
|
|
39
|
+
"xtarget": tmc_5160.XTarget(fake_com),
|
|
40
|
+
"rampmode": tmc_5160.RampMode(fake_com),
|
|
41
|
+
"rampstat": tmc_5160.RampStat(fake_com),
|
|
42
|
+
"vstart": tmc_5160.VStart(fake_com),
|
|
43
|
+
"vmax": tmc_5160.VMax(fake_com),
|
|
44
|
+
"v1": tmc_5160.V1(fake_com),
|
|
45
|
+
"amax": tmc_5160.AMax(fake_com),
|
|
46
|
+
"a1": tmc_5160.A1(fake_com),
|
|
47
|
+
"dmax": tmc_5160.DMax(fake_com),
|
|
48
|
+
"d1": tmc_5160.D1(fake_com),
|
|
49
|
+
"vstop": tmc_5160.VStop(fake_com),
|
|
50
|
+
"loststeps": tmc_5160.LostSteps(fake_com),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def register_callback(reg: str):
|
|
55
|
+
"""register_callback function for testing purposes"""
|
|
56
|
+
return reg_dict.get(reg, None)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class TestTMCMove(unittest.TestCase):
|
|
60
|
+
"""TestTMCMove"""
|
|
61
|
+
|
|
62
|
+
def setUp(self):
|
|
63
|
+
"""setUp"""
|
|
64
|
+
self.tmc = Tmc5160(None, TmcMotionControlIntRampGenerator())
|
|
65
|
+
self.tmc.tmc_mc.set_get_register_callback(register_callback)
|
|
66
|
+
|
|
67
|
+
# these values are normally set by reading the driver
|
|
68
|
+
self.tmc.mres = 2
|
|
69
|
+
|
|
70
|
+
self.tmc.acceleration_fullstep = 100000
|
|
71
|
+
self.tmc.max_speed_fullstep = 10000
|
|
72
|
+
self.tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
|
|
73
|
+
|
|
74
|
+
def tearDown(self):
|
|
75
|
+
"""tearDown"""
|
|
76
|
+
|
|
77
|
+
def test_run_to_position_steps(self):
|
|
78
|
+
"""test_run_to_position_steps"""
|
|
79
|
+
|
|
80
|
+
self.tmc.run_to_position_steps(400, MovementAbsRel.RELATIVE)
|
|
81
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
82
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
83
|
+
|
|
84
|
+
self.tmc.run_to_position_steps(-200, MovementAbsRel.RELATIVE)
|
|
85
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
86
|
+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
|
|
87
|
+
|
|
88
|
+
self.tmc.run_to_position_steps(400)
|
|
89
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
90
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
91
|
+
|
|
92
|
+
def test_run_to_position_other(self):
|
|
93
|
+
"""test_run_to_position_other"""
|
|
94
|
+
self.tmc.run_to_position_fullsteps(200) # move to position 200 (fullsteps)
|
|
95
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
96
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
97
|
+
|
|
98
|
+
self.tmc.run_to_position_fullsteps(0) # move to position 0
|
|
99
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
100
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
101
|
+
|
|
102
|
+
self.tmc.run_to_position_fullsteps(
|
|
103
|
+
200, MovementAbsRel.RELATIVE
|
|
104
|
+
) # move 200 fullsteps forward
|
|
105
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
106
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
107
|
+
|
|
108
|
+
self.tmc.run_to_position_fullsteps(
|
|
109
|
+
-200, MovementAbsRel.RELATIVE
|
|
110
|
+
) # move 200 fullsteps backward
|
|
111
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
112
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
113
|
+
|
|
114
|
+
self.tmc.run_to_position_steps(400) # move to position 400 (µsteps)
|
|
115
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
116
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
117
|
+
|
|
118
|
+
self.tmc.run_to_position_steps(0) # move to position 0
|
|
119
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
120
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
121
|
+
|
|
122
|
+
self.tmc.run_to_position_revolutions(1) # move 1 revolution forward
|
|
123
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
124
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
125
|
+
|
|
126
|
+
self.tmc.run_to_position_revolutions(0) # move 1 revolution backward
|
|
127
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
128
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == "__main__":
|
|
132
|
+
unittest.main()
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""
|
|
2
|
+
test for _tmc_move.py
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import unittest
|
|
7
|
+
from src.tmc_driver.tmc_2209 import *
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestTMCMove(unittest.TestCase):
|
|
11
|
+
"""TestTMCMove"""
|
|
12
|
+
|
|
13
|
+
def setUp(self):
|
|
14
|
+
"""setUp"""
|
|
15
|
+
self.tmc = Tmc2209(None, TmcMotionControlStepPwmDir(16, 20))
|
|
16
|
+
|
|
17
|
+
# these values are normally set by reading the driver
|
|
18
|
+
self.tmc.mres = 2
|
|
19
|
+
|
|
20
|
+
self.tmc.acceleration_fullstep = 100000
|
|
21
|
+
self.tmc.max_speed_fullstep = 10000
|
|
22
|
+
self.tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
|
|
23
|
+
|
|
24
|
+
def tearDown(self):
|
|
25
|
+
"""tearDown"""
|
|
26
|
+
|
|
27
|
+
def test_run_to_position_steps(self):
|
|
28
|
+
"""test_run_to_position_steps"""
|
|
29
|
+
|
|
30
|
+
self.tmc.run_to_position_steps(400, MovementAbsRel.RELATIVE)
|
|
31
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
32
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
33
|
+
|
|
34
|
+
self.tmc.run_to_position_steps(-200, MovementAbsRel.RELATIVE)
|
|
35
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
36
|
+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
|
|
37
|
+
|
|
38
|
+
self.tmc.run_to_position_steps(400)
|
|
39
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
40
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
41
|
+
|
|
42
|
+
def test_run_to_position_other(self):
|
|
43
|
+
"""test_run_to_position_other"""
|
|
44
|
+
self.tmc.run_to_position_fullsteps(200) # move to position 200 (fullsteps)
|
|
45
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
46
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
47
|
+
|
|
48
|
+
self.tmc.run_to_position_fullsteps(0) # move to position 0
|
|
49
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
50
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
51
|
+
|
|
52
|
+
self.tmc.run_to_position_fullsteps(
|
|
53
|
+
200, MovementAbsRel.RELATIVE
|
|
54
|
+
) # move 200 fullsteps forward
|
|
55
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
56
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
57
|
+
|
|
58
|
+
self.tmc.run_to_position_fullsteps(
|
|
59
|
+
-200, MovementAbsRel.RELATIVE
|
|
60
|
+
) # move 200 fullsteps backward
|
|
61
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
62
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
63
|
+
|
|
64
|
+
self.tmc.run_to_position_steps(400) # move to position 400 (µsteps)
|
|
65
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
66
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
67
|
+
|
|
68
|
+
self.tmc.run_to_position_steps(0) # move to position 0
|
|
69
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
70
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
71
|
+
|
|
72
|
+
self.tmc.run_to_position_revolutions(1) # move 1 revolution forward
|
|
73
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
74
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
75
|
+
|
|
76
|
+
self.tmc.run_to_position_revolutions(0) # move 1 revolution backward
|
|
77
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
78
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
79
|
+
|
|
80
|
+
def test_run_pwm(self):
|
|
81
|
+
"""test_run_to_position_steps_threaded"""
|
|
82
|
+
# continous movement using pwm
|
|
83
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(250)
|
|
84
|
+
time.sleep(0.1)
|
|
85
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(0)
|
|
86
|
+
time.sleep(0.1)
|
|
87
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(-250)
|
|
88
|
+
time.sleep(0.1)
|
|
89
|
+
self.tmc.tmc_mc.run_speed_pwm_fullstep(0)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
unittest.main()
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""
|
|
2
|
+
test for _tmc_move.py
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import unittest
|
|
7
|
+
from src.tmc_driver.tmc_2209 import *
|
|
8
|
+
from src.tmc_driver import tmc_2209
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class _FakeTmcCom:
|
|
12
|
+
"""_FakeTmcCom class for testing purposes"""
|
|
13
|
+
|
|
14
|
+
def read_int(self, addr: int, tries: int = 3):
|
|
15
|
+
"""fake read_int method for testing purposes"""
|
|
16
|
+
value = 0
|
|
17
|
+
if addr == tmc_2209.GConf.ADDR:
|
|
18
|
+
value = 0
|
|
19
|
+
return value, None
|
|
20
|
+
|
|
21
|
+
def write_reg(self, addr: int, data: int):
|
|
22
|
+
"""fake write_reg method for testing purposes"""
|
|
23
|
+
# if addr == tmc_5160.XActual.ADDR:
|
|
24
|
+
# current_pos = data
|
|
25
|
+
# if addr == tmc_5160.XTarget.ADDR:
|
|
26
|
+
# current_pos = data
|
|
27
|
+
|
|
28
|
+
def write_reg_check(self, addr: int, data: int):
|
|
29
|
+
"""fake write_reg_check method for testing purposes"""
|
|
30
|
+
self.write_reg(addr, data)
|
|
31
|
+
return True
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
fake_com = _FakeTmcCom()
|
|
35
|
+
|
|
36
|
+
reg_dict = {
|
|
37
|
+
"gconf": tmc_2209.GConf(fake_com),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def register_callback(reg: str):
|
|
42
|
+
"""register_callback function for testing purposes"""
|
|
43
|
+
return reg_dict.get(reg, None)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TestTMCMove(unittest.TestCase):
|
|
47
|
+
"""TestTMCMove"""
|
|
48
|
+
|
|
49
|
+
def setUp(self):
|
|
50
|
+
"""setUp"""
|
|
51
|
+
self.tmc = Tmc2209(None, TmcMotionControlStepReg(16))
|
|
52
|
+
self.tmc.tmc_mc.set_get_register_callback(register_callback)
|
|
53
|
+
|
|
54
|
+
# these values are normally set by reading the driver
|
|
55
|
+
self.tmc.mres = 2
|
|
56
|
+
|
|
57
|
+
self.tmc.acceleration_fullstep = 100000
|
|
58
|
+
self.tmc.max_speed_fullstep = 10000
|
|
59
|
+
self.tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
|
|
60
|
+
|
|
61
|
+
def tearDown(self):
|
|
62
|
+
"""tearDown"""
|
|
63
|
+
|
|
64
|
+
def test_run_to_position_steps(self):
|
|
65
|
+
"""test_run_to_position_steps"""
|
|
66
|
+
|
|
67
|
+
self.tmc.run_to_position_steps(400, MovementAbsRel.RELATIVE)
|
|
68
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
69
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
70
|
+
|
|
71
|
+
self.tmc.run_to_position_steps(-200, MovementAbsRel.RELATIVE)
|
|
72
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
73
|
+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
|
|
74
|
+
|
|
75
|
+
self.tmc.run_to_position_steps(400)
|
|
76
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
77
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
78
|
+
|
|
79
|
+
def test_run_to_position_other(self):
|
|
80
|
+
"""test_run_to_position_other"""
|
|
81
|
+
self.tmc.run_to_position_fullsteps(200) # move to position 200 (fullsteps)
|
|
82
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
83
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
84
|
+
|
|
85
|
+
self.tmc.run_to_position_fullsteps(0) # move to position 0
|
|
86
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
87
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
88
|
+
|
|
89
|
+
self.tmc.run_to_position_fullsteps(
|
|
90
|
+
200, MovementAbsRel.RELATIVE
|
|
91
|
+
) # move 200 fullsteps forward
|
|
92
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
93
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
94
|
+
|
|
95
|
+
self.tmc.run_to_position_fullsteps(
|
|
96
|
+
-200, MovementAbsRel.RELATIVE
|
|
97
|
+
) # move 200 fullsteps backward
|
|
98
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
99
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
100
|
+
|
|
101
|
+
self.tmc.run_to_position_steps(400) # move to position 400 (µsteps)
|
|
102
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
103
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
104
|
+
|
|
105
|
+
self.tmc.run_to_position_steps(0) # move to position 0
|
|
106
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
107
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
108
|
+
|
|
109
|
+
self.tmc.run_to_position_revolutions(1) # move 1 revolution forward
|
|
110
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
111
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
112
|
+
|
|
113
|
+
self.tmc.run_to_position_revolutions(0) # move 1 revolution backward
|
|
114
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
115
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
116
|
+
|
|
117
|
+
def test_run_to_position_steps_threaded(self):
|
|
118
|
+
"""test_run_to_position_steps_threaded"""
|
|
119
|
+
self.tmc.tmc_mc.run_to_position_steps_threaded(400, MovementAbsRel.RELATIVE)
|
|
120
|
+
self.tmc.tmc_mc.wait_for_movement_finished_threaded()
|
|
121
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
122
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
123
|
+
|
|
124
|
+
self.tmc.tmc_mc.run_to_position_steps_threaded(-200, MovementAbsRel.RELATIVE)
|
|
125
|
+
self.tmc.tmc_mc.wait_for_movement_finished_threaded()
|
|
126
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
127
|
+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
|
|
128
|
+
|
|
129
|
+
self.tmc.tmc_mc.run_to_position_steps_threaded(400)
|
|
130
|
+
self.tmc.tmc_mc.wait_for_movement_finished_threaded()
|
|
131
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
132
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
133
|
+
|
|
134
|
+
self.tmc.tmc_mc.run_to_position_steps_threaded(800)
|
|
135
|
+
time.sleep(0.05)
|
|
136
|
+
self.tmc.tmc_mc.stop()
|
|
137
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
138
|
+
print(f"motorposition: {pos}")
|
|
139
|
+
self.assertTrue(
|
|
140
|
+
400 < pos < 800,
|
|
141
|
+
f"actual position: {pos}, expected position: 400 < pos < 800",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
unittest.main()
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""
|
|
2
|
+
test for _tmc_move.py
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import unittest
|
|
7
|
+
from src.tmc_driver.tmc_2209 import *
|
|
8
|
+
from src.tmc_driver import tmc_2209
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class _FakeTmcCom:
|
|
12
|
+
"""_FakeTmcCom class for testing purposes"""
|
|
13
|
+
|
|
14
|
+
def read_int(self, addr: int, tries: int = 3):
|
|
15
|
+
"""fake read_int method for testing purposes"""
|
|
16
|
+
value = 0
|
|
17
|
+
if addr == tmc_2209.GConf.ADDR:
|
|
18
|
+
value = 0
|
|
19
|
+
return value, None
|
|
20
|
+
|
|
21
|
+
def write_reg(self, addr: int, data: int):
|
|
22
|
+
"""fake write_reg method for testing purposes"""
|
|
23
|
+
# if addr == tmc_5160.XActual.ADDR:
|
|
24
|
+
# current_pos = data
|
|
25
|
+
# if addr == tmc_5160.XTarget.ADDR:
|
|
26
|
+
# current_pos = data
|
|
27
|
+
|
|
28
|
+
def write_reg_check(self, addr: int, data: int):
|
|
29
|
+
"""fake write_reg_check method for testing purposes"""
|
|
30
|
+
self.write_reg(addr, data)
|
|
31
|
+
return True
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
fake_com = _FakeTmcCom()
|
|
35
|
+
|
|
36
|
+
reg_dict = {
|
|
37
|
+
"gconf": tmc_2209.GConf(fake_com),
|
|
38
|
+
"vactual": tmc_2209.VActual(fake_com),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def register_callback(reg: str):
|
|
43
|
+
"""register_callback function for testing purposes"""
|
|
44
|
+
return reg_dict.get(reg, None)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestTMCMove(unittest.TestCase):
|
|
48
|
+
"""TestTMCMove"""
|
|
49
|
+
|
|
50
|
+
def setUp(self):
|
|
51
|
+
"""setUp"""
|
|
52
|
+
self.tmc = Tmc2209(None, TmcMotionControlVActual())
|
|
53
|
+
self.tmc.tmc_mc.set_get_register_callback(register_callback)
|
|
54
|
+
|
|
55
|
+
# these values are normally set by reading the driver
|
|
56
|
+
self.tmc.mres = 2
|
|
57
|
+
|
|
58
|
+
self.tmc.acceleration_fullstep = 100000
|
|
59
|
+
self.tmc.max_speed_fullstep = 10000
|
|
60
|
+
self.tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
|
|
61
|
+
|
|
62
|
+
def tearDown(self):
|
|
63
|
+
"""tearDown"""
|
|
64
|
+
|
|
65
|
+
def test_run_to_position_steps(self):
|
|
66
|
+
"""test_run_to_position_steps"""
|
|
67
|
+
|
|
68
|
+
self.tmc.run_to_position_steps(400, MovementAbsRel.RELATIVE)
|
|
69
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
70
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
71
|
+
|
|
72
|
+
self.tmc.run_to_position_steps(-200, MovementAbsRel.RELATIVE)
|
|
73
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
74
|
+
self.assertEqual(pos, 200, f"actual position: {pos}, expected position: 200")
|
|
75
|
+
|
|
76
|
+
self.tmc.run_to_position_steps(400)
|
|
77
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
78
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
79
|
+
|
|
80
|
+
def test_run_to_position_other(self):
|
|
81
|
+
"""test_run_to_position_other"""
|
|
82
|
+
self.tmc.run_to_position_fullsteps(200) # move to position 200 (fullsteps)
|
|
83
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
84
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
85
|
+
|
|
86
|
+
self.tmc.run_to_position_fullsteps(0) # move to position 0
|
|
87
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
88
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
89
|
+
|
|
90
|
+
self.tmc.run_to_position_fullsteps(
|
|
91
|
+
200, MovementAbsRel.RELATIVE
|
|
92
|
+
) # move 200 fullsteps forward
|
|
93
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
94
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
95
|
+
|
|
96
|
+
self.tmc.run_to_position_fullsteps(
|
|
97
|
+
-200, MovementAbsRel.RELATIVE
|
|
98
|
+
) # move 200 fullsteps backward
|
|
99
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
100
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
101
|
+
|
|
102
|
+
self.tmc.run_to_position_steps(400) # move to position 400 (µsteps)
|
|
103
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
104
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
105
|
+
|
|
106
|
+
self.tmc.run_to_position_steps(0) # move to position 0
|
|
107
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
108
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
109
|
+
|
|
110
|
+
self.tmc.run_to_position_revolutions(1) # move 1 revolution forward
|
|
111
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
112
|
+
self.assertEqual(pos, 400, f"actual position: {pos}, expected position: 400")
|
|
113
|
+
|
|
114
|
+
self.tmc.run_to_position_revolutions(0) # move 1 revolution backward
|
|
115
|
+
pos = self.tmc.tmc_mc.current_pos
|
|
116
|
+
self.assertEqual(pos, 0, f"actual position: {pos}, expected position: 400")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
unittest.main()
|
|
@@ -7,9 +7,11 @@ import unittest
|
|
|
7
7
|
from unittest import mock
|
|
8
8
|
from src.tmc_driver.tmc_2209 import *
|
|
9
9
|
from src.tmc_driver.tmc_2240 import *
|
|
10
|
+
from src.tmc_driver.tmc_5160 import *
|
|
10
11
|
from src.tmc_driver.com._tmc_com import *
|
|
11
12
|
import src.tmc_driver.reg._tmc2209_reg as tmc2209_reg
|
|
12
13
|
import src.tmc_driver.reg._tmc224x_reg as tmc224x_reg
|
|
14
|
+
import src.tmc_driver.reg._tmc5160_reg as tmc5160_reg
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
class TestTmcCom(TmcCom):
|
|
@@ -165,6 +167,38 @@ class TestTMCCurrent(unittest.TestCase):
|
|
|
165
167
|
self.assertEqual(tmc.global_scaler.global_scaler, global_scaler)
|
|
166
168
|
self.assertEqual(tmc.ihold_irun.irun, irun)
|
|
167
169
|
|
|
170
|
+
def test_tmc5160_set_current_rms(self):
|
|
171
|
+
"""test_tmc5160_set_current"""
|
|
172
|
+
tmc_com_test = TestTmcCom()
|
|
173
|
+
|
|
174
|
+
tmc = Tmc5160(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), None)
|
|
175
|
+
tmc.drv_conf = tmc5160_reg.DrvConf(tmc_com_test)
|
|
176
|
+
tmc.global_scaler = tmc5160_reg.GlobalScaler(tmc_com_test)
|
|
177
|
+
tmc.ihold_irun = tmc5160_reg.IHoldIRun(tmc_com_test)
|
|
178
|
+
|
|
179
|
+
# desired_current: (global_scaler, irun)
|
|
180
|
+
TEST_CASES = {
|
|
181
|
+
(300): (25, 31),
|
|
182
|
+
(400): (33, 31),
|
|
183
|
+
(500): (42, 31),
|
|
184
|
+
(1500): (125, 31),
|
|
185
|
+
(3000): (251, 31),
|
|
186
|
+
(3200): (256, 31),
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for desired_current, (
|
|
190
|
+
global_scaler,
|
|
191
|
+
irun,
|
|
192
|
+
) in TEST_CASES.items():
|
|
193
|
+
with self.subTest(desired_current=desired_current):
|
|
194
|
+
result = tmc.set_current_rms(desired_current)
|
|
195
|
+
|
|
196
|
+
self.assertAlmostEqual(
|
|
197
|
+
result, desired_current, delta=desired_current * 0.05
|
|
198
|
+
)
|
|
199
|
+
self.assertEqual(tmc.global_scaler.global_scaler, global_scaler)
|
|
200
|
+
self.assertEqual(tmc.ihold_irun.irun, irun)
|
|
201
|
+
|
|
168
202
|
|
|
169
203
|
if __name__ == "__main__":
|
|
170
204
|
unittest.main()
|
|
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
|
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_spi_circuitpython.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/com/_tmc_com_uart_circuitpython.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
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py
RENAMED
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py
RENAMED
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py
RENAMED
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/motion_control/_tmc_mc_vactual.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_circuitpython.py
RENAMED
|
File without changes
|
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py
RENAMED
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py
RENAMED
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py
RENAMED
|
File without changes
|
{pytmcstepper-0.18.2 → pytmcstepper-0.18.4}/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/pytmcstepper-0.18.2/tests/test_tmc_move.py → /pytmcstepper-0.18.4/tests/test_tmc_move_stepdir.py
RENAMED
|
File without changes
|
|
File without changes
|