viesturz / klipper-toolchanger

Toolcahnging extension for Klipper
GNU General Public License v3.0
72 stars 22 forks source link

Store calibration results #16

Open RNGIllSkillz opened 5 months ago

RNGIllSkillz commented 5 months ago

Implemented a command TOOL_CALIBRATE_STORE_TOOL_OFFSET that will append results in to a txt file at printer_data/config/tools_calibrate_results/

VIN-y commented 5 months ago

Hi guys,

I have been on the fence about how useful this feature is for for a while. Now that I have had a proper thought about. This might actually be pretty handy for a dynamic hardware config, like MissChanger, where the multi-tool-head hardware is designed to be quickly removable.

At the moment, even if I can disconnect all the hardware in less than a minute, I will still need to manually go to the printer.cfg to comment out the tool-head profile, and move the PID and offsets another file. Then, I will have to do all of that in reverse when I want to put them back... This gets old really quickly.

In this context, to have the data being saved in a separate file, from which I can use a script to automatically re-import into printer.cfg, is pretty helpful. Nevertheless, this is not a universal problem for all printer, and the feature set might need to be expanded to do have the automatic re-import function. All of that code will not be relevant to non-dynamic hardware configs, thus will only serve as potential sources of bugs for them.

Therefore, I propose that we put what you got here, and any feature that related to data management into a separate .py file. So, we can have the features, but in an isolated form.

joseph-greiner commented 5 months ago

An option that could be used is a [save_variables] file in Klipper, from each of the tool_calibrate_tool_offset call a separate macro to store and update the offsets:

[save_variables] filename: ~/printer_data/config/offset-variables.cfg

[gcode_macro save_offsets_to_disk] gcode: {% set svv = printer.save_variables.variables %} {% set tool = params.T|default(1)|int %} SAVE_VARIABLE VARIABLE=t{tool}_offset_x VALUE=printer.tools_calibrate.last_x_result|round(6)} SAVE_VARIABLE VARIABLE=t[tool}_offset_y VALUE=printer.tools_calibrate.last_y_result|round(6)} SAVE_VARIABLE VARIABLE=t{tool}_offset_z VALUE=printer.tools_calibrate.last_z_result|round(6)}

Then you can load them from the file at run time in a macro: {% set svv = printer.save_variables.variables %} {% set load_x_offset = svv.t1_offset_x|float %} {% set load_y_offset = svv.t1_offset_y|float %} {% set load_z_offset = svv.t1_offset_z|float %}

And adjust your offsets from there.

russiancatfood commented 5 months ago

Same idea, but using the last_result to set Gcode macro variables (since everything in IDEX land is hacked together with macros)

SET_GCODE_VARIABLE MACRO=DC_VARS VARIABLE=offset_x VALUE={printer.tools_calibrate.last_x_result|round(6)}
SET_GCODE_VARIABLE MACRO=DC_VARS VARIABLE=offset_y VALUE={printer.tools_calibrate.last_y_result|round(6)}
SET_GCODE_VARIABLE MACRO=DC_VARS VARIABLE=offset_z VALUE={printer.tools_calibrate.last_z_result|round(6)}
VIN-y commented 5 months ago

[save_variables]

I actually totally forgot that existed. Thanks. I will see what I can do with it.

VIN-y commented 5 months ago

I found it. There is a macro called [gcode_shell_command] that can be installed via KIAUH, which allows me to run bash commands. I just use that to toggle the config for multi-toolhead and single-toolhead.