sporkus / probe_accuracy_tests

GNU General Public License v3.0
139 stars 29 forks source link

KeyError: 'safe_z_home' for sensorless homing config ('using homing_override') #13

Closed dspears0809 closed 1 year ago

dspears0809 commented 1 year ago

While running:

python3 $HOME/probe_accuracy_tests/probe_accuracy_test_suite.py

Receive python exception for missing key name safe_z_home:

pi@fluidd-v2-851:~ $ python3 $HOME/probe_accuracy_tests/probe_accuracy_test_suite.py
Leveling
Traceback (most recent call last):
  File "/home/pi/probe_accuracy_tests/probe_accuracy_test_suite.py", line 599, in <module>
    main(args)
  File "/home/pi/probe_accuracy_tests/probe_accuracy_test_suite.py", line 45, in main
    move_to_safe_z()
  File "/home/pi/probe_accuracy_tests/probe_accuracy_test_suite.py", line 367, in move_to_safe_z
    safe_z = settings["safe_z_home"]["z_hop"]
KeyError: 'safe_z_home'

I'm running sensorless homing using custom gcode in homing_override to handle custom movements and energizing Z-motors to combat gantry sag prior to homing procedures instead of having a safe_z_home section.

Code where it appears to fail:

def move_to_safe_z():
    safe_z = None

    if isKlicky:
        safe_z = query_printer_objects("gcode_macro _User_Variables", "safe_z")
    elif isTap:
        settings = query_printer_objects("configfile", "settings")
        safe_z = settings["safe_z_home"]["z_hop"]

    if not safe_z:
        print("Safe z has not been set in klicky-variables or in [safe_z_home]")
        safe_z = input("Enter safe z height to avoid crash:")

    send_gcode(f"G1 Z{safe_z}")

What would you recommend to work-around the issue?

Saij commented 1 year ago

I have modified the function the following way:

def move_to_safe_z():
    safe_z = None

    if isKlicky:
        safe_z = query_printer_objects("gcode_macro _User_Variables", "safe_z")
    elif isTap:
        settings = query_printer_objects("configfile", "settings")
        if "safe_z_home" in settings:
            safe_z = settings["safe_z_home"]["z_hop"]

    if not safe_z:
        print("Safe z has not been set in klicky-variables or in [safe_z_home]")
        safe_z = input("Enter safe z height to avoid crash:")

    send_gcode(f"G1 Z{safe_z}")

That way the script asks for a safe_z value and does not crash because safe_z_home is not present

dspears0809 commented 1 year ago

This seems a reasonable solution. Thanks!

sporkus commented 1 year ago

@saji thanks. Fixed in https://github.com/sporkus/probe_accuracy_tests/commit/1a659d04b548436ffe7d058018ee79896b59239f