Skip to content

Commit

Permalink
Feature for hole probing (#2197)
Browse files Browse the repository at this point in the history
Added feature for probing the center of holes

Co-authored-by: Richard Toth <risko@iklub.sk>
  • Loading branch information
risototh and Richard Toth committed Apr 12, 2023
1 parent 423e73b commit c9249b3
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 17 deletions.
4 changes: 4 additions & 0 deletions ugs-core/src/resources/MessagesBundle_cs_CZ.properties
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,13 @@ probe.y-distance = Posun měřící sondy Y
probe.z-distance = Posun měřící sondy Z
probe.retract-height = výška retrakce
probe.retract-amount = Rozsah retrakce
probe.hole-diameter = Približný průmer díry
probe.hole-center-hint = Přesuňte sondu do přibližného středu
probe.measure.hole-center = Změrit střed díry
probe.measure.outside-corner = Změřte venkovní roh
probe.measure.inside-corner = Změřte vnitřní roh
probe.visualizer.corner-preview = Náhled rohového měření sondy
probe.visualizer.hole-center-preview = Náhled měření středu díry
probe.visualizer.z-preview = Náhled Z měření sondy
parser.gcode.multiple-axis-commands = Více kódů vyžadujících osová slova na jednom řádku
parser.gcode.missing-axis-commands = Chybí slova os pro příkaz pohybu
Expand Down
4 changes: 4 additions & 0 deletions ugs-core/src/resources/MessagesBundle_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,13 @@ probe.y-distance = Antasten Y-Abstand
probe.z-distance = Antasten Z-Abstand
probe.retract-height = Höhe Zurückziehen
probe.retract-amount = Anzahl Zurückziehen
probe.hole-diameter = Ungefährer Lochdurchmesser
probe.hole-center-hint = Bewegen Sie die Sonde ungefähr in die Mitte
probe.measure.hole-center = Lochmitte messen
probe.measure.outside-corner = Messung Außenecke
probe.measure.inside-corner = Messung Innenecke
probe.visualizer.corner-preview = Ecke antasten Vorschau
probe.visualizer.hole-center-preview = Lochmittensonde Vorschau
probe.visualizer.z-preview = Z antasten Vorschau
parser.gcode.multiple-axis-commands = Mehrere Programme erfordern Achsangaben auf einer Zeile
parser.gcode.missing-axis-commands = Achsangabe für Bewegungsbefehl fehlt
Expand Down
4 changes: 4 additions & 0 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,13 @@ probe.y-distance = Probe Y Distance
probe.z-distance = Probe Z Distance
probe.retract-height = Retract height
probe.retract-amount = Retract amount
probe.hole-diameter = Approximate hole diameter
probe.hole-center-hint = Move probe to approximate center
probe.measure.hole-center = Measure hole center
probe.measure.outside-corner = Measure outside corner
probe.measure.inside-corner = Measure inside corner
probe.visualizer.corner-preview = Corner probe preview
probe.visualizer.hole-center-preview = Hole center probe preview
probe.visualizer.z-preview = Z probe preview
parser.gcode.multiple-axis-commands = Multiple codes requiring axis words on one line
parser.gcode.missing-axis-commands = Axis words missing for motion command
Expand Down
26 changes: 15 additions & 11 deletions ugs-core/src/resources/MessagesBundle_sk_SK.properties
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,21 @@ mainWindow.swing.checkMode = Režim kontroly
mainWindow.swing.getState = Zobraziť stav
platform.window.probe-module =
platform.window.probe-module.tooltip =
probe.find-rate =
probe.measure-rate =
probe.x-distance =
probe.y-distance =
probe.z-distance =
probe.retract-height =
probe.retract-amount =
probe.measure.outside-corner =
probe.measure.inside-corner =
probe.visualizer.corner-preview =
probe.visualizer.z-preview =
probe.find-rate = Rýchlosť hľadania
probe.measure-rate = Rýchlosť merania
probe.x-distance = Vzdialenosť sondy X
probe.y-distance = Vzdialenosť sondy Y
probe.z-distance = Vzdialenosť sondy Z
probe.retract-height = Výška retrakcie
probe.retract-amount = Rozsah retrakcie
probe.hole-diameter = Prubližný priemer diery
probe.hole-center-hint = Presuňte sondu približne do stredu
probe.measure.hole-center = Zmerať stred diery
probe.measure.outside-corner = Zmerať vonkajší roh
probe.measure.inside-corner = Zmerať vnútorný roh
probe.visualizer.corner-preview = Náhľad rohového merania
probe.visualizer.hole-center-preview = Náhľad merania stredu diery
probe.visualizer.z-preview = Náhľad merania Z
parser.gcode.multiple-axis-commands =
parser.gcode.missing-axis-commands =
sender.nightly-warning = Zobraziť upozornenie pre Nightly Builds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private enum ProbeOperation {
OUTSIDE_XY(4),
OUTSIDE_XYZ(6),
//INSIDE_XY (4),
//INSIDE_CIRCLE(4)
INSIDE_CIRCLE(8)
;

private final int numProbes;
Expand Down Expand Up @@ -92,6 +92,7 @@ public static class ProbeParameters {
public final double xOffset;
public final double yOffset;
public final double zOffset;
public final double holeDiameter;
public final double feedRate;
public final double feedRateSlow;
public final double retractAmount;
Expand All @@ -105,6 +106,7 @@ public static class ProbeParameters {
public ProbeParameters(double diameter, Position start,
double xSpacing, double ySpacing, double zSpacing,
double xOffset, double yOffset, double zOffset,
double holeDiameter,
double feedRate, double feedRateSlow, double retractAmount,
Units u, WorkCoordinateSystem wcs) {
this.endPosition = null;
Expand All @@ -116,6 +118,7 @@ public ProbeParameters(double diameter, Position start,
this.xOffset = xOffset;
this.yOffset = yOffset;
this.zOffset = zOffset;
this.holeDiameter = holeDiameter;
this.feedRate = feedRate;
this.feedRateSlow = feedRateSlow;
this.retractAmount = retractAmount;
Expand Down Expand Up @@ -378,6 +381,91 @@ private void performXYZProbeInternal(int stepNumber) throws IllegalStateExceptio
}
}

void performHoleCenterProbe(ProbeParameters params) throws IllegalStateException {
validateState();
currentOperation = ProbeOperation.INSIDE_CIRCLE;
this.params = params;
performHoleCenterProbeInternal(0);
}

private void performHoleCenterProbeInternal(int stepNumber) throws IllegalStateException {
String g = GcodeUtils.unitCommand(params.units);
String g0Abs = "G90 " + g + " G0";
String g0Rel = "G91 " + g + " G0";
String g0MCS = "G53 " + g + " G0";
double holeRadius = params.holeDiameter / 2.0;

continuation = () -> performHoleCenterProbeInternal(stepNumber + 1);

try {
switch (stepNumber) { // NOTE: G code comments are with radius 25 and retract 2, G21, G54
case 0: { // find -X
// Reset (0,0,_) to make it easier to retract.
updateWCS(params.wcsToUpdate, 0.0, 0.0, null); // G10 L20 P0 X0 Y0
probe('X', params.feedRate, -holeRadius, params.units); // G21 G91 G49; G38.2 X-25.0 F250
break;
}
case 1: { // retract & measure -X
gcode(g0Rel + " X" + Utils.formatter.format(params.retractAmount)); // G91 G21 G0 X2.0
probe('X', params.feedRateSlow, -holeRadius, params.units); // G21 G91 G49; G38.2 X-25.0 F50
break;
}
case 2: { // move to X origin, find +X
gcode(g0Abs + " X0"); // G90 G21 G0 X0.0
probe('X', params.feedRate, holeRadius, params.units); // G21 G91 G49; G38.2 X25.0 F250
break;
}
case 3: { // retract & measure +X
gcode(g0Rel + " X" + Utils.formatter.format(-1.0 * params.retractAmount)); // G91 G21 G0 X-2.0
probe('X', params.feedRateSlow, holeRadius, params.units); // G21 G91 G49; G38.2 X25.0 F50
break;
}
case 4: { // calculate and move to X center, find -Y
Preconditions.checkState(probePositions.size() == 4, "Unexpected number of probe positions.");

Position min = probePositions.get(1).getPositionIn(params.units);
Position max = probePositions.get(3).getPositionIn(params.units);
double midX = min.x + (max.x - min.x) / 2.0;

gcode(g0MCS + " X" + Utils.formatter.format(midX)); // G53 G21 G0 X-336.29
probe('Y', params.feedRate, -holeRadius, params.units); // G21 G91 G49; G38.2 Y-25.0 F250
break;
}
case 5: { // retract & measure -Y
gcode(g0Rel + " Y" + Utils.formatter.format(params.retractAmount)); // G91 G21 G0 Y2.0
probe('Y', params.feedRateSlow, -holeRadius, params.units); // G21 G91 G49; G38.2 Y-25.0 F50
break;
}
case 6: { // move to Y origin, find +Y
gcode(g0Abs + " Y0"); // G90 G21 G0 Y0.0
probe('Y', params.feedRate, holeRadius, params.units); // G21 G91 G49; G38.2 Y25.0 F250
break;
}
case 7: { // retract & measure +Y
gcode(g0Rel + " Y" + Utils.formatter.format(-1.0 * params.retractAmount));// G91 G21 G0 Y-2.0
probe('Y', params.feedRateSlow, holeRadius, params.units);// G21 G91 G49; G38.2 Y25.0 F50
break;
}
case 8: { // calculate Y center and move to X/Y center, zero X/Y WCS
Preconditions.checkState(probePositions.size() == 8, "Unexpected number of probe positions.");

Position min = probePositions.get(5).getPositionIn(params.units);
Position max = probePositions.get(7).getPositionIn(params.units);
double midY = min.y + (max.y - min.y) / 2.0;

gcode(g0MCS + " Y" + Utils.formatter.format(midY)); // G53 G0 Y-322.116
updateWCS(params.wcsToUpdate, 0.0, 0.0, null); // G10 L20 P0 X0 Y0
break;
}
default:
throw new UnsupportedOperationException("Invalid step number: " + stepNumber);
}
} catch (Exception e) {
resetProbe();
logger.log(Level.SEVERE, "Exception during outside corner probe operation.", e);
}
}

private void updateWCS(WorkCoordinateSystem wcs, Double x, Double y, Double z) throws Exception {
StringBuilder sb = new StringBuilder();
// Format the x, y, and z to prevent printing with double "E" notation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.lib.services.TopComponentLocalizer;
import com.willwinder.ugs.platform.probe.ProbeService.ProbeParameters;
import com.willwinder.ugs.platform.probe.renderable.CornerProbePathPreview;
import com.willwinder.ugs.platform.probe.renderable.HoleCenterPathPreview;
import com.willwinder.ugs.platform.probe.renderable.ZProbePathPreview;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.listeners.UGSEventListener;
Expand Down Expand Up @@ -87,6 +88,8 @@ public final class ProbeTopComponent extends TopComponent implements UGSEventLis
Localization.getString("probe.visualizer.corner-preview"));
private ZProbePathPreview zRenderable = new ZProbePathPreview(
Localization.getString("probe.visualizer.z-preview"));
private HoleCenterPathPreview hcRenderable = new HoleCenterPathPreview(
Localization.getString("probe.visualizer.hole-center-preview"));

private static final String X_OFFSET = Localization.getString("autoleveler.option.offset-x") + ":";
private static final String Y_OFFSET = Localization.getString("autoleveler.option.offset-y") + ":";
Expand All @@ -95,12 +98,18 @@ public final class ProbeTopComponent extends TopComponent implements UGSEventLis
private static final String X_DISTANCE = Localization.getString("probe.x-distance") + ":";
private static final String Y_DISTANCE = Localization.getString("probe.y-distance") + ":";
private static final String Z_DISTANCE = Localization.getString("probe.probe-distance") + ":";
private static final String HC_DIAMETER = Localization.getString("probe.hole-diameter");
private static final String HC_HINT = Localization.getString("probe.hole-center-hint");

public final static String ProbeTitle = Localization.getString("platform.window.probe-module", lang);
public final static String ProbeTooltip = Localization.getString("platform.window.probe-module.tooltip", lang);
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 SpinnerNumberModel hcDiameterModel;
private final JButton measureHC = new JButton(Localization.getString("probe.measure.hole-center"));

// xyz tab
private static final String XYZ_TAB = "XYZ";
Expand Down Expand Up @@ -168,6 +177,8 @@ protected class ProbeSettings {
private double outsideXOffset;
private double outsideYOffset;

private double hcDiameter;

private double zDistance;
private double zOffset;

Expand Down Expand Up @@ -197,6 +208,9 @@ public ProbeTopComponent() {

double largeSpinner = 1000000;

// hole diameter tab
hcDiameterModel = new SpinnerNumberModel(10., -largeSpinner, largeSpinner, 0.1);

// XYZ TAB
xyzXDistanceModel = new SpinnerNumberModel(10., -largeSpinner, largeSpinner, 0.1);
xyzYDistanceModel = new SpinnerNumberModel(10., -largeSpinner, largeSpinner, 0.1);
Expand Down Expand Up @@ -232,11 +246,24 @@ public ProbeTopComponent() {
settingsSlowMeasureRate = new SpinnerNumberModel(100., 1, largeSpinner, 1.);
settingsRetractAmount = new SpinnerNumberModel(1, 0.1, largeSpinner, 0.1);

measureHC.addActionListener(e -> {
ProbeParameters pc = new ProbeParameters(
getDouble(settingsProbeDiameter), backend.getMachinePosition(),
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
getDouble(hcDiameterModel),
getDouble(settingsFastFindRate), getDouble(settingsSlowMeasureRate),
getDouble(settingsRetractAmount), getUnits(), get(settingsWorkCoordinate));
this.hcRenderable.setContext(pc, backend.getWorkPosition(), backend.getMachinePosition());
ps2.performHoleCenterProbe(pc);
});

measureXYZ.addActionListener(e -> {
ProbeParameters pc = new ProbeParameters(
getDouble(settingsProbeDiameter), backend.getMachinePosition(),
getDouble(xyzXDistanceModel), getDouble(xyzYDistanceModel), getDouble(xyzZDistanceModel),
getDouble(xyzXOffsetModel), getDouble(xyzYOffsetModel), getDouble(xyzZOffsetModel),
0.0,
getDouble(settingsFastFindRate), getDouble(settingsSlowMeasureRate),
getDouble(settingsRetractAmount), getUnits(), get(settingsWorkCoordinate));
this.cornerRenderable.setContext(pc, backend.getWorkPosition(), backend.getMachinePosition());
Expand All @@ -248,6 +275,7 @@ public ProbeTopComponent() {
getDouble(settingsProbeDiameter), backend.getMachinePosition(),
getDouble(outsideXDistanceModel), getDouble(outsideYDistanceModel), 0.,
getDouble(outsideXOffsetModel), getDouble(outsideYOffsetModel), 0.,
0.0,
getDouble(settingsFastFindRate), getDouble(settingsSlowMeasureRate),
getDouble(settingsRetractAmount), getUnits(), get(settingsWorkCoordinate));
this.cornerRenderable.setContext(pc, backend.getWorkPosition(), backend.getMachinePosition());
Expand All @@ -268,6 +296,7 @@ public ProbeTopComponent() {
getDouble(settingsProbeDiameter), backend.getMachinePosition(),
0., 0., getDouble(zProbeDistance),
0., 0., getDouble(zProbeOffset),
0.0,
getDouble(settingsFastFindRate), getDouble(settingsSlowMeasureRate),
getDouble(settingsRetractAmount), getUnits(), get(settingsWorkCoordinate));
this.zRenderable.setStart(backend.getWorkPosition());
Expand All @@ -278,6 +307,8 @@ public ProbeTopComponent() {
updateControls();

// Listeners...
this.hcDiameterModel.addChangeListener(l -> controlChangeListener());

this.xyzXDistanceModel.addChangeListener(l -> controlChangeListener());
this.xyzYDistanceModel.addChangeListener(l -> controlChangeListener());
this.xyzZDistanceModel.addChangeListener(l -> controlChangeListener());
Expand Down Expand Up @@ -311,6 +342,11 @@ private void controlChangeListener() {
Renderable before = active;
//switch (this.jtp.getTabComponentAt(this.jtp.getSelectedIndex()).getName()) {
switch (this.jtp.getTitleAt(this.jtp.getSelectedIndex())) {
case HC_TAB:
// TODO
active = hcRenderable;
hcRenderable.updateSpacing(getDouble(hcDiameterModel));
break;
case XYZ_TAB:
// TODO: XYZ Renderable
active = cornerRenderable;
Expand Down Expand Up @@ -349,6 +385,7 @@ private void controlChangeListener() {

public void updateControls() {
boolean enabled = backend.isIdle();
this.measureHC.setEnabled(enabled);
this.measureInside.setEnabled(enabled);
this.measureOutside.setEnabled(enabled);
this.zProbeButton.setEnabled(enabled);
Expand All @@ -371,6 +408,15 @@ private static WorkCoordinateSystem get(JComboBox<WorkCoordinateSystem> wcsCombo
}

private void initComponents() {
// HC TAB
JPanel hc = new JPanel(new MigLayout("wrap 4"));
hc.add(new JLabel(HC_DIAMETER));
hc.add(new JSpinner(this.hcDiameterModel), "growx");

hc.add(this.measureHC, "spanx 2, spany 2, growx, growy");

hc.add(new JLabel(HC_HINT), "spanx 2, growx");

// XYZ TAB
JPanel xyz = new JPanel(new MigLayout("flowy, wrap 3"));
xyz.add(new JLabel(X_DISTANCE));
Expand Down Expand Up @@ -447,6 +493,7 @@ private void initComponents() {
settings.add(new JLabel(Localization.getString("probe.retract-amount") + ":"), "al right");
settings.add(new JSpinner(settingsRetractAmount), "growx");

jtp.add(HC_TAB, hc);
jtp.add(XYZ_TAB, xyz);
jtp.add(OUTSIDE_TAB, outside);
jtp.add(Z_TAB, z);
Expand Down Expand Up @@ -482,6 +529,8 @@ public void writeProperties(java.util.Properties p) {
p.setProperty("version", "1.0");

ProbeSettings ps = new ProbeSettings();
ps.hcDiameter = getDouble(hcDiameterModel);

ps.xyzXDistance = getDouble(this.xyzXDistanceModel);
ps.xyzYDistance = getDouble(xyzYDistanceModel);
ps.xyzZDistance = getDouble(xyzZDistanceModel);
Expand Down Expand Up @@ -521,6 +570,8 @@ public void readProperties(java.util.Properties p) {
if (jsonData == null) return;

ProbeSettings ps = new Gson().fromJson(jsonData, ProbeSettings.class);
hcDiameterModel.setValue(ps.hcDiameter);

xyzXDistanceModel.setValue(ps.xyzXDistance);
xyzYDistanceModel.setValue(ps.xyzYDistance);
xyzZDistanceModel.setValue(ps.xyzZDistance);
Expand Down

0 comments on commit c9249b3

Please sign in to comment.