Frix-x / klippain-shaketune

Klipper streamlined input shaper workflow and calibration tools
GNU General Public License v3.0
627 stars 70 forks source link

Allow other measuring devices than ADXL345 #11

Closed JurajMik closed 8 months ago

JurajMik commented 9 months ago

K-Shake&Tune module branch

Version

v 1.1.2 6e88452

Describe the bug and expected behavior

get_vibrations_graph in is_workflow.py uses hardcoded accelerometer name: globbed_files = glob.glob('/tmp/adxl345-*.csv')

I do not have adxl345, instead USB lis2dw (biqu). Passing chip name as "hotend" it looks into lis2dw.cfg (I have two probes, one on hotend, one on bed) :

lis2dw.cfg

[mcu lis2dwHotend] serial: /dev/serial/by-path/platform-5200000.usb-usb-0:1.3:1.0

[mcu lis2dwBed] serial: /dev/serial/by-path/platform-5200000.usb-usb-0:1.4:1.0

[lis2dw hotend] cs_pin: lis2dwHotend:gpio9

spi_bus: spi1a

spi_software_sclk_pin: lis2dwHotend:gpio10 spi_software_mosi_pin: lis2dwHotend:gpio11 spi_software_miso_pin: lis2dwHotend:gpio8 axes_map: -x,y,z

[lis2dw bed] cs_pin: lis2dwBed:gpio9

spi_bus: spi1a

spi_software_sclk_pin: lis2dwBed:gpio10 spi_software_mosi_pin: lis2dwBed:gpio11 spi_software_miso_pin: lis2dwBed:gpio8 axes_map: -y,x,z

Macro VIBRATIONS_CALIBRATION generates csv file names based on chip, so graph generation failed on line globbed_files = glob.glob('/tmp/adxl345-*.csv')

Additional information and klippy.log

No response

Frix-x commented 9 months ago

Thanks for the issue!

I didn't thought about making this name more flexible since I never thought about the other compatible chips. But thanks for pointing it!

However, since almost all people are running the good old ADXL345, this issue is not having a big impact for now. Moreover, looking at the datasheets of the chips, it look like the ADXL345 is more precise than the LIS2DW so ADXL345 is still a prefered chip. So I will add this to the backlog but it is not on my priority list since I need to work on other things before. If you want to do a PR in the meantime, I'll be happy to merge it :)

JurajMik commented 9 months ago

Hi, please see https://biqu.equipment/products/adxl-345-accelerometer-board-for-36-stepper-motors?variant=40446852759650 S2DW V1.0 has higher sensitivity, lower noise and improved temperature stability over ADXL345.

Frix-x commented 9 months ago

Hi, please see https://biqu.equipment/products/adxl-345-accelerometer-board-for-36-stepper-motors?variant=40446852759650 S2DW V1.0 has higher sensitivity, lower noise and improved temperature stability over ADXL345.

I would suggest you to read at the datasheets of the components directly since I think this is just some "marketing" and it's technically wrong. Indeed, ADXL345 is more precise and has lower noise than S2DW. The only thing that S2DW has better is the sampling rate but that doesn't matter that much for our use case. I think BIQU started to use this chip since it's also 5x cheaper than an ADXL345.

But whatever, as it's supported by Klipper, I will definitely need to add support for it in this Shake&Tune module :)

OoSTARTERoO commented 9 months ago

Hi! I've recently got into this awesome project and happened to have the same problem. Belts graph and input shaper graphs work, but Viberations graph doesn't This is console log

오후 4:55
Command {plot_graph} finished

오후 4:55
No CSV files found in the /tmp folder to create the vibration graphs!

오후 4:55
Running Command {plot_graph}...:

오후 4:55
echo: Graphs generation... Please wait a minute or two and look in the configured folder.

오후 4:55
Writing raw accelerometer data to /tmp/lis2dw-sp200_00n1.csv file

Since the default option doesn't work, I changed ACCEL_CHIP to lis2dw Which actually runs, and saves some data but eventually it cannot generate the graph. lis2dw-sp102_00n1.zip here's the raw data Hope this helps!

Frix-x commented 9 months ago

Hello, yes this is normal due to how the script currently handle the vibration files here: https://github.com/Frix-x/klippain-shaketune/blob/d1c18748d8235a038b713662f2ecb17873405352/K-ShakeTune/scripts/is_workflow.py#L123-L162

It's looking for files with the adxl345 name inside. I'll see how to improve it and standardize the system

JurajMik commented 9 months ago

Some inspiration (I did it like that...) printer.cfg includes vibrations_bed_lis2dw.cfg (note: this includes IS_vibrations_measurements.cfg from home dir)

vibrations_bed_lis2dw.cfg

` [include K-ShakeTune/IS_workflow_cmd.cfg] [include K-ShakeTune/IS_shaper_calibrate.cfg] [include IS_vibrations_measurements.cfg]

[mcu lis] serial: /dev/serial/by-path/platform-5200000.usb-usb-0:1.4:1.0

[lis2dw] cs_pin: lis:gpio9

spi_bus: spi1a

spi_software_sclk_pin: lis:gpio10 spi_software_mosi_pin: lis:gpio11 spi_software_miso_pin: lis:gpio8 axes_map: y,-x,z

[resonance_tester] accel_chip: lis2dw probe_points: 147, 158, 20`

IS_vibrations_measurements.cfg (only relevant lines)

` [include K-ShakeTuneSettings.cfg]

[gcode_macro VIBRATIONS_CALIBRATION] gcode:

-----------------------------------------

{% set accel_chip = chip_name %}
#------------------------------------------
# Going to the start position
G1 Z{z_height}
G1 X{mid_x + (size * direction_factor[direction].start.x) } Y{mid_y + (size * direction_factor[direction].start.y)} F{feedrate_travel}

# vibration pattern for each frequency
{% for curr_sample in range(0, nb_samples) %}
    {% set curr_speed = min_speed + curr_sample * speed_increment %}
    {% if verbose %}
        RESPOND MSG="{"Current speed: %.2f mm/s" % (curr_speed / 60)|float}"
    {% endif %}

    ACCELEROMETER_MEASURE CHIP={accel_chip}

------------------------------------------------------------

    {% if direction == 'E' %}
        G0 E{curr_speed*direction_factor[direction].move_factor} F{curr_speed}
    {% else %}
        {% for key, factor in direction_factor[direction].move_factors|dictsort %}
            G1 X{mid_x + (size * factor.x) } Y{mid_y + (size * factor.y)} Z{z_height + (size * factor.z)} F{curr_speed}
        {% endfor %}
    {% endif %}
    ACCELEROMETER_MEASURE CHIP={accel_chip} NAME=sp{("%.2f" % (curr_speed / 60)|float)|replace('.','_')}n1

---------------------------------------------------------------------------------------------------------------------------

    # original code

    RUN_SHELL_COMMAND CMD=plot_graph PARAMS="VIBRATIONS {direction} {accel_chip}"

---------------------------------------------------------------------------------------------------------

`

K-ShakeTuneSettings.cfg

[gcode_macro _K-ShakeTuneSettings]
description: This macro contains settings K-ShakeTune 

variable_accel_chip_name: 'lis2dw'

gcode: # Gcode section left intentionally blank. Do not disturb.

    {action_respond_info(" Running the _K-ShakeTuneSettings macro does nothing.")}

scripts attached... (only is_workflow.py needed) scripts.zip

Frix-x commented 9 months ago

Oh yes, this part is indeed a good idea!

RUN_SHELL_COMMAND CMD=plot_graph PARAMS="VIBRATIONS {direction} {accel_chip}"

I'll probably use you suggestion to fix this issue!

JurajMik commented 9 months ago

Even AXES_MAP_CALIBRATION macro is not working (you recommend replace adxl.. with our chip name), because also find_axesmap (is_workflow.py) has baked "adxl345" in globbed_files = glob.glob('/tmp/adxl345-*.csv')

So I have csv in tmp folder, but as axpected, procedure fails with print("No CSV files found in the /tmp folder to analyze and find the axes_map!")

Also you should mention in AXES_MAPCALIBRATION readme (at least), user should not use "" (underscore) character in adxl chip name, as then vibration measurement cannot parse csv files and find speed...

SpeCter commented 8 months ago

Just saw this after creating the same issue. Got the same problem and changing the fixed string to search for it works but the spectrogram looks kinda scuffed not sure what I forgot.

Frix-x commented 8 months ago

Just saw this after creating the same issue. Got the same problem and changing the fixed string to search for it works but the spectrogram looks kinda scuffed not sure what I forgot.

Can you share the spectrogram to have a look? I need to fix some bugs and try to lower the memory use of the Shake&Tune package first and then I'll work on this issue.

SpeCter commented 8 months ago

Just saw this after creating the same issue. Got the same problem and changing the fixed string to search for it works but the spectrogram looks kinda scuffed not sure what I forgot.

Can you share the spectrogram to have a look? I need to fix some bugs and try to lower the memory use of the Shake&Tune package first and then I'll work on this issue.

vibrations_20231223_032926_XY

Frix-x commented 8 months ago

Hello, thanks for sharing all your data.

Quick update: I've worked on this and it's mostly finished (just need more testing).

I've done a major rewriting of how the parameters are passed in order to be more flexible. This allow to change the number of results to keep in the result folder, and also if the CSV file need to be archived or only the PNGs, or a couple of other things like the adxl name for the vibration graphs, etc... :)

I plan to release it this weekend alongside the code optimizations that were done for the memory issue #28 .

JurajMik commented 8 months ago

Thank you for great work.
Just quick-view workflow-rework branch -> is_workflow.py:

cleanfilename = os.path.basename(filename).replace('adxl345', f'vibr_{current_date}')

Frix-x commented 8 months ago

cleanfilename = os.path.basename(filename).replace('adxl345', f'vibr_{current_date}')

Good catch, thanks. I've fixed it in my last commit. Currently installing a LIS2DW accelerometer to test it and validate before merging :)