8
8
"""
9
9
10
10
import statistics
11
- import types
12
11
from .tmc_220x import *
13
12
from ._tmc_stallguard import StallGuard
14
- from ._tmc_gpio_board import GpioPUD
15
13
from .reg ._tmc2209_reg import *
16
14
17
15
@@ -89,7 +87,7 @@ def __del__(self):
89
87
90
88
# Tmc2209 methods
91
89
# ----------------------------
92
- def do_homing (self , diag_pin , revolutions = 10 , threshold = None , speed_rpm = None ) -> bool :
90
+ def do_homing (self , diag_pin , revolutions = 10 , threshold = 100 , speed_rpm = None ) -> bool :
93
91
"""homes the motor in the given direction using stallguard.
94
92
this method is using vactual to move the motor and an interrupt on the DIAG pin
95
93
@@ -107,10 +105,7 @@ def do_homing(self, diag_pin, revolutions = 10, threshold = None, speed_rpm = No
107
105
self .tmc_logger .log ("do_homing only works with VActual register control via COM" , Loglevel .ERROR )
108
106
return False
109
107
110
- if threshold is not None :
111
- self ._sg_threshold = threshold
112
-
113
- self .tmc_logger .log (f"Stallguard threshold: { self ._sg_threshold } " , Loglevel .DEBUG )
108
+ self .tmc_logger .log (f"Stallguard threshold: { threshold } " , Loglevel .DEBUG )
114
109
115
110
if speed_rpm is None :
116
111
speed_rpm = tmc_math .steps_to_rps (self .tmc_mc .max_speed_homing , self .tmc_mc .steps_per_rev )* 60
@@ -125,7 +120,7 @@ def do_homing(self, diag_pin, revolutions = 10, threshold = None, speed_rpm = No
125
120
mc_homing .tmc_com = self .tmc_com
126
121
mc_homing .tmc_logger = self .tmc_logger
127
122
128
- self .set_stallguard_callback (diag_pin , self . _sg_threshold , mc_homing .stop ,
123
+ self .set_stallguard_callback (diag_pin , threshold , mc_homing .stop ,
129
124
0.5 * tmc_math .rps_to_steps (speed_rpm / 60 , self .tmc_mc .steps_per_rev ))
130
125
131
126
homing_failed = mc_homing .set_vactual_rpm (speed_rpm , revolutions = revolutions )
@@ -142,7 +137,7 @@ def do_homing(self, diag_pin, revolutions = 10, threshold = None, speed_rpm = No
142
137
143
138
144
139
145
- def do_homing2 (self , revolutions , threshold = None ):
140
+ def do_homing2 (self , revolutions = 10 , threshold = 100 ):
146
141
"""homes the motor in the given direction using stallguard
147
142
old function, uses STEP/DIR to move the motor and pulls the StallGuard result
148
143
from the interface
@@ -156,13 +151,10 @@ def do_homing2(self, revolutions, threshold=None):
156
151
return
157
152
sgresults = []
158
153
159
- if threshold is not None :
160
- self ._sg_threshold = threshold
161
-
162
154
self .tmc_logger .log ("---" , Loglevel .INFO )
163
155
self .tmc_logger .log ("homing" , Loglevel .INFO )
164
156
165
- self .tmc_logger .log (f"Stallguard threshold: { self . _sg_threshold } " , Loglevel .DEBUG )
157
+ self .tmc_logger .log (f"Stallguard threshold: { threshold } " , Loglevel .DEBUG )
166
158
167
159
self .tmc_mc .set_direction_pin (revolutions > 0 )
168
160
@@ -192,7 +184,7 @@ def do_homing2(self, revolutions, threshold=None):
192
184
sgresults .append (sgresult )
193
185
if len (sgresults )> 20 :
194
186
sgresult_average = statistics .mean (sgresults [- 6 :])
195
- if sgresult_average < self . _sg_threshold :
187
+ if sgresult_average < threshold :
196
188
break
197
189
198
190
if step_counter < self .tmc_mc .steps_per_rev :
0 commit comments