probe: add ability to save babystepping (#4404)

Created two new extended gcodes: Z_OFFSET_APPLY_ENDSTOP, and Z_OFFSET_APPLY_PROBE.
These use the z gcode offset to revise the probe offset, or z endstop position
allowing users to make a frequently used babystepping value permanent without
manual config editing.

Signed-off-by: Ben Eastep <shifting@shifting.ca>
This commit is contained in:
shiftingtech 2021-07-25 18:20:15 -06:00 committed by GitHub
parent 0075b29081
commit f949bc882d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 5 deletions

View File

@ -206,6 +206,10 @@ The following standard commands are supported:
for calibrating a Z position_endstop config setting. See the for calibrating a Z position_endstop config setting. See the
MANUAL_PROBE command for details on the parameters and the MANUAL_PROBE command for details on the parameters and the
additional commands available while the tool is active. additional commands available while the tool is active.
`Z_ENDSTOP_UPDATE_POSITION`: Take the current Z Gcode offset (aka,
babystepping), and subtract it from the stepper_z endstop_position.
This acts to take a frequently used babystepping value, and "make
it permanent". Requires a `SAVE_CONFIG` to take effect.
- `TUNING_TOWER COMMAND=<command> PARAMETER=<name> START=<value> - `TUNING_TOWER COMMAND=<command> PARAMETER=<name> START=<value>
FACTOR=<value> [BAND=<value>]`: A tool for tuning a parameter on FACTOR=<value> [BAND=<value>]`: A tool for tuning a parameter on
each Z height during a print. The tool will run the given COMMAND each Z height during a print. The tool will run the given COMMAND
@ -351,11 +355,13 @@ the [probe calibrate guide](Probe_Calibrate.md)):
section. section.
- `PROBE_CALIBRATE [SPEED=<speed>] [<probe_parameter>=<value>]`: Run a - `PROBE_CALIBRATE [SPEED=<speed>] [<probe_parameter>=<value>]`: Run a
helper script useful for calibrating the probe's z_offset. See the helper script useful for calibrating the probe's z_offset. See the
PROBE command for details on the optional probe parameters. See the PROBE command for details on the optional probe parameters. See
MANUAL_PROBE command for details on the SPEED parameter and the the MANUAL_PROBE command for details on the SPEED parameter and the additional commands available while the tool is active. Please note, the PROBE_CALIBRATE command uses the speed variable
additional commands available while the tool is active. Please note, to move in XY direction as well as Z.
the PROBE_CALIBRATE command uses the speed variable to move in XY direction `PROBE_UPDATE_OFFSET`: Take the current Z Gcode offset (aka,
as well as Z. babystepping), and subtract if from the probe's z_offset.
This acts to take a frequently used babystepping value, and "make
it permanent". Requires a `SAVE_CONFIG` to take effect.
## BLTouch ## BLTouch

View File

@ -10,6 +10,7 @@ class ManualProbe:
self.printer = config.get_printer() self.printer = config.get_printer()
# Register commands # Register commands
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
self.gcode_move = self.printer.load_object(config, "gcode_move")
self.gcode.register_command('MANUAL_PROBE', self.cmd_MANUAL_PROBE, self.gcode.register_command('MANUAL_PROBE', self.cmd_MANUAL_PROBE,
desc=self.cmd_MANUAL_PROBE_help) desc=self.cmd_MANUAL_PROBE_help)
zconfig = config.getsection('stepper_z') zconfig = config.getsection('stepper_z')
@ -19,6 +20,10 @@ class ManualProbe:
self.gcode.register_command( self.gcode.register_command(
'Z_ENDSTOP_CALIBRATE', self.cmd_Z_ENDSTOP_CALIBRATE, 'Z_ENDSTOP_CALIBRATE', self.cmd_Z_ENDSTOP_CALIBRATE,
desc=self.cmd_Z_ENDSTOP_CALIBRATE_help) desc=self.cmd_Z_ENDSTOP_CALIBRATE_help)
self.gcode.register_command(
'Z_OFFSET_APPLY_ENDSTOP',
self.cmd_Z_OFFSET_APPLY_ENDSTOP,
desc=self.cmd_Z_OFFSET_APPLY_ENDSTOP_help)
def manual_probe_finalize(self, kin_pos): def manual_probe_finalize(self, kin_pos):
if kin_pos is not None: if kin_pos is not None:
self.gcode.respond_info("Z position is %.3f" % (kin_pos[2],)) self.gcode.respond_info("Z position is %.3f" % (kin_pos[2],))
@ -38,6 +43,20 @@ class ManualProbe:
cmd_Z_ENDSTOP_CALIBRATE_help = "Calibrate a Z endstop" cmd_Z_ENDSTOP_CALIBRATE_help = "Calibrate a Z endstop"
def cmd_Z_ENDSTOP_CALIBRATE(self, gcmd): def cmd_Z_ENDSTOP_CALIBRATE(self, gcmd):
ManualProbeHelper(self.printer, gcmd, self.z_endstop_finalize) ManualProbeHelper(self.printer, gcmd, self.z_endstop_finalize)
def cmd_Z_OFFSET_APPLY_ENDSTOP(self,gcmd):
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_position_endstop - offset
self.gcode.respond_info(
"stepper_z: position_endstop: %.3f\n"
"The SAVE_CONFIG command will update the printer config file\n"
"with the above and restart the printer." % (new_calibrate))
configfile.set('stepper_z', 'position_endstop',
"%.3f" % (new_calibrate,))
cmd_Z_OFFSET_APPLY_ENDSTOP_help = "Adjust the z endstop_position"
# Verify that a manual probe isn't already in progress # Verify that a manual probe isn't already in progress
def verify_no_manual_probe(printer): def verify_no_manual_probe(printer):

View File

@ -27,6 +27,7 @@ class PrinterProbe:
self.multi_probe_pending = False self.multi_probe_pending = False
self.last_state = False self.last_state = False
self.last_z_result = 0. self.last_z_result = 0.
self.gcode_move = self.printer.load_object(config, "gcode_move")
# Infer Z position to move to during a probe # Infer Z position to move to during a probe
if config.has_section('stepper_z'): if config.has_section('stepper_z'):
zconfig = config.getsection('stepper_z') zconfig = config.getsection('stepper_z')
@ -70,6 +71,9 @@ class PrinterProbe:
desc=self.cmd_PROBE_CALIBRATE_help) desc=self.cmd_PROBE_CALIBRATE_help)
self.gcode.register_command('PROBE_ACCURACY', self.cmd_PROBE_ACCURACY, self.gcode.register_command('PROBE_ACCURACY', self.cmd_PROBE_ACCURACY,
desc=self.cmd_PROBE_ACCURACY_help) desc=self.cmd_PROBE_ACCURACY_help)
self.gcode.register_command('Z_OFFSET_APPLY_PROBE',
self.cmd_Z_OFFSET_APPLY_PROBE,
desc=self.cmd_Z_OFFSET_APPLY_PROBE_help)
def _handle_homing_move_begin(self, hmove): def _handle_homing_move_begin(self, hmove):
if self.mcu_probe in hmove.get_mcu_endstops(): if self.mcu_probe in hmove.get_mcu_endstops():
self.mcu_probe.probe_prepare(hmove) self.mcu_probe.probe_prepare(hmove)
@ -262,6 +266,21 @@ class PrinterProbe:
# Start manual probe # Start manual probe
manual_probe.ManualProbeHelper(self.printer, gcmd, manual_probe.ManualProbeHelper(self.printer, gcmd,
self.probe_calibrate_finalize) self.probe_calibrate_finalize)
def cmd_Z_OFFSET_APPLY_PROBE(self,gcmd):
z_offset = self.probe_calibrate_z
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.probe_calibrate_z - 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"
# Endstop wrapper that enables probe specific features # Endstop wrapper that enables probe specific features
class ProbeEndstopWrapper: class ProbeEndstopWrapper: