From e1764efb4d2d997bc9939fa72a3fb06561c40403 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Thu, 17 Aug 2023 16:22:37 +0200 Subject: [PATCH] Bugfixes on probing (#2281) * Fixed problem with setting enable which can't be done in the event thread causing exceptions * Added a tooltip that describes how the retract amount works * Shows/hides the probing/autoleveling preview when the component is shown * Fixed the wrong mapping of X -> Y value in autoleveler * Fixed problem with equals matching doubles, lowered the precision. * Fixed problem with concurrent updates to list of renderables --- .../src/resources/MessagesBundle_en_US.properties | 1 + .../ugs/platform/probe/ProbeParameters.java | 4 ++++ .../ugs/platform/probe/ProbeTopComponent.java | 14 ++++++++++++-- .../probe/actions/AbstractProbeAction.java | 2 +- .../probe/renderable/ProbePreviewManager.java | 11 +++++++++-- .../ugs/platform/probe/ui/SettingsPanel.java | 4 +++- .../surfacescanner/AutoLevelerTopComponent.java | 15 ++++++++++++++- .../platform/surfacescanner/SurfaceScanner.java | 5 ++++- .../surfacescanner/ui/AutoLevelerPanel.java | 2 +- .../ugs/nbm/visualizer/shared/GcodeRenderer.java | 6 +++--- 10 files changed, 52 insertions(+), 12 deletions(-) diff --git a/ugs-core/src/resources/MessagesBundle_en_US.properties b/ugs-core/src/resources/MessagesBundle_en_US.properties index ea2fc34c62..98be3978c9 100644 --- a/ugs-core/src/resources/MessagesBundle_en_US.properties +++ b/ugs-core/src/resources/MessagesBundle_en_US.properties @@ -508,6 +508,7 @@ probe.measure-rate = Slow measure rate probe.x-distance = Probe X Distance probe.y-distance = Probe Y Distance probe.retract-amount = Retract amount +probe.retract-amount.tooltip = Distance to retract after the fast probe cycle before running the slow probe probe.hole-diameter = Approximate hole diameter probe.hole-center-hint = Move probe to approximate center probe.work-coordinates = Work Coordinates diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeParameters.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeParameters.java index 864c1ebdb0..56787d5877 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeParameters.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeParameters.java @@ -36,6 +36,10 @@ public class ProbeParameters { public final double holeDiameter; public final double feedRate; public final double feedRateSlow; + + /** + * The distance to retract after first fast probe cycle before running the next slow probe cycle + */ public final double retractAmount; public final WorkCoordinateSystem wcsToUpdate; public final UnitUtils.Units units; diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java index e8bacdf307..69c98b1856 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ProbeTopComponent.java @@ -68,7 +68,7 @@ public final class ProbeTopComponent extends TopComponent implements UGSEventLis public final static String ProbeActionId = "com.willwinder.ugs.platform.probe.ProbeTopComponent.renamed"; public final static String ProbeCategory = LocalizingService.CATEGORY_WINDOW; // hole diameter tab - private static final String HC_TAB = "HC"; + private static final String HC_TAB = "Hole center"; // xyz tab private static final String XYZ_TAB = "XYZ"; // outside tab @@ -163,7 +163,17 @@ public void componentOpened() { @Override public void componentClosed() { - probePreviewManager.clear(); + probePreviewManager.inactivate(); + } + + @Override + protected void componentHidden() { + probePreviewManager.inactivate(); + } + + @Override + protected void componentShowing() { + probePreviewManager.activate(); } @OnStart diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/AbstractProbeAction.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/AbstractProbeAction.java index 7395bdf76a..ae9ed3ec1b 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/AbstractProbeAction.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/actions/AbstractProbeAction.java @@ -94,7 +94,7 @@ public void setEnabled(boolean enabled) { @Override public void UGSEvent(UGSEvent evt) { if (evt instanceof ControllerStateEvent) { - setEnabled(isEnabled()); + SwingUtilities.invokeLater(() -> setEnabled(isEnabled())); } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java index 7a3342c92e..f160125744 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ProbePreviewManager.java @@ -37,7 +37,7 @@ public void register(String name, AbstractProbePreview probePreview) { } public void setActive(String name) { - clear(); + inactivate(); AbstractProbePreview currentPreview = probePreviewMap.get(name); activePreview.set(currentPreview); if (currentPreview != null) { @@ -46,7 +46,7 @@ public void setActive(String name) { } } - public void clear() { + public void inactivate() { AbstractProbePreview currentPreview = activePreview.get(); if (currentPreview != null) { RenderableUtils.removeRenderable(currentPreview); @@ -66,4 +66,11 @@ public void updateSettings() { currentPreview.updateSettings(); } } + + public void activate() { + AbstractProbePreview currentPreview = activePreview.get(); + if (currentPreview != null) { + RenderableUtils.registerRenderable(currentPreview); + } + } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java index 86cccd3a3a..5891b8127c 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/ui/SettingsPanel.java @@ -75,7 +75,9 @@ private void createLayout() { add(new JSpinner(settingsSlowMeasureRate), "growx"); add(new JLabel(Localization.getString("probe.retract-amount") + ":"), "al right"); - add(new JSpinner(settingsRetractAmount), "growx"); + JSpinner retractSpinner = new JSpinner(settingsRetractAmount); + retractSpinner.setToolTipText(Localization.getString("probe.retract-amount.tooltip")); + add(retractSpinner, "growx"); } private void registerListeners() { diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/AutoLevelerTopComponent.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/AutoLevelerTopComponent.java index 39e7c99b7d..fdab64ced5 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/AutoLevelerTopComponent.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/AutoLevelerTopComponent.java @@ -103,7 +103,6 @@ public void componentOpened() { if (autoLevelPreview == null) { autoLevelPreview = new AutoLevelPreview(Localization.getString("platform.visualizer.renderable.autolevel-preview")); - RenderableUtils.registerRenderable(autoLevelPreview); } initComponents(); @@ -117,6 +116,20 @@ public void componentClosed() { meshLevelManager.clear(); } + @Override + protected void componentHidden() { + if (autoLevelPreview != null) { + RenderableUtils.removeRenderable(autoLevelPreview); + } + } + + @Override + protected void componentShowing() { + if (autoLevelPreview != null) { + RenderableUtils.registerRenderable(autoLevelPreview); + } + } + private void updatePreview() { if (autoLevelPreview != null) { autoLevelPreview.updateSettings( diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java index 5ee0b8aa07..3f6357d305 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/SurfaceScanner.java @@ -166,7 +166,10 @@ public void probeEvent(final Position p) { Position expectedProbePosition = pendingPositions.pop(); Position probedPosition = p.getPositionIn(expectedProbePosition.getUnits()); - if (!isEqual(probedPosition.getX(), expectedProbePosition.getX(), 0.0001) || !isEqual(probedPosition.getY(), expectedProbePosition.getY(), 0.0001)) { + // The position reported from controller might lack some precision on the X/Y position. + // We therefore need to lower the precision when checking the probed X/Y axes + double delta = expectedProbePosition.getUnits() == Units.MM ? 0.01 : 0.001; + if (!isEqual(probedPosition.getX(), expectedProbePosition.getX(), delta) || !isEqual(probedPosition.getY(), expectedProbePosition.getY(), delta)) { reset(); throw new RuntimeException(String.format("Unexpected probe location, expected %s to be %s", probedPosition, expectedProbePosition)); } diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java index 0818c3512b..2747097d2d 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/ui/AutoLevelerPanel.java @@ -69,7 +69,7 @@ public AutoLevelerPanel(SurfaceScanner surfaceScanner, MeshLevelManager meshLeve } private void initComponents() { - xMin = new Spinner(autoLevelSettings.getMinZ()); + xMin = new Spinner(autoLevelSettings.getMinX()); yMin = new Spinner(autoLevelSettings.getMinY()); zMin = new Spinner(autoLevelSettings.getMinZ()); xMax = new Spinner(autoLevelSettings.getMaxX(), 0.0001); diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java index 7f8021b720..801a0dcde6 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java @@ -41,9 +41,9 @@ This file is part of Universal Gcode Sender (UGS). import java.awt.*; import java.awt.event.InputEvent; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; import java.util.logging.Logger; @@ -111,7 +111,7 @@ public class GcodeRenderer implements GLEventListener, IRenderableRegistrationSe private Overlay overlay; private final String dimensionsLabel = ""; - private final ArrayList objects; + private final java.util.List objects; private boolean idle = true; // Preferences @@ -133,7 +133,7 @@ public GcodeRenderer() { setVerticalTranslationVector(); setHorizontalTranslationVector(); - objects = new ArrayList<>(); + objects = new CopyOnWriteArrayList<>(); objects.add(new MachineBoundries(Localization.getString("platform.visualizer.renderable.machine-boundries"))); objects.add(new Tool(Localization.getString("platform.visualizer.renderable.tool-location"))); objects.add(new MouseOver(Localization.getString("platform.visualizer.renderable.mouse-indicator")));