-
-
Notifications
You must be signed in to change notification settings - Fork 792
Open
Description
Description
If one forgets to set zero and zero is set below the probe, the tool will try and move to zero before starting the leveling routine. I have crushed 2 probes because of this BS behaviour.
Do the same for the PROBE code.
Replace the ScanSurfaceAction.java with this code and Z will only move if it's inside the scan bounding box for Z- and Z+
This adds pop up windows for errors.
/*
Copyright 2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.platform.surfacescanner.actions;
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup;
import com.willwinder.ugs.platform.surfacescanner.SurfaceScanner;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.listeners.UGSEventListener;
import com.willwinder.universalgcodesender.model.BackendAPI;
import com.willwinder.universalgcodesender.model.UGSEvent;
import com.willwinder.universalgcodesender.model.events.ControllerStatusEvent;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.ImageUtilities;
import javax.swing.*;
import java.awt.event.ActionEvent;
import static com.willwinder.ugs.platform.surfacescanner.Utils.shouldEraseProbedData;
import com.willwinder.universalgcodesender.utils.AutoLevelSettings;
public class ScanSurfaceAction extends AbstractAction implements UGSEventListener {
public static final String ICON_BASE = "com/willwinder/ugs/platform/surfacescanner/icons/scan.svg";
private final SurfaceScanner surfaceScanner;
private final BackendAPI backend;
public ScanSurfaceAction(SurfaceScanner surfaceScanner) {
this.backend = CentralLookup.getDefault().lookup(BackendAPI.class);
if (this.backend != null) {
this.backend.addUGSEventListener(this);
}
this.surfaceScanner = surfaceScanner;
String title = Localization.getString("autoleveler.panel.scan-surface");
putValue(NAME, title);
putValue("menuText", title);
putValue(Action.SHORT_DESCRIPTION, title);
putValue("iconBase", ICON_BASE);
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(ICON_BASE, false));
putValue(Action.SELECTED_KEY, false);
}
@Override
public boolean isEnabled() {
return backend != null && backend.isConnected() && backend.isIdle();
}
@Override
public void actionPerformed(ActionEvent e) {
if (surfaceScanner.isValid() && !shouldEraseProbedData()) {
return;
}
if (!validateZBeforeScan()) {
return;
}
surfaceScanner.reset();
surfaceScanner.scan();
}
@Override
public void UGSEvent(UGSEvent evt) {
if (evt instanceof ControllerStatusEvent) {
setEnabled(isEnabled());
}
}
private boolean validateZBeforeScan() {
double zMin, zMax, clearance;
try {
AutoLevelSettings settings = backend.getSettings().getAutoLevelSettings();
zMin = settings.getMinZ();
zMax = settings.getMaxZ();
} catch (Exception ex) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
"Could not read Auto-Level Z settings.", NotifyDescriptor.WARNING_MESSAGE));
return false;
}
if (zMin >= zMax) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
"Z range is invalid (Z Min ≥ Z Max).", NotifyDescriptor.WARNING_MESSAGE));
return false;
}
double z;
try {
z = backend.getWorkPosition().z;
} catch (Exception ex) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
"Could not read current Z position. Aborting scan.",
NotifyDescriptor.ERROR_MESSAGE));
return false;
}
if (z < zMin) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
String.format("Current Z (%.3f) is below Z-Min (%.3f). This may crash the probe. Aborting scan.", z, zMin),
NotifyDescriptor.ERROR_MESSAGE));
return false;
}
if (z > zMax ) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
String.format("Current Z (%.3f) is above Z-Max (%.3f ). Aborting scan.", z, zMax),
NotifyDescriptor.WARNING_MESSAGE));
return false;
}
if ((zMax - zMin) < 0.050) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
String.format("Z scan range is very small (%.3f in). Aborting scan.", (zMax - zMin)),
NotifyDescriptor.WARNING_MESSAGE));
return false;
}
return true;
}
}
Edited POM file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.willwinder</groupId>
<artifactId>ugs-platform-parent</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>ugs-platform-surfacescanner</artifactId>
<packaging>nbm</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<version>4.8</version>
<extensions>true</extensions>
<configuration>
<moduleDependencies>
<module>
<id>org.netbeans.api:org-netbeans-api-annotations-common</id>
<explicitValue>org.netbeans.api.annotations.common/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-awt</id>
<explicitValue>org.openide.awt/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-dialogs</id>
<explicitValue>org.openide.dialogs/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-util</id>
<explicitValue>org.openide.util/9</explicitValue>
</module>
<module>
<id>org.openide:org-openide-util-lookup</id>
<explicitValue>org.openide.util.lookup/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-windows</id>
<explicitValue>org.openide.windows/2</explicitValue>
</module>
</moduleDependencies>
<publicPackages>
</publicPackages>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-dialogs</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-annotations-common</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-awt</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ugs-platform-visualizer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ugs-platform-ugslib</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.willwinder</groupId>
<artifactId>ugs-platform-ugscore</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-ui</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-options-api</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.modules</groupId>
<artifactId>org-openide-util-ui-svg</artifactId>
<version>${netbeans.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
PROBE fix ProbeZAction.java
/*
Copyright 2023 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.platform.probe.actions;
import com.willwinder.ugs.nbp.lib.services.LocalizingService;
import com.willwinder.ugs.platform.probe.ProbeParameters;
import com.willwinder.ugs.platform.probe.ProbeService;
import com.willwinder.ugs.platform.probe.ProbeSettings;
import com.willwinder.ugs.platform.probe.renderable.ProbePreviewManager;
import com.willwinder.universalgcodesender.i18n.Localization;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.Lookup;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.ImageUtilities;
@ActionID(
category = LocalizingService.CATEGORY_MACHINE,
id = "com.willwinder.ugs.platform.probe.actions.ProbeZAction")
@ActionRegistration(
iconBase = ProbeZAction.BASE_ICON,
displayName = "Probe and zero Z",
lazy = false)
@ActionReferences({
@ActionReference(
path = LocalizingService.MENU_MACHINE_PROBE,
position = 10)
})
public class ProbeZAction extends AbstractProbeAction {
public static final String BASE_ICON = "com/willwinder/ugs/platform/probe/icons/zprobe.svg";
public static final String BASE_ICON_LARGE = "com/willwinder/ugs/platform/probe/icons/zprobe24.svg";
public ProbeZAction() {
putValue("iconBase", BASE_ICON);
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(BASE_ICON, false));
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(BASE_ICON_LARGE, false));
putValue("menuText", Localization.getString("probe.action.z"));
putValue(NAME, Localization.getString("probe.action.z"));
}
@Override
public void performProbeAction() {
ProbeService probeService = Lookup.getDefault().lookup(ProbeService.class);
// Get current position
double z;
try {
z = getBackend().getWorkPosition().getZ();
} catch (Exception ex) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
"Could not read current Z position. Aborting probe.",
NotifyDescriptor.ERROR_MESSAGE));
return;
}
// Read probe range settings
double zMin = ProbeSettings.getzDistance();
double zMax = 0.0;
if (z < zMin) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
String.format("Current Z (%.3f) is below Z-Min (%.3f). Aborting probe.", z, zMin),
NotifyDescriptor.ERROR_MESSAGE));
return;
}
if (z > zMax) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
String.format("Current Z (%.3f) is above Z-Max (%.3f). Aborting probe.", z, zMax),
NotifyDescriptor.WARNING_MESSAGE));
return;
}
if ((zMax - zMin) < 0.050) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
String.format("Z probe range is very small (%.3f in). Aborting probe.", zMax - zMin),
NotifyDescriptor.WARNING_MESSAGE));
return;
}
// Build probe config
ProbeParameters pc = new ProbeParameters(
ProbeSettings.getSettingsProbeDiameter(),
getBackend().getMachinePosition(),
0., 0., ProbeSettings.getzDistance(),
0., 0., ProbeSettings.getzOffset(),
0.0,
ProbeSettings.getSettingsFastFindRate(),
ProbeSettings.getSettingsSlowMeasureRate(),
ProbeSettings.getSettingsRetractAmount(),
ProbeSettings.getSettingsDelayAfterRetract(),
getBackend().getSettings().getPreferredUnits(),
ProbeSettings.getSettingsWorkCoordinate()
);
// Update preview
ProbePreviewManager probePreviewManager = Lookup.getDefault().lookup(ProbePreviewManager.class);
probePreviewManager.updateContext(pc, getBackend().getWorkPosition(), getBackend().getMachinePosition());
// Run probe
probeService.performZProbe(pc);
}
@Override
public String getProbeConfirmationText() {
return Localization.getString("probe.action.z.confirmation");
}
}
ProbeModule POM file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.willwinder</groupId>
<artifactId>ugs-platform-parent</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>ProbeModule</artifactId>
<packaging>nbm</packaging>
<name>ProbeModule</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<moduleDependencies>
<module>
<id>org.netbeans.api:org-netbeans-api-annotations-common</id>
<explicitValue>org.netbeans.api.annotations.common/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-awt</id>
<explicitValue>org.openide.awt/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-dialogs</id>
<explicitValue>org.openide.dialogs/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-util</id>
<explicitValue>org.openide.util/9</explicitValue>
</module>
<module>
<id>org.openide:org-openide-util-lookup</id>
<explicitValue>org.openide.util.lookup/1</explicitValue>
</module>
<module>
<id>org.openide:org-openide-windows</id>
<explicitValue>org.openide.windows/2</explicitValue>
</module>
</moduleDependencies>
<publicPackages>
</publicPackages>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-dialogs</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-annotations-common</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-awt</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ugs-platform-ugslib</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ugs-platform-ugscore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ugs-platform-visualizer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-ui</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-options-api</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-settings</artifactId>
<version>${netbeans.version}</version>
</dependency>
</dependencies>
</project>
Metadata
Metadata
Assignees
Labels
No labels