Skip to content

Commit

Permalink
homing: allow homing_accel to be configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz committed Dec 23, 2024
1 parent b0c0ce6 commit a0ce69c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
3 changes: 3 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ position_max:
#homing_speed: 5.0
# Maximum velocity (in mm/s) of the stepper when homing. The default
# is 5mm/s.
#homing_accel:
# Maximum accel (in mm/s) of the stepper when homing. The default
# is to use the max accel configured in the [printer]'s object.
#homing_retract_dist: 5.0
# Distance to backoff (in mm) before homing a second time during
# homing. If `use_sensorless_homing` is false, this setting can be set
Expand Down
47 changes: 32 additions & 15 deletions klippy/extras/homing.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ 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, pre_homing):
def _set_homing_accel(self, accel, pre_homing):
if accel is None:
return
if pre_homing:
self.toolhead.set_accel(accel)
else:
self.toolhead.reset_accel()

def _set_homing_current(self, homing_axes, pre_homing):
print_time = self.toolhead.get_last_move_time()
affected_rails = set()
for axis in homing_axes:
Expand Down Expand Up @@ -312,10 +320,13 @@ def home_rails(self, rails, forcepos, movepos):
hi = rails[0].get_homing_info()
hmove = HomingMove(self.printer, endstops)

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

hmove.homing_move(homepos, hi.speed)
try:
self._set_homing_accel(hi.accel, pre_homing=True)
self._set_homing_current(homing_axes, pre_homing=True)
self._reset_endstop_states(endstops)
hmove.homing_move(homepos, hi.speed)
finally:
self._set_homing_accel(hi.accel, pre_homing=False)

needs_rehome = False
retract_dist = hi.retract_dist
Expand All @@ -337,15 +348,18 @@ def home_rails(self, rails, forcepos, movepos):
]
self.toolhead.move(retractpos, hi.retract_speed)
if not hi.use_sensorless_homing or needs_rehome:
# Home again
startpos = [
rp - ad * retract_r for rp, ad in zip(retractpos, axes_d)
]
self.toolhead.set_position(startpos)
self._reset_endstop_states(endstops)
hmove = HomingMove(self.printer, endstops)
hmove.homing_move(homepos, hi.second_homing_speed)
try:
# Home again
startpos = [
rp - ad * retract_r
for rp, ad in zip(retractpos, axes_d)
]
self.toolhead.set_position(startpos)
self._reset_endstop_states(endstops)

hmove = HomingMove(self.printer, endstops)
hmove.homing_move(homepos, hi.second_homing_speed)

if hmove.check_no_movement() is not None:
raise self.printer.command_error(
"Endstop %s still triggered after retract"
Expand All @@ -362,7 +376,9 @@ def home_rails(self, rails, forcepos, movepos):
"Early homing trigger on second home!"
)
finally:
self._set_current_homing(homing_axes, pre_homing=False)
self._set_homing_accel(hi.accel, pre_homing=False)
self._set_homing_current(homing_axes, pre_homing=False)

if hi.retract_dist:
# Retract (again)
startpos = self._fill_coord(forcepos)
Expand All @@ -375,7 +391,8 @@ def home_rails(self, rails, forcepos, movepos):
]
self.toolhead.move(retractpos, hi.retract_speed)

self._set_current_homing(homing_axes, pre_homing=False)
self._set_homing_accel(hi.accel, pre_homing=False)
self._set_homing_current(homing_axes, pre_homing=False)
# Signal home operation complete
self.toolhead.flush_step_generation()
self.trigger_mcu_pos = {
Expand Down
6 changes: 6 additions & 0 deletions klippy/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ def __init__(
"min_home_dist", self.homing_retract_dist, minval=0.0
)

self.homing_accel = config.get("homing_accel", None)
if self.homing_accel is not None:
self.homing_accel = config.getfloat("homing_accel", minval=0.0)

if self.homing_positive_dir is None:
axis_len = self.position_max - self.position_min
if self.position_endstop <= self.position_min + axis_len / 4.0:
Expand Down Expand Up @@ -507,6 +511,7 @@ def get_homing_info(self):
"second_homing_speed",
"use_sensorless_homing",
"min_home_dist",
"accel",
],
)(
self.homing_speed,
Expand All @@ -517,6 +522,7 @@ def get_homing_info(self):
self.second_homing_speed,
self.use_sensorless_homing,
self.min_home_dist,
self.homing_accel,
)
return homing_info

Expand Down
8 changes: 8 additions & 0 deletions klippy/toolhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,14 @@ def cmd_M204(self, gcmd):
self.max_accel = accel
self._calc_junction_deviation()

def set_accel(self, accel):
self.max_accel = accel
self._calc_junction_deviation()

def reset_accel(self):
self.max_accel = self.orig_cfg["max_accel"]
self._calc_junction_deviation()


def add_printer_objects(config):
config.get_printer().add_object("toolhead", ToolHead(config))
Expand Down

0 comments on commit a0ce69c

Please sign in to comment.