mirror of https://github.com/Desuuuu/klipper.git
probe: Separate out manual probing from automatic probing code
Only call cmd_NEXT() for manual probing. This simplifies the code as the automatic probing and manual probing have slightly different probing mechanisms. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
cb3fede19a
commit
e5ef15ad0f
|
@ -183,9 +183,7 @@ 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):
|
def _lift_z(self, z_pos, add=False, speed=None):
|
||||||
return self.toolhead.get_kinematics().calc_position()
|
|
||||||
def lift_z(self, z_pos, add=False, speed=None):
|
|
||||||
# Lift toolhead
|
# Lift toolhead
|
||||||
curpos = self.toolhead.get_position()
|
curpos = self.toolhead.get_position()
|
||||||
if add:
|
if add:
|
||||||
|
@ -197,10 +195,19 @@ class ProbePointsHelper:
|
||||||
try:
|
try:
|
||||||
self.toolhead.move(curpos, speed)
|
self.toolhead.move(curpos, 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 move_next(self):
|
def _move_next(self):
|
||||||
x, y = self.probe_points[len(self.results)/self.samples]
|
# Lift toolhead
|
||||||
|
self._lift_z(self.horizontal_move_z)
|
||||||
|
# Check if done probing
|
||||||
|
point_num = len(self.results) // self.samples
|
||||||
|
if point_num >= len(self.probe_points):
|
||||||
|
self.toolhead.get_last_move_time()
|
||||||
|
self._finalize(True)
|
||||||
|
return
|
||||||
|
# Move to next XY probe point
|
||||||
|
x, y = self.probe_points[point_num]
|
||||||
curpos = self.toolhead.get_position()
|
curpos = self.toolhead.get_position()
|
||||||
curpos[0] = x
|
curpos[0] = x
|
||||||
curpos[1] = y
|
curpos[1] = y
|
||||||
|
@ -208,53 +215,46 @@ class ProbePointsHelper:
|
||||||
try:
|
try:
|
||||||
self.toolhead.move(curpos, self.speed)
|
self.toolhead.move(curpos, self.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))
|
||||||
self.gcode.reset_last_position()
|
self.gcode.reset_last_position()
|
||||||
def probe_point(self):
|
def _automatic_probe_point(self):
|
||||||
for i in range(self.samples):
|
for i in range(self.samples):
|
||||||
self.gcode.run_script_from_command("PROBE")
|
try:
|
||||||
self.toolhead.wait_moves()
|
self.gcode.run_script_from_command("PROBE")
|
||||||
self.results.append(self.get_probed_position())
|
except self.gcode.error as e:
|
||||||
|
self._finalize(False)
|
||||||
|
raise
|
||||||
|
self.results.append(self.toolhead.get_position()[:3])
|
||||||
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)
|
||||||
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')
|
||||||
self.gcode = self.printer.lookup_object('gcode')
|
self.gcode = self.printer.lookup_object('gcode')
|
||||||
# Unregister NEXT command in case we are starting over from an
|
|
||||||
# unfinalized calibration
|
|
||||||
self.gcode.register_command('NEXT', None)
|
|
||||||
self.gcode.register_command(
|
|
||||||
'NEXT', self.cmd_NEXT, desc=self.cmd_NEXT_help)
|
|
||||||
self.results = []
|
self.results = []
|
||||||
self.busy = True
|
self.busy = True
|
||||||
self.lift_z(self.horizontal_move_z, speed=self.speed)
|
self._lift_z(self.horizontal_move_z, speed=self.speed)
|
||||||
self.move_next()
|
self._move_next()
|
||||||
if self.probe is not None:
|
if self.probe is None:
|
||||||
try:
|
# Setup for manual probing
|
||||||
while self.busy:
|
self.gcode.register_command('NEXT', None)
|
||||||
self.probe_point()
|
self.gcode.register_command('NEXT', self.cmd_NEXT,
|
||||||
self.cmd_NEXT({})
|
desc=self.cmd_NEXT_help)
|
||||||
except:
|
else:
|
||||||
self.finalize(False)
|
# Perform automatic probing
|
||||||
raise
|
while self.busy:
|
||||||
|
self._automatic_probe_point()
|
||||||
|
self._move_next()
|
||||||
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):
|
||||||
if self.probe is None:
|
# Record current position for manual probe
|
||||||
# Record current position for manual probe
|
self.toolhead.get_last_move_time()
|
||||||
self.toolhead.wait_moves()
|
self.results.append(self.toolhead.get_kinematics().calc_position())
|
||||||
self.results.append(self.get_probed_position())
|
|
||||||
# Lift toolhead
|
|
||||||
self.lift_z(self.horizontal_move_z)
|
|
||||||
# Move to next position
|
# Move to next position
|
||||||
if len(self.results) / self.samples == len(self.probe_points):
|
self._move_next()
|
||||||
self.toolhead.get_last_move_time()
|
def _finalize(self, success):
|
||||||
self.finalize(True)
|
|
||||||
return
|
|
||||||
self.move_next()
|
|
||||||
def finalize(self, success):
|
|
||||||
self.busy = False
|
self.busy = False
|
||||||
self.gcode.reset_last_position()
|
self.gcode.reset_last_position()
|
||||||
self.gcode.register_command('NEXT', None)
|
self.gcode.register_command('NEXT', None)
|
||||||
|
|
Loading…
Reference in New Issue