PyTmcStepper 0.7.1__tar.gz → 0.7.3__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.3}/PKG-INFO +23 -18
  2. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/README.md +22 -17
  3. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/setup.cfg +1 -1
  4. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3/src/PyTmcStepper.egg-info}/PKG-INFO +23 -18
  5. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/SOURCES.txt +1 -0
  6. pytmcstepper-0.7.3/src/tmc_driver/_tmc_stallguard.py +139 -0
  7. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_stepperdriver.py +7 -6
  8. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/com/_tmc_com.py +6 -0
  9. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/com/_tmc_com_spi.py +54 -27
  10. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/com/_tmc_com_uart.py +13 -8
  11. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +2 -2
  12. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +3 -3
  13. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc224x_reg.py +5 -5
  14. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc_reg.py +14 -5
  15. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_2209.py +20 -135
  16. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_220x.py +4 -0
  17. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_2240.py +30 -128
  18. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/tests/test_tmc_com_spi.py +2 -3
  19. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/tests/test_tmc_com_uart.py +2 -3
  20. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/LICENSE +0 -0
  21. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/pyproject.toml +0 -0
  22. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  23. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  24. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  25. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/__init__.py +0 -0
  26. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_gpio_board.py +0 -0
  27. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_logger.py +0 -0
  28. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_math.py +0 -0
  29. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/com/__init__.py +0 -0
  30. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/__init__.py +0 -0
  31. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  32. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  33. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
  34. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/__init__.py +0 -0
  35. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  36. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
  37. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/reg/__init__.py +0 -0
  38. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  39. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc220x_reg.py +0 -0
  40. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_2208.py +0 -0
  41. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/tests/test_tmc2209.py +0 -0
  42. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/tests/test_tmc2240.py +0 -0
  43. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/tests/test_tmc_ec_pin.py +0 -0
  44. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/tests/test_tmc_math.py +0 -0
  45. {pytmcstepper-0.7.1 → pytmcstepper-0.7.3}/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.3
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
 
@@ -96,7 +96,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
96
  gpiozero | RASPBERRY_PI5 | Pi5
97
97
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
98
  pheriphery | LUCKFOX_PICO | Luckfox Pico
99
- pheriphery | LUCKFOX_PICO | Luckfox Pico
100
99
  OPi.GPIO | ORANGE_PI | Orange Pi
101
100
 
102
101
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -123,20 +122,24 @@ is split into their own classes to be able to support the diverse methods.
123
122
 
124
123
  ### EnableControl
125
124
 
125
+ 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.
126
+
126
127
  EnableControl | Class | Driver | Notes
127
128
  -- | -- | -- | --
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).
129
+ 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
+ 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
131
 
131
132
  ### MotionControl
132
133
 
134
+ 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.
135
+
133
136
  MotionControl | Class | Driver | Notes
134
137
  -- | -- | -- | --
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.
138
+ STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
139
+ STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
140
+ 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
141
 
139
- Further methods of controlling a motor could be:
142
+ Further methods of controlling the motion of a motor could be:
140
143
 
141
144
  - using the built in Motion Controller of the TMC5130
142
145
  - via a µC which controlls the Motor
@@ -146,8 +149,8 @@ Further methods of controlling a motor could be:
146
149
 
147
150
  Com | Class | Driver | Notes
148
151
  -- | -- | -- | --
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
152
+ 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
153
+ 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
154
 
152
155
  ## Wiring
153
156
 
@@ -159,10 +162,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
159
162
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
160
163
  VM | RED | 12V or 24V of power supply | power for the motor
161
164
  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
165
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
166
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
167
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
168
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
166
169
 
167
170
  The GPIO pins can be specific when initiating the class.
168
171
  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.
@@ -209,23 +212,25 @@ if not, check the connection of the pin.
209
212
 
210
213
  ### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
211
214
 
212
- This script should move the motor 6 times, one revolution back and forth.
215
+ This script shows the different functions available to move the motors.
216
+ The motor is moved 4 times one revolution back and forth.
213
217
 
214
218
  ### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
215
219
 
216
- In this script the stallguard feature of the TMC2209 is beeing setup.
220
+ In this script the stallguard feature of the TMC2209 is being setup.
217
221
  A funtion will be called, if the driver detects a stall. The function stops the current movement.
218
222
  The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs ```Movement finished successfully```.
219
223
  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
224
 
221
225
  ### [demo_script_05_vactual.py](demo/demo_script_05_vactual.py)
222
226
 
223
- VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]
227
+ 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
228
 
225
229
  ### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
226
230
 
227
231
  Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins.
228
232
  Simultaneous movement of multiple motors can be done with threaded movement.
233
+ When using SPI different Drivers are accessed via the Chip Select pin.
229
234
 
230
235
  ### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
231
236
 
@@ -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
 
@@ -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,20 +92,24 @@ 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
- 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).
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
+ 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
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
- 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.
108
+ STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
109
+ STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
110
+ 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
111
 
109
- Further methods of controlling a motor could be:
112
+ Further methods of controlling the motion of a motor could be:
110
113
 
111
114
  - using the built in Motion Controller of the TMC5130
112
115
  - via a µC which controlls the Motor
@@ -116,8 +119,8 @@ Further methods of controlling a motor could be:
116
119
 
117
120
  Com | Class | Driver | Notes
118
121
  -- | -- | -- | --
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
122
+ 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
123
+ 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
124
 
122
125
  ## Wiring
123
126
 
@@ -129,10 +132,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
129
132
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
130
133
  VM | RED | 12V or 24V of power supply | power for the motor
131
134
  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
135
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
136
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
137
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
138
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
136
139
 
137
140
  The GPIO pins can be specific when initiating the class.
138
141
  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.
@@ -179,23 +182,25 @@ if not, check the connection of the pin.
179
182
 
180
183
  ### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
181
184
 
182
- This script should move the motor 6 times, one revolution back and forth.
185
+ This script shows the different functions available to move the motors.
186
+ The motor is moved 4 times one revolution back and forth.
183
187
 
184
188
  ### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
185
189
 
186
- In this script the stallguard feature of the TMC2209 is beeing setup.
190
+ In this script the stallguard feature of the TMC2209 is being setup.
187
191
  A funtion will be called, if the driver detects a stall. The function stops the current movement.
188
192
  The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs ```Movement finished successfully```.
189
193
  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
194
 
191
195
  ### [demo_script_05_vactual.py](demo/demo_script_05_vactual.py)
192
196
 
193
- VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]
197
+ 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
198
 
195
199
  ### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
196
200
 
197
201
  Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins.
198
202
  Simultaneous movement of multiple motors can be done with threaded movement.
203
+ When using SPI different Drivers are accessed via the Chip Select pin.
199
204
 
200
205
  ### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
201
206
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = PyTmcStepper
3
- version = 0.7.1
3
+ version = 0.7.3
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.3
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
 
@@ -96,7 +96,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
96
  gpiozero | RASPBERRY_PI5 | Pi5
97
97
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
98
  pheriphery | LUCKFOX_PICO | Luckfox Pico
99
- pheriphery | LUCKFOX_PICO | Luckfox Pico
100
99
  OPi.GPIO | ORANGE_PI | Orange Pi
101
100
 
102
101
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -123,20 +122,24 @@ is split into their own classes to be able to support the diverse methods.
123
122
 
124
123
  ### EnableControl
125
124
 
125
+ 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.
126
+
126
127
  EnableControl | Class | Driver | Notes
127
128
  -- | -- | -- | --
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).
129
+ 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
+ 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
131
 
131
132
  ### MotionControl
132
133
 
134
+ 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.
135
+
133
136
  MotionControl | Class | Driver | Notes
134
137
  -- | -- | -- | --
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.
138
+ STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
139
+ STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
140
+ 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
141
 
139
- Further methods of controlling a motor could be:
142
+ Further methods of controlling the motion of a motor could be:
140
143
 
141
144
  - using the built in Motion Controller of the TMC5130
142
145
  - via a µC which controlls the Motor
@@ -146,8 +149,8 @@ Further methods of controlling a motor could be:
146
149
 
147
150
  Com | Class | Driver | Notes
148
151
  -- | -- | -- | --
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
152
+ 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
153
+ 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
154
 
152
155
  ## Wiring
153
156
 
@@ -159,10 +162,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
159
162
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
160
163
  VM | RED | 12V or 24V of power supply | power for the motor
161
164
  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
165
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
166
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
167
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
168
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
166
169
 
167
170
  The GPIO pins can be specific when initiating the class.
168
171
  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.
@@ -209,23 +212,25 @@ if not, check the connection of the pin.
209
212
 
210
213
  ### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
211
214
 
212
- This script should move the motor 6 times, one revolution back and forth.
215
+ This script shows the different functions available to move the motors.
216
+ The motor is moved 4 times one revolution back and forth.
213
217
 
214
218
  ### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
215
219
 
216
- In this script the stallguard feature of the TMC2209 is beeing setup.
220
+ In this script the stallguard feature of the TMC2209 is being setup.
217
221
  A funtion will be called, if the driver detects a stall. The function stops the current movement.
218
222
  The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs ```Movement finished successfully```.
219
223
  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
224
 
221
225
  ### [demo_script_05_vactual.py](demo/demo_script_05_vactual.py)
222
226
 
223
- VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]
227
+ 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
228
 
225
229
  ### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
226
230
 
227
231
  Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins.
228
232
  Simultaneous movement of multiple motors can be done with threaded movement.
233
+ When using SPI different Drivers are accessed via the Chip Select pin.
229
234
 
230
235
  ### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
231
236
 
@@ -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
@@ -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