Skip to content

z_compensations: 0.0, 0.0, 0.0 in axis_twist_compensation appears to read 0.0 value as None, and Kalico crashes with a TypeError #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
synthead opened this issue Feb 28, 2025 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@synthead
Copy link
Contributor

synthead commented Feb 28, 2025

Related to #589

When using z_compensations: 0.0, 0.0, 0.0 in the [axis_twist_compensation] section, like so:

[axis_twist_compensation]                                                                                                                                                                                          
speed: 2000

# X-axis compensation                                                                                                                                                                                              
calibrate_start_x: 0                                                                                                                                                                                               
calibrate_end_x: 230                                                                                                                                                                                               
calibrate_y: 115
z_compensations: 0.0, 0.0, 0.0                                                                                                                                                                                     

# Y-axis compensation                                                                                                                                                                                              
calibrate_start_y: 43.3                                                                                                                                                                                            
calibrate_end_y: 230                                                                                                                                                                                               
calibrate_x: 115                                                                                                                                                                                                   
zy_compensations: 0.0, 0.0, 0.0                                                                                                                                                                                    

...Kalico starts, the bed and extruder will warm up, it'll home, but when Kalico attempts to perform a BED_MESH_CALIBRATE, this exception is raised (truncated)

  File "/usr/lib/kalico/klippy/extras/axis_twist_compensation.py", line 87, in _get_interpolated_z_compensation
    spacing = (comp_end - comp_start) / (sample_count - 1)
               ~~~~~~~~~^~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
Here is the full output (with systemd log prefixes)
Feb 27 16:50:29 enderng python[5480]: Upcoming (66572): 'MESH_CALIBRATE ADAPTIVE=1\n; G1 Z30.0 F3000 ; Move Z Axis up little to
 prevent scratching of Heat Bed\nG1 X0.1 Y20 Z0.3 F5000.0 ; '
Feb 27 16:50:29 enderng python[5480]: INFO:root:gcode state: absolute_coord=True absolute_extrude=True base_position=[0.0, 0.0,
 0.0, 0.0] last_position=[9.47500000004721, 0.7000000000531648, 4.1662500000001845, 0.0] homing_position=[0.0, 0.0, 0.0, 0.0] s
peed_factor=0.016666666666666666 extrude_factor=1.0 speed=25.0
Feb 27 16:50:29 enderng python[5480]: INFO:root:Reactor garbage collection: (8012.713696271, 0.0, 0.0)
Feb 27 16:50:29 enderng python[5480]: WARNING:root:Internal error on command:"BED_MESH_CALIBRATE"
Feb 27 16:50:29 enderng python[5480]: ERROR:root:virtual_sdcard dispatch
Feb 27 16:50:29 enderng python[5480]: Traceback (most recent call last):
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/virtual_sdcard.py", line 322, in work_handler
Feb 27 16:50:29 enderng python[5480]:     self.gcode.run_script(line)
Feb 27 16:50:29 enderng python[5480]:     ~~~~~~~~~~~~~~~~~~~~~^^^^^^
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/gcode.py", line 333, in run_script
Feb 27 16:50:29 enderng python[5480]:     self._process_commands(script.split("\n"), need_ack=False)
Feb 27 16:50:29 enderng python[5480]:     ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/gcode.py", line 310, in _process_commands
Feb 27 16:50:29 enderng python[5480]:     handler(gcmd)
Feb 27 16:50:29 enderng python[5480]:     ~~~~~~~^^^^^^
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/gcode.py", line 221, in func
Feb 27 16:50:29 enderng python[5480]:     return origfunc(self._get_extended_params(params))
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/bed_mesh.py", line 896, in cmd_BED_MESH_CALIBRATE
Feb 27 16:50:29 enderng python[5480]:     self.probe_helper.start_probe(gcmd)
Feb 27 16:50:29 enderng python[5480]:     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/probe.py", line 617, in start_probe
Feb 27 16:50:29 enderng python[5480]:     pos = probe.run_probe(gcmd)
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/probe.py", line 229, in run_probe
Feb 27 16:50:29 enderng python[5480]:     pos = self._probe(speed)
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/probe.py", line 173, in _probe
Feb 27 16:50:29 enderng python[5480]:     z_compensation = axis_twist_compensation.get_z_compensation_value(
Feb 27 16:50:29 enderng python[5480]:         pos
Feb 27 16:50:29 enderng python[5480]:     )
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/axis_twist_compensation.py", line 63, in get_z_comp
ensation_value
Feb 27 16:50:29 enderng python[5480]:     self._get_interpolated_z_compensation(
Feb 27 16:50:29 enderng python[5480]:     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Feb 27 16:50:29 enderng python[5480]:         pos[0],
Feb 27 16:50:29 enderng python[5480]:         ^^^^^^^
Feb 27 16:50:29 enderng python[5480]:     ...<2 lines>...
Feb 27 16:50:29 enderng python[5480]:         self.compensation_end_x,
Feb 27 16:50:29 enderng python[5480]:         ^^^^^^^^^^^^^^^^^^^^^^^^
Feb 27 16:50:29 enderng python[5480]:     )
Feb 27 16:50:29 enderng python[5480]:     ^
Feb 27 16:50:29 enderng python[5480]:   File "/usr/lib/kalico/klippy/extras/axis_twist_compensation.py", line 87, in _get_inter
polated_z_compensation
Feb 27 16:50:29 enderng python[5480]:     spacing = (comp_end - comp_start) / (sample_count - 1)
Feb 27 16:50:29 enderng python[5480]:                ~~~~~~~~~^~~~~~~~~~~~
Feb 27 16:50:29 enderng python[5480]: TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
Feb 27 16:50:29 enderng python[5480]: INFO:root:MCU 'usb-adxl345' shutdown: Command request

0.0 should be a valid value. It appears that a 0.0 value is read as None here.

@synthead
Copy link
Contributor Author

Okay, this is pretty confusing, but I got to the bottom of it. This is where the compensation values are read:

self.z_compensations = config.getlists(
"z_compensations", default=[], parser=float
)
self.compensation_start_x = config.getfloat(
"compensation_start_x", default=None
)
self.compensation_end_x = config.getfloat(
"compensation_end_x", default=None
)

When the values are being read from the config, AxisTwistCompensation expects:

  • compensation_start_x
  • compensation_end_x

...but when a calibration starts, these values are read from the config from AxisTwistCompensation instead:

  • calibrate_start_x
  • calibrate_end_x

This makes sense, because you can adjust calibrate_start_x and leave the old compensation in-place. This will ensure that nothing changes until BED_MESH_CALIBRATE is called again, and a new twist calibration is written.

This should be documented when fixing this issue:

@rogerlz rogerlz added the documentation Improvements or additions to documentation label Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants