probe: Simplify ProbePointsHelper start and end tracking
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
bbc8637ed6
commit
15011012e5
|
@ -246,6 +246,7 @@ class ProbePointsHelper:
|
||||||
self.finalize_callback = finalize_callback
|
self.finalize_callback = finalize_callback
|
||||||
self.probe_points = default_points
|
self.probe_points = default_points
|
||||||
self.name = config.get_name()
|
self.name = config.get_name()
|
||||||
|
self.gcode = self.printer.lookup_object('gcode')
|
||||||
# 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:
|
||||||
points = config.get('points').split('\n')
|
points = config.get('points').split('\n')
|
||||||
|
@ -257,93 +258,77 @@ class ProbePointsHelper:
|
||||||
raise config.error("Unable to parse probe points in %s" % (
|
raise config.error("Unable to parse probe points in %s" % (
|
||||||
self.name))
|
self.name))
|
||||||
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
|
self.horizontal_move_z = config.getfloat('horizontal_move_z', 5.)
|
||||||
self.speed = self.lift_speed = config.getfloat('speed', 50., above=0.)
|
self.speed = config.getfloat('speed', 50., above=0.)
|
||||||
self.probe_offsets = (0., 0., 0.)
|
|
||||||
# Internal probing state
|
# Internal probing state
|
||||||
|
self.lift_speed = self.speed
|
||||||
|
self.probe_offsets = (0., 0., 0.)
|
||||||
self.results = []
|
self.results = []
|
||||||
self.busy = self.manual_probe = False
|
|
||||||
self.gcode = self.toolhead = None
|
|
||||||
def minimum_points(self,n):
|
def minimum_points(self,n):
|
||||||
if len(self.probe_points) < n:
|
if len(self.probe_points) < n:
|
||||||
raise self.printer.config_error(
|
raise self.printer.config_error(
|
||||||
"Need at least %d probe points for %s" % (n, self.name))
|
"Need at least %d probe points for %s" % (n, self.name))
|
||||||
def get_lift_speed(self):
|
def get_lift_speed(self):
|
||||||
return self.lift_speed
|
return self.lift_speed
|
||||||
def _lift_z(self, z_pos, speed):
|
|
||||||
# Lift toolhead
|
|
||||||
curpos = self.toolhead.get_position()
|
|
||||||
curpos[2] = z_pos
|
|
||||||
try:
|
|
||||||
self.toolhead.move(curpos, speed)
|
|
||||||
except homing.EndstopError as e:
|
|
||||||
self._finalize(False)
|
|
||||||
raise self.gcode.error(str(e))
|
|
||||||
self.gcode.reset_last_position()
|
|
||||||
def _move_next(self):
|
def _move_next(self):
|
||||||
|
toolhead = self.printer.lookup_object('toolhead')
|
||||||
# Lift toolhead
|
# Lift toolhead
|
||||||
self._lift_z(self.horizontal_move_z, self.lift_speed)
|
speed = self.lift_speed
|
||||||
# Check if done probing
|
if not self.results:
|
||||||
if len(self.results) >= len(self.probe_points):
|
# Use full speed to first probe position
|
||||||
self.toolhead.get_last_move_time()
|
speed = self.speed
|
||||||
self._finalize(True)
|
curpos = toolhead.get_position()
|
||||||
return
|
|
||||||
# Move to next XY probe point
|
|
||||||
x, y = self.probe_points[len(self.results)]
|
|
||||||
curpos = self.toolhead.get_position()
|
|
||||||
curpos[0] = x
|
|
||||||
curpos[1] = y
|
|
||||||
curpos[2] = self.horizontal_move_z
|
curpos[2] = self.horizontal_move_z
|
||||||
try:
|
try:
|
||||||
self.toolhead.move(curpos, self.speed)
|
toolhead.move(curpos, speed)
|
||||||
|
except homing.EndstopError as e:
|
||||||
|
raise self.gcode.error(str(e))
|
||||||
|
# Check if done probing
|
||||||
|
if len(self.results) >= len(self.probe_points):
|
||||||
|
self.gcode.reset_last_position()
|
||||||
|
toolhead.get_last_move_time()
|
||||||
|
self.finalize_callback(self.probe_offsets, self.results)
|
||||||
|
return True
|
||||||
|
# Move to next XY probe point
|
||||||
|
curpos[:2] = self.probe_points[len(self.results)]
|
||||||
|
try:
|
||||||
|
toolhead.move(curpos, self.speed)
|
||||||
except homing.EndstopError as e:
|
except homing.EndstopError as e:
|
||||||
self._finalize(False)
|
|
||||||
raise self.gcode.error(str(e))
|
raise self.gcode.error(str(e))
|
||||||
self.gcode.reset_last_position()
|
self.gcode.reset_last_position()
|
||||||
if self.manual_probe:
|
return False
|
||||||
manual_probe.ManualProbeHelper(self.printer, {},
|
|
||||||
self._manual_probe_finalize)
|
|
||||||
def start_probe(self, params):
|
def start_probe(self, params):
|
||||||
# Lookup objects
|
# Lookup objects
|
||||||
self.toolhead = self.printer.lookup_object('toolhead')
|
|
||||||
self.gcode = self.printer.lookup_object('gcode')
|
|
||||||
probe = self.printer.lookup_object('probe', None)
|
probe = self.printer.lookup_object('probe', None)
|
||||||
method = self.gcode.get_str('METHOD', params, 'automatic').lower()
|
method = self.gcode.get_str('METHOD', params, 'automatic').lower()
|
||||||
if probe is not None and method == 'automatic':
|
self.results = []
|
||||||
self.manual_probe = False
|
if probe is None or method != 'automatic':
|
||||||
self.lift_speed = min(self.speed, probe.speed)
|
# Manual probe
|
||||||
self.probe_offsets = probe.get_offsets()
|
|
||||||
if self.horizontal_move_z < self.probe_offsets[2]:
|
|
||||||
raise self.gcode.error("horizontal_move_z can't be less than"
|
|
||||||
" probe's z_offset")
|
|
||||||
else:
|
|
||||||
self.manual_probe = True
|
|
||||||
self.lift_speed = self.speed
|
self.lift_speed = self.speed
|
||||||
self.probe_offsets = (0., 0., 0.)
|
self.probe_offsets = (0., 0., 0.)
|
||||||
# Start probe
|
self._manual_probe_start()
|
||||||
self.results = []
|
return
|
||||||
self.busy = True
|
# Perform automatic probing
|
||||||
self._lift_z(self.horizontal_move_z, self.speed)
|
self.lift_speed = min(self.speed, probe.speed)
|
||||||
self._move_next()
|
self.probe_offsets = probe.get_offsets()
|
||||||
if not self.manual_probe:
|
if self.horizontal_move_z < self.probe_offsets[2]:
|
||||||
# Perform automatic probing
|
raise self.gcode.error("horizontal_move_z can't be less than"
|
||||||
while self.busy:
|
" probe's z_offset")
|
||||||
try:
|
while 1:
|
||||||
pos = probe.run_probe()
|
done = self._move_next()
|
||||||
except self.gcode.error as e:
|
if done:
|
||||||
self._finalize(False)
|
break
|
||||||
raise
|
pos = probe.run_probe()
|
||||||
self.results.append(pos)
|
self.results.append(pos)
|
||||||
self._move_next()
|
def _manual_probe_start(self):
|
||||||
|
done = self._move_next()
|
||||||
|
if not done:
|
||||||
|
manual_probe.ManualProbeHelper(self.printer, {},
|
||||||
|
self._manual_probe_finalize)
|
||||||
def _manual_probe_finalize(self, kin_pos):
|
def _manual_probe_finalize(self, kin_pos):
|
||||||
if kin_pos is None:
|
if kin_pos is None:
|
||||||
self._finalize(False)
|
|
||||||
return
|
return
|
||||||
self.results.append(kin_pos)
|
self.results.append(kin_pos)
|
||||||
self._move_next()
|
self._manual_probe_start()
|
||||||
def _finalize(self, success):
|
|
||||||
self.busy = False
|
|
||||||
if success:
|
|
||||||
self.finalize_callback(self.probe_offsets, self.results)
|
|
||||||
|
|
||||||
def load_config(config):
|
def load_config(config):
|
||||||
return PrinterProbe(config, ProbeEndstopWrapper(config))
|
return PrinterProbe(config, ProbeEndstopWrapper(config))
|
||||||
|
|
Loading…
Reference in New Issue