From 16a7b50ce9866d1bec07899391cd123e7f6aaa44 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 12 Jan 2024 16:47:55 -0500 Subject: [PATCH 1/2] bed_mesh: fix manual mode point generation Do not generate points for the zero_reference_position or faulty_regions when manual probing is requested. Signed-off-by: Eric Callahan --- klippy/extras/bed_mesh.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index 9e30846f0..bc386c387 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -323,7 +323,7 @@ def __init__(self, config, bedmesh): self.gcode.register_command( 'BED_MESH_CALIBRATE', self.cmd_BED_MESH_CALIBRATE, desc=self.cmd_BED_MESH_CALIBRATE_help) - def _generate_points(self, error): + def _generate_points(self, error, probe_method="automatic"): x_cnt = self.mesh_config['x_count'] y_cnt = self.mesh_config['y_count'] min_x, min_y = self.mesh_min @@ -372,7 +372,7 @@ def _generate_points(self, error): if rri >= len(self.points): raise error("bed_mesh: relative reference index out of range") self.zero_ref_pos = points[rri] - if self.zero_ref_pos is None: + if self.zero_ref_pos is None or probe_method == "manual": # Zero Reference Disabled self.zero_reference_mode = ZrefMode.DISABLED elif within(self.zero_ref_pos, self.mesh_min, self.mesh_max): @@ -398,6 +398,8 @@ def _generate_points(self, error): % (self.zero_ref_pos[0], self.zero_ref_pos[1], opt,) ) # Check to see if any points fall within faulty regions + if probe_method == "manual": + return last_y = self.points[0][1] is_reversed = False for i, coord in enumerate(self.points): @@ -724,10 +726,11 @@ def update_config(self, gcmd): need_cfg_update = True need_cfg_update |= self.set_adaptive_mesh(gcmd) + probe_method = gcmd.get("METHOD", "automatic") if need_cfg_update: self._verify_algorithm(gcmd.error) - self._generate_points(gcmd.error) + self._generate_points(gcmd.error, probe_method) gcmd.respond_info("Generating new points...") self.print_generated_points(gcmd.respond_info) pts = self._get_adjusted_points() @@ -738,7 +741,7 @@ def update_config(self, gcmd): in self.mesh_config.items()]) logging.info("Updated Mesh Configuration:\n" + msg) else: - self._generate_points(gcmd.error) + self._generate_points(gcmd.error, probe_method) pts = self._get_adjusted_points() self.probe_helper.update_probe_points(pts, 3) def _get_adjusted_points(self): @@ -769,7 +772,7 @@ def probe_finalize(self, offsets, positions): x_offset, y_offset, z_offset = offsets positions = [[round(p[0], 2), round(p[1], 2), p[2]] for p in positions] - if self.zero_reference_mode == ZrefMode.PROBE : + if self.zero_reference_mode == ZrefMode.PROBE: ref_pos = positions.pop() logging.info( "bed_mesh: z-offset replaced with probed z value at " From 9f41f53c5e364694b9b41279b3b3aee34250b93a Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 27 Jan 2024 11:44:39 -0500 Subject: [PATCH 2/2] bed_mesh: fix profile_name reporting in get_status() Adaptive meshing avoids saving the mesh after calibration to prevent users from inadvertently overwriting an existing profile with an adaptive mesh. This introduced a change in behavior of how get_status() reports the profile_name, as it can now be an empty string when a mesh is active. This patch assigns adaptive meshes a name with a unique postfix. In addition, it moves profile name tracking from the profile manager to the ZMesh class. Signed-off-by: Eric Callahan --- klippy/extras/bed_mesh.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/klippy/extras/bed_mesh.py b/klippy/extras/bed_mesh.py index bc386c387..afedb6aaf 100644 --- a/klippy/extras/bed_mesh.py +++ b/klippy/extras/bed_mesh.py @@ -233,7 +233,7 @@ def update_status(self): mesh_max = (params['max_x'], params['max_y']) probed_matrix = self.z_mesh.get_probed_matrix() mesh_matrix = self.z_mesh.get_mesh_matrix() - self.status['profile_name'] = self.pmgr.get_current_profile() + self.status['profile_name'] = self.z_mesh.get_profile_name() self.status['mesh_min'] = mesh_min self.status['mesh_max'] = mesh_max self.status['probed_matrix'] = probed_matrix @@ -314,7 +314,7 @@ def __init__(self, config, bedmesh): self.mesh_config = collections.OrderedDict() self._init_mesh_config(config) self._generate_points(config.error) - self._profile_name = None + self._profile_name = "default" self.probe_helper = probe.ProbePointsHelper( config, self.probe_finalize, self._get_adjusted_points()) self.probe_helper.minimum_points(3) @@ -881,7 +881,7 @@ def probe_finalize(self, offsets, positions): "Probed table length: %d Probed Table:\n%s") % (len(probed_matrix), str(probed_matrix))) - z_mesh = ZMesh(params) + z_mesh = ZMesh(params, self._profile_name) try: z_mesh.build_mesh(probed_matrix) except BedMeshError as e: @@ -980,7 +980,8 @@ def split(self): class ZMesh: - def __init__(self, params): + def __init__(self, params, name): + self.profile_name = name or "adaptive-%X" % (id(self),) self.probed_matrix = self.mesh_matrix = None self.mesh_params = params self.mesh_offsets = [0., 0.] @@ -1029,6 +1030,8 @@ def get_probed_matrix(self): return [[]] def get_mesh_params(self): return self.mesh_params + def get_profile_name(self): + return self.profile_name def print_probed_matrix(self, print_func): if self.probed_matrix is not None: msg = "Mesh Leveling Probed Z positions:\n" @@ -1289,7 +1292,6 @@ def __init__(self, config, bedmesh): self.gcode = self.printer.lookup_object('gcode') self.bedmesh = bedmesh self.profiles = {} - self.current_profile = "" self.incompatible_profiles = [] # Fetch stored profiles from Config stored_profs = config.get_prefix_sections(self.name) @@ -1323,8 +1325,6 @@ def __init__(self, config, bedmesh): desc=self.cmd_BED_MESH_PROFILE_help) def get_profiles(self): return self.profiles - def get_current_profile(self): - return self.current_profile def _check_incompatible_profiles(self): if self.incompatible_profiles: configfile = self.printer.lookup_object('configfile') @@ -1365,7 +1365,6 @@ def save_profile(self, prof_name): profile['points'] = probed_matrix profile['mesh_params'] = collections.OrderedDict(mesh_params) self.profiles = profiles - self.current_profile = prof_name self.bedmesh.update_status() self.gcode.respond_info( "Bed Mesh state has been saved to profile [%s]\n" @@ -1379,12 +1378,11 @@ def load_profile(self, prof_name): "bed_mesh: Unknown profile [%s]" % prof_name) probed_matrix = profile['points'] mesh_params = profile['mesh_params'] - z_mesh = ZMesh(mesh_params) + z_mesh = ZMesh(mesh_params, prof_name) try: z_mesh.build_mesh(probed_matrix) except BedMeshError as e: raise self.gcode.error(str(e)) - self.current_profile = prof_name self.bedmesh.set_mesh(z_mesh) def remove_profile(self, prof_name): if prof_name in self.profiles: