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:
Kevin O'Connor 2018-09-26 10:32:57 -04:00 committed by KevinOConnor
parent ae4eb35a70
commit 8e7eac9b08
6 changed files with 18 additions and 30 deletions

View File

@ -136,7 +136,8 @@ class BedMeshCalibrate:
self.probe_params = {} self.probe_params = {}
points = self._generate_points(config) points = self._generate_points(config)
self._init_probe_params(config, points) 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 self.z_endstop_pos = None
if config.has_section('stepper_z'): if config.has_section('stepper_z'):
zconfig = config.getsection('stepper_z') zconfig = config.getsection('stepper_z')
@ -212,9 +213,6 @@ class BedMeshCalibrate:
self.bedmesh.set_mesh(None) self.bedmesh.set_mesh(None)
self.gcode.run_script_from_command("G28") self.gcode.run_script_from_command("G28")
self.probe_helper.start_probe() 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): def print_probed_positions(self, print_func):
if self.probed_z_table is not None: if self.probed_z_table is not None:
msg = "Mesh Leveling Probed Z positions:\n" msg = "Mesh Leveling Probed Z positions:\n"
@ -225,7 +223,7 @@ class BedMeshCalibrate:
print_func(msg) print_func(msg)
else: else:
print_func("bed_mesh: bed has not been probed") 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['x_offset'] = offsets[0]
self.probe_params['y_offset'] = offsets[1] self.probe_params['y_offset'] = offsets[1]
z_offset = offsets[2] z_offset = offsets[2]

View File

@ -42,7 +42,7 @@ class BedTiltCalibrate:
def __init__(self, config, bedtilt): def __init__(self, config, bedtilt):
self.printer = config.get_printer() self.printer = config.get_printer()
self.bedtilt = bedtilt 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 # Automatic probe:z_virtual_endstop XY detection
self.z_position_endstop = None self.z_position_endstop = None
if config.has_section('stepper_z'): if config.has_section('stepper_z'):
@ -57,10 +57,7 @@ class BedTiltCalibrate:
def cmd_BED_TILT_CALIBRATE(self, params): def cmd_BED_TILT_CALIBRATE(self, params):
self.gcode.run_script_from_command("G28") self.gcode.run_script_from_command("G28")
self.probe_helper.start_probe() self.probe_helper.start_probe()
def get_probed_position(self): def probe_finalize(self, offsets, positions):
kin = self.printer.lookup_object('toolhead').get_kinematics()
return kin.calc_position()
def finalize(self, offsets, positions):
z_offset = offsets[2] z_offset = offsets[2]
logging.info("Calculating bed_tilt with: %s", positions) logging.info("Calculating bed_tilt with: %s", positions)
params = { 'x_adjust': self.bedtilt.x_adjust, params = { 'x_adjust': self.bedtilt.x_adjust,

View File

@ -142,7 +142,7 @@ class DeltaCalibrate:
dist = radius * scatter[i] dist = radius * scatter[i]
points.append((math.cos(r) * dist, math.sin(r) * dist)) points.append((math.cos(r) * dist, math.sin(r) * dist))
self.probe_helper = probe.ProbePointsHelper( self.probe_helper = probe.ProbePointsHelper(
config, self, default_points=points) config, self.probe_finalize, default_points=points)
# Restore probe stable positions # Restore probe stable positions
self.last_probe_positions = [] self.last_probe_positions = []
for i in range(999): for i in range(999):
@ -192,10 +192,7 @@ class DeltaCalibrate:
"%.3f,%.3f,%.3f" % tuple(spos1)) "%.3f,%.3f,%.3f" % tuple(spos1))
configfile.set(section, "distance%d_pos2" % (i,), configfile.set(section, "distance%d_pos2" % (i,),
"%.3f,%.3f,%.3f" % tuple(spos2)) "%.3f,%.3f,%.3f" % tuple(spos2))
def get_probed_position(self): def probe_finalize(self, offsets, positions):
kin = self.printer.lookup_object('toolhead').get_kinematics()
return kin.calc_position()
def finalize(self, offsets, positions):
# Convert positions into (z_offset, stable_position) pairs # Convert positions into (z_offset, stable_position) pairs
z_offset = offsets[2] z_offset = offsets[2]
kin = self.printer.lookup_object('toolhead').get_kinematics() kin = self.printer.lookup_object('toolhead').get_kinematics()

View File

@ -136,9 +136,9 @@ class ProbeVirtualEndstop:
# Helper code that can probe a series of points and report the # Helper code that can probe a series of points and report the
# position at each point. # position at each point.
class ProbePointsHelper: 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.printer = config.get_printer()
self.callback = callback self.finalize_callback = finalize_callback
self.probe_points = default_points self.probe_points = default_points
# Read config settings # Read config settings
if default_points is None or config.get('points', None) is not None: 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() return self.probe.last_home_position()
else: else:
return None return None
def get_probed_position(self):
return self.toolhead.get_kinematics().calc_position()
def lift_z(self, z_pos, add=False, speed=None): def lift_z(self, z_pos, add=False, speed=None):
# Lift toolhead # Lift toolhead
curpos = self.toolhead.get_position() curpos = self.toolhead.get_position()
@ -201,7 +203,7 @@ class ProbePointsHelper:
for i in range(self.samples): for i in range(self.samples):
self.gcode.run_script_from_command("PROBE") self.gcode.run_script_from_command("PROBE")
self.toolhead.wait_moves() self.toolhead.wait_moves()
self.results.append(self.callback.get_probed_position()) self.results.append(self.get_probed_position())
if i < self.samples - 1: if i < self.samples - 1:
# retract # retract
self.lift_z(self.sample_retract_dist, add=True) self.lift_z(self.sample_retract_dist, add=True)
@ -243,7 +245,7 @@ class ProbePointsHelper:
if self.probe is None: if self.probe is None:
# Record current position for manual probe # Record current position for manual probe
self.toolhead.wait_moves() self.toolhead.wait_moves()
self.results.append(self.callback.get_probed_position()) self.results.append(self.get_probed_position())
# Lift toolhead # Lift toolhead
self.lift_z(self.horizontal_move_z) self.lift_z(self.horizontal_move_z)
# Move to next position # Move to next position
@ -257,7 +259,7 @@ class ProbePointsHelper:
self.gcode.reset_last_position() self.gcode.reset_last_position()
self.gcode.register_command('NEXT', None) self.gcode.register_command('NEXT', None)
if success: if success:
self.callback.finalize(self.probe_offsets, self.results) self.finalize_callback(self.probe_offsets, self.results)
def load_config(config): def load_config(config):
return PrinterProbe(config) return PrinterProbe(config)

View File

@ -9,7 +9,7 @@ import probe
class QuadGantryLevel: class QuadGantryLevel:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() 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') gantry_corners = config.get('gantry_corners').split('\n')
try: try:
gantry_corners = [line.split(',', 1) 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" cmd_QUAD_GANTRY_LEVEL_help = "Conform a moving, twistable gantry to the shape of a stationary bed"
def cmd_QUAD_GANTRY_LEVEL(self, params): def cmd_QUAD_GANTRY_LEVEL(self, params):
self.probe_helper.start_probe() 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): def squash_positions(self,positions):
# Group multi-probe data and average out the Z readings # Group multi-probe data and average out the Z readings
# Assumes samples come in sequentially # Assumes samples come in sequentially
@ -55,7 +52,7 @@ class QuadGantryLevel:
for id,pos in enumerate(grouped_pos): for id,pos in enumerate(grouped_pos):
grouped_pos[id][2] = sum(grouped_pos[id][2]) / len(grouped_pos[id][2]) grouped_pos[id][2] = sum(grouped_pos[id][2]) / len(grouped_pos[id][2])
return grouped_pos return grouped_pos
def finalize(self, offsets, positions): def probe_finalize(self, offsets, positions):
if len(positions) > 4: if len(positions) > 4:
positions = self.squash_positions(positions) positions = self.squash_positions(positions)
logging.info("quad_gantry_level Calculating gantry geometry with: %s", positions) logging.info("quad_gantry_level Calculating gantry geometry with: %s", positions)

View File

@ -20,7 +20,7 @@ class ZTilt:
config.get_name())) config.get_name()))
if len(z_positions) < 2: if len(z_positions) < 2:
raise config.error("z_tilt requires at least two z_positions") 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 = [] self.z_steppers = []
# Register Z_TILT_ADJUST command # Register Z_TILT_ADJUST command
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
@ -40,10 +40,7 @@ class ZTilt:
cmd_Z_TILT_ADJUST_help = "Adjust the Z tilt" cmd_Z_TILT_ADJUST_help = "Adjust the Z tilt"
def cmd_Z_TILT_ADJUST(self, params): def cmd_Z_TILT_ADJUST(self, params):
self.probe_helper.start_probe() self.probe_helper.start_probe()
def get_probed_position(self): def probe_finalize(self, offsets, positions):
kin = self.printer.lookup_object('toolhead').get_kinematics()
return kin.calc_position()
def finalize(self, offsets, positions):
z_offset = offsets[2] z_offset = offsets[2]
logging.info("Calculating bed tilt with: %s", positions) logging.info("Calculating bed tilt with: %s", positions)
params = { 'x_adjust': 0., 'y_adjust': 0., 'z_adjust': z_offset } params = { 'x_adjust': 0., 'y_adjust': 0., 'z_adjust': z_offset }