Skip to content

STEAPP-656: Probe_sensor offset check added #170

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions klippy/extras/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ def probe_calibrate_finalize(self, kin_pos):
"with the above and restart the printer." % (self.name, z_offset))
configfile = self.printer.lookup_object('configfile')
configfile.set(self.name, 'z_offset', "%.3f" % (z_offset,))
def check_diff_offset(self, gcmd, axis):
# function to check the difference between the old and new offset for the sensor
restore_state = gcmd.get_int('FROM_VARS', 0)
old_offset = getattr(self, axis.lower() + '_offset')
new_offset = gcmd.get_float(axis, old_offset)
if restore_state or (new_offset >= old_offset - 5. and new_offset <= old_offset + 5.):
return True
else:
msg = 'New offset for axis %s out of the range, be apply old offsets!' % axis
logging.warning(msg)
self.gcode.respond_info(msg)
return False
cmd_PROBE_CALIBRATE_help = "Calibrate the probe's z_offset"
def cmd_PROBE_CALIBRATE(self, gcmd):
manual_probe.verify_no_manual_probe(self.printer)
Expand All @@ -296,26 +308,17 @@ def cmd_PROBE_CALIBRATE(self, gcmd):
curpos[0] += self.x_offset
curpos[1] += self.y_offset
self._move(curpos, self.speed)

def cmd_Z_OFFSET_APPLY_PROBE(self,gcmd):
cmd_Z_OFFSET_APPLY_PROBE_help = "Adjust the probe's offset"
def cmd_Z_OFFSET_APPLY_PROBE(self, gcmd):
if gcmd.get_float('Z', 0.0) > 0.0:
self.z_offset = gcmd.get_float('Z', 0.0)
self.gcode.respond_info("Z Offset is %.3f" % (self.z_offset))
self.x_offset = gcmd.get_float('X', self.x_offset)
self.y_offset = gcmd.get_float('Y', self.y_offset)
offset = self.gcode_move.get_status()['homing_origin'].z
configfile = self.printer.lookup_object('configfile')
if offset == 0:
self.gcode.respond_info("Nothing to do: Z Offset is 0")
else:
new_calibrate = self.z_offset - offset
self.gcode.respond_info(
"%s: z_offset: %.3f\n"
"The SAVE_CONFIG command will update the printer config file\n"
"with the above and restart the printer."
% (self.name, new_calibrate))
configfile.set(self.name, 'z_offset', "%.3f" % (new_calibrate,))
cmd_Z_OFFSET_APPLY_PROBE_help = "Adjust the probe's z_offset"
if self.check_diff_offset(gcmd, 'X'):
self.x_offset = gcmd.get_float('X', self.x_offset)
if self.check_diff_offset(gcmd, 'Y'):
self.y_offset = gcmd.get_float('Y', self.y_offset)
self.gcode.respond_info("Apply offset for probe_sensor: x=%s, y=%s, z=%s" % (
self.x_offset, self.y_offset, self.z_offset))

# Endstop wrapper that enables probe specific features
class ProbeEndstopWrapper:
Expand Down
3 changes: 3 additions & 0 deletions stereotech_config/probe_main.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ gcode:
{% set coord_y = printer.gcode_move.position.y + y_shift - printer.gcode_move.homing_origin.y %}
{% set delta_x = wcs_0[0] - coord_x %}
{% set delta_y = wcs_0[1] - coord_y %}
# edit offset between nozzle and probe_sensor
Z_OFFSET_APPLY_PROBE X={offsets[0] - delta_x} Y={offsets[1] - delta_y}
# set b_compensation vars
{% if params.ADJUST_CALIBRATION|default(0) %}
{% set b_axis_params = printer.b_axis_compensation %}
B_AXIS_COMPENSATION_VARS X={b_axis_params.rot_center_x - delta_x}
{% endif %}
# edit wcs in auto_wcs module from the new offsets
{% if params.ADJUST_WCS|default(0) %}
{% set auto_wcs_params = printer.auto_wcs.wcs %}
{% set x0 = auto_wcs_params[0][0] - delta_x %}
Expand Down
2 changes: 1 addition & 1 deletion stereotech_config/variables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gcode:
SET_GCODE_VARIABLE MACRO=SET_NOZZLE_OFFSET VARIABLE=offset_y VALUE={svv.nozzle_y_offset|default(0.0)}
{% if printer.probe %}
{% set probe_offsets = printer.probe.offsets %}
Z_OFFSET_APPLY_PROBE X={svv.probe_offset_x|default(probe_offsets[0])} Y={svv.probe_offset_y|default(probe_offsets[1])} Z={svv.probe_offset_z|default(probe_offsets[2])}
Z_OFFSET_APPLY_PROBE X={svv.probe_offset_x|default(probe_offsets[0])} Y={svv.probe_offset_y|default(probe_offsets[1])} Z={svv.probe_offset_z|default(probe_offsets[2])} FROM_VARS=1

B_AXIS_COMPENSATION_VARS B={svv.b_angle|default(0.0)} X={svv.rot_center_x|default(0.0)} Z={svv.rot_center_z|default(0.0)}
{% for key, profile in printer.bed_mesh.profiles.items() %}
Expand Down