probe: Implement ProbePointsHelper get_probed_position() locally
Now that all users of ProbePointsHelper use the same get_probed_position() code, it is possible to implement that locally within the ProbePointsHelper class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
ae4eb35a70
commit
8e7eac9b08
|
@ -136,7 +136,8 @@ class BedMeshCalibrate:
|
|||
self.probe_params = {}
|
||||
points = self._generate_points(config)
|
||||
self._init_probe_params(config, points)
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self, points)
|
||||
self.probe_helper = probe.ProbePointsHelper(
|
||||
config, self.probe_finalize, points)
|
||||
self.z_endstop_pos = None
|
||||
if config.has_section('stepper_z'):
|
||||
zconfig = config.getsection('stepper_z')
|
||||
|
@ -212,9 +213,6 @@ class BedMeshCalibrate:
|
|||
self.bedmesh.set_mesh(None)
|
||||
self.gcode.run_script_from_command("G28")
|
||||
self.probe_helper.start_probe()
|
||||
def get_probed_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.calc_position()
|
||||
def print_probed_positions(self, print_func):
|
||||
if self.probed_z_table is not None:
|
||||
msg = "Mesh Leveling Probed Z positions:\n"
|
||||
|
@ -225,7 +223,7 @@ class BedMeshCalibrate:
|
|||
print_func(msg)
|
||||
else:
|
||||
print_func("bed_mesh: bed has not been probed")
|
||||
def finalize(self, offsets, positions):
|
||||
def probe_finalize(self, offsets, positions):
|
||||
self.probe_params['x_offset'] = offsets[0]
|
||||
self.probe_params['y_offset'] = offsets[1]
|
||||
z_offset = offsets[2]
|
||||
|
|
|
@ -42,7 +42,7 @@ class BedTiltCalibrate:
|
|||
def __init__(self, config, bedtilt):
|
||||
self.printer = config.get_printer()
|
||||
self.bedtilt = bedtilt
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self)
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize)
|
||||
# Automatic probe:z_virtual_endstop XY detection
|
||||
self.z_position_endstop = None
|
||||
if config.has_section('stepper_z'):
|
||||
|
@ -57,10 +57,7 @@ class BedTiltCalibrate:
|
|||
def cmd_BED_TILT_CALIBRATE(self, params):
|
||||
self.gcode.run_script_from_command("G28")
|
||||
self.probe_helper.start_probe()
|
||||
def get_probed_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.calc_position()
|
||||
def finalize(self, offsets, positions):
|
||||
def probe_finalize(self, offsets, positions):
|
||||
z_offset = offsets[2]
|
||||
logging.info("Calculating bed_tilt with: %s", positions)
|
||||
params = { 'x_adjust': self.bedtilt.x_adjust,
|
||||
|
|
|
@ -142,7 +142,7 @@ class DeltaCalibrate:
|
|||
dist = radius * scatter[i]
|
||||
points.append((math.cos(r) * dist, math.sin(r) * dist))
|
||||
self.probe_helper = probe.ProbePointsHelper(
|
||||
config, self, default_points=points)
|
||||
config, self.probe_finalize, default_points=points)
|
||||
# Restore probe stable positions
|
||||
self.last_probe_positions = []
|
||||
for i in range(999):
|
||||
|
@ -192,10 +192,7 @@ class DeltaCalibrate:
|
|||
"%.3f,%.3f,%.3f" % tuple(spos1))
|
||||
configfile.set(section, "distance%d_pos2" % (i,),
|
||||
"%.3f,%.3f,%.3f" % tuple(spos2))
|
||||
def get_probed_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.calc_position()
|
||||
def finalize(self, offsets, positions):
|
||||
def probe_finalize(self, offsets, positions):
|
||||
# Convert positions into (z_offset, stable_position) pairs
|
||||
z_offset = offsets[2]
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
|
|
|
@ -136,9 +136,9 @@ class ProbeVirtualEndstop:
|
|||
# Helper code that can probe a series of points and report the
|
||||
# position at each point.
|
||||
class ProbePointsHelper:
|
||||
def __init__(self, config, callback, default_points=None):
|
||||
def __init__(self, config, finalize_callback, default_points=None):
|
||||
self.printer = config.get_printer()
|
||||
self.callback = callback
|
||||
self.finalize_callback = finalize_callback
|
||||
self.probe_points = default_points
|
||||
# Read config settings
|
||||
if default_points is None or config.get('points', None) is not None:
|
||||
|
@ -183,6 +183,8 @@ class ProbePointsHelper:
|
|||
return self.probe.last_home_position()
|
||||
else:
|
||||
return None
|
||||
def get_probed_position(self):
|
||||
return self.toolhead.get_kinematics().calc_position()
|
||||
def lift_z(self, z_pos, add=False, speed=None):
|
||||
# Lift toolhead
|
||||
curpos = self.toolhead.get_position()
|
||||
|
@ -201,7 +203,7 @@ class ProbePointsHelper:
|
|||
for i in range(self.samples):
|
||||
self.gcode.run_script_from_command("PROBE")
|
||||
self.toolhead.wait_moves()
|
||||
self.results.append(self.callback.get_probed_position())
|
||||
self.results.append(self.get_probed_position())
|
||||
if i < self.samples - 1:
|
||||
# retract
|
||||
self.lift_z(self.sample_retract_dist, add=True)
|
||||
|
@ -243,7 +245,7 @@ class ProbePointsHelper:
|
|||
if self.probe is None:
|
||||
# Record current position for manual probe
|
||||
self.toolhead.wait_moves()
|
||||
self.results.append(self.callback.get_probed_position())
|
||||
self.results.append(self.get_probed_position())
|
||||
# Lift toolhead
|
||||
self.lift_z(self.horizontal_move_z)
|
||||
# Move to next position
|
||||
|
@ -257,7 +259,7 @@ class ProbePointsHelper:
|
|||
self.gcode.reset_last_position()
|
||||
self.gcode.register_command('NEXT', None)
|
||||
if success:
|
||||
self.callback.finalize(self.probe_offsets, self.results)
|
||||
self.finalize_callback(self.probe_offsets, self.results)
|
||||
|
||||
def load_config(config):
|
||||
return PrinterProbe(config)
|
||||
|
|
|
@ -9,7 +9,7 @@ import probe
|
|||
class QuadGantryLevel:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self)
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize)
|
||||
gantry_corners = config.get('gantry_corners').split('\n')
|
||||
try:
|
||||
gantry_corners = [line.split(',', 1)
|
||||
|
@ -39,9 +39,6 @@ class QuadGantryLevel:
|
|||
cmd_QUAD_GANTRY_LEVEL_help = "Conform a moving, twistable gantry to the shape of a stationary bed"
|
||||
def cmd_QUAD_GANTRY_LEVEL(self, params):
|
||||
self.probe_helper.start_probe()
|
||||
def get_probed_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.calc_position()
|
||||
def squash_positions(self,positions):
|
||||
# Group multi-probe data and average out the Z readings
|
||||
# Assumes samples come in sequentially
|
||||
|
@ -55,7 +52,7 @@ class QuadGantryLevel:
|
|||
for id,pos in enumerate(grouped_pos):
|
||||
grouped_pos[id][2] = sum(grouped_pos[id][2]) / len(grouped_pos[id][2])
|
||||
return grouped_pos
|
||||
def finalize(self, offsets, positions):
|
||||
def probe_finalize(self, offsets, positions):
|
||||
if len(positions) > 4:
|
||||
positions = self.squash_positions(positions)
|
||||
logging.info("quad_gantry_level Calculating gantry geometry with: %s", positions)
|
||||
|
|
|
@ -20,7 +20,7 @@ class ZTilt:
|
|||
config.get_name()))
|
||||
if len(z_positions) < 2:
|
||||
raise config.error("z_tilt requires at least two z_positions")
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self)
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self.probe_finalize)
|
||||
self.z_steppers = []
|
||||
# Register Z_TILT_ADJUST command
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
|
@ -40,10 +40,7 @@ class ZTilt:
|
|||
cmd_Z_TILT_ADJUST_help = "Adjust the Z tilt"
|
||||
def cmd_Z_TILT_ADJUST(self, params):
|
||||
self.probe_helper.start_probe()
|
||||
def get_probed_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.calc_position()
|
||||
def finalize(self, offsets, positions):
|
||||
def probe_finalize(self, offsets, positions):
|
||||
z_offset = offsets[2]
|
||||
logging.info("Calculating bed tilt with: %s", positions)
|
||||
params = { 'x_adjust': 0., 'y_adjust': 0., 'z_adjust': z_offset }
|
||||
|
|
Loading…
Reference in New Issue