aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/input_shaper.py
diff options
context:
space:
mode:
authorDmitry Butyugin <dmbutyugin@google.com>2023-02-20 01:18:57 +0100
committerKevinOConnor <kevin@koconnor.net>2023-06-06 20:17:49 -0400
commit345934bd681caf11a52810291d9255d6987c6e7a (patch)
tree19a2a9b8324d703c5dc049370dc8e81306461f2d /klippy/extras/input_shaper.py
parent98ed0a8168d88e013ab3fb7809a3c1af0de11fbe (diff)
downloadkutter-345934bd681caf11a52810291d9255d6987c6e7a.tar.gz
kutter-345934bd681caf11a52810291d9255d6987c6e7a.tar.xz
kutter-345934bd681caf11a52810291d9255d6987c6e7a.zip
idex_modes: Native input shaping support with dual carriages
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Diffstat (limited to 'klippy/extras/input_shaper.py')
-rw-r--r--klippy/extras/input_shaper.py62
1 files changed, 36 insertions, 26 deletions
diff --git a/klippy/extras/input_shaper.py b/klippy/extras/input_shaper.py
index 2eebb59c..fdfdf546 100644
--- a/klippy/extras/input_shaper.py
+++ b/klippy/extras/input_shaper.py
@@ -61,7 +61,6 @@ class AxisInputShaper:
self.params.update(gcmd)
old_n, old_A, old_T = self.n, self.A, self.T
self.n, self.A, self.T = self.params.get_shaper()
- return (old_n, old_A, old_T) != (self.n, self.A, self.T)
def set_shaper_kinematics(self, sk):
ffi_main, ffi_lib = chelper.get_ffi()
success = ffi_lib.input_shaper_set_shaper_params(
@@ -98,7 +97,7 @@ class InputShaper:
self.toolhead = None
self.shapers = [AxisInputShaper('x', config),
AxisInputShaper('y', config)]
- self.stepper_kinematics = []
+ self.input_shaper_stepper_kinematics = []
self.orig_stepper_kinematics = []
# Register gcode commands
gcode = self.printer.lookup_object('gcode')
@@ -109,38 +108,50 @@ class InputShaper:
return self.shapers
def connect(self):
self.toolhead = self.printer.lookup_object("toolhead")
- kin = self.toolhead.get_kinematics()
- # Lookup stepper kinematics
- ffi_main, ffi_lib = chelper.get_ffi()
- steppers = kin.get_steppers()
- for s in steppers:
- sk = ffi_main.gc(ffi_lib.input_shaper_alloc(), ffi_lib.free)
- orig_sk = s.set_stepper_kinematics(sk)
- res = ffi_lib.input_shaper_set_sk(sk, orig_sk)
- if res < 0:
- s.set_stepper_kinematics(orig_sk)
- continue
- self.stepper_kinematics.append(sk)
- self.orig_stepper_kinematics.append(orig_sk)
# Configure initial values
self.old_delay = 0.
self._update_input_shaping(error=self.printer.config_error)
+ def _get_input_shaper_stepper_kinematics(self, stepper):
+ # Lookup stepper kinematics
+ sk = stepper.get_stepper_kinematics()
+ if sk in self.orig_stepper_kinematics:
+ # Already processed this stepper kinematics unsuccessfully
+ return None
+ if sk in self.input_shaper_stepper_kinematics:
+ return sk
+ self.orig_stepper_kinematics.append(sk)
+ ffi_main, ffi_lib = chelper.get_ffi()
+ is_sk = ffi_main.gc(ffi_lib.input_shaper_alloc(), ffi_lib.free)
+ stepper.set_stepper_kinematics(is_sk)
+ res = ffi_lib.input_shaper_set_sk(is_sk, sk)
+ if res < 0:
+ stepper.set_stepper_kinematics(sk)
+ return None
+ self.input_shaper_stepper_kinematics.append(is_sk)
+ return is_sk
def _update_input_shaping(self, error=None):
self.toolhead.flush_step_generation()
new_delay = max([s.get_step_generation_window() for s in self.shapers])
self.toolhead.note_step_generation_scan_time(new_delay,
old_delay=self.old_delay)
- failed = []
- for sk in self.stepper_kinematics:
+ self.old_delay = new_delay
+ kin = self.toolhead.get_kinematics()
+ failed_shapers = []
+ for s in kin.get_steppers():
+ if s.get_trapq() is None:
+ continue
+ is_sk = self._get_input_shaper_stepper_kinematics(s)
+ if is_sk is None:
+ continue
for shaper in self.shapers:
- if shaper in failed:
+ if shaper in failed_shapers:
continue
- if not shaper.set_shaper_kinematics(sk):
- failed.append(shaper)
- if failed:
+ if not shaper.set_shaper_kinematics(is_sk):
+ failed_shapers.append(shaper)
+ if failed_shapers:
error = error or self.printer.command_error
raise error("Failed to configure shaper(s) %s with given parameters"
- % (', '.join([s.get_name() for s in failed])))
+ % (', '.join([s.get_name() for s in failed_shapers])))
def disable_shaping(self):
for shaper in self.shapers:
shaper.disable_shaping()
@@ -151,10 +162,9 @@ class InputShaper:
self._update_input_shaping()
cmd_SET_INPUT_SHAPER_help = "Set cartesian parameters for input shaper"
def cmd_SET_INPUT_SHAPER(self, gcmd):
- updated = False
- for shaper in self.shapers:
- updated |= shaper.update(gcmd)
- if updated:
+ if gcmd.get_command_parameters():
+ for shaper in self.shapers:
+ shaper.update(gcmd)
self._update_input_shaping()
for shaper in self.shapers:
shaper.report(gcmd)