PyTmcStepper 0.7.3__tar.gz → 0.7.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.
Files changed (47) hide show
  1. {pytmcstepper-0.7.3/src/PyTmcStepper.egg-info → pytmcstepper-0.7.4}/PKG-INFO +9 -5
  2. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/README.md +6 -3
  3. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/setup.cfg +1 -1
  4. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4/src/PyTmcStepper.egg-info}/PKG-INFO +9 -5
  5. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/SOURCES.txt +2 -0
  6. pytmcstepper-0.7.4/src/tmc_driver/_tmc_exceptions.py +16 -0
  7. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_gpio_board.py +78 -6
  8. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_stepperdriver.py +1 -0
  9. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/com/_tmc_com_spi.py +5 -5
  10. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/com/_tmc_com_uart.py +4 -2
  11. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +1 -0
  12. pytmcstepper-0.7.4/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +96 -0
  13. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +31 -0
  14. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc2209_reg.py +1 -1
  15. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc220x_reg.py +12 -0
  16. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc224x_reg.py +15 -0
  17. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_2209.py +1 -1
  18. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_220x.py +1 -0
  19. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_2240.py +1 -0
  20. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/LICENSE +0 -0
  21. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/pyproject.toml +0 -0
  22. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  23. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  24. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  25. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/__init__.py +0 -0
  26. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_logger.py +0 -0
  27. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_math.py +0 -0
  28. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_stallguard.py +0 -0
  29. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/com/__init__.py +0 -0
  30. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/com/_tmc_com.py +0 -0
  31. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/__init__.py +0 -0
  32. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  33. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  34. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
  35. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/__init__.py +0 -0
  36. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  37. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
  38. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/reg/__init__.py +0 -0
  39. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc_reg.py +0 -0
  40. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_2208.py +0 -0
  41. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc2209.py +0 -0
  42. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc2240.py +0 -0
  43. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc_com_spi.py +0 -0
  44. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc_com_uart.py +0 -0
  45. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc_ec_pin.py +0 -0
  46. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc_math.py +0 -0
  47. {pytmcstepper-0.7.3 → pytmcstepper-0.7.4}/tests/test_tmc_move.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.7.3
3
+ Version: 0.7.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
  Home-page: https://github.com/Chr157i4n/PyTmcStepper
6
6
  Author: Christian Köhlke
@@ -27,6 +27,7 @@ Provides-Extra: luckfox-pico
27
27
  Requires-Dist: python-periphery; extra == "luckfox-pico"
28
28
  Provides-Extra: orange-pi
29
29
  Requires-Dist: OPi.GPIO; extra == "orange-pi"
30
+ Dynamic: license-file
30
31
 
31
32
  # PyTmcStepper
32
33
 
@@ -54,7 +55,7 @@ Because the TMC2209 uses one shared pin for transmit and receive in the UART com
54
55
  Well, the Pi receives 4 bytes from itself and 8 bytes from the driver. So the Pi receives a total of 12 bytes and only the last 8 are the reply, of which only 4 are data bytes.
55
56
 
56
57
  The Documentation of the TMC2209 can be found here:
57
- [TMC2209 - Datsheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
58
+ [TMC2209 - Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
58
59
 
59
60
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
60
61
 
@@ -138,6 +139,7 @@ MotionControl | Class | Driver | Notes
138
139
  STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
139
140
  STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
140
141
  VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
142
+ STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
141
143
 
142
144
  Further methods of controlling the motion of a motor could be:
143
145
 
@@ -249,6 +251,8 @@ So you don't need to connect anything to the Vio pin of the driver.
249
251
 
250
252
  ## Usage
251
253
 
254
+ The library currently uses functions to access the TMC registers, but Python properties for internal getters/setters.
255
+
252
256
  ```python
253
257
  from tmc_driver.tmc_2209 import *
254
258
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
@@ -260,8 +264,8 @@ tmc.set_spreadcycle(False)
260
264
  tmc.set_microstepping_resolution(2)
261
265
  tmc.set_internal_rsense(False)
262
266
 
263
- tmc.set_acceleration(2000)
264
- tmc.set_max_speed(500)
267
+ tmc.acceleration_fullstep = 1000
268
+ tmc.max_speed_fullstep = 250
265
269
 
266
270
  tmc.set_motor_enabled(True)
267
271
 
@@ -24,7 +24,7 @@ Because the TMC2209 uses one shared pin for transmit and receive in the UART com
24
24
  Well, the Pi receives 4 bytes from itself and 8 bytes from the driver. So the Pi receives a total of 12 bytes and only the last 8 are the reply, of which only 4 are data bytes.
25
25
 
26
26
  The Documentation of the TMC2209 can be found here:
27
- [TMC2209 - Datsheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
27
+ [TMC2209 - Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
28
28
 
29
29
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
30
30
 
@@ -108,6 +108,7 @@ MotionControl | Class | Driver | Notes
108
108
  STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
109
109
  STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
110
110
  VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
111
+ STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
111
112
 
112
113
  Further methods of controlling the motion of a motor could be:
113
114
 
@@ -219,6 +220,8 @@ So you don't need to connect anything to the Vio pin of the driver.
219
220
 
220
221
  ## Usage
221
222
 
223
+ The library currently uses functions to access the TMC registers, but Python properties for internal getters/setters.
224
+
222
225
  ```python
223
226
  from tmc_driver.tmc_2209 import *
224
227
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
@@ -230,8 +233,8 @@ tmc.set_spreadcycle(False)
230
233
  tmc.set_microstepping_resolution(2)
231
234
  tmc.set_internal_rsense(False)
232
235
 
233
- tmc.set_acceleration(2000)
234
- tmc.set_max_speed(500)
236
+ tmc.acceleration_fullstep = 1000
237
+ tmc.max_speed_fullstep = 250
235
238
 
236
239
  tmc.set_motor_enabled(True)
237
240
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = PyTmcStepper
3
- version = 0.7.3
3
+ version = 0.7.4
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
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.7.3
3
+ Version: 0.7.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
  Home-page: https://github.com/Chr157i4n/PyTmcStepper
6
6
  Author: Christian Köhlke
@@ -27,6 +27,7 @@ Provides-Extra: luckfox-pico
27
27
  Requires-Dist: python-periphery; extra == "luckfox-pico"
28
28
  Provides-Extra: orange-pi
29
29
  Requires-Dist: OPi.GPIO; extra == "orange-pi"
30
+ Dynamic: license-file
30
31
 
31
32
  # PyTmcStepper
32
33
 
@@ -54,7 +55,7 @@ Because the TMC2209 uses one shared pin for transmit and receive in the UART com
54
55
  Well, the Pi receives 4 bytes from itself and 8 bytes from the driver. So the Pi receives a total of 12 bytes and only the last 8 are the reply, of which only 4 are data bytes.
55
56
 
56
57
  The Documentation of the TMC2209 can be found here:
57
- [TMC2209 - Datsheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
58
+ [TMC2209 - Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
58
59
 
59
60
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
60
61
 
@@ -138,6 +139,7 @@ MotionControl | Class | Driver | Notes
138
139
  STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
139
140
  STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
140
141
  VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
142
+ STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
141
143
 
142
144
  Further methods of controlling the motion of a motor could be:
143
145
 
@@ -249,6 +251,8 @@ So you don't need to connect anything to the Vio pin of the driver.
249
251
 
250
252
  ## Usage
251
253
 
254
+ The library currently uses functions to access the TMC registers, but Python properties for internal getters/setters.
255
+
252
256
  ```python
253
257
  from tmc_driver.tmc_2209 import *
254
258
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
@@ -260,8 +264,8 @@ tmc.set_spreadcycle(False)
260
264
  tmc.set_microstepping_resolution(2)
261
265
  tmc.set_internal_rsense(False)
262
266
 
263
- tmc.set_acceleration(2000)
264
- tmc.set_max_speed(500)
267
+ tmc.acceleration_fullstep = 1000
268
+ tmc.max_speed_fullstep = 250
265
269
 
266
270
  tmc.set_motor_enabled(True)
267
271
 
@@ -8,6 +8,7 @@ src/PyTmcStepper.egg-info/dependency_links.txt
8
8
  src/PyTmcStepper.egg-info/requires.txt
9
9
  src/PyTmcStepper.egg-info/top_level.txt
10
10
  src/tmc_driver/__init__.py
11
+ src/tmc_driver/_tmc_exceptions.py
11
12
  src/tmc_driver/_tmc_gpio_board.py
12
13
  src/tmc_driver/_tmc_logger.py
13
14
  src/tmc_driver/_tmc_math.py
@@ -28,6 +29,7 @@ src/tmc_driver/enable_control/_tmc_ec_toff.py
28
29
  src/tmc_driver/motion_control/__init__.py
29
30
  src/tmc_driver/motion_control/_tmc_mc.py
30
31
  src/tmc_driver/motion_control/_tmc_mc_step_dir.py
32
+ src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py
31
33
  src/tmc_driver/motion_control/_tmc_mc_step_reg.py
32
34
  src/tmc_driver/motion_control/_tmc_mc_vactual.py
33
35
  src/tmc_driver/reg/__init__.py
@@ -0,0 +1,16 @@
1
+ """Exceptions module"""
2
+
3
+ class TmcException(Exception):
4
+ """Base class for all TMC exceptions"""
5
+
6
+ class TmcDriverException(TmcException):
7
+ """Base class for all TMC driver exceptions"""
8
+
9
+ class TmcComException(TmcException):
10
+ """Base class for all TMC communication exceptions"""
11
+
12
+ class TmcMotionControlException(TmcException):
13
+ """Base class for all TMC motion control exceptions"""
14
+
15
+ class TmcEnableControlException(TmcException):
16
+ """Base class for all TMC enable control exceptions"""
@@ -81,7 +81,7 @@ class BaseGPIOWrapper:
81
81
  """cleanup GPIO pin"""
82
82
  raise NotImplementedError
83
83
 
84
- def gpio_input(self, pin:int):
84
+ def gpio_input(self, pin:int) -> int:
85
85
  """read GPIO pin"""
86
86
  raise NotImplementedError
87
87
 
@@ -89,6 +89,23 @@ class BaseGPIOWrapper:
89
89
  """write GPIO pin"""
90
90
  raise NotImplementedError
91
91
 
92
+ def gpio_pwm_setup(self, pin:int, frequency:int = 10, duty_cycle:int = 0):
93
+ """setup PWM"""
94
+ raise NotImplementedError
95
+
96
+ def gpio_pwm_set_frequency(self, pin:int, frequency:int):
97
+ """set PWM frequency"""
98
+ raise NotImplementedError
99
+
100
+ def gpio_pwm_set_duty_cycle(self, pin:int, duty_cycle:int):
101
+ """set PWM duty cycle
102
+
103
+ Args:
104
+ pin (int): pin number
105
+ duty_cycle (int): duty cycle in percent (0-100)
106
+ """
107
+ raise NotImplementedError
108
+
92
109
  def gpio_add_event_detect(self, pin:int, callback:types.FunctionType):
93
110
  """add event detect"""
94
111
  raise NotImplementedError
@@ -100,6 +117,8 @@ class BaseGPIOWrapper:
100
117
  class BaseRPiGPIOWrapper(BaseGPIOWrapper):
101
118
  """RPI.GPIO base wrapper"""
102
119
 
120
+ _gpios_pwm = [None] * 200
121
+
103
122
  def init(self, gpio_mode=None):
104
123
  """initialize GPIO library"""
105
124
  self.GPIO.setwarnings(False)
@@ -125,7 +144,7 @@ class BaseRPiGPIOWrapper(BaseGPIOWrapper):
125
144
  """cleanup GPIO pin"""
126
145
  self.GPIO.cleanup(pin)
127
146
 
128
- def gpio_input(self, pin:int):
147
+ def gpio_input(self, pin:int) -> int:
129
148
  """read GPIO pin"""
130
149
  return self.GPIO.input(pin)
131
150
 
@@ -133,6 +152,25 @@ class BaseRPiGPIOWrapper(BaseGPIOWrapper):
133
152
  """write GPIO pin"""
134
153
  self.GPIO.output(pin, value)
135
154
 
155
+ def gpio_pwm_setup(self, pin:int, frequency:int = 10, duty_cycle:int = 0):
156
+ """setup PWM"""
157
+ self.GPIO.setup(pin, int(GpioMode.OUT), initial=int(Gpio.LOW))
158
+ self._gpios_pwm[pin] = self.GPIO.PWM(pin, frequency)
159
+ self._gpios_pwm[pin].start(duty_cycle)
160
+
161
+ def gpio_pwm_set_frequency(self, pin:int, frequency:int):
162
+ """set PWM frequency"""
163
+ self._gpios_pwm[pin].ChangeFrequency(frequency)
164
+
165
+ def gpio_pwm_set_duty_cycle(self, pin:int, duty_cycle:int):
166
+ """set PWM duty cycle
167
+
168
+ Args:
169
+ pin (int): pin number
170
+ duty_cycle (int): duty cycle in percent (0-100)
171
+ """
172
+ self._gpios_pwm[pin].ChangeDutyCycle(duty_cycle)
173
+
136
174
  def gpio_add_event_detect(self, pin:int, callback:types.FunctionType):
137
175
  """add event detect"""
138
176
  self.GPIO.add_event_detect(pin, self.GPIO.RISING, callback=callback, bouncetime=300)
@@ -141,6 +179,7 @@ class BaseRPiGPIOWrapper(BaseGPIOWrapper):
141
179
  """remove event detect"""
142
180
  self.GPIO.remove_event_detect(pin)
143
181
 
182
+
144
183
  class MockGPIOWrapper(BaseRPiGPIOWrapper):
145
184
  """Mock.GPIO wrapper"""
146
185
 
@@ -176,11 +215,13 @@ class OPiGPIOWrapper(BaseRPiGPIOWrapper):
176
215
  class GpiozeroWrapper(BaseGPIOWrapper):
177
216
  """gpiozero GPIO wrapper"""
178
217
 
218
+ _gpios = [None] * 200
219
+ _gpios_pwm = [None] * 200
220
+
179
221
  def __init__(self):
180
222
  """constructor, imports gpiozero"""
181
223
  self.gpiozero = import_module('gpiozero')
182
224
  dependencies_logger.log("using gpiozero for GPIO control", Loglevel.INFO)
183
- self._gpios = [None] * 200
184
225
 
185
226
  def init(self, gpio_mode=None):
186
227
  """initialize GPIO library. pass on gpiozero"""
@@ -199,9 +240,12 @@ class GpiozeroWrapper(BaseGPIOWrapper):
199
240
 
200
241
  def gpio_cleanup(self, pin:int):
201
242
  """cleanup GPIO pin"""
202
- self._gpios[pin].close()
243
+ if self._gpios[pin] is not None:
244
+ self._gpios[pin].close()
245
+ if self._gpios_pwm[pin] is not None:
246
+ self._gpios_pwm[pin].close()
203
247
 
204
- def gpio_input(self, pin:int):
248
+ def gpio_input(self, pin:int) -> int:
205
249
  """read GPIO pin"""
206
250
  return self._gpios[pin].value
207
251
 
@@ -209,6 +253,34 @@ class GpiozeroWrapper(BaseGPIOWrapper):
209
253
  """write GPIO pin"""
210
254
  self._gpios[pin].value = value
211
255
 
256
+ def gpio_pwm_enable(self, pin:int, enable:bool):
257
+ """switch to PWM"""
258
+ if enable:
259
+ if self._gpios[pin] is not None:
260
+ self._gpios[pin] = None
261
+ self._gpios_pwm[pin] = self.gpiozero.PWMOutputDevice(pin)
262
+ else:
263
+ if self._gpios_pwm[pin] is not None:
264
+ self._gpios_pwm[pin] = None
265
+ self._gpios[pin] = self.gpiozero.DigitalOutputDevice(pin)
266
+
267
+ def gpio_pwm_setup(self, pin:int, frequency:int = 10, duty_cycle:int = 0):
268
+ """setup PWM"""
269
+ # self._gpios_pwm[pin] = self.gpiozero.PWMOutputDevice(pin)
270
+
271
+ def gpio_pwm_set_frequency(self, pin:int, frequency:int):
272
+ """set PWM frequency"""
273
+ self._gpios_pwm[pin].frequency = frequency
274
+
275
+ def gpio_pwm_set_duty_cycle(self, pin:int, duty_cycle:int):
276
+ """set PWM duty cycle
277
+
278
+ Args:
279
+ pin (int): pin number
280
+ duty_cycle (int): duty cycle in percent (0-100)
281
+ """
282
+ self._gpios_pwm[pin].value = duty_cycle/100
283
+
212
284
  def gpio_add_event_detect(self, pin:int, callback:types.FunctionType):
213
285
  """add event detect"""
214
286
  self._gpios[pin].when_activated = callback
@@ -244,7 +316,7 @@ class peripheryWrapper(BaseGPIOWrapper):
244
316
  """cleanup GPIO pin"""
245
317
  self._gpios[pin].close()
246
318
 
247
- def gpio_input(self, pin:int):
319
+ def gpio_input(self, pin:int) -> int:
248
320
  """read GPIO pin"""
249
321
  return self._gpios[pin].read()
250
322
 
@@ -16,6 +16,7 @@ from .motion_control._tmc_mc import TmcMotionControl, MovementAbsRel, MovementPh
16
16
  from .enable_control._tmc_ec import TmcEnableControl
17
17
  from .enable_control._tmc_ec_pin import TmcEnableControlPin
18
18
  from .motion_control._tmc_mc_step_dir import TmcMotionControlStepDir
19
+ from .motion_control._tmc_mc_step_pwm_dir import TmcMotionControlStepPwmDir
19
20
  from ._tmc_logger import TmcLogger, Loglevel
20
21
  from . import _tmc_math as tmc_math
21
22
 
@@ -12,6 +12,7 @@ TmcComSpi stepper driver spi module
12
12
 
13
13
  import spidev
14
14
  from ._tmc_com import *
15
+ from .._tmc_exceptions import TmcComException, TmcDriverException
15
16
 
16
17
  # class MockSpiDev:
17
18
  # """MockSpiDev"""
@@ -111,9 +112,9 @@ class TmcComSpi(TmcCom):
111
112
  }
112
113
 
113
114
  if flags["reset_flag"]:
114
- self._tmc_logger.log("TMC reset flag is set", Loglevel.ERROR)
115
+ raise TmcDriverException("TMC224X: reset detected")
115
116
  if flags["driver_error"]:
116
- self._tmc_logger.log("TMC driver error flag is set", Loglevel.ERROR)
117
+ raise TmcDriverException("TMC224X: driver error detected")
117
118
  if flags["sg2"]:
118
119
  self._tmc_logger.log("TMC stallguard2 flag is set", Loglevel.MOVEMENT)
119
120
  if flags["standstill"]:
@@ -182,9 +183,8 @@ class TmcComSpi(TmcCom):
182
183
  self.error_handler_running = True
183
184
  self._tmc_registers["gstat"].read()
184
185
  self._tmc_registers["gstat"].log(self.tmc_logger)
185
-
186
- self._tmc_logger.log("EXITING!", Loglevel.INFO)
187
- raise SystemExit
186
+ self._tmc_registers["gstat"].check()
187
+ raise TmcDriverException("TMC220X: unknown error detected")
188
188
 
189
189
 
190
190
  def test_com(self, addr):
@@ -2,12 +2,14 @@
2
2
  #pylint: disable=broad-exception-caught
3
3
  #pylint: disable=wildcard-import
4
4
  #pylint: disable=unused-wildcard-import
5
+ #pylint: disable=unused-import
5
6
  """
6
7
  TmcComUart stepper driver uart module
7
8
  """
8
9
 
9
10
  import serial
10
11
  from ._tmc_com import *
12
+ from .._tmc_exceptions import TmcComException, TmcDriverException
11
13
 
12
14
 
13
15
 
@@ -255,9 +257,9 @@ class TmcComUart(TmcCom):
255
257
  self.error_handler_running = True
256
258
  self._tmc_registers["gstat"].read()
257
259
  self._tmc_registers["gstat"].log(self.tmc_logger)
260
+ self._tmc_registers["gstat"].check()
261
+ raise TmcDriverException("TMC220X: unknown error detected")
258
262
 
259
- self._tmc_logger.log("EXITING!", Loglevel.INFO)
260
- raise SystemExit
261
263
 
262
264
 
263
265
  def test_com(self, addr):
@@ -116,6 +116,7 @@ class TmcMotionControlStepDir(TmcMotionControl):
116
116
  """_pin_dir property"""
117
117
  return self._pin_dir
118
118
 
119
+
119
120
  def __init__(self, pin_step:int, pin_dir:int):
120
121
  """constructor"""
121
122
  self._pin_step = pin_step
@@ -0,0 +1,96 @@
1
+ #pylint: disable=too-many-instance-attributes
2
+ #pylint: disable=too-many-arguments
3
+ #pylint: disable=too-many-branches
4
+ #pylint: disable=too-many-positional-arguments
5
+ """
6
+ STEP_PWM/DIR Motion Control module
7
+ """
8
+
9
+ from ._tmc_mc import MovementAbsRel, Direction, StopMode
10
+ from ._tmc_mc_step_dir import TmcMotionControlStepDir
11
+ from .._tmc_logger import TmcLogger, Loglevel
12
+ from .._tmc_gpio_board import tmc_gpio, GpiozeroWrapper
13
+
14
+
15
+ class TmcMotionControlStepPwmDir(TmcMotionControlStepDir):
16
+ """STEP_PWM/DIR Motion Control class"""
17
+
18
+ @property
19
+ def speed(self):
20
+ """_speed property"""
21
+ return self._speed
22
+
23
+ @speed.setter
24
+ def speed(self, speed:int):
25
+ """_speed setter"""
26
+ self._speed = speed
27
+ tmc_gpio.gpio_pwm_set_frequency(self._pin_step, self._speed)
28
+ self._tmc_logger.log(f"Speed: {self._speed} µsteps/s", Loglevel.DEBUG)
29
+
30
+
31
+ def init(self, tmc_logger:TmcLogger):
32
+ """init: called by the Tmc class"""
33
+ super().init(tmc_logger)
34
+ tmc_gpio.gpio_pwm_setup(self._pin_step, 1, 0)
35
+
36
+
37
+ def stop(self, stop_mode = StopMode.HARDSTOP):
38
+ """stop the current movement
39
+
40
+ Args:
41
+ stop_mode (enum): whether the movement should be stopped immediately or softly
42
+ (Default value = StopMode.HARDSTOP)
43
+ """
44
+ super().stop(stop_mode)
45
+ tmc_gpio.gpio_pwm_set_duty_cycle(self._pin_step, 0)
46
+
47
+
48
+ def run_to_position_steps(self, steps, movement_abs_rel:MovementAbsRel = None) -> StopMode:
49
+ """runs the motor to a specific position
50
+
51
+ Args:
52
+ steps (int): position in µsteps
53
+ movement_abs_rel (enum, optional): whether the movement is absolute or relative
54
+ (Default value = None)
55
+
56
+ Returns:
57
+ StopMode: the stop mode
58
+ """
59
+ if isinstance(tmc_gpio, GpiozeroWrapper):
60
+ tmc_gpio.gpio_pwm_enable(self._pin_step, False)
61
+
62
+ return super().run_to_position_steps(steps, movement_abs_rel)
63
+
64
+
65
+ def run_speed_pwm(self, speed:int = None):
66
+ """runs the motor
67
+ does not block the code
68
+ """
69
+ if speed is None:
70
+ speed = self.max_speed
71
+
72
+ if isinstance(tmc_gpio, GpiozeroWrapper):
73
+ tmc_gpio.gpio_pwm_enable(self._pin_step, True)
74
+
75
+ if speed == 0:
76
+ # stop movement
77
+ tmc_gpio.gpio_pwm_set_duty_cycle(self._pin_step, 0)
78
+ else:
79
+ if speed < 0:
80
+ self.set_direction(Direction.CCW)
81
+ speed = -speed
82
+ else:
83
+ self.set_direction(Direction.CW)
84
+
85
+ # change pwm frequency
86
+ self.speed = speed
87
+ tmc_gpio.gpio_pwm_set_duty_cycle(self._pin_step, 50)
88
+
89
+
90
+ def run_speed_pwm_fullstep(self, speed:int = None):
91
+ """runs the motor
92
+ does not block the code
93
+ """
94
+ if speed is None:
95
+ speed = self.max_speed_fullstep
96
+ self.run_speed_pwm(speed * self.mres)
@@ -40,6 +40,17 @@ class TmcMotionControlVActual(TmcMotionControl):
40
40
  raise NotImplementedError
41
41
 
42
42
 
43
+ def stop(self, stop_mode = StopMode.HARDSTOP):
44
+ """stop the current movement
45
+
46
+ Args:
47
+ stop_mode (enum): whether the movement should be stopped immediately or softly
48
+ (Default value = StopMode.HARDSTOP)
49
+ """
50
+ super().stop(stop_mode)
51
+ self.set_vactual(0)
52
+
53
+
43
54
  def run_to_position_steps(self, steps, movement_abs_rel:MovementAbsRel = None):
44
55
  """runs the motor to the given position.
45
56
  with acceleration and deceleration
@@ -177,3 +188,23 @@ class TmcMotionControlVActual(TmcMotionControl):
177
188
  stop (enum): how the movement was finished
178
189
  """
179
190
  return self.set_vactual_rps(rpm/60, duration, revolutions, acceleration)
191
+
192
+
193
+ def run_speed(self, speed:int):
194
+ """runs the motor
195
+ does not block the code
196
+
197
+ Args:
198
+ speed (int): speed in µsteps per second
199
+ """
200
+ self.set_vactual(speed/0.715)
201
+
202
+
203
+ def run_speed_fullstep(self, speed:int):
204
+ """runs the motor
205
+ does not block the code
206
+
207
+ Args:
208
+ speed (int): speed in fullsteps per second
209
+ """
210
+ self.run_speed(speed * self.mres)
@@ -2,6 +2,7 @@
2
2
  #pylint: disable=unused-wildcard-import
3
3
  #pylint: disable=unused-import
4
4
  #pylint: disable=attribute-defined-outside-init
5
+ #pylint: disable=no-member
5
6
  """
6
7
  Register module
7
8
  """
@@ -9,7 +10,6 @@ Register module
9
10
  from ._tmc220x_reg import *
10
11
 
11
12
 
12
-
13
13
  class TCoolThrs(TmcReg):
14
14
  """TCOOLTHRS register class"""
15
15
 
@@ -2,12 +2,14 @@
2
2
  #pylint: disable=unused-wildcard-import
3
3
  #pylint: disable=unused-import
4
4
  #pylint: disable=attribute-defined-outside-init
5
+ #pylint: disable=no-member
5
6
  """
6
7
  Register module
7
8
  """
8
9
 
9
10
  import math
10
11
  from ._tmc_reg import *
12
+ from .._tmc_exceptions import TmcDriverException
11
13
 
12
14
 
13
15
  class GConf(TmcReg):
@@ -44,6 +46,16 @@ class GStat(TmcReg):
44
46
  ]
45
47
  super().__init__(0x1, "GSTAT", tmc_com, reg_map)
46
48
 
49
+ def check(self):
50
+ """check if the driver is ok"""
51
+ self.read()
52
+ if self.reset:
53
+ raise TmcDriverException("TMC220X: reset detected")
54
+ if self.uv_cp:
55
+ raise TmcDriverException("TMC220X: undervoltage detected")
56
+ if self.drv_err:
57
+ raise TmcDriverException("TMC220X: driver error detected")
58
+
47
59
 
48
60
  class IfCnt(TmcReg):
49
61
  """IFCNT register class"""
@@ -9,6 +9,7 @@ Register module
9
9
 
10
10
  import math
11
11
  from ._tmc_reg import *
12
+ from .._tmc_exceptions import TmcDriverException
12
13
 
13
14
 
14
15
  class GConf(TmcReg):
@@ -52,6 +53,20 @@ class GStat(TmcReg):
52
53
  ]
53
54
  super().__init__(0x1, "GSTAT", tmc_com, reg_map)
54
55
 
56
+ def check(self):
57
+ """check if the driver is ok"""
58
+ self.read()
59
+ if self.vm_uvlo:
60
+ raise TmcDriverException("TMC224X: Vmotor undervoltage detected")
61
+ if self.register_reset:
62
+ raise TmcDriverException("TMC224X: register reset detected")
63
+ if self.uv_cp:
64
+ raise TmcDriverException("TMC224X: Charge Pump undervoltage detected")
65
+ if self.drv_err:
66
+ raise TmcDriverException("TMC224X: driver error detected")
67
+ if self.reset:
68
+ raise TmcDriverException("TMC224X: reset detected")
69
+
55
70
 
56
71
  class IfCnt(TmcReg):
57
72
  """IFCNT register class"""
@@ -117,8 +117,8 @@ class Tmc2209(Tmc220x, StallGuard):
117
117
  self.set_spreadcycle(0)
118
118
 
119
119
  mc_homing = TmcMotionControlVActual()
120
+ mc_homing.init(self.tmc_logger)
120
121
  mc_homing.tmc_com = self.tmc_com
121
- mc_homing.tmc_logger = self.tmc_logger
122
122
 
123
123
  self.set_stallguard_callback(diag_pin, threshold, mc_homing.stop,
124
124
  0.5*tmc_math.rps_to_steps(speed_rpm/60, self.tmc_mc.steps_per_rev))
@@ -29,6 +29,7 @@ from .motion_control._tmc_mc_vactual import TmcMotionControlVActual
29
29
  from ._tmc_logger import TmcLogger, Loglevel
30
30
  from .reg._tmc220x_reg import *
31
31
  from . import _tmc_math as tmc_math
32
+ from ._tmc_exceptions import TmcException, TmcComException, TmcMotionControlException, TmcEnableControlException, TmcDriverException
32
33
 
33
34
 
34
35
 
@@ -30,6 +30,7 @@ from ._tmc_stallguard import StallGuard
30
30
  from ._tmc_logger import TmcLogger, Loglevel
31
31
  from .reg._tmc224x_reg import *
32
32
  from . import _tmc_math as tmc_math
33
+ from ._tmc_exceptions import TmcException, TmcComException, TmcMotionControlException, TmcEnableControlException, TmcDriverException
33
34
 
34
35
 
35
36
 
File without changes