Skip to content

Commit

Permalink
sensorless: consolidate set_current methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Jun 15, 2024
1 parent 1f7a1ba commit 42534ba
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions klippy/extras/homing.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,41 +253,24 @@ def _fill_coord(self, coord):
def set_homed_position(self, pos):
self.toolhead.set_position(self._fill_coord(pos))

def _set_current_homing(self, homing_axes):
def _set_current_homing(self, homing_axes, pre_homing):
print_time = self.toolhead.get_last_move_time()
affected_rails = set()
for axis in homing_axes:
axis_name = "xyz"[axis] # only works for cartesian
partial_rails = self.toolhead.get_active_rails_for_axis(axis_name)
affected_rails = affected_rails | set(partial_rails)

dwell_time = None
dwell_time = 0.0
for rail in affected_rails:
chs = rail.get_tmc_current_helpers()
for ch in chs:
if ch is not None and ch.needs_home_current_change():
if dwell_time is None:
dwell_time = ch.current_change_dwell_time
ch.set_current_for_homing(print_time)
if dwell_time:
self.toolhead.dwell(dwell_time)

def _set_current_post_homing(self, homing_axes):
print_time = self.toolhead.get_last_move_time()
affected_rails = set()
for axis in homing_axes:
axis_name = "xyz"[axis] # only works for cartesian
partial_rails = self.toolhead.get_active_rails_for_axis(axis_name)
affected_rails = affected_rails | set(partial_rails)

dwell_time = None
for rail in affected_rails:
chs = rail.get_tmc_current_helpers()
for ch in chs:
if ch is not None and ch.needs_run_current_change():
if dwell_time is None:
dwell_time = ch.current_change_dwell_time
ch.set_current_for_normal(print_time)
dwell_time = max(dwell_time, ch.current_change_dwell_time)
if pre_homing:
ch.set_current_for_homing(print_time)
else:
ch.set_current_for_normal(print_time)
if dwell_time:
self.toolhead.dwell(dwell_time)

Expand All @@ -304,7 +287,7 @@ def home_rails(self, rails, forcepos, movepos):
hi = rails[0].get_homing_info()
hmove = HomingMove(self.printer, endstops)

self._set_current_homing(homing_axes)
self._set_current_homing(homing_axes, pre_homing=True)

hmove.homing_move(homepos, hi.speed)

Expand Down Expand Up @@ -367,7 +350,8 @@ def home_rails(self, rails, forcepos, movepos):
hp - ad * retract_r for hp, ad in zip(homepos, axes_d)
]
self.toolhead.move(retractpos, hi.retract_speed)
self._set_current_post_homing(homing_axes)

self._set_current_homing(homing_axes, pre_homing=False)
# Signal home operation complete
self.toolhead.flush_step_generation()
self.trigger_mcu_pos = {
Expand Down

0 comments on commit 42534ba

Please sign in to comment.