PyTmcStepper 0.7.2__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.2/src/PyTmcStepper.egg-info → pytmcstepper-0.7.4}/PKG-INFO +18 -11
  2. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/README.md +15 -9
  3. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/setup.cfg +1 -1
  4. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4/src/PyTmcStepper.egg-info}/PKG-INFO +18 -11
  5. {pytmcstepper-0.7.2 → 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.2 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_gpio_board.py +78 -6
  8. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_stepperdriver.py +1 -0
  9. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/com/_tmc_com.py +6 -0
  10. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/com/_tmc_com_spi.py +58 -31
  11. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/com/_tmc_com_uart.py +17 -10
  12. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +1 -0
  13. pytmcstepper-0.7.4/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +96 -0
  14. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +31 -0
  15. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc2209_reg.py +1 -1
  16. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc220x_reg.py +12 -0
  17. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc224x_reg.py +15 -0
  18. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/reg/_tmc_reg.py +12 -3
  19. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_2209.py +1 -1
  20. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_220x.py +1 -0
  21. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_2240.py +1 -0
  22. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/tests/test_tmc_com_spi.py +2 -3
  23. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/tests/test_tmc_com_uart.py +2 -3
  24. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/LICENSE +0 -0
  25. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/pyproject.toml +0 -0
  26. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  27. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  28. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  29. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/__init__.py +0 -0
  30. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_logger.py +0 -0
  31. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_math.py +0 -0
  32. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/_tmc_stallguard.py +0 -0
  33. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/com/__init__.py +0 -0
  34. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/__init__.py +0 -0
  35. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  36. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  37. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
  38. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/__init__.py +0 -0
  39. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  40. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
  41. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/reg/__init__.py +0 -0
  42. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/src/tmc_driver/tmc_2208.py +0 -0
  43. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/tests/test_tmc2209.py +0 -0
  44. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/tests/test_tmc2240.py +0 -0
  45. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/tests/test_tmc_ec_pin.py +0 -0
  46. {pytmcstepper-0.7.2 → pytmcstepper-0.7.4}/tests/test_tmc_math.py +0 -0
  47. {pytmcstepper-0.7.2 → 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.2
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
 
@@ -96,7 +97,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
97
  gpiozero | RASPBERRY_PI5 | Pi5
97
98
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
99
  pheriphery | LUCKFOX_PICO | Luckfox Pico
99
- pheriphery | LUCKFOX_PICO | Luckfox Pico
100
100
  OPi.GPIO | ORANGE_PI | Orange Pi
101
101
 
102
102
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -123,6 +123,8 @@ is split into their own classes to be able to support the diverse methods.
123
123
 
124
124
  ### EnableControl
125
125
 
126
+ The EnableControl module controls the motor current output. It has a function `set_motor_enabled` with one boolean parameter. This function is used to enable or disable the Motor current output.
127
+
126
128
  EnableControl | Class | Driver | Notes
127
129
  -- | -- | -- | --
128
130
  Pin | [TmcEnableControlPin](src/tmc_driver/enable_control/_tmc_ec_pin.py) | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
@@ -130,13 +132,16 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
130
132
 
131
133
  ### MotionControl
132
134
 
135
+ The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
136
+
133
137
  MotionControl | Class | Driver | Notes
134
138
  -- | -- | -- | --
135
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
136
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.
137
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
138
143
 
139
- Further methods of controlling a motor could be:
144
+ Further methods of controlling the motion of a motor could be:
140
145
 
141
146
  - using the built in Motion Controller of the TMC5130
142
147
  - via a µC which controlls the Motor
@@ -159,10 +164,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
159
164
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
160
165
  VM | RED | 12V or 24V of power supply | power for the motor
161
166
  GND | BLACK | GND of power supply | power for the motor
162
- EN | RED |GPIO21 of Raspberry Pi | enable the motor output
163
- STEP | GREEN |GPIO16 of Raspberry Pi | moves the motor one step per pulse
164
- DIR | WHITE |GPIO20 of Raspberry Pi | set the direction of the motor
165
- DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
167
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
168
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
169
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
170
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
166
171
 
167
172
  The GPIO pins can be specific when initiating the class.
168
173
  If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.
@@ -246,6 +251,8 @@ So you don't need to connect anything to the Vio pin of the driver.
246
251
 
247
252
  ## Usage
248
253
 
254
+ The library currently uses functions to access the TMC registers, but Python properties for internal getters/setters.
255
+
249
256
  ```python
250
257
  from tmc_driver.tmc_2209 import *
251
258
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
@@ -257,8 +264,8 @@ tmc.set_spreadcycle(False)
257
264
  tmc.set_microstepping_resolution(2)
258
265
  tmc.set_internal_rsense(False)
259
266
 
260
- tmc.set_acceleration(2000)
261
- tmc.set_max_speed(500)
267
+ tmc.acceleration_fullstep = 1000
268
+ tmc.max_speed_fullstep = 250
262
269
 
263
270
  tmc.set_motor_enabled(True)
264
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
 
@@ -66,7 +66,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
66
66
  gpiozero | RASPBERRY_PI5 | Pi5
67
67
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
68
68
  pheriphery | LUCKFOX_PICO | Luckfox Pico
69
- pheriphery | LUCKFOX_PICO | Luckfox Pico
70
69
  OPi.GPIO | ORANGE_PI | Orange Pi
71
70
 
72
71
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -93,6 +92,8 @@ is split into their own classes to be able to support the diverse methods.
93
92
 
94
93
  ### EnableControl
95
94
 
95
+ The EnableControl module controls the motor current output. It has a function `set_motor_enabled` with one boolean parameter. This function is used to enable or disable the Motor current output.
96
+
96
97
  EnableControl | Class | Driver | Notes
97
98
  -- | -- | -- | --
98
99
  Pin | [TmcEnableControlPin](src/tmc_driver/enable_control/_tmc_ec_pin.py) | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
@@ -100,13 +101,16 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
100
101
 
101
102
  ### MotionControl
102
103
 
104
+ The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
105
+
103
106
  MotionControl | Class | Driver | Notes
104
107
  -- | -- | -- | --
105
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
106
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.
107
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
108
112
 
109
- Further methods of controlling a motor could be:
113
+ Further methods of controlling the motion of a motor could be:
110
114
 
111
115
  - using the built in Motion Controller of the TMC5130
112
116
  - via a µC which controlls the Motor
@@ -129,10 +133,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
129
133
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
130
134
  VM | RED | 12V or 24V of power supply | power for the motor
131
135
  GND | BLACK | GND of power supply | power for the motor
132
- EN | RED |GPIO21 of Raspberry Pi | enable the motor output
133
- STEP | GREEN |GPIO16 of Raspberry Pi | moves the motor one step per pulse
134
- DIR | WHITE |GPIO20 of Raspberry Pi | set the direction of the motor
135
- DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
136
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
137
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
138
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
139
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
136
140
 
137
141
  The GPIO pins can be specific when initiating the class.
138
142
  If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.
@@ -216,6 +220,8 @@ So you don't need to connect anything to the Vio pin of the driver.
216
220
 
217
221
  ## Usage
218
222
 
223
+ The library currently uses functions to access the TMC registers, but Python properties for internal getters/setters.
224
+
219
225
  ```python
220
226
  from tmc_driver.tmc_2209 import *
221
227
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
@@ -227,8 +233,8 @@ tmc.set_spreadcycle(False)
227
233
  tmc.set_microstepping_resolution(2)
228
234
  tmc.set_internal_rsense(False)
229
235
 
230
- tmc.set_acceleration(2000)
231
- tmc.set_max_speed(500)
236
+ tmc.acceleration_fullstep = 1000
237
+ tmc.max_speed_fullstep = 250
232
238
 
233
239
  tmc.set_motor_enabled(True)
234
240
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = PyTmcStepper
3
- version = 0.7.2
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.2
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
 
@@ -96,7 +97,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
97
  gpiozero | RASPBERRY_PI5 | Pi5
97
98
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
99
  pheriphery | LUCKFOX_PICO | Luckfox Pico
99
- pheriphery | LUCKFOX_PICO | Luckfox Pico
100
100
  OPi.GPIO | ORANGE_PI | Orange Pi
101
101
 
102
102
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -123,6 +123,8 @@ is split into their own classes to be able to support the diverse methods.
123
123
 
124
124
  ### EnableControl
125
125
 
126
+ The EnableControl module controls the motor current output. It has a function `set_motor_enabled` with one boolean parameter. This function is used to enable or disable the Motor current output.
127
+
126
128
  EnableControl | Class | Driver | Notes
127
129
  -- | -- | -- | --
128
130
  Pin | [TmcEnableControlPin](src/tmc_driver/enable_control/_tmc_ec_pin.py) | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
@@ -130,13 +132,16 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
130
132
 
131
133
  ### MotionControl
132
134
 
135
+ The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
136
+
133
137
  MotionControl | Class | Driver | Notes
134
138
  -- | -- | -- | --
135
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
136
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.
137
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
138
143
 
139
- Further methods of controlling a motor could be:
144
+ Further methods of controlling the motion of a motor could be:
140
145
 
141
146
  - using the built in Motion Controller of the TMC5130
142
147
  - via a µC which controlls the Motor
@@ -159,10 +164,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
159
164
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
160
165
  VM | RED | 12V or 24V of power supply | power for the motor
161
166
  GND | BLACK | GND of power supply | power for the motor
162
- EN | RED |GPIO21 of Raspberry Pi | enable the motor output
163
- STEP | GREEN |GPIO16 of Raspberry Pi | moves the motor one step per pulse
164
- DIR | WHITE |GPIO20 of Raspberry Pi | set the direction of the motor
165
- DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
167
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
168
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
169
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
170
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
166
171
 
167
172
  The GPIO pins can be specific when initiating the class.
168
173
  If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.
@@ -246,6 +251,8 @@ So you don't need to connect anything to the Vio pin of the driver.
246
251
 
247
252
  ## Usage
248
253
 
254
+ The library currently uses functions to access the TMC registers, but Python properties for internal getters/setters.
255
+
249
256
  ```python
250
257
  from tmc_driver.tmc_2209 import *
251
258
  tmc = Tmc2209(TmcEnableControlPin(21), TmcMotionControlStepDir(16, 20), TmcComUart("/dev/serial0"))
@@ -257,8 +264,8 @@ tmc.set_spreadcycle(False)
257
264
  tmc.set_microstepping_resolution(2)
258
265
  tmc.set_internal_rsense(False)
259
266
 
260
- tmc.set_acceleration(2000)
261
- tmc.set_max_speed(500)
267
+ tmc.acceleration_fullstep = 1000
268
+ tmc.max_speed_fullstep = 250
262
269
 
263
270
  tmc.set_motor_enabled(True)
264
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
 
@@ -95,6 +95,9 @@ class TmcCom:
95
95
 
96
96
  Args:
97
97
  addr (int): HEX, which register to read
98
+ Returns:
99
+ int: register value
100
+ Dict: flags
98
101
  """
99
102
  raise NotImplementedError
100
103
 
@@ -106,6 +109,9 @@ class TmcCom:
106
109
  Args:
107
110
  addr (int): HEX, which register to read
108
111
  tries (int): how many tries, before error is raised (Default value = 10)
112
+ Returns:
113
+ int: register value
114
+ Dict: flags
109
115
  """
110
116
  raise NotImplementedError
111
117
 
@@ -4,13 +4,15 @@
4
4
  #pylint: disable=wildcard-import
5
5
  #pylint: disable=unused-wildcard-import
6
6
  #pylint: disable=too-few-public-methods
7
+ #pylint: disable=too-many-arguments
8
+ #pylint: disable=too-many-positional-arguments
7
9
  """
8
10
  TmcComSpi stepper driver spi module
9
11
  """
10
12
 
11
- import sys
12
13
  import spidev
13
14
  from ._tmc_com import *
15
+ from .._tmc_exceptions import TmcComException, TmcDriverException
14
16
 
15
17
  # class MockSpiDev:
16
18
  # """MockSpiDev"""
@@ -35,13 +37,17 @@ class TmcComSpi(TmcCom):
35
37
  like the current or the microsteppingmode
36
38
  """
37
39
 
38
- _spi = spidev.SpiDev()
40
+ spi = spidev.SpiDev()
39
41
  _spi_bus: int
40
42
  _spi_dev: int
43
+ _spi_speed: int
44
+
45
+
41
46
 
42
47
  def __init__(self,
43
48
  spi_bus,
44
49
  spi_dev,
50
+ spi_speed:int = 8000000,
45
51
  mtr_id:int = 0,
46
52
  tmc_logger = None
47
53
  ):
@@ -55,6 +61,7 @@ class TmcComSpi(TmcCom):
55
61
 
56
62
  self._spi_bus = spi_bus
57
63
  self._spi_dev = spi_dev
64
+ self._spi_speed = spi_speed
58
65
 
59
66
  self._r_frame = [0x55, 0, 0, 0, 0]
60
67
  self._w_frame = [0x55, 0, 0, 0, 0]
@@ -63,18 +70,18 @@ class TmcComSpi(TmcCom):
63
70
  def init(self):
64
71
  """init"""
65
72
  try:
66
- self._spi.open(self._spi_bus, self._spi_dev)
73
+ self.spi.open(self._spi_bus, self._spi_dev)
67
74
  except Exception as e:
68
75
  self._tmc_logger.log(f"Error opening SPI: {e}", Loglevel.ERROR)
69
76
  errnum = e.args[0]
70
77
  if errnum == 2:
71
78
  self._tmc_logger.log(f"SPI Device {self._spi_dev} on Bus {self._spi_bus} does not exist.", Loglevel.ERROR)
72
79
  self._tmc_logger.log("You need to activate the SPI interface with \"sudo raspi-config\"", Loglevel.ERROR)
73
- sys.exit()
80
+ raise SystemExit from e
74
81
 
75
- self._spi.max_speed_hz = 5000
76
- self._spi.mode = 0b11
77
- self._spi.lsbfirst = False
82
+ self.spi.max_speed_hz = self._spi_speed
83
+ self.spi.mode = 0b11
84
+ self.spi.lsbfirst = False
78
85
 
79
86
 
80
87
  def __del__(self):
@@ -87,30 +94,34 @@ class TmcComSpi(TmcCom):
87
94
 
88
95
  Args:
89
96
  addr (int): HEX, which register to read
97
+ Returns:
98
+ int: register value
99
+ Dict: flags
90
100
  """
91
101
  self._w_frame = [addr, 0x00, 0x00, 0x00, 0x00]
92
102
  dummy_data = [0x00, 0x00, 0x00, 0x00, 0x00]
93
103
 
94
- self._spi.xfer2(self._w_frame)
95
- rtn = self._spi.xfer2(dummy_data)
96
-
97
- reset_flag = rtn[0] >> 0 & 0x01
98
- driver_error = rtn[0] >> 1 & 0x01
99
- sg2 = rtn[0] >> 2 & 0x01
100
- standstill = rtn[0] >> 3 & 0x01
101
-
102
-
103
- if reset_flag:
104
- self._tmc_logger.log("TMC reset flag is set", Loglevel.ERROR)
105
- if driver_error:
106
- self._tmc_logger.log("TMC driver error flag is set", Loglevel.ERROR)
107
- if sg2:
104
+ self.spi.xfer2(self._w_frame)
105
+ rtn = self.spi.xfer2(dummy_data)
106
+
107
+ flags = {
108
+ "reset_flag": rtn[0] >> 0 & 0x01,
109
+ "driver_error": rtn[0] >> 1 & 0x01,
110
+ "sg2": rtn[0] >> 2 & 0x01,
111
+ "standstill": rtn[0] >> 3 & 0x01
112
+ }
113
+
114
+ if flags["reset_flag"]:
115
+ raise TmcDriverException("TMC224X: reset detected")
116
+ if flags["driver_error"]:
117
+ raise TmcDriverException("TMC224X: driver error detected")
118
+ if flags["sg2"]:
108
119
  self._tmc_logger.log("TMC stallguard2 flag is set", Loglevel.MOVEMENT)
109
- if standstill:
120
+ if flags["standstill"]:
110
121
  self._tmc_logger.log("TMC standstill flag is set", Loglevel.MOVEMENT)
111
122
 
112
123
 
113
- return rtn[1:]
124
+ return rtn[1:], flags
114
125
 
115
126
 
116
127
  def read_int(self, addr:hex, tries:int = 10):
@@ -120,9 +131,12 @@ class TmcComSpi(TmcCom):
120
131
  Args:
121
132
  addr (int): HEX, which register to read
122
133
  tries (int): how many tries, before error is raised (Default value = 10)
134
+ Returns:
135
+ int: register value
136
+ Dict: flags
123
137
  """
124
- data = self.read_reg(addr)
125
- return int.from_bytes(data, byteorder='big', signed=False)
138
+ data, flags = self.read_reg(addr)
139
+ return int.from_bytes(data, byteorder='big', signed=False), flags
126
140
 
127
141
 
128
142
  def write_reg(self, addr:hex, val:int):
@@ -143,13 +157,12 @@ class TmcComSpi(TmcCom):
143
157
  self._w_frame[4] = 0xFF & val
144
158
  # self.w_frame[7] = compute_crc8_atm(self.w_frame[:-1])
145
159
 
146
- self._spi.xfer2(self._w_frame)
160
+ self.spi.xfer2(self._w_frame)
147
161
 
148
162
 
149
163
  def write_reg_check(self, addr:hex, val:int, tries:int=10):
150
- """this function als writes a value to the register of the TMC
151
- but it also checks if the writing process was successfully by checking
152
- the InterfaceTransmissionCounter before and after writing
164
+ """IFCNT is disabled in SPI mode. Therefore, no check is possible.
165
+ This only calls the write_reg function
153
166
 
154
167
  Args:
155
168
  addr: HEX, which register to write
@@ -165,7 +178,13 @@ class TmcComSpi(TmcCom):
165
178
 
166
179
  def handle_error(self):
167
180
  """error handling"""
168
- raise NotImplementedError
181
+ if self.error_handler_running:
182
+ return
183
+ self.error_handler_running = True
184
+ self._tmc_registers["gstat"].read()
185
+ self._tmc_registers["gstat"].log(self.tmc_logger)
186
+ self._tmc_registers["gstat"].check()
187
+ raise TmcDriverException("TMC220X: unknown error detected")
169
188
 
170
189
 
171
190
  def test_com(self, addr):
@@ -174,4 +193,12 @@ class TmcComSpi(TmcCom):
174
193
  Args:
175
194
  addr (int): HEX, which register to test
176
195
  """
177
- raise NotImplementedError
196
+ self._tmc_registers["ioin"].read()
197
+ self._tmc_registers["ioin"].log(self.tmc_logger)
198
+ if self._tmc_registers["ioin"].data_int == 0:
199
+ self._tmc_logger.log("No answer from TMC received", Loglevel.ERROR)
200
+ return False
201
+ if self._tmc_registers["ioin"].version < 0x40:
202
+ self._tmc_logger.log("No correct Version from TMC received", Loglevel.ERROR)
203
+ return False
204
+ return True
@@ -2,13 +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
- import sys
10
10
  import serial
11
11
  from ._tmc_com import *
12
+ from .._tmc_exceptions import TmcComException, TmcDriverException
12
13
 
13
14
 
14
15
 
@@ -59,13 +60,13 @@ class TmcComUart(TmcCom):
59
60
  if errnum == 2:
60
61
  self._tmc_logger.log(f""""{self.ser.serialport} does not exist.
61
62
  You need to activate the serial port with \"sudo raspi-config\"""", Loglevel.ERROR)
62
- sys.exit()
63
+ raise SystemExit from e
63
64
 
64
65
  if errnum == 13:
65
66
  self._tmc_logger.log("""you have no permission to use the serial port.
66
67
  You may need to add your user to the dialout group
67
68
  with \"sudo usermod -a -G dialout pi\"""", Loglevel.ERROR)
68
- sys.exit()
69
+ raise SystemExit from e
69
70
 
70
71
  # adjust per baud and hardware. Sequential reads without some delay fail.
71
72
  self.communication_pause = 500 / self.ser.baudrate
@@ -96,6 +97,9 @@ class TmcComUart(TmcCom):
96
97
 
97
98
  Args:
98
99
  register (int): HEX, which register to read
100
+ Returns:
101
+ int: register value
102
+ Dict: flags
99
103
  """
100
104
  if self.ser is None:
101
105
  self._tmc_logger.log("Cannot read reg, serial is not initialized", Loglevel.ERROR)
@@ -122,7 +126,7 @@ class TmcComUart(TmcCom):
122
126
 
123
127
  time.sleep(self.communication_pause)
124
128
 
125
- return rtn
129
+ return rtn, None
126
130
 
127
131
 
128
132
  def read_int(self, addr:hex, tries:int = 10):
@@ -132,13 +136,16 @@ class TmcComUart(TmcCom):
132
136
  Args:
133
137
  addr (int): HEX, which register to read
134
138
  tries (int): how many tries, before error is raised (Default value = 10)
139
+ Returns:
140
+ int: register value
141
+ Dict: flags
135
142
  """
136
143
  if self.ser is None:
137
144
  self._tmc_logger.log("Cannot read int, serial is not initialized", Loglevel.ERROR)
138
145
  return -1
139
146
  while True:
140
147
  tries -= 1
141
- rtn = self.read_reg(addr)
148
+ rtn, flags = self.read_reg(addr)
142
149
  rtn_data = rtn[7:11]
143
150
  not_zero_count = len([elem for elem in rtn if elem != 0])
144
151
 
@@ -153,13 +160,13 @@ class TmcComUart(TmcCom):
153
160
 
154
161
  if tries<=0:
155
162
  self._tmc_logger.log("after 10 tries not valid answer", Loglevel.ERROR)
156
- self._tmc_logger.log(f"snd:\t{bytes(self.r_frame)}", Loglevel.DEBUG)
163
+ self._tmc_logger.log(f"addr:\t{addr}", Loglevel.DEBUG)
157
164
  self._tmc_logger.log(f"rtn:\t{rtn}", Loglevel.DEBUG)
158
165
  self.handle_error()
159
166
  return -1
160
167
 
161
168
  val = struct.unpack(">i",rtn_data)[0]
162
- return val
169
+ return val, flags
163
170
 
164
171
 
165
172
  def write_reg(self, addr:hex, val:int):
@@ -232,7 +239,7 @@ class TmcComUart(TmcCom):
232
239
  if tries<=0:
233
240
  self._tmc_logger.log("after 10 tries no valid write access", Loglevel.ERROR)
234
241
  self.handle_error()
235
- return -1
242
+ return False
236
243
 
237
244
 
238
245
  def flush_serial_buffer(self):
@@ -250,9 +257,9 @@ class TmcComUart(TmcCom):
250
257
  self.error_handler_running = True
251
258
  self._tmc_registers["gstat"].read()
252
259
  self._tmc_registers["gstat"].log(self.tmc_logger)
260
+ self._tmc_registers["gstat"].check()
261
+ raise TmcDriverException("TMC220X: unknown error detected")
253
262
 
254
- self._tmc_logger.log("EXITING!", Loglevel.INFO)
255
- raise SystemExit
256
263
 
257
264
 
258
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"""
@@ -17,6 +17,7 @@ class TmcReg():
17
17
  _tmc_com: TmcCom
18
18
  _reg_map: typing.List
19
19
  _data_int: int
20
+ _flags: typing.Dict
20
21
 
21
22
 
22
23
  @property
@@ -39,6 +40,11 @@ class TmcReg():
39
40
  """data_int property"""
40
41
  return self._data_int
41
42
 
43
+ @property
44
+ def flags(self) -> typing.Dict:
45
+ """flags property"""
46
+ return self._flags
47
+
42
48
 
43
49
  def __init__(self, address:hex, name:str, tmc_com:TmcCom, reg_map:typing.List):
44
50
  """Constructor"""
@@ -54,8 +60,6 @@ class TmcReg():
54
60
  Args:
55
61
  data (int): register value
56
62
  """
57
- self._data_int = data
58
-
59
63
  for reg in self._reg_map:
60
64
  name, pos, mask, reg_class, _, _ = reg
61
65
  value = data >> pos & mask
@@ -93,8 +97,13 @@ class TmcReg():
93
97
 
94
98
  def read(self):
95
99
  """read this register"""
96
- data = self._tmc_com.read_int(self._addr)
100
+ data, flags = self._tmc_com.read_int(self._addr)
101
+
102
+ self._data_int = data
103
+ self._flags = flags
104
+
97
105
  self.deserialise(data)
106
+ return data, flags
98
107
 
99
108
 
100
109
  def write(self):
@@ -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
 
@@ -18,9 +18,8 @@ class TestTmcComSpi(unittest.TestCase):
18
18
 
19
19
  def test_read_int(self):
20
20
  """test_read_int"""
21
- with mock.patch.object(TmcComSpi, 'read_reg', return_value=
22
- b'U\xc0\x1e\x00\x00\xca'):
23
- reg_ans = self.tmc_uart.read_int(0x00)
21
+ with mock.patch.object(TmcComSpi, 'read_reg', return_value= (b'U\xc0\x1e\x00\x00\xca', None)):
22
+ reg_ans, _ = self.tmc_uart.read_int(0x00)
24
23
  self.assertEqual(reg_ans, 94283625398474, "read_int is wrong")
25
24
 
26
25
 
@@ -19,9 +19,8 @@ class TestTmcComUart(unittest.TestCase):
19
19
  def test_read_int(self):
20
20
  """test_read_int"""
21
21
  self.tmc_uart.ser = 1 # to avoid early return, due to ser being None
22
- with mock.patch.object(TmcComUart, 'read_reg', return_value=
23
- b'U\x00o\x03\x05\xffo\xc0\x1e\x00\x00\xca'):
24
- reg_ans = self.tmc_uart.read_int(0x00)
22
+ with mock.patch.object(TmcComUart, 'read_reg', return_value= (b'U\x00o\x03\x05\xffo\xc0\x1e\x00\x00\xca', None)):
23
+ reg_ans, _ = self.tmc_uart.read_int(0x00)
25
24
  self.assertEqual(reg_ans, -1071775744, "read_int is wrong")
26
25
 
27
26
 
File without changes