probe: Move code from bed_tilt and delta_calibrate into ProbePointsHelper
Move the common config reading and probe object lookup from the bed_tilt.py and delta_calibrate.py code into the ProbePointsHelper class. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
11816295e7
commit
c5bff88943
|
@ -31,26 +31,15 @@ class BedTilt:
|
|||
# Helper script to calibrate the bed tilt
|
||||
class BedTiltCalibrate:
|
||||
def __init__(self, config, bedtilt):
|
||||
self.bedtilt = bedtilt
|
||||
self.printer = config.get_printer()
|
||||
points = config.get('points').split('\n')
|
||||
try:
|
||||
points = [line.split(',', 1) for line in points if line.strip()]
|
||||
self.points = [(float(p[0].strip()), float(p[1].strip()))
|
||||
for p in points]
|
||||
except:
|
||||
raise config.error("Unable to parse bed tilt points")
|
||||
if len(self.points) < 3:
|
||||
raise config.error("Need at least 3 points for bed_tilt_calibrate")
|
||||
self.speed = config.getfloat('speed', 50., above=0.)
|
||||
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
|
||||
self.bedtilt = bedtilt
|
||||
self.probe_helper = probe.ProbePointsHelper(config, self)
|
||||
# Automatic probe:z_virtual_endstop XY detection
|
||||
self.z_position_endstop = None
|
||||
if config.has_section('stepper_z'):
|
||||
zconfig = config.getsection('stepper_z')
|
||||
self.z_position_endstop = zconfig.getfloat('position_endstop', None)
|
||||
self.manual_probe = config.getboolean('manual_probe', None)
|
||||
if self.manual_probe is None:
|
||||
self.manual_probe = not config.has_section('probe')
|
||||
# Register BED_TILT_CALIBRATE command
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command(
|
||||
'BED_TILT_CALIBRATE', self.cmd_BED_TILT_CALIBRATE,
|
||||
|
@ -58,9 +47,7 @@ class BedTiltCalibrate:
|
|||
cmd_BED_TILT_CALIBRATE_help = "Bed tilt calibration script"
|
||||
def cmd_BED_TILT_CALIBRATE(self, params):
|
||||
self.gcode.run_script("G28")
|
||||
probe.ProbePointsHelper(
|
||||
self.printer, self.points, self.horizontal_move_z,
|
||||
self.speed, self.manual_probe, self)
|
||||
self.probe_helper.start_probe()
|
||||
def get_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.get_position()
|
||||
|
|
|
@ -11,29 +11,25 @@ class DeltaCalibrate:
|
|||
self.printer = config.get_printer()
|
||||
if config.getsection('printer').get('kinematics') != 'delta':
|
||||
raise config.error("Delta calibrate is only for delta printers")
|
||||
self.radius = config.getfloat('radius', above=0.)
|
||||
self.speed = config.getfloat('speed', 50., above=0.)
|
||||
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
|
||||
self.manual_probe = config.getboolean('manual_probe', None)
|
||||
if self.manual_probe is None:
|
||||
self.manual_probe = not config.has_section('probe')
|
||||
# Calculate default probing points
|
||||
radius = config.getfloat('radius', above=0.)
|
||||
points = [(0., 0.)]
|
||||
scatter = [.95, .90, .85, .70, .75, .80]
|
||||
for i in range(6):
|
||||
r = math.radians(90. + 60. * i)
|
||||
dist = radius * scatter[i]
|
||||
points.append((math.cos(r) * dist, math.sin(r) * dist))
|
||||
self.probe_helper = probe.ProbePointsHelper(
|
||||
config, self, default_points=points)
|
||||
# Register DELTA_CALIBRATE command
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command(
|
||||
'DELTA_CALIBRATE', self.cmd_DELTA_CALIBRATE,
|
||||
desc=self.cmd_DELTA_CALIBRATE_help)
|
||||
cmd_DELTA_CALIBRATE_help = "Delta calibration script"
|
||||
def cmd_DELTA_CALIBRATE(self, params):
|
||||
# Setup probe points
|
||||
points = [(0., 0.)]
|
||||
scatter = [.95, .90, .85, .70, .75, .80]
|
||||
for i in range(6):
|
||||
r = math.radians(90. + 60. * i)
|
||||
dist = self.radius * scatter[i]
|
||||
points.append((math.cos(r) * dist, math.sin(r) * dist))
|
||||
# Probe them
|
||||
self.gcode.run_script("G28")
|
||||
probe.ProbePointsHelper(self.printer, points, self.horizontal_move_z,
|
||||
self.speed, self.manual_probe, self)
|
||||
self.probe_helper.start_probe()
|
||||
def get_position(self):
|
||||
kin = self.printer.lookup_object('toolhead').get_kinematics()
|
||||
return kin.get_stable_position()
|
||||
|
|
|
@ -132,26 +132,50 @@ class ProbeVirtualEndstop:
|
|||
# Helper code that can probe a series of points and report the
|
||||
# position at each point.
|
||||
class ProbePointsHelper:
|
||||
def __init__(self, printer, probe_points, horizontal_move_z, speed,
|
||||
manual_probe, callback):
|
||||
self.printer = printer
|
||||
self.probe_points = probe_points
|
||||
self.horizontal_move_z = horizontal_move_z
|
||||
self.speed = self.lift_speed = speed
|
||||
self.manual_probe = manual_probe
|
||||
def __init__(self, config, callback, default_points=None):
|
||||
self.printer = config.get_printer()
|
||||
self.callback = callback
|
||||
self.toolhead = self.printer.lookup_object('toolhead')
|
||||
self.probe_points = default_points
|
||||
# Read config settings
|
||||
if default_points is None or config.get('points', None) is not None:
|
||||
points = config.get('points').split('\n')
|
||||
try:
|
||||
points = [line.split(',', 1) for line in points if line.strip()]
|
||||
self.probe_points = [(float(p[0].strip()), float(p[1].strip()))
|
||||
for p in points]
|
||||
except:
|
||||
raise config.error("Unable to parse probe points in %s" % (
|
||||
config.get_name()))
|
||||
if len(self.probe_points) < 3:
|
||||
raise config.error("Need at least 3 points for %s" % (
|
||||
config.get_name()))
|
||||
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
|
||||
self.speed = self.lift_speed = config.getfloat('speed', 50., above=0.)
|
||||
# Lookup probe object
|
||||
self.probe = None
|
||||
self.probe_z_offset = 0.
|
||||
manual_probe = config.getboolean('manual_probe', None)
|
||||
if manual_probe is None:
|
||||
manual_probe = not config.has_section('probe')
|
||||
if not manual_probe:
|
||||
self.printer.try_load_module(config, 'probe')
|
||||
self.probe = self.printer.lookup_object('probe')
|
||||
self.lift_speed = min(self.speed, self.probe.speed)
|
||||
self.probe_z_offset = self.probe.z_offset
|
||||
# Internal probing state
|
||||
self.results = []
|
||||
self.busy = True
|
||||
self.busy = False
|
||||
self.gcode = self.toolhead = None
|
||||
def start_probe(self):
|
||||
# Begin probing
|
||||
self.toolhead = self.printer.lookup_object('toolhead')
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_command(
|
||||
'NEXT', self.cmd_NEXT, desc=self.cmd_NEXT_help)
|
||||
# Begin probing
|
||||
self.results = []
|
||||
self.busy = True
|
||||
self.move_next()
|
||||
if not manual_probe:
|
||||
probe = self.printer.lookup_object('probe', None)
|
||||
if probe is not None:
|
||||
self.lift_speed = min(self.lift_speed, probe.speed)
|
||||
if self.probe is not None:
|
||||
while self.busy:
|
||||
self.gcode.run_script("PROBE")
|
||||
self.cmd_NEXT({})
|
||||
|
@ -183,11 +207,7 @@ class ProbePointsHelper:
|
|||
self.gcode.reset_last_position()
|
||||
self.gcode.register_command('NEXT', None)
|
||||
if success:
|
||||
z_offset = 0.
|
||||
if not self.manual_probe:
|
||||
probe = self.printer.lookup_object('probe')
|
||||
z_offset = probe.z_offset
|
||||
self.callback.finalize(z_offset, self.results)
|
||||
self.callback.finalize(self.probe_z_offset, self.results)
|
||||
|
||||
def load_config(config):
|
||||
return PrinterProbe(config)
|
||||
|
|
Loading…
Reference in New Issue