Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homing: allow homing_accel to be configurable #474

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for the try/finally here?
since we dont catch any errors we are going into estop if one occurs so no need for the finally right?

Also wouldnt it be cleaner to use with instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to make sure that homing_accel always resets regardless of the deeper exceptions

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
4 changes: 4 additions & 0 deletions klippy/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ def __init__(
"min_home_dist", self.homing_retract_dist, minval=0.0
)

self.homing_accel = config.getfloat("homing_accel", None, above=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 +509,7 @@ def get_homing_info(self):
"second_homing_speed",
"use_sensorless_homing",
"min_home_dist",
"accel",
],
)(
self.homing_speed,
Expand All @@ -517,6 +520,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
3 changes: 3 additions & 0 deletions test/klippy/tmc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ endstop_pin: tmc5160_stepper_y:virtual_endstop
position_endstop: 0
position_max: 210
use_sensorless_homing: true
homing_speed: 100
homing_accel: 1000


[tmc5160 stepper_y]
cs_pin: PG2
Expand Down
Loading