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:
Kevin O'Connor 2018-09-26 11:25:56 -04:00 committed by KevinOConnor
parent cb3fede19a
commit e5ef15ad0f
1 changed files with 39 additions and 39 deletions

View File

@ -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):
try:
self.gcode.run_script_from_command("PROBE") self.gcode.run_script_from_command("PROBE")
self.toolhead.wait_moves() except self.gcode.error as e:
self.results.append(self.get_probed_position()) 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
self.gcode.register_command('NEXT', None)
self.gcode.register_command('NEXT', self.cmd_NEXT,
desc=self.cmd_NEXT_help)
else:
# Perform automatic probing
while self.busy: while self.busy:
self.probe_point() self._automatic_probe_point()
self.cmd_NEXT({}) self._move_next()
except:
self.finalize(False)
raise
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.wait_moves()
self.results.append(self.get_probed_position())
# Lift toolhead
self.lift_z(self.horizontal_move_z)
# Move to next position
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.results.append(self.toolhead.get_kinematics().calc_position())
return # Move to next position
self.move_next() self._move_next()
def finalize(self, success): 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)