toolhead: Add a manual_move() helper function

Add a helper function for submitting relative movements.  This
function will also automatically ensure gcode.reset_last_position() is
called.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-08-16 22:43:03 -04:00
parent b9ac6d6306
commit 2caaaea9a4
6 changed files with 34 additions and 55 deletions

View File

@ -46,13 +46,7 @@ class BedScrews:
self.cmd_BED_SCREWS_ADJUST,
desc=self.cmd_BED_SCREWS_ADJUST_help)
def move(self, coord, speed):
toolhead = self.printer.lookup_object('toolhead')
curpos = toolhead.get_position()
for i in range(len(coord)):
if coord[i] is not None:
curpos[i] = coord[i]
toolhead.move(curpos, speed)
self.gcode.reset_last_position()
self.printer.lookup_object('toolhead').manual_move(coord, speed)
def move_to_screw(self, state, screw):
# Move up, over, and then down
self.move((None, None, self.horizontal_move_z), self.lift_speed)

View File

@ -93,11 +93,10 @@ class ManualProbeHelper:
def move_z(self, z_pos):
curpos = self.toolhead.get_position()
try:
if curpos[2] - z_pos < Z_BOB_MINIMUM:
curpos[2] = z_pos + Z_BOB_MINIMUM
self.toolhead.move(curpos, self.speed)
curpos[2] = z_pos
self.toolhead.move(curpos, self.speed)
z_bob_pos = z_pos + Z_BOB_MINIMUM
if curpos[2] < z_bob_pos:
self.toolhead.manual_move([None, None, z_bob_pos], self.speed)
self.toolhead.manual_move([None, None, z_pos], self.speed)
except homing.CommandError as e:
self.finalize(False)
raise

View File

@ -125,13 +125,7 @@ class PrinterProbe:
% (pos[0], pos[1], pos[2]))
return pos[:3]
def _move(self, coord, speed):
toolhead = self.printer.lookup_object('toolhead')
curpos = toolhead.get_position()
for i in range(len(coord)):
if coord[i] is not None:
curpos[i] = coord[i]
toolhead.move(curpos, speed)
self.gcode.reset_last_position()
self.printer.lookup_object('toolhead').manual_move(coord, speed)
def _calc_mean(self, positions):
count = float(len(positions))
return [sum([pos[i] for pos in positions]) / count
@ -354,24 +348,20 @@ class ProbePointsHelper:
if not self.results:
# Use full speed to first probe position
speed = self.speed
curpos = toolhead.get_position()
curpos[2] = self.horizontal_move_z
toolhead.move(curpos, speed)
toolhead.manual_move([None, None, self.horizontal_move_z], speed)
# Check if done probing
if len(self.results) >= len(self.probe_points):
self.gcode.reset_last_position()
toolhead.get_last_move_time()
res = self.finalize_callback(self.probe_offsets, self.results)
if res != "retry":
return True
self.results = []
# Move to next XY probe point
curpos[:2] = self.probe_points[len(self.results)]
nextpos = list(self.probe_points[len(self.results)])
if self.use_offsets:
curpos[0] -= self.probe_offsets[0]
curpos[1] -= self.probe_offsets[1]
toolhead.move(curpos, self.speed)
self.gcode.reset_last_position()
nextpos[0] -= self.probe_offsets[0]
nextpos[1] -= self.probe_offsets[1]
toolhead.manual_move(nextpos, self.speed)
return False
def start_probe(self, gcmd):
manual_probe.verify_no_manual_probe(self.printer)

View File

@ -30,23 +30,23 @@ class SafeZHoming:
def cmd_G28(self, gcmd):
toolhead = self.printer.lookup_object('toolhead')
curtime = self.printer.get_reactor().monotonic()
kin_status = toolhead.get_kinematics().get_status(curtime)
# Perform Z Hop if necessary
if self.z_hop != 0.0:
pos = toolhead.get_position()
# Check if Z axis is homed or has a known position
curtime = self.printer.get_reactor().monotonic()
kin_status = toolhead.get_kinematics().get_status(curtime)
if 'z' in kin_status['homed_axes']:
# Check if the zhop would exceed the printer limits
pos = toolhead.get_position()
if pos[2] + self.z_hop > self.max_z:
gcmd.respond_info(
"No zhop performed, target Z out of bounds: " +
str(pos[2] + self.z_hop))
elif pos[2] < self.z_hop:
self._perform_z_hop(pos)
self._perform_z_hop()
else:
self._perform_z_hop(pos)
self._perform_z_hop()
if hasattr(toolhead.get_kinematics(), "note_z_not_homed"):
toolhead.get_kinematics().note_z_not_homed()
@ -66,46 +66,33 @@ class SafeZHoming:
g28_gcmd = self.gcode.create_gcode_command("G28", "G28", new_params)
self.prev_G28(g28_gcmd)
# Update the currently homed axes
curtime = self.printer.get_reactor().monotonic()
kin_status = toolhead.get_kinematics().get_status(curtime)
# Home Z axis if necessary
if need_z:
pos = toolhead.get_position()
prev_x = pos[0]
prev_y = pos[1]
pos[0] = self.home_x_pos
pos[1] = self.home_y_pos
# Throw an error if X or Y are not homed
curtime = self.printer.get_reactor().monotonic()
kin_status = toolhead.get_kinematics().get_status(curtime)
if ('x' not in kin_status['homed_axes'] or
'y' not in kin_status['homed_axes']):
raise gcmd.error("Must home X and Y axes first")
# Move to safe XY homing position
toolhead.move(pos, self.speed)
self.gcode.reset_last_position()
prevpos = toolhead.get_position()
toolhead.manual_move([self.home_x_pos, self.home_y_pos], self.speed)
# Home Z
g28_gcmd = self.gcode.create_gcode_command("G28", "G28", {'Z': '0'})
self.prev_G28(g28_gcmd)
# Perform Z Hop again for pressure-based probes
pos = toolhead.get_position()
if self.z_hop:
pos[2] = self.z_hop
toolhead.move(pos, self.z_hop_speed)
toolhead.manual_move([None, None, self.z_hop], self.z_hop_speed)
# Move XY back to previous positions
if self.move_to_previous:
pos[0] = prev_x
pos[1] = prev_y
toolhead.move(pos, self.speed)
self.gcode.reset_last_position()
toolhead.manual_move(prevpos[:2], self.speed)
def _perform_z_hop(self, pos):
def _perform_z_hop(self):
toolhead = self.printer.lookup_object('toolhead')
# Perform the Z-Hop
pos = toolhead.get_position()
toolhead.set_position(pos, homing_axes=[2])
pos[2] = pos[2] + self.z_hop
toolhead.move(pos, self.z_hop_speed)
self.gcode.reset_last_position()
toolhead.manual_move([None, None, pos[2]+self.z_hop], self.z_hop_speed)
def load_config(config):
return SafeZHoming(config)

View File

@ -78,6 +78,8 @@ class GCodeParser:
self._handle_disconnect)
printer.register_event_handler("toolhead:set_position",
self.reset_last_position)
printer.register_event_handler("toolhead:manual_move",
self.reset_last_position)
printer.register_event_handler("extruder:activate_extruder",
self._handle_activate_extruder)
# Command handling

View File

@ -413,6 +413,13 @@ class ToolHead:
self.move_queue.add_move(move)
if self.print_time > self.need_check_stall:
self._check_stall()
def manual_move(self, coord, speed):
curpos = list(self.commanded_pos)
for i in range(len(coord)):
if coord[i] is not None:
curpos[i] = coord[i]
self.move(curpos, speed)
self.printer.send_event("toolhead:manual_move")
def dwell(self, delay):
next_print_time = self.get_last_move_time() + max(0., delay)
self._update_move_time(next_print_time)