-
-
Notifications
You must be signed in to change notification settings - Fork 2
Visualise Resonances Graph inside web interface
One of the amazing features of Klipper is for sure Input Shaper but to use it we first need to measure the resonance of our printers and use the generated values to configure the Input Shaper properly.
This process can be quite long because not only involves a lot of preparation for the accelerometer mount and wiring but also require the execution of several commands.
Usually, we first need to run the resonance test on an axe using a command inside the Klipper console. This command will generate a csv file containing all the data coming from the accelerometer and after this, we will use another command via SSH to generate the resonance graph that will be useful to understand if there is some problem with the printer. The generated graph will be available to be downloaded via FTP.
This is a long and complicated process that can be simplified using the macro described in this guide.
- Basic knowledge of shell commands
- Python3 installed and tested on your pi
- G-Code Shell Command Extension installed via Kiauh on your pi
As described before, the goal of this macro is to simplify the process of generating and visualising the resonance graph of the axe that you just tested. After finishing the setup the macro will perform 3 actions:
- Home all the axis
- Launch the resonance test command on the provided axe to generate the csv file
- Run a python script that will generate the graph for us and move both the csv and the generated graph into this path
~/klipper_config/resonances
Since both the csv and the graph will be in a path that is accessible via the web interface of MainsailOS of Fluidd it will be also possible to download or visualise both files without the need of connecting in FTP to the Raspberry Pi.
As a first step, we need to integrate the script that will generate the graph for us and move it to the desired location.
Inside your klipper_config folder create a new folder called scripts and inside this folder create a new file called generate_resonances_graph.py
Edit this file and paste the following code:
#!/usr/bin/env python3
import os
import glob
import sys
axe = sys.argv[1].lower()
source = "/tmp"
dest = "/home/pi/klipper_config/resonances"
os.chdir(source)
csv_file = glob.glob('resonances_'+axe+'_*.csv')[0]
graph_file = os.path.splitext(csv_file)[0] + ".png"
if not os.path.exists(dest):
os.makedirs(dest)
generate_command = "~/klipper/scripts/calibrate_shaper.py " + source + "/" + csv_file + " -o " + dest + "/" + graph_file
os.system(generate_command)
os.rename(source + "/" + csv_file, dest + "/" + csv_file)
Now we need to make this file executable so we will need to execute the following command via ssh inside the scripts folder:
sudo chmod +x ./generate_resonances_graph.py
If you configured the G-Code Shell Command Extension
correctly you should have a shell_commands.cfg
where we need to copy and paste the following command:
[gcode_shell_command generate_resonance_graph]
command: ~/klipper_config/scripts/generate_resonances_graph.py
timeout: 30.
verbose: True
This command will be used from the macro to call the script to generate the graph.
Now we need to add this macro to our config file:
[gcode_macro GENERATE_RESONANCES_GRAPH]
description: "Test resonance on the provided axe and generate graph"
@param {string} [AXIS=X] - The axe where you want to run the test
gcode:
{% set axe = params.AXIS|default("X")|string %}
G28
TEST_RESONANCES AXIS={axe}
RUN_SHELL_COMMAND CMD=generate_resonance_graph PARAMS={axe}
To test the Macro you just need to run the following command inside the Klipper console GENERATE_RESONANCES_GRAPH AXIS=X
This command will launch the Macro and execute the resonance test on the X axe.
You can do the same for the Y axe but remember that the AXIS parameter is mandatory.
When you finished with the testing you should see a new folder inside the config files of your Klipper interface
Go inside the resonances folder and you will find all the results of the resonance test that you just did
And that's it!
Enjoy this Macro and Happy Printing!