PyTmcStepper 0.7.1__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {pytmcstepper-0.7.1/src/PyTmcStepper.egg-info → pytmcstepper-0.7.2}/PKG-INFO +14 -12
  2. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/README.md +13 -11
  3. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/setup.cfg +1 -1
  4. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2/src/PyTmcStepper.egg-info}/PKG-INFO +14 -12
  5. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/PyTmcStepper.egg-info/SOURCES.txt +1 -0
  6. pytmcstepper-0.7.2/src/tmc_driver/_tmc_stallguard.py +139 -0
  7. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/_tmc_stepperdriver.py +7 -6
  8. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +2 -2
  9. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +3 -3
  10. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/reg/_tmc224x_reg.py +5 -5
  11. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/reg/_tmc_reg.py +2 -2
  12. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/tmc_2209.py +20 -135
  13. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/tmc_220x.py +4 -0
  14. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/tmc_2240.py +30 -128
  15. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/LICENSE +0 -0
  16. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/pyproject.toml +0 -0
  17. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  18. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  19. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  20. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/__init__.py +0 -0
  21. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/_tmc_gpio_board.py +0 -0
  22. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/_tmc_logger.py +0 -0
  23. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/_tmc_math.py +0 -0
  24. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/com/__init__.py +0 -0
  25. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/com/_tmc_com.py +0 -0
  26. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
  27. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
  28. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/enable_control/__init__.py +0 -0
  29. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  30. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  31. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
  32. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/motion_control/__init__.py +0 -0
  33. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  34. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
  35. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/reg/__init__.py +0 -0
  36. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  37. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/reg/_tmc220x_reg.py +0 -0
  38. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/src/tmc_driver/tmc_2208.py +0 -0
  39. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc2209.py +0 -0
  40. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc2240.py +0 -0
  41. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc_com_spi.py +0 -0
  42. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc_com_uart.py +0 -0
  43. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc_ec_pin.py +0 -0
  44. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc_math.py +0 -0
  45. {pytmcstepper-0.7.1 → pytmcstepper-0.7.2}/tests/test_tmc_move.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyTmcStepper
3
- Version: 0.7.1
3
+ Version: 0.7.2
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Home-page: https://github.com/Chr157i4n/PyTmcStepper
6
6
  Author: Christian Köhlke
@@ -58,7 +58,7 @@ The Documentation of the TMC2209 can be found here:
58
58
 
59
59
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
60
60
 
61
- ## Installation
61
+ ## Installation (on Raspberry Pi)
62
62
 
63
63
  ### Installation with PIP
64
64
 
@@ -125,16 +125,16 @@ is split into their own classes to be able to support the diverse methods.
125
125
 
126
126
  EnableControl | Class | Driver | Notes
127
127
  -- | -- | -- | --
128
- Pin | TmcEnableControlPin | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
129
- TOff | TmcEnableControlToff | all | the EN Pin needs to be connected to GND.<br />On the TMC2209 this enables current Output on Startup!<br />On the TMC2240 this works fine, because TOff is per default 0 (off).
128
+ 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
129
+ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_toff.py) | all | the EN Pin needs to be connected to GND.<br />On the TMC2209 this enables current Output on Startup!<br />On the TMC2240 this works fine, because TOff is per default 0 (off).
130
130
 
131
131
  ### MotionControl
132
132
 
133
133
  MotionControl | Class | Driver | Notes
134
134
  -- | -- | -- | --
135
- STEP/DIR | TmcMotionControlStepDir | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
136
- STEP/REG | TmcMotionControlStepReg | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
137
- VACTUAL | TmcMotionControlVActual | 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.
135
+ 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
+ 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
+ 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.
138
138
 
139
139
  Further methods of controlling a motor could be:
140
140
 
@@ -146,8 +146,8 @@ Further methods of controlling a motor could be:
146
146
 
147
147
  Com | Class | Driver | Notes
148
148
  -- | -- | -- | --
149
- UART | TmcComUart | all | Communication via UART (RX, TX). See [Wiring](#uart)<br />[pyserial](https://pypi.org/project/pyserial) needs to be installed
150
- SPI | TmcComSpi | TMC2240 | Communication via SPI (MOSI, MISO, CLK, CS). See [Wiring](#spi)<br />[spidev](https://pypi.org/project/spidev) needs to be installed
149
+ UART | [TmcComUart](src/tmc_driver/com/_tmc_com_uart.py) | all | Communication via UART (RX, TX). See [Wiring](#uart)<br />[pyserial](https://pypi.org/project/pyserial) needs to be installed
150
+ SPI | [TmcComSpi](src/tmc_driver/com/_tmc_com_spi.py) | TMC2240 | Communication via SPI (MOSI, MISO, CLK, CS). See [Wiring](#spi)<br />[spidev](https://pypi.org/project/spidev) needs to be installed
151
151
 
152
152
  ## Wiring
153
153
 
@@ -209,23 +209,25 @@ if not, check the connection of the pin.
209
209
 
210
210
  ### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
211
211
 
212
- This script should move the motor 6 times, one revolution back and forth.
212
+ This script shows the different functions available to move the motors.
213
+ The motor is moved 4 times one revolution back and forth.
213
214
 
214
215
  ### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
215
216
 
216
- In this script the stallguard feature of the TMC2209 is beeing setup.
217
+ In this script the stallguard feature of the TMC2209 is being setup.
217
218
  A funtion will be called, if the driver detects a stall. The function stops the current movement.
218
219
  The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs ```Movement finished successfully```.
219
220
  If you block the motor with pliers or something similar, the the motor will stop and the script outputs ```StallGuard!``` and ```Movement was not completed```
220
221
 
221
222
  ### [demo_script_05_vactual.py](demo/demo_script_05_vactual.py)
222
223
 
223
- VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]
224
+ VACTUAL enables the motor to be moved via the COM interface (UART) without additional GPIOs. The motor speed is transmitted as a value in +-(2^23)-1 [µsteps / t] via the COM interface.
224
225
 
225
226
  ### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
226
227
 
227
228
  Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins.
228
229
  Simultaneous movement of multiple motors can be done with threaded movement.
230
+ When using SPI different Drivers are accessed via the Chip Select pin.
229
231
 
230
232
  ### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
231
233
 
@@ -28,7 +28,7 @@ The Documentation of the TMC2209 can be found here:
28
28
 
29
29
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
30
30
 
31
- ## Installation
31
+ ## Installation (on Raspberry Pi)
32
32
 
33
33
  ### Installation with PIP
34
34
 
@@ -95,16 +95,16 @@ is split into their own classes to be able to support the diverse methods.
95
95
 
96
96
  EnableControl | Class | Driver | Notes
97
97
  -- | -- | -- | --
98
- Pin | TmcEnableControlPin | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
99
- TOff | TmcEnableControlToff | all | the EN Pin needs to be connected to GND.<br />On the TMC2209 this enables current Output on Startup!<br />On the TMC2240 this works fine, because TOff is per default 0 (off).
98
+ 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
99
+ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_toff.py) | all | the EN Pin needs to be connected to GND.<br />On the TMC2209 this enables current Output on Startup!<br />On the TMC2240 this works fine, because TOff is per default 0 (off).
100
100
 
101
101
  ### MotionControl
102
102
 
103
103
  MotionControl | Class | Driver | Notes
104
104
  -- | -- | -- | --
105
- STEP/DIR | TmcMotionControlStepDir | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
106
- STEP/REG | TmcMotionControlStepReg | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
107
- VACTUAL | TmcMotionControlVActual | 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.
105
+ 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
+ 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
+ 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.
108
108
 
109
109
  Further methods of controlling a motor could be:
110
110
 
@@ -116,8 +116,8 @@ Further methods of controlling a motor could be:
116
116
 
117
117
  Com | Class | Driver | Notes
118
118
  -- | -- | -- | --
119
- UART | TmcComUart | all | Communication via UART (RX, TX). See [Wiring](#uart)<br />[pyserial](https://pypi.org/project/pyserial) needs to be installed
120
- SPI | TmcComSpi | TMC2240 | Communication via SPI (MOSI, MISO, CLK, CS). See [Wiring](#spi)<br />[spidev](https://pypi.org/project/spidev) needs to be installed
119
+ UART | [TmcComUart](src/tmc_driver/com/_tmc_com_uart.py) | all | Communication via UART (RX, TX). See [Wiring](#uart)<br />[pyserial](https://pypi.org/project/pyserial) needs to be installed
120
+ SPI | [TmcComSpi](src/tmc_driver/com/_tmc_com_spi.py) | TMC2240 | Communication via SPI (MOSI, MISO, CLK, CS). See [Wiring](#spi)<br />[spidev](https://pypi.org/project/spidev) needs to be installed
121
121
 
122
122
  ## Wiring
123
123
 
@@ -179,23 +179,25 @@ if not, check the connection of the pin.
179
179
 
180
180
  ### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
181
181
 
182
- This script should move the motor 6 times, one revolution back and forth.
182
+ This script shows the different functions available to move the motors.
183
+ The motor is moved 4 times one revolution back and forth.
183
184
 
184
185
  ### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
185
186
 
186
- In this script the stallguard feature of the TMC2209 is beeing setup.
187
+ In this script the stallguard feature of the TMC2209 is being setup.
187
188
  A funtion will be called, if the driver detects a stall. The function stops the current movement.
188
189
  The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs ```Movement finished successfully```.
189
190
  If you block the motor with pliers or something similar, the the motor will stop and the script outputs ```StallGuard!``` and ```Movement was not completed```
190
191
 
191
192
  ### [demo_script_05_vactual.py](demo/demo_script_05_vactual.py)
192
193
 
193
- VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]
194
+ VACTUAL enables the motor to be moved via the COM interface (UART) without additional GPIOs. The motor speed is transmitted as a value in +-(2^23)-1 [µsteps / t] via the COM interface.
194
195
 
195
196
  ### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
196
197
 
197
198
  Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins.
198
199
  Simultaneous movement of multiple motors can be done with threaded movement.
200
+ When using SPI different Drivers are accessed via the Chip Select pin.
199
201
 
200
202
  ### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
201
203
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = PyTmcStepper
3
- version = 0.7.1
3
+ version = 0.7.2
4
4
  author = Christian Köhlke
5
5
  author_email = christian@koehlke.de
6
6
  description = This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyTmcStepper
3
- Version: 0.7.1
3
+ Version: 0.7.2
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Home-page: https://github.com/Chr157i4n/PyTmcStepper
6
6
  Author: Christian Köhlke
@@ -58,7 +58,7 @@ The Documentation of the TMC2209 can be found here:
58
58
 
59
59
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
60
60
 
61
- ## Installation
61
+ ## Installation (on Raspberry Pi)
62
62
 
63
63
  ### Installation with PIP
64
64
 
@@ -125,16 +125,16 @@ is split into their own classes to be able to support the diverse methods.
125
125
 
126
126
  EnableControl | Class | Driver | Notes
127
127
  -- | -- | -- | --
128
- Pin | TmcEnableControlPin | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
129
- TOff | TmcEnableControlToff | all | the EN Pin needs to be connected to GND.<br />On the TMC2209 this enables current Output on Startup!<br />On the TMC2240 this works fine, because TOff is per default 0 (off).
128
+ 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
129
+ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_toff.py) | all | the EN Pin needs to be connected to GND.<br />On the TMC2209 this enables current Output on Startup!<br />On the TMC2240 this works fine, because TOff is per default 0 (off).
130
130
 
131
131
  ### MotionControl
132
132
 
133
133
  MotionControl | Class | Driver | Notes
134
134
  -- | -- | -- | --
135
- STEP/DIR | TmcMotionControlStepDir | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
136
- STEP/REG | TmcMotionControlStepReg | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
137
- VACTUAL | TmcMotionControlVActual | 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.
135
+ 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
+ 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
+ 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.
138
138
 
139
139
  Further methods of controlling a motor could be:
140
140
 
@@ -146,8 +146,8 @@ Further methods of controlling a motor could be:
146
146
 
147
147
  Com | Class | Driver | Notes
148
148
  -- | -- | -- | --
149
- UART | TmcComUart | all | Communication via UART (RX, TX). See [Wiring](#uart)<br />[pyserial](https://pypi.org/project/pyserial) needs to be installed
150
- SPI | TmcComSpi | TMC2240 | Communication via SPI (MOSI, MISO, CLK, CS). See [Wiring](#spi)<br />[spidev](https://pypi.org/project/spidev) needs to be installed
149
+ UART | [TmcComUart](src/tmc_driver/com/_tmc_com_uart.py) | all | Communication via UART (RX, TX). See [Wiring](#uart)<br />[pyserial](https://pypi.org/project/pyserial) needs to be installed
150
+ SPI | [TmcComSpi](src/tmc_driver/com/_tmc_com_spi.py) | TMC2240 | Communication via SPI (MOSI, MISO, CLK, CS). See [Wiring](#spi)<br />[spidev](https://pypi.org/project/spidev) needs to be installed
151
151
 
152
152
  ## Wiring
153
153
 
@@ -209,23 +209,25 @@ if not, check the connection of the pin.
209
209
 
210
210
  ### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
211
211
 
212
- This script should move the motor 6 times, one revolution back and forth.
212
+ This script shows the different functions available to move the motors.
213
+ The motor is moved 4 times one revolution back and forth.
213
214
 
214
215
  ### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
215
216
 
216
- In this script the stallguard feature of the TMC2209 is beeing setup.
217
+ In this script the stallguard feature of the TMC2209 is being setup.
217
218
  A funtion will be called, if the driver detects a stall. The function stops the current movement.
218
219
  The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs ```Movement finished successfully```.
219
220
  If you block the motor with pliers or something similar, the the motor will stop and the script outputs ```StallGuard!``` and ```Movement was not completed```
220
221
 
221
222
  ### [demo_script_05_vactual.py](demo/demo_script_05_vactual.py)
222
223
 
223
- VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]
224
+ VACTUAL enables the motor to be moved via the COM interface (UART) without additional GPIOs. The motor speed is transmitted as a value in +-(2^23)-1 [µsteps / t] via the COM interface.
224
225
 
225
226
  ### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
226
227
 
227
228
  Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins.
228
229
  Simultaneous movement of multiple motors can be done with threaded movement.
230
+ When using SPI different Drivers are accessed via the Chip Select pin.
229
231
 
230
232
  ### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
231
233
 
@@ -11,6 +11,7 @@ src/tmc_driver/__init__.py
11
11
  src/tmc_driver/_tmc_gpio_board.py
12
12
  src/tmc_driver/_tmc_logger.py
13
13
  src/tmc_driver/_tmc_math.py
14
+ src/tmc_driver/_tmc_stallguard.py
14
15
  src/tmc_driver/_tmc_stepperdriver.py
15
16
  src/tmc_driver/tmc_2208.py
16
17
  src/tmc_driver/tmc_2209.py
@@ -0,0 +1,139 @@
1
+ #pylint: disable=too-many-arguments
2
+ #pylint: disable=too-many-public-methods
3
+ #pylint: disable=too-many-branches
4
+ #pylint: disable=too-many-instance-attributes
5
+ #pylint: disable=too-many-positional-arguments
6
+ #pylint: disable=bare-except
7
+ #pylint: disable=no-member
8
+ #pylint: disable=unused-import
9
+ #pylint: disable=wildcard-import
10
+ #pylint: disable=unused-wildcard-import
11
+ """StallGuard mixin
12
+ """
13
+
14
+ import types
15
+ from ._tmc_stepperdriver import *
16
+ from .com._tmc_com import TmcCom
17
+ from ._tmc_gpio_board import GpioPUD, GpioMode
18
+ from ._tmc_logger import Loglevel
19
+ from .reg._tmc224x_reg import *
20
+ from . import _tmc_math as tmc_math
21
+
22
+
23
+
24
+
25
+
26
+ class StallGuard():
27
+ """StallGuard
28
+
29
+ This class is used to control the stallguard feature of the TMC stepper driver.
30
+ The drivers class needs to inherit from this class to use the stallguard feature (mixin).
31
+ """
32
+ tmc_com:TmcCom = None
33
+
34
+ _pin_stallguard:int = None
35
+ _sg_callback:types.FunctionType = None
36
+
37
+
38
+
39
+ def set_stallguard_callback(self, pin_stallguard, threshold, callback,
40
+ min_speed = 100):
41
+ """set a function to call back, when the driver detects a stall
42
+ via stallguard
43
+ high value on the diag pin can also mean a driver error
44
+
45
+ Args:
46
+ pin_stallguard (int): pin needs to be connected to DIAG
47
+ threshold (int): value for SGTHRS
48
+ callback (func): will be called on StallGuard trigger
49
+ min_speed (int): min speed [steps/s] for StallGuard (Default value = 100)
50
+ """
51
+ self.tmc_logger.log(f"setup stallguard callback on GPIO {pin_stallguard}", Loglevel.INFO)
52
+ self.tmc_logger.log(f"StallGuard Threshold: {threshold} | minimum Speed: {min_speed}", Loglevel.INFO)
53
+
54
+ self._set_stallguard_threshold(threshold)
55
+ self._set_coolstep_threshold(tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution()))
56
+ self._sg_callback = callback
57
+ self._pin_stallguard = pin_stallguard
58
+
59
+ tmc_gpio.gpio_setup(self._pin_stallguard, GpioMode.IN, pull_up_down=GpioPUD.PUD_DOWN)
60
+ # first remove existing events
61
+ tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
62
+ tmc_gpio.gpio_add_event_detect(self._pin_stallguard, self.stallguard_callback)
63
+
64
+
65
+
66
+ def stallguard_callback(self, gpio_pin):
67
+ """the callback function for StallGuard.
68
+ only checks whether the duration of the current movement is longer than
69
+ _sg_delay and then calls the actual callback
70
+
71
+ Args:
72
+ gpio_pin (int): pin number of the interrupt pin
73
+ """
74
+ del gpio_pin
75
+ if self._sg_callback is None:
76
+ self.tmc_logger.log("StallGuard callback is None", Loglevel.DEBUG)
77
+ return
78
+ self._sg_callback()
79
+
80
+
81
+
82
+ def enable_coolstep(self, semin_sg:int = 150, semax_sg:int = 200, seup:int = 1, sedn:int = 3, min_speed:int = 100):
83
+ """enables coolstep and sets the parameters for coolstep
84
+ The values for semin etc. can be tested with the test_stallguard_threshold function
85
+
86
+ Args:
87
+ semin_sg (int): lower threshold. Current will be increased if SG_Result goes below this
88
+ semax_sg (int): upper threshold. Current will be decreased if SG_Result goes above this
89
+ seup (int): current increment step
90
+ sedn (int): number of SG_Result readings for each current decrement
91
+ """
92
+ semax_sg = semax_sg - semin_sg
93
+
94
+ self.coolconf.read()
95
+ self.coolconf.semin = round(max(0, min(semin_sg/32, 15)))
96
+ self.coolconf.semax = round(max(0, min(semax_sg/32, 15)))
97
+ self.coolconf.seimin = 1 # scale down to until 1/4 of IRun (7 - 31)
98
+ self.coolconf.seup = seup
99
+ self.coolconf.sedn = sedn
100
+ self.coolconf.write_check()
101
+
102
+ self._set_coolstep_threshold(tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution()))
103
+
104
+
105
+
106
+ def get_stallguard_result(self):
107
+ """return the current stallguard result
108
+ its will be calculated with every fullstep
109
+ higher values means a lower motor load
110
+
111
+ Returns:
112
+ sgresult (int): StallGuard Result
113
+ """
114
+ self.sgresult.read()
115
+ return self.sgresult.sgresult
116
+
117
+
118
+
119
+ def _set_stallguard_threshold(self, threshold):
120
+ """sets the register bit "SGTHRS" to to a given value
121
+ this is needed for the stallguard interrupt callback
122
+ SGRESULT becomes compared to the double of this threshold.
123
+ SGRESULT ≤ SGTHRS*2
124
+
125
+ Args:
126
+ threshold (int): value for SGTHRS
127
+ """
128
+ self.sgthrs.modify("sgthrs", threshold)
129
+
130
+
131
+
132
+ def _set_coolstep_threshold(self, threshold):
133
+ """This is the lower threshold velocity for switching
134
+ on smart energy CoolStep and StallGuard to DIAG output. (unsigned)
135
+
136
+ Args:
137
+ threshold (int): threshold velocity for coolstep
138
+ """
139
+ self.tcoolthrs.modify("tcoolthrs", threshold)
@@ -253,20 +253,21 @@ class TmcStepperDriver:
253
253
  self.tmc_mc.acceleration_fullstep = acceleration_fullstep
254
254
 
255
255
 
256
- def run_to_position_steps(self, steps, movement_abs_rel:MovementAbsRel = None):
256
+ def run_to_position_steps(self, steps, movement_abs_rel:MovementAbsRel = None) -> StopMode:
257
257
  """motioncontrol wrapper"""
258
258
  if self.tmc_mc is not None:
259
- self.tmc_mc.run_to_position_steps(steps, movement_abs_rel)
259
+ return self.tmc_mc.run_to_position_steps(steps, movement_abs_rel)
260
+ return None
260
261
 
261
262
 
262
- def run_to_position_fullsteps(self, steps, movement_abs_rel:MovementAbsRel = None):
263
+ def run_to_position_fullsteps(self, steps, movement_abs_rel:MovementAbsRel = None) -> StopMode:
263
264
  """motioncontrol wrapper"""
264
- self.run_to_position_steps(steps * self.mres, movement_abs_rel)
265
+ return self.run_to_position_steps(steps * self.mres, movement_abs_rel)
265
266
 
266
267
 
267
- def run_to_position_revolutions(self, revs, movement_abs_rel:MovementAbsRel = None):
268
+ def run_to_position_revolutions(self, revs, movement_abs_rel:MovementAbsRel = None) -> StopMode:
268
269
  """motioncontrol wrapper"""
269
- self.run_to_position_steps(revs * self.steps_per_rev, movement_abs_rel)
270
+ return self.run_to_position_steps(revs * self.steps_per_rev, movement_abs_rel)
270
271
 
271
272
 
272
273
  # StepperDriver methods
@@ -164,7 +164,7 @@ class TmcMotionControlStepDir(TmcMotionControl):
164
164
  tmc_gpio.gpio_output(self._pin_dir, direction.value)
165
165
 
166
166
 
167
- def run_to_position_steps(self, steps, movement_abs_rel:MovementAbsRel = None):
167
+ def run_to_position_steps(self, steps, movement_abs_rel:MovementAbsRel = None) -> StopMode:
168
168
  """runs the motor to the given position.
169
169
  with acceleration and deceleration
170
170
  blocks the code until finished or stopped from a different thread!
@@ -203,7 +203,7 @@ class TmcMotionControlStepDir(TmcMotionControl):
203
203
  return self._stop
204
204
 
205
205
 
206
- def run_to_position_revolutions(self, revolutions, movement_abs_rel:MovementAbsRel = None):
206
+ def run_to_position_revolutions(self, revolutions, movement_abs_rel:MovementAbsRel = None) -> StopMode:
207
207
  """runs the motor to the given position.
208
208
  with acceleration and deceleration
209
209
  blocks the code until finished!
@@ -72,7 +72,7 @@ class TmcMotionControlVActual(TmcMotionControl):
72
72
 
73
73
 
74
74
  def set_vactual_dur(self, vactual, duration=0, acceleration=0,
75
- show_stallguard_result=False, show_tstep=False):
75
+ show_stallguard_result=False, show_tstep=False) -> StopMode:
76
76
  """sets the register bit "VACTUAL" to to a given value
77
77
  VACTUAL allows moving the motor by UART control.
78
78
  It gives the motor velocity in +-(2^23)-1 [μsteps / t]
@@ -140,7 +140,7 @@ class TmcMotionControlVActual(TmcMotionControl):
140
140
  return self._stop
141
141
 
142
142
 
143
- def set_vactual_rps(self, rps, duration=0, revolutions=0, acceleration=0):
143
+ def set_vactual_rps(self, rps, duration=0, revolutions=0, acceleration=0) -> StopMode:
144
144
  """converts the rps parameter to a vactual value which represents
145
145
  rotation speed in revolutions per second
146
146
  With internal oscillator:
@@ -163,7 +163,7 @@ class TmcMotionControlVActual(TmcMotionControl):
163
163
  return self.set_vactual_dur(vactual, duration, acceleration=acceleration)
164
164
 
165
165
 
166
- def set_vactual_rpm(self, rpm, duration=0, revolutions=0, acceleration=0):
166
+ def set_vactual_rpm(self, rpm, duration=0, revolutions=0, acceleration=0) -> StopMode:
167
167
  """converts the rps parameter to a vactual value which represents
168
168
  rotation speed in revolutions per minute
169
169
 
@@ -294,7 +294,7 @@ class DrvStatus(TmcReg):
294
294
  ["stealth", 14, 0x1, bool, None, ""],
295
295
  ["s2vsb", 13, 0x1, bool, None, ""],
296
296
  ["s2vsa", 12, 0x1, bool, None, ""],
297
- ["sg_result", 0, 0x3FF, int, None, ""]
297
+ ["sgresult", 0, 0x3FF, int, None, ""]
298
298
  ]
299
299
  super().__init__(0x6F, "DRVSTATUS", tmc_com, reg_map)
300
300
 
@@ -320,9 +320,9 @@ class SgThrs(TmcReg):
320
320
  reg_map = [
321
321
  ["sg_angle_offset", 9, 0x1, bool, None, ""],
322
322
  ["sg4_filt_en", 8, 0x1, bool, None, ""],
323
- ["sg_thrs", 0, 0xFFF, int, None, ""]
323
+ ["sgthrs", 0, 0xFFF, int, None, ""]
324
324
  ]
325
- super().__init__(0x74, "SG_THRS", tmc_com, reg_map)
325
+ super().__init__(0x74, "SGTHRS", tmc_com, reg_map)
326
326
 
327
327
 
328
328
  class SgResult(TmcReg):
@@ -332,9 +332,9 @@ class SgResult(TmcReg):
332
332
  """constructor"""
333
333
 
334
334
  reg_map = [
335
- ["sg_result", 0, 0xFFFFF, int, None, ""]
335
+ ["sgresult", 0, 0xFFFFF, int, None, ""]
336
336
  ]
337
- super().__init__(0x75, "SG_RESULT", tmc_com, reg_map)
337
+ super().__init__(0x75, "SGRESULT", tmc_com, reg_map)
338
338
 
339
339
 
340
340
  class SgInd(TmcReg):
@@ -57,9 +57,9 @@ class TmcReg():
57
57
  self._data_int = data
58
58
 
59
59
  for reg in self._reg_map:
60
- name, pos, mask, _, _, _ = reg
60
+ name, pos, mask, reg_class, _, _ = reg
61
61
  value = data >> pos & mask
62
- setattr(self, name, reg[3](value))
62
+ setattr(self, name, reg_class(value))
63
63
 
64
64
 
65
65
  def serialise(self) -> int:
@@ -8,19 +8,14 @@
8
8
  """
9
9
 
10
10
  import statistics
11
- import types
12
11
  from .tmc_220x import *
13
- from ._tmc_gpio_board import GpioPUD
12
+ from ._tmc_stallguard import StallGuard
14
13
  from .reg._tmc2209_reg import *
15
14
 
16
15
 
17
- class Tmc2209(Tmc220x):
16
+ class Tmc2209(Tmc220x, StallGuard):
18
17
  """Tmc2209"""
19
18
 
20
- _pin_stallguard:int = None
21
- _sg_callback:types.FunctionType = None
22
- _sg_threshold:int = 100 # threshold for stallguard
23
-
24
19
 
25
20
 
26
21
  # Constructor/Destructor
@@ -78,6 +73,7 @@ class Tmc2209(Tmc220x):
78
73
  self.tmc_logger.log("TMC2209 Init finished", Loglevel.INFO)
79
74
 
80
75
 
76
+
81
77
  def __del__(self):
82
78
  """destructor"""
83
79
  if self._deinit_finished is False:
@@ -89,50 +85,9 @@ class Tmc2209(Tmc220x):
89
85
 
90
86
 
91
87
 
92
- def set_stallguard_callback(self, pin_stallguard, threshold, callback,
93
- min_speed = 100):
94
- """set a function to call back, when the driver detects a stall
95
- via stallguard
96
- high value on the diag pin can also mean a driver error
97
-
98
- Args:
99
- pin_stallguard (int): pin needs to be connected to DIAG
100
- threshold (int): value for SGTHRS
101
- callback (func): will be called on StallGuard trigger
102
- min_speed (int): min speed [steps/s] for StallGuard (Default value = 100)
103
- """
104
- self.tmc_logger.log(f"setup stallguard callback on GPIO {pin_stallguard}", Loglevel.INFO)
105
- self.tmc_logger.log(f"StallGuard Threshold: {threshold} | minimum Speed: {min_speed}", Loglevel.INFO)
106
-
107
- self._set_stallguard_threshold(threshold)
108
- self._set_coolstep_threshold(tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution()))
109
- self._sg_callback = callback
110
- self._pin_stallguard = pin_stallguard
111
-
112
- tmc_gpio.gpio_setup(self._pin_stallguard, GpioMode.IN, pull_up_down=GpioPUD.PUD_DOWN)
113
- # first remove existing events
114
- tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
115
- tmc_gpio.gpio_add_event_detect(self._pin_stallguard, self.stallguard_callback)
116
-
117
-
118
-
119
- def stallguard_callback(self, gpio_pin):
120
- """the callback function for StallGuard.
121
- only checks whether the duration of the current movement is longer than
122
- _sg_delay and then calls the actual callback
123
-
124
- Args:
125
- gpio_pin (int): pin number of the interrupt pin
126
- """
127
- del gpio_pin
128
- if self._sg_callback is None:
129
- self.tmc_logger.log("StallGuard callback is None", Loglevel.DEBUG)
130
- return
131
- self._sg_callback()
132
-
133
-
134
-
135
- def do_homing(self, diag_pin, revolutions = 10, threshold = None, speed_rpm = None) -> bool:
88
+ # Tmc2209 methods
89
+ # ----------------------------
90
+ def do_homing(self, diag_pin, revolutions = 10, threshold = 100, speed_rpm = None) -> bool:
136
91
  """homes the motor in the given direction using stallguard.
137
92
  this method is using vactual to move the motor and an interrupt on the DIAG pin
138
93
 
@@ -150,10 +105,7 @@ class Tmc2209(Tmc220x):
150
105
  self.tmc_logger.log("do_homing only works with VActual register control via COM", Loglevel.ERROR)
151
106
  return False
152
107
 
153
- if threshold is not None:
154
- self._sg_threshold = threshold
155
-
156
- self.tmc_logger.log(f"Stallguard threshold: {self._sg_threshold}", Loglevel.DEBUG)
108
+ self.tmc_logger.log(f"Stallguard threshold: {threshold}", Loglevel.DEBUG)
157
109
 
158
110
  if speed_rpm is None:
159
111
  speed_rpm = tmc_math.steps_to_rps(self.tmc_mc.max_speed_homing, self.tmc_mc.steps_per_rev)*60
@@ -168,7 +120,7 @@ class Tmc2209(Tmc220x):
168
120
  mc_homing.tmc_com = self.tmc_com
169
121
  mc_homing.tmc_logger = self.tmc_logger
170
122
 
171
- self.set_stallguard_callback(diag_pin, self._sg_threshold, mc_homing.stop,
123
+ self.set_stallguard_callback(diag_pin, threshold, mc_homing.stop,
172
124
  0.5*tmc_math.rps_to_steps(speed_rpm/60, self.tmc_mc.steps_per_rev))
173
125
 
174
126
  homing_failed = mc_homing.set_vactual_rpm(speed_rpm, revolutions=revolutions)
@@ -185,7 +137,7 @@ class Tmc2209(Tmc220x):
185
137
 
186
138
 
187
139
 
188
- def do_homing2(self, revolutions, threshold=None):
140
+ def do_homing2(self, revolutions = 10, threshold = 100):
189
141
  """homes the motor in the given direction using stallguard
190
142
  old function, uses STEP/DIR to move the motor and pulls the StallGuard result
191
143
  from the interface
@@ -197,15 +149,12 @@ class Tmc2209(Tmc220x):
197
149
  if not isinstance(self.tmc_mc, TmcMotionControlStepDir):
198
150
  self.tmc_logger.log("do_homing2 only works with STEP/DIR Control", Loglevel.ERROR)
199
151
  return
200
- sg_results = []
201
-
202
- if threshold is not None:
203
- self._sg_threshold = threshold
152
+ sgresults = []
204
153
 
205
154
  self.tmc_logger.log("---", Loglevel.INFO)
206
155
  self.tmc_logger.log("homing", Loglevel.INFO)
207
156
 
208
- self.tmc_logger.log(f"Stallguard threshold: {self._sg_threshold}", Loglevel.DEBUG)
157
+ self.tmc_logger.log(f"Stallguard threshold: {threshold}", Loglevel.DEBUG)
209
158
 
210
159
  self.tmc_mc.set_direction_pin(revolutions > 0)
211
160
 
@@ -231,88 +180,29 @@ class Tmc2209(Tmc220x):
231
180
  if self.tmc_mc.run_speed(): #returns true, when a step is made
232
181
  step_counter += 1
233
182
  self.tmc_mc.compute_new_speed()
234
- sg_result = self.get_stallguard_result()
235
- sg_results.append(sg_result)
236
- if len(sg_results)>20:
237
- sg_result_average = statistics.mean(sg_results[-6:])
238
- if sg_result_average < self._sg_threshold:
183
+ sgresult = self.get_stallguard_result()
184
+ sgresults.append(sgresult)
185
+ if len(sgresults)>20:
186
+ sgresult_average = statistics.mean(sgresults[-6:])
187
+ if sgresult_average < threshold:
239
188
  break
240
189
 
241
190
  if step_counter<self.tmc_mc.steps_per_rev:
242
191
  self.tmc_logger.log("homing successful",Loglevel.INFO)
243
192
  self.tmc_logger.log(f"Stepcounter: {step_counter}",Loglevel.DEBUG)
244
- self.tmc_logger.log(str(sg_results),Loglevel.DEBUG)
193
+ self.tmc_logger.log(str(sgresults),Loglevel.DEBUG)
245
194
  self.tmc_mc.current_pos = 0
246
195
  else:
247
196
  self.tmc_logger.log("homing failed", Loglevel.INFO)
248
197
  self.tmc_logger.log(f"Stepcounter: {step_counter}", Loglevel.DEBUG)
249
- self.tmc_logger.log(str(sg_results),Loglevel.DEBUG)
198
+ self.tmc_logger.log(str(sgresults),Loglevel.DEBUG)
250
199
 
251
200
  self.tmc_logger.log("---", Loglevel.INFO)
252
201
 
253
202
 
254
203
 
255
- def get_stallguard_result(self):
256
- """return the current stallguard result
257
- its will be calculated with every fullstep
258
- higher values means a lower motor load
259
-
260
- Returns:
261
- sg_result (int): StallGuard Result
262
- """
263
- self.sgresult.read()
264
- return self.sgresult.sgresult
265
-
266
-
267
-
268
- def _set_stallguard_threshold(self, threshold):
269
- """sets the register bit "SGTHRS" to to a given value
270
- this is needed for the stallguard interrupt callback
271
- SG_RESULT becomes compared to the double of this threshold.
272
- SG_RESULT ≤ SGTHRS*2
273
-
274
- Args:
275
- threshold (int): value for SGTHRS
276
- """
277
- self.sgthrs.modify("sgthrs", threshold)
278
-
279
-
280
-
281
- def _set_coolstep_threshold(self, threshold):
282
- """This is the lower threshold velocity for switching
283
- on smart energy CoolStep and StallGuard to DIAG output. (unsigned)
284
-
285
- Args:
286
- threshold (int): threshold velocity for coolstep
287
- """
288
- self.tcoolthrs.modify("tcoolthrs", threshold)
289
-
290
-
291
-
292
- def enable_coolstep(self, semin_sg:int = 150, semax_sg:int = 200, seup:int = 1, sedn:int = 3, min_speed:int = 100):
293
- """enables coolstep and sets the parameters for coolstep
294
- The values for semin etc. can be tested with the test_stallguard_threshold function
295
-
296
- Args:
297
- semin_sg (int): lower threshold. Current will be increased if SG_Result goes below this
298
- semax_sg (int): upper threshold. Current will be decreased if SG_Result goes above this
299
- seup (int): current increment step
300
- sedn (int): number of SG_Result readings for each current decrement
301
- """
302
- semax_sg = semax_sg - semin_sg
303
-
304
- self.coolconf.read()
305
- self.coolconf.semin = round(max(0, min(semin_sg/32, 15)))
306
- self.coolconf.semax = round(max(0, min(semax_sg/32, 15)))
307
- self.coolconf.seimin = 1 # scale down to until 1/4 of IRun (7 - 31)
308
- self.coolconf.seup = seup
309
- self.coolconf.sedn = sedn
310
- self.coolconf.write_check()
311
-
312
- self._set_coolstep_threshold(tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution()))
313
-
314
-
315
-
204
+ # Test methods
205
+ # ----------------------------
316
206
  def test_stallguard_threshold(self, steps):
317
207
  """test method for tuning stallguard threshold
318
208
 
@@ -322,7 +212,6 @@ class Tmc2209(Tmc220x):
322
212
  Args:
323
213
  steps (int):
324
214
  """
325
-
326
215
  self.tmc_logger.log("---", Loglevel.INFO)
327
216
  self.tmc_logger.log("test_stallguard_threshold", Loglevel.INFO)
328
217
 
@@ -339,14 +228,10 @@ class Tmc2209(Tmc220x):
339
228
  stallguard_result = self.get_stallguard_result()
340
229
  self.drvstatus.read()
341
230
  cs_actual = self.drvstatus.cs_actual
342
- # stallguard_result = self.get_stallguard_result()
343
231
 
344
232
  self.tmc_logger.log(f"{self.tmc_mc.movement_phase} | {stallguard_result} | {cs_actual}",
345
233
  Loglevel.INFO)
346
234
 
347
- self.tmc_logger.log(f"{self.tmc_mc.movement_phase} | {stallguard_result}",
348
- Loglevel.INFO)
349
-
350
235
  if (self.tmc_mc.movement_phase == MovementPhase.ACCELERATING and
351
236
  stallguard_result < min_stallguard_result_accel):
352
237
  min_stallguard_result_accel = stallguard_result
@@ -45,6 +45,7 @@ class Tmc220x(TmcStepperDriver):
45
45
  tmc_com:TmcComUart = None
46
46
 
47
47
 
48
+
48
49
  # Constructor/Destructor
49
50
  # ----------------------------
50
51
  def __init__(self,
@@ -151,6 +152,7 @@ class Tmc220x(TmcStepperDriver):
151
152
  self._deinit_finished = True
152
153
 
153
154
 
155
+
154
156
  # Tmc220x methods
155
157
  # ----------------------------
156
158
  def read_steps_per_rev(self) -> int:
@@ -622,6 +624,8 @@ class Tmc220x(TmcStepperDriver):
622
624
 
623
625
 
624
626
 
627
+ # Test methods
628
+ # ----------------------------
625
629
  def test_pin(self, pin, ioin_reg_bp):
626
630
  """tests one pin
627
631
 
@@ -26,6 +26,7 @@ from ._tmc_gpio_board import GpioPUD
26
26
  from .motion_control._tmc_mc_step_reg import TmcMotionControlStepReg
27
27
  from .enable_control._tmc_ec_toff import TmcEnableControlToff
28
28
  from .motion_control._tmc_mc_vactual import TmcMotionControlVActual
29
+ from ._tmc_stallguard import StallGuard
29
30
  from ._tmc_logger import TmcLogger, Loglevel
30
31
  from .reg._tmc224x_reg import *
31
32
  from . import _tmc_math as tmc_math
@@ -34,7 +35,7 @@ from . import _tmc_math as tmc_math
34
35
 
35
36
 
36
37
 
37
- class Tmc2240(TmcStepperDriver):
38
+ class Tmc2240(TmcStepperDriver, StallGuard):
38
39
  """Tmc220X
39
40
 
40
41
  this class has two different functions:
@@ -49,6 +50,7 @@ class Tmc2240(TmcStepperDriver):
49
50
  _sg_threshold:int = 100 # threshold for stallguard
50
51
 
51
52
 
53
+
52
54
  # Constructor/Destructor
53
55
  # ----------------------------
54
56
  def __init__(self,
@@ -163,7 +165,8 @@ class Tmc2240(TmcStepperDriver):
163
165
  self._deinit_finished = True
164
166
 
165
167
 
166
- # Tmc220x methods
168
+
169
+ # Tmc224x methods
167
170
  # ----------------------------
168
171
  def read_steps_per_rev(self) -> int:
169
172
  """returns how many steps are needed for one revolution.
@@ -514,20 +517,6 @@ class Tmc2240(TmcStepperDriver):
514
517
 
515
518
 
516
519
 
517
- def set_vactual(self, vactual:int):
518
- """sets the register bit "VACTUAL" to to a given value
519
- VACTUAL allows moving the motor by UART control.
520
- It gives the motor velocity in +-(2^23)-1 [μsteps / t]
521
- 0: Normal operation. Driver reacts to STEP input
522
-
523
- Args:
524
- vactual (int): value for VACTUAL
525
- """
526
- self.vactual.vactual = vactual
527
- self.vactual.write_check()
528
-
529
-
530
-
531
520
  def get_microstep_counter(self) -> int:
532
521
  """returns the current Microstep counter.
533
522
  Indicates actual position in the microstep table for CUR_A
@@ -557,110 +546,47 @@ class Tmc2240(TmcStepperDriver):
557
546
 
558
547
 
559
548
 
560
- def set_stallguard_callback(self, pin_stallguard, threshold, callback,
561
- min_speed = 100):
562
- """set a function to call back, when the driver detects a stall
563
- via stallguard
564
- high value on the diag pin can also mean a driver error
565
-
566
- Args:
567
- pin_stallguard (int): pin needs to be connected to DIAG
568
- threshold (int): value for SGTHRS
569
- callback (func): will be called on StallGuard trigger
570
- min_speed (int): min speed [steps/s] for StallGuard (Default value = 100)
571
- """
572
- self.tmc_logger.log(f"setup stallguard callback on GPIO {pin_stallguard}", Loglevel.INFO)
573
- self.tmc_logger.log(f"StallGuard Threshold: {threshold} | minimum Speed: {min_speed}", Loglevel.INFO)
574
-
575
- self._set_stallguard_threshold(threshold)
576
- self._set_coolstep_threshold(tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution()))
577
- self._sg_callback = callback
578
- self._pin_stallguard = pin_stallguard
579
-
580
- tmc_gpio.gpio_setup(self._pin_stallguard, GpioMode.IN, pull_up_down=GpioPUD.PUD_DOWN)
581
- # first remove existing events
582
- tmc_gpio.gpio_remove_event_detect(self._pin_stallguard)
583
- tmc_gpio.gpio_add_event_detect(self._pin_stallguard, self.stallguard_callback)
584
-
585
-
586
-
587
- def stallguard_callback(self, gpio_pin):
588
- """the callback function for StallGuard.
589
- only checks whether the duration of the current movement is longer than
590
- _sg_delay and then calls the actual callback
591
-
592
- Args:
593
- gpio_pin (int): pin number of the interrupt pin
594
- """
595
- del gpio_pin
596
- if self._sg_callback is None:
597
- self.tmc_logger.log("StallGuard callback is None", Loglevel.DEBUG)
598
- return
599
- self._sg_callback()
600
-
601
-
602
-
603
- def _set_coolstep_threshold(self, threshold):
604
- """This is the lower threshold velocity for switching
605
- on smart energy CoolStep and StallGuard to DIAG output. (unsigned)
606
-
607
- Args:
608
- threshold (int): threshold velocity for coolstep
609
- """
610
- self.tcoolthrs.modify("tcoolthrs", threshold)
611
-
612
-
613
-
614
- def enable_coolstep(self, semin_sg:int = 150, semax_sg:int = 200, seup:int = 1, sedn:int = 3, min_speed:int = 100):
615
- """enables coolstep and sets the parameters for coolstep
616
- The values for semin etc. can be tested with the test_stallguard_threshold function
549
+ def get_vsupply(self) -> int:
550
+ """reads the ADC_VSUPPLY_AIN register
617
551
 
618
- Args:
619
- semin_sg (int): lower threshold. Current will be increased if SG_Result goes below this
620
- semax_sg (int): upper threshold. Current will be decreased if SG_Result goes above this
621
- seup (int): current increment step
622
- sedn (int): number of SG_Result readings for each current decrement
552
+ Returns:
553
+ int: ADC_VSUPPLY_AIN register value
623
554
  """
624
- semax_sg = semax_sg - semin_sg
625
-
626
- self.coolconf.read()
627
- self.coolconf.semin = round(max(0, min(semin_sg/32, 15)))
628
- self.coolconf.semax = round(max(0, min(semax_sg/32, 15)))
629
- self.coolconf.seimin = 1 # scale down to until 1/4 of IRun (7 - 31)
630
- self.coolconf.seup = seup
631
- self.coolconf.sedn = sedn
632
- self.coolconf.write_check()
633
-
634
- self._set_coolstep_threshold(tmc_math.steps_to_tstep(min_speed, self.get_microstepping_resolution()))
555
+ self.adcv_supply_ain.read()
556
+ return self.adcv_supply_ain.adc_vsupply_v
635
557
 
636
558
 
637
559
 
638
- def get_stallguard_result(self):
639
- """return the current stallguard result
640
- its will be calculated with every fullstep
641
- higher values means a lower motor load
560
+ def get_temperature(self) -> float:
561
+ """reads the ADC_TEMP register and returns the temperature
642
562
 
643
563
  Returns:
644
- sg_result (int): StallGuard Result
564
+ float: temperature in °C
645
565
  """
646
- self.sg_result.read()
647
- return self.sg_result.sg_result
566
+ self.adc_temp.read()
567
+ return self.adc_temp.adc_temp_c
648
568
 
649
569
 
650
570
 
651
- def _set_stallguard_threshold(self, threshold):
652
- """sets the register bit "SGTHRS" to to a given value
653
- this is needed for the stallguard interrupt callback
654
- SG_RESULT becomes compared to the double of this threshold.
655
- SG_RESULT ≤ SGTHRS*2
571
+ def set_stallguard_callback(self, pin_stallguard, threshold, callback,
572
+ min_speed = 100):
573
+ """set a function to call back, when the driver detects a stall
574
+ via stallguard
575
+ high value on the diag pin can also mean a driver error
656
576
 
657
577
  Args:
578
+ pin_stallguard (int): pin needs to be connected to DIAG
658
579
  threshold (int): value for SGTHRS
580
+ callback (func): will be called on StallGuard trigger
581
+ min_speed (int): min speed [steps/s] for StallGuard (Default value = 100)
659
582
  """
660
- self.sg_thrs.modify("sg_thrs", threshold)
661
-
583
+ super().set_stallguard_callback(pin_stallguard, threshold, callback, min_speed)
584
+ self.gconf.modify("diag0_stall", 1)
585
+ self.gconf.modify("diag0_pushpull", 1)
662
586
 
663
587
 
588
+ # Test methods
589
+ # ----------------------------
664
590
  def test_stallguard_threshold(self, steps):
665
591
  """test method for tuning stallguard threshold
666
592
 
@@ -670,7 +596,6 @@ class Tmc2240(TmcStepperDriver):
670
596
  Args:
671
597
  steps (int):
672
598
  """
673
-
674
599
  self.tmc_logger.log("---", Loglevel.INFO)
675
600
  self.tmc_logger.log("test_stallguard_threshold", Loglevel.INFO)
676
601
 
@@ -685,10 +610,9 @@ class Tmc2240(TmcStepperDriver):
685
610
 
686
611
  while self.tmc_mc.movement_phase != MovementPhase.STANDSTILL:
687
612
  self.drvstatus.read()
688
- stallguard_result = self.drvstatus.sg_result
613
+ stallguard_result = self.drvstatus.sgresult
689
614
  stallguard_triggered = self.drvstatus.stallguard
690
615
  cs_actual = self.drvstatus.cs_actual
691
- # stallguard_result = self.get_stallguard_result()
692
616
 
693
617
  self.tmc_logger.log(f"{self.tmc_mc.movement_phase} | {stallguard_result} | {stallguard_triggered} | {cs_actual}",
694
618
  Loglevel.INFO)
@@ -716,28 +640,6 @@ class Tmc2240(TmcStepperDriver):
716
640
 
717
641
 
718
642
 
719
- def get_vsupply(self) -> int:
720
- """reads the ADC_VSUPPLY_AIN register
721
-
722
- Returns:
723
- int: ADC_VSUPPLY_AIN register value
724
- """
725
- self.adcv_supply_ain.read()
726
- return self.adcv_supply_ain.adc_vsupply_v
727
-
728
-
729
-
730
- def get_temperature(self) -> float:
731
- """reads the ADC_TEMP register and returns the temperature
732
-
733
- Returns:
734
- float: temperature in °C
735
- """
736
- self.adc_temp.read()
737
- return self.adc_temp.adc_temp_c
738
-
739
-
740
-
741
643
  def test_pin(self, pin, ioin_reg_bp):
742
644
  """tests one pin
743
645
 
File without changes