Skip to content

Commit

Permalink
Merge pull request #5 from elpopo-eng/main
Browse files Browse the repository at this point in the history
Suppress double home for each attempt
  • Loading branch information
Anonoei authored Nov 3, 2023
2 parents e575cac + d856a6e commit aa1d8bb
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions auto_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def __init__(self):
self.margin: float = None
self.accel: float = 0.0
self.veloc: float = 0.0


self.home_steps: float = None

self.tries: int = 0
self.move: Move = None
self.move_dist: float = 0.0
Expand Down Expand Up @@ -270,8 +272,9 @@ def __init__(self, config):

def handle_connect(self):
self.toolhead = self.printer.lookup_object('toolhead')
self.th_accel = self.toolhead.max_accel
self.th_veloc = self.toolhead.max_velocity
# Reduce speed/acceleration for positioning movement
self.th_accel = self.toolhead.max_accel/2
self.th_veloc = self.toolhead.max_velocity/2

# Find and define leveling method
if self.printer.lookup_object("screw_tilt_adjust", None) is not None:
Expand Down Expand Up @@ -693,6 +696,7 @@ def binary_search(self, aw: AttemptWrapper):
measuring = True
measured_val = None
aw.tries = 0
aw.home_steps, aw.move_time_prehome = self._prehome(aw.move.home)
while measuring:
aw.tries += 1
if aw.type in ("accel", "graph"):
Expand Down Expand Up @@ -740,7 +744,6 @@ def binary_search(self, aw: AttemptWrapper):

def _attempt(self, aw: AttemptWrapper):
timeAttempt = perf_counter()
start_steps, aw.move_time_prehome = self._pretest(aw.move.home)

self._set_velocity(self.th_veloc, self.th_accel)
self._move([aw.move.pos["x"][0], aw.move.pos["y"][0], aw.move.pos["z"][0]], self.th_veloc)
Expand All @@ -753,7 +756,7 @@ def _attempt(self, aw: AttemptWrapper):
aw.move_time = perf_counter() - timeMove
aw.move_dist = aw.move.dist

valid, aw.missed, aw.move_time_posthome = self._posttest(start_steps, aw.max_missed, aw.move.home)
valid, aw.home_steps, aw.missed, aw.move_time_posthome = self._posttest(aw.home_steps, aw.max_missed, aw.move.home)
aw.time_last = perf_counter() - timeAttempt
return valid

Expand Down Expand Up @@ -881,15 +884,15 @@ def _get_steps(self):
pos[s_name[-1]] = s.get_mcu_position()
return pos

def _pretest(self, home: list):
def _prehome(self, home: list):
self.toolhead.wait_moves()
dur = perf_counter()
self._home(home[0], home[1], home[2])
self.toolhead.wait_moves()
dur = perf_counter() - dur

start_steps = self._get_steps()
return start_steps, dur
home_steps = self._get_steps()
return home_steps, dur

def _posttest(self, start_steps, max_missed, home: list):
self.toolhead.wait_moves()
Expand Down Expand Up @@ -918,7 +921,7 @@ def _posttest(self, start_steps, max_missed, home: list):
if missed["z"] > max_missed:
valid = False

return valid, missed, dur
return valid, stop_steps, missed, dur

def _set_velocity(self, velocity: float, accel: float):
#self.gcode.respond_info(f"AUTO SPEED setting limits to VELOCITY={velocity} ACCEL={accel}")
Expand Down

0 comments on commit aa1d8bb

Please sign in to comment.