def execute(self, g): if g.num_tokens() == 0: # If no token is given, home all axes_list = self.printer.config.get('Homing', 'G28_default_axes').replace( ' ', '') tokens = [ax + '0' for ax in axes_list.split(",")] g.set_tokens(tokens) axis_home = [] for i in range(g.num_tokens()): # Run through all tokens axis = g.token_letter(i) if axis.upper( ) in self.printer.AXES and self.printer.config.getboolean( 'Endstops', 'has_' + axis.lower()): axis_home.append(axis) if len(axis_home): self.printer.path_planner.wait_until_done() self.printer.path_planner.home(axis_home) if g.has_letter("M"): #matrix = self.printer.path_planner.prev.end_pos[:3].dot(self.printer.matrix_bed_comp) current = self.printer.path_planner.get_current_pos(mm=False, ideal=True) p = G92Path({"Z": current["Z"]}, cancelable=False, use_bed_matrix=True) self.printer.path_planner.add_path(p) logging.info("Homing done.") self.printer.send_message(g.prot, "Homing done.")
def _go_to_home(self, axis): """ go to the designated home position do this as a separate call from _home_internal due to delta platforms performing home in cartesian mode """ path_home = {} speed = self.printer.home_speed[0] accel = self.printer.acceleration[0] for a in axis: path_home[a] = self.home_pos[a] speed = min(abs(speed), abs(self.printer.home_speed[Printer.axis_to_index(a)])) logging.debug("Home: %s" % path_home) # Move to home position p = AbsolutePath(path_home, speed, accel, True, False, False, False) self.add_path(p) self.wait_until_done() # Due to rounding errors, we explicitly set the found # position to the right value. # Reset (final) position to offset p = G92Path(path_home) self.add_path(p) return
def _home_internal(self, axis): """ Private method for homing a set or a single axis """ logging.debug("homing " + str(axis)) path_back = {} path_center = {} path_zero = {} speed = Path.home_speed[0] for a in axis: if not self.printer.steppers[a].has_endstop: logging.debug("Skipping homing for " + str(a)) continue path_back[a] = -self.travel_length[a] path_center[a] = -self.center_offset[a] path_zero[a] = 0 speed = min(speed, Path.home_speed[Path.axis_to_index(a)]) # Move until endstop is hit p = RelativePath(path_back, speed, True) self.add_path(p) # Reset position to offset p = G92Path(path_center, speed) self.add_path(p) # Move to offset p = AbsolutePath(path_zero, speed) self.add_path(p) self.wait_until_done() logging.debug("homing done for " + str(axis))
def __init__(self, printer, pru_firmware): """ Init the planner """ self.printer = printer self.steppers = printer.steppers self.pru_firmware = pru_firmware self.printer.path_planner = self self.travel_length = { "X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0, "A": 0.0, "B": 0.0, "C": 0.0 } self.center_offset = { "X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0, "A": 0.0, "B": 0.0, "C": 0.0 } self.home_pos = { "X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0, "A": 0.0, "B": 0.0, "C": 0.0 } self.prev = G92Path( { "X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0, "A": 0.0, "B": 0.0, "C": 0.0 }, 0) self.prev.set_prev(None) if pru_firmware: self.__init_path_planner() else: self.native_planner = None # do some checking of values self.printer.check_values()
def home(self, axis): """ Home the given axis using endstops (min) """ logging.debug("homing " + str(axis)) # allow for endstops that may only be active during homing self.printer.homing(True) # Home axis for core X,Y and H-Belt independently to avoid hardware # damages. if self.printer.axis_config == Printer.AXIS_CONFIG_CORE_XY or \ self.printer.axis_config == Printer.AXIS_CONFIG_H_BELT: for a in axis: self._home_internal(a) # For delta, switch to cartesian when homing elif self.printer.axis_config == Printer.AXIS_CONFIG_DELTA: if 0 < len({"X", "Y", "Z"}.intersection(set(axis))) < 3: axis = list(set(axis).union({"X", "Y", "Z" })) # Deltas must home all axes. self.printer.axis_config = Printer.AXIS_CONFIG_XY path_center, speed = self._home_internal(axis) self.printer.axis_config = Printer.AXIS_CONFIG_DELTA # homing was performed in cartesian mode # need to convert back to delta Az = path_center['X'] Bz = path_center['Y'] Cz = path_center['Z'] z_offset = self.native_planner.delta_bot.vertical_offset( Az, Bz, Cz) # vertical offset xyz = self.native_planner.delta_bot.forward_kinematics( Az, Bz, Cz) # effector position xyz[2] += z_offset path = {'X': xyz[0], 'Y': xyz[1], 'Z': xyz[2]} logging.debug("Delta Home: " + str(xyz)) p = G92Path(path) self.add_path(p) self.wait_until_done() else: # AXIS_CONFIG_XY self._home_internal(axis) # allow for endstops that may only be active during homing self.printer.homing(False) # go to the designated home position self._go_to_home(axis) # Reset backlash compensation self.native_planner.resetBacklash() logging.debug("homing done for " + str(axis)) return
def execute(self, g): if g.num_tokens() == 0: # If no token is present, do this for all steppers logging.debug("Adding all to G92") g.set_tokens(["X0", "Y0", "Z0", "E0", "H0"]) pos = {} for i in range(g.num_tokens()): axis = g.token_letter(i) # Get the axis, X, Y, Z or E # Get the value, new position or vector pos[axis] = float(g.token_value(i)) / 1000.0 # Make a path segment from the axes path = G92Path(pos, self.printer.feed_rate) self.printer.path_planner.add_path(path)
def execute(self, g): # restore previous position of E an H axis if self.printer.movement == Path.ABSOLUTE: pos = self.printer.path_planner.get_current_pos() pos['E'] /= self.printer.extrude_factor pos['H'] /= self.printer.extrude_factor self.printer.path_planner.add_path( G92Path(pos, self.printer.feed_rate)) # apply new extrude factor if g.has_letter("S"): self.printer.extrude_factor = float( g.get_value_by_letter("S")) / 100 else: self.printer.extrude_factor = 1.0 # set E and H to new Positions if self.printer.movement == Path.ABSOLUTE: pos = self.printer.path_planner.get_current_pos() pos['E'] *= self.printer.extrude_factor pos['H'] *= self.printer.extrude_factor self.printer.path_planner.add_path( G92Path(pos, self.printer.feed_rate))
def __init__(self, printer, pru_firmware): """ Init the planner """ self.printer = printer self.steppers = printer.steppers self.pru_firmware = pru_firmware self.travel_length = {"X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0} self.center_offset = {"X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0} self.prev = G92Path({ "X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0 }, 0) self.prev.set_prev(None) if pru_firmware: self.__init_path_planner() else: self.native_planner = None
def probe(self, z, speed, accel): self.wait_until_done() self.printer.ensure_steppers_enabled() # save the starting position start_pos = self.get_current_pos(ideal=True) start_state = self.native_planner.getState() # calculate how many steps the requested z movement will require steps = np.ceil(z * self.printer.steps_pr_meter[2]) z_dist = steps / self.printer.steps_pr_meter[2] logging.debug("Steps total: " + str(steps)) # select the relative end point # this is not axis_config dependent as we are not swapping # axis_config like we do when homing end = {"Z": -z_dist} # tell the printer we are now in homing mode (updates firmware if required) self.printer.homing(True) # add a relative move to the path planner # this tells the head to move down a set distance # the probe end-stop should be triggered during this move path = RelativePath(end, speed, accel, cancelable=True, use_bed_matrix=True, use_backlash_compensation=True, enable_soft_endstops=False) self.add_path(path) self.wait_until_done() # get the number of steps that we haven't done steps_remaining = PruInterface.get_steps_remaining() logging.debug("Steps remaining : " + str(steps_remaining)) # Calculate how many steps the Z axis moved steps -= steps_remaining z_dist = steps / self.printer.steps_pr_meter[2] # make a move to take us back to where we started end = {"Z": z_dist} path = RelativePath(end, speed, accel, cancelable=True, use_bed_matrix=True, use_backlash_compensation=True, enable_soft_endstops=False) self.add_path(path) self.wait_until_done() # reset position back to where we actually are path = G92Path({"Z": start_pos["Z"]}, use_bed_matrix=True) self.add_path(path) self.wait_until_done() start_state = self.native_planner.getState() # tell the printer we are no longer in homing mode (updates firmware if required) self.printer.homing(False) return -z_dist + start_pos["Z"]
def _home_internal(self, axis): """ Private method for homing a set or a single axis """ logging.debug("homing internal " + str(axis)) path_search = {} path_backoff = {} path_fine_search = {} path_center = {} path_zero = {} speed = self.printer.home_speed[0] # TODO: speed for each axis accel = self.printer.acceleration[0] # TODO: accel for each axis for a in axis: if not self.printer.steppers[a].has_endstop: logging.debug("Skipping homing for " + str(a)) continue logging.debug("Doing homing for " + str(a)) if self.printer.home_speed[Printer.axis_to_index(a)] < 0: # Search to positive ends path_search[a] = self.travel_length[a] path_center[a] = self.center_offset[a] else: # Search to negative ends path_search[a] = -self.travel_length[a] path_center[a] = -self.center_offset[a] backoff_length = -np.sign( path_search[a]) * self.printer.home_backoff_offset[ Printer.axis_to_index(a)] path_backoff[a] = backoff_length path_fine_search[a] = -backoff_length * 1.2 speed = min(abs(speed), abs(self.printer.home_speed[Printer.axis_to_index(a)])) accel = min(accel, self.printer.acceleration[Printer.axis_to_index(a)]) fine_search_speed = min( abs(speed), abs(self.printer.home_backoff_speed[Printer.axis_to_index(a)])) logging.debug("Search: %s at %s m/s, %s m/s^2" % (path_search, speed, accel)) logging.debug("Backoff to: %s" % path_backoff) logging.debug("Fine search: %s" % path_fine_search) logging.debug("Center: %s" % path_center) # Move until endstop is hit p = RelativePath(path_search, speed, accel, True, False, True, False) self.add_path(p) self.wait_until_done() logging.debug("Coarse search done!") # Reset position to offset p = G92Path(path_center) self.add_path(p) self.wait_until_done() # Back off a bit p = RelativePath(path_backoff, speed, accel, True, False, True, False) self.add_path(p) # Hit the endstop slowly p = RelativePath(path_fine_search, fine_search_speed, accel, True, False, True, False) self.add_path(p) self.wait_until_done() # Reset (final) position to offset p = G92Path(path_center) self.add_path(p) return path_center, speed
def home(self, axis): """ Home the given axis using endstops (min) """ logging.debug("homing " + str(axis)) # Home axis for core X,Y and H-Belt independently to avoid hardware # damages. if Path.axis_config == Path.AXIS_CONFIG_CORE_XY or \ Path.axis_config == Path.AXIS_CONFIG_H_BELT: for a in axis: self._home_internal(a) # For delta, switch to cartesian when homing elif Path.axis_config == Path.AXIS_CONFIG_DELTA: if 0 < len({"X", "Y", "Z"}.intersection(set(axis))) < 3: axis = list(set(axis).union({"X", "Y", "Z" })) # Deltas must home all axes. Path.axis_config = Path.AXIS_CONFIG_XY path_center, speed = self._home_internal(axis) Path.axis_config = Path.AXIS_CONFIG_DELTA # homing was performed in cartesian mode # need to convert back to delta Az = path_center['X'] Bz = path_center['Y'] Cz = path_center['Z'] z_offset = Delta.vertical_offset(Az, Bz, Cz) # vertical offset xyz = Delta.forward_kinematics2(Az, Bz, Cz) # effector position xyz[2] += z_offset path = {'X': xyz[0], 'Y': xyz[1], 'Z': xyz[2]} p = G92Path(path, speed) self.add_path(p) self.wait_until_done() # For scar, switch also to cartesian when homing elif Path.axis_config == Path.AXIS_CONFIG_SCARA: # TODO: implement individual homing ( needs to take care of position after homing) if 0 < len({"X", "Y", "Z"}.intersection(set(axis))) < 3: axis = list(set(axis).union({ "X", "Y", "Z" })) # For now Scaras must home all axes. Than can changed Path.axis_config = Path.AXIS_CONFIG_XY path_center, speed = self._home_internal(axis) Path.axis_config = Path.AXIS_CONFIG_SCARA # homing was performed in cartesian mode # need to convert back to delta A = path_center['X'] B = path_center['Y'] C = path_center['Z'] #z_offset = Delta.vertical_offset(Az,Bz,Cz) # vertical offset # xyz = Scara.inverse_kinematics(A, B, C) # effector position # logging.debug("HomeXYZ: %s", xyz) #xyz[2] += z_offset # don't cpnvert home_pos to effector spac # home offset is defined in cartesian space # xyz = np.array([path_center['X'], path_center['Y'], path_center['Z']]) #path = {'X':xyz[0], 'Y':xyz[1], 'Z':xyz[2]} path = {A, B, C} p = G92Path(path, speed) self.add_path(p) self.wait_until_done() else: self._home_internal(axis) # go to the designated home position self._go_to_home(axis) # Reset backlash compensation Path.backlash_reset() logging.debug("homing done for " + str(axis)) return