aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-01-26 13:26:14 -0500
committerKevinOConnor <kevin@koconnor.net>2019-10-01 14:46:24 -0400
commit698159921f91a872c4eb7b5c66c3021d2dd26c4b (patch)
tree5abcc99c63fb0c628c5d4770b434200a66423fa8
parent1b8a007969603fd00959e525c94b1a41f93280d3 (diff)
downloadkutter-698159921f91a872c4eb7b5c66c3021d2dd26c4b.tar.gz
kutter-698159921f91a872c4eb7b5c66c3021d2dd26c4b.tar.xz
kutter-698159921f91a872c4eb7b5c66c3021d2dd26c4b.zip
tuning_tower: Tool for tuning parameters based on print Z height
This adds a testing tool that can run a command on each Z layer of a print. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--docs/G-Codes.md8
-rw-r--r--klippy/extras/tuning_tower.py72
-rw-r--r--klippy/toolhead.py1
3 files changed, 81 insertions, 0 deletions
diff --git a/docs/G-Codes.md b/docs/G-Codes.md
index cf5f2784..247a960a 100644
--- a/docs/G-Codes.md
+++ b/docs/G-Codes.md
@@ -160,6 +160,14 @@ The following standard commands are supported:
for calibrating a Z position_endstop config setting. See the
MANUAL_PROBE command for details on the parameters and the
additional commands available while the tool is active.
+- `TUNING_TOWER COMMAND=<command> PARAMETER=<name> START=<value>
+ FACTOR=<value> [BAND=<value>]`: A tool for tuning a parameter on
+ each Z height during a print. The tool will run the given COMMAND
+ with the given PARAMETER assigned to the value using the formula
+ `value = start + factor * z_height`. If BAND is provided then the
+ adjustment will only be made every BAND millimeters of z height - in
+ that case the formula used is `value = start + factor *
+ ((floor(z_height / band) + .5) * band)`.
- `SET_IDLE_TIMEOUT [TIMEOUT=<timeout>]`: Allows the user to set the
idle timeout (in seconds).
- `RESTART`: This will cause the host software to reload its config
diff --git a/klippy/extras/tuning_tower.py b/klippy/extras/tuning_tower.py
new file mode 100644
index 00000000..7f536108
--- /dev/null
+++ b/klippy/extras/tuning_tower.py
@@ -0,0 +1,72 @@
+# Helper script to adjust parameters based on Z level
+#
+# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+import math, logging
+
+class TuningTower:
+ def __init__(self, config):
+ self.printer = config.get_printer()
+ self.normal_transform = None
+ self.last_position = [0., 0., 0., 0.]
+ self.last_z = self.start = self.factor = self.band = 0.
+ self.command = self.parameter = ""
+ # Register command
+ gcode = self.printer.lookup_object("gcode")
+ gcode.register_command("TUNING_TOWER", self.cmd_TUNING_TOWER,
+ desc=self.cmd_TUNING_TOWER_help)
+ cmd_TUNING_TOWER_help = "Tool to adjust a parameter at each Z height"
+ def cmd_TUNING_TOWER(self, params):
+ if self.normal_transform is not None:
+ self.end_test()
+ # Get parameters
+ gcode = self.printer.lookup_object("gcode")
+ self.command = gcode.get_str('COMMAND', params)
+ self.parameter = gcode.get_str('PARAMETER', params)
+ self.start = gcode.get_float('START', params, 0.)
+ self.factor = gcode.get_float('FACTOR', params)
+ self.band = gcode.get_float('BAND', params, 0., minval=0.)
+ # Enable test mode
+ logging.info("Starting tuning test (start=%.6f factor=%.6f)",
+ self.start, self.factor)
+ self.normal_transform = gcode.set_move_transform(self, force=True)
+ self.last_z = -99999999.9
+ gcode.reset_last_position()
+ self.get_position()
+ def get_position(self):
+ pos = self.normal_transform.get_position()
+ self.last_postition = list(pos)
+ return pos
+ def calc_value(self, z):
+ if self.band:
+ z = (math.floor(z / self.band) + .5) * self.band
+ return self.start + z * self.factor
+ def move(self, newpos, speed):
+ normal_transform = self.normal_transform
+ if (newpos[3] > self.last_position[3] and newpos[2] != self.last_z
+ and newpos[:3] != self.last_position[:3]):
+ # Extrusion move at new z height
+ z = newpos[2]
+ if z > self.last_z:
+ # Process update
+ oldval = self.calc_value(self.last_z)
+ newval = self.calc_value(z)
+ self.last_z = z
+ if newval != oldval:
+ gcode = self.printer.lookup_object("gcode")
+ gcode.run_script_from_command("%s %s=%.9f" % (
+ self.command, self.parameter, newval))
+ else:
+ self.end_test()
+ # Forward move to actual handler
+ self.last_position[:] = newpos
+ normal_transform.move(newpos, speed)
+ def end_test(self):
+ gcode = self.printer.lookup_object("gcode")
+ gcode.respond_info("Ending tuning test mode")
+ gcode.set_move_transform(self.normal_transform, force=True)
+ self.normal_transform = None
+
+def load_config(config):
+ return TuningTower(config)
diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index f697cb1b..b354f807 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -274,6 +274,7 @@ class ToolHead:
self.printer.try_load_module(config, "idle_timeout")
self.printer.try_load_module(config, "statistics")
self.printer.try_load_module(config, "manual_probe")
+ self.printer.try_load_module(config, "tuning_tower")
# Print time tracking
def update_move_time(self, movetime):
self.print_time += movetime