probe: Add ability to multi-sample points to ProbePointsHelper
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
1588426229
commit
40b7ba5111
|
@ -129,3 +129,9 @@ radius: 50
|
||||||
# NEXT extended g-code command to record the position at that
|
# NEXT extended g-code command to record the position at that
|
||||||
# point. The default is false if a [probe] config section is present
|
# point. The default is false if a [probe] config section is present
|
||||||
# and true otherwise.
|
# and true otherwise.
|
||||||
|
#samples: 1
|
||||||
|
# The number of times to probe each point. The probed z-values
|
||||||
|
# will be averaged. The default is to probe 1 time.
|
||||||
|
#sample_retract_dist: 2.0
|
||||||
|
# The distance (in mm) to retract between each sample if
|
||||||
|
# sampling more than once. Default is 2mm.
|
||||||
|
|
|
@ -69,6 +69,12 @@
|
||||||
# NEXT extended g-code command to record the position at that
|
# NEXT extended g-code command to record the position at that
|
||||||
# point. The default is false if a [probe] config section is present
|
# point. The default is false if a [probe] config section is present
|
||||||
# and true otherwise.
|
# and true otherwise.
|
||||||
|
#samples: 1
|
||||||
|
# The number of times to probe each point. The probed z-values
|
||||||
|
# will be averaged. The default is to probe 1 time.
|
||||||
|
#sample_retract_dist: 2.0
|
||||||
|
# The distance (in mm) to retract between each sample if
|
||||||
|
# sampling more than once. Default is 2mm.
|
||||||
|
|
||||||
|
|
||||||
# Mesh Bed Leveling. One may define a [bed_mesh] config section
|
# Mesh Bed Leveling. One may define a [bed_mesh] config section
|
||||||
|
@ -82,6 +88,12 @@
|
||||||
#horizontal_move_z: 5
|
#horizontal_move_z: 5
|
||||||
# The height (in mm) that the head should be commanded to move to
|
# The height (in mm) that the head should be commanded to move to
|
||||||
# just prior to starting a probe operation. The default is 5.
|
# just prior to starting a probe operation. The default is 5.
|
||||||
|
#samples: 1
|
||||||
|
# The number of times to probe each point. The probed z-values
|
||||||
|
# will be averaged. The default is to probe 1 time.
|
||||||
|
#sample_retract_dist: 2.0
|
||||||
|
# The distance (in mm) to retract between each sample if
|
||||||
|
# sampling more than once. Default is 2mm.
|
||||||
#min_point:
|
#min_point:
|
||||||
# An X,Y point defining the minimum coordinate to probe on
|
# An X,Y point defining the minimum coordinate to probe on
|
||||||
# the bed. Note that this refers to the nozzle position,
|
# the bed. Note that this refers to the nozzle position,
|
||||||
|
@ -150,7 +162,12 @@
|
||||||
#horizontal_move_z: 5
|
#horizontal_move_z: 5
|
||||||
# The height (in mm) that the head should be commanded to move to
|
# The height (in mm) that the head should be commanded to move to
|
||||||
# just prior to starting a probe operation. The default is 5.
|
# just prior to starting a probe operation. The default is 5.
|
||||||
|
#samples: 1
|
||||||
|
# The number of times to probe each point. The probed z-values
|
||||||
|
# will be averaged. The default is to probe 1 time.
|
||||||
|
#sample_retract_dist: 2.0
|
||||||
|
# The distance (in mm) to retract between each sample if
|
||||||
|
# sampling more than once. Default is 2mm.
|
||||||
|
|
||||||
# In a multi-extruder printer add an additional extruder section for
|
# In a multi-extruder printer add an additional extruder section for
|
||||||
# each additional extruder. The additional extruder sections should be
|
# each additional extruder. The additional extruder sections should be
|
||||||
|
|
|
@ -245,9 +245,15 @@ class BedMeshCalibrate:
|
||||||
# create a 2-D array representing the probed z-positions.
|
# create a 2-D array representing the probed z-positions.
|
||||||
self.probed_z_table = [
|
self.probed_z_table = [
|
||||||
[0. for i in range(x_cnt)] for j in range(y_cnt)]
|
[0. for i in range(x_cnt)] for j in range(y_cnt)]
|
||||||
# Extract probed z-positions from probed positions and add
|
# Check for multi-sampled points
|
||||||
# them to organized list
|
z_table_len = x_cnt * y_cnt
|
||||||
for i, pos in enumerate(positions):
|
if len(positions) % z_table_len:
|
||||||
|
raise self.gcode.error(
|
||||||
|
("bed_mesh: Invalid probe table length:\n"
|
||||||
|
"Sampled table length: %d") % len(positions))
|
||||||
|
samples = len(positions) / z_table_len
|
||||||
|
# Populate the organized probed table
|
||||||
|
for i in range(z_table_len):
|
||||||
y_position = i / x_cnt
|
y_position = i / x_cnt
|
||||||
x_position = 0
|
x_position = 0
|
||||||
if y_position & 1 == 0:
|
if y_position & 1 == 0:
|
||||||
|
@ -256,8 +262,11 @@ class BedMeshCalibrate:
|
||||||
else:
|
else:
|
||||||
# Odd y count, x probed in the negative directon
|
# Odd y count, x probed in the negative directon
|
||||||
x_position = (x_cnt - 1) - (i % x_cnt)
|
x_position = (x_cnt - 1) - (i % x_cnt)
|
||||||
|
idx = i * samples
|
||||||
|
end = idx + samples
|
||||||
|
avg_z = sum(p[2] for p in positions[idx:end]) / samples
|
||||||
self.probed_z_table[y_position][x_position] = \
|
self.probed_z_table[y_position][x_position] = \
|
||||||
pos[2] - z_offset
|
avg_z - z_offset
|
||||||
if self.build_map:
|
if self.build_map:
|
||||||
outdict = {'z_probe_offsets:': self.probed_z_table}
|
outdict = {'z_probe_offsets:': self.probed_z_table}
|
||||||
self.gcode.respond(json.dumps(outdict))
|
self.gcode.respond(json.dumps(outdict))
|
||||||
|
|
|
@ -158,6 +158,9 @@ class ProbePointsHelper:
|
||||||
# Lookup probe object
|
# Lookup probe object
|
||||||
self.probe = None
|
self.probe = None
|
||||||
self.probe_offsets = (0., 0., 0.)
|
self.probe_offsets = (0., 0., 0.)
|
||||||
|
self.samples = config.getint('samples', 1, minval=1)
|
||||||
|
self.sample_retract_dist = config.getfloat(
|
||||||
|
'sample_retract_dist', 2., above=0.)
|
||||||
manual_probe = config.getboolean('manual_probe', None)
|
manual_probe = config.getboolean('manual_probe', None)
|
||||||
if manual_probe is None:
|
if manual_probe is None:
|
||||||
manual_probe = not config.has_section('probe')
|
manual_probe = not config.has_section('probe')
|
||||||
|
@ -180,15 +183,26 @@ class ProbePointsHelper:
|
||||||
return self.probe.last_home_position()
|
return self.probe.last_home_position()
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
def lift_z(self, z_pos):
|
def lift_z(self, z_pos, add=False):
|
||||||
# Lift toolhead
|
# Lift toolhead
|
||||||
curpos = self.toolhead.get_position()
|
curpos = self.toolhead.get_position()
|
||||||
curpos[2] = z_pos
|
if add:
|
||||||
|
curpos[2] += z_pos
|
||||||
|
else:
|
||||||
|
curpos[2] = z_pos
|
||||||
try:
|
try:
|
||||||
self.toolhead.move(curpos, self.lift_speed)
|
self.toolhead.move(curpos, self.lift_speed)
|
||||||
except homing.EndstopError as e:
|
except homing.EndstopError as e:
|
||||||
self.finalize(False)
|
self.finalize(False)
|
||||||
raise self.gcode.error(str(e))
|
raise self.gcode.error(str(e))
|
||||||
|
def probe_point(self):
|
||||||
|
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())
|
||||||
|
if i < self.samples - 1:
|
||||||
|
# retract
|
||||||
|
self.lift_z(self.sample_retract_dist, add=True)
|
||||||
def start_probe(self):
|
def start_probe(self):
|
||||||
# Begin probing
|
# Begin probing
|
||||||
self.toolhead = self.printer.lookup_object('toolhead')
|
self.toolhead = self.printer.lookup_object('toolhead')
|
||||||
|
@ -205,13 +219,13 @@ class ProbePointsHelper:
|
||||||
if self.probe is not None:
|
if self.probe is not None:
|
||||||
try:
|
try:
|
||||||
while self.busy:
|
while self.busy:
|
||||||
self.gcode.run_script_from_command("PROBE")
|
self.probe_point()
|
||||||
self.cmd_NEXT({})
|
self.cmd_NEXT({})
|
||||||
except:
|
except:
|
||||||
self.finalize(False)
|
self.finalize(False)
|
||||||
raise
|
raise
|
||||||
def move_next(self):
|
def move_next(self):
|
||||||
x, y = self.probe_points[len(self.results)]
|
x, y = self.probe_points[len(self.results)/self.samples]
|
||||||
curpos = self.toolhead.get_position()
|
curpos = self.toolhead.get_position()
|
||||||
curpos[0] = x
|
curpos[0] = x
|
||||||
curpos[1] = y
|
curpos[1] = y
|
||||||
|
@ -224,13 +238,14 @@ class ProbePointsHelper:
|
||||||
self.gcode.reset_last_position()
|
self.gcode.reset_last_position()
|
||||||
cmd_NEXT_help = "Move to the next XY position to probe"
|
cmd_NEXT_help = "Move to the next XY position to probe"
|
||||||
def cmd_NEXT(self, params):
|
def cmd_NEXT(self, params):
|
||||||
# Record current position
|
if self.probe is None:
|
||||||
self.toolhead.wait_moves()
|
# Record current position for manual probe
|
||||||
self.results.append(self.callback.get_probed_position())
|
self.toolhead.wait_moves()
|
||||||
|
self.results.append(self.callback.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
|
||||||
if len(self.results) == len(self.probe_points):
|
if len(self.results) / self.samples == len(self.probe_points):
|
||||||
self.toolhead.get_last_move_time()
|
self.toolhead.get_last_move_time()
|
||||||
self.finalize(True)
|
self.finalize(True)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue