Search in sources :

Example 26 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class GcodeTilerTopComponent method loadDimensions.

private boolean loadDimensions() {
    if (backend.getProcessedGcodeFile() == null) {
        GUIHelpers.displayErrorDialog("Must load gcode file first.");
        return false;
    }
    Settings.FileStats fs = backend.getSettings().getFileStats();
    UnitUtils.Units u = selectedUnit(this.units.getSelectedIndex());
    Position min = fs.minCoordinate.getPositionIn(u);
    Position max = fs.maxCoordinate.getPositionIn(u);
    GcodeTilerTopComponent.xWidth = max.x - min.x;
    GcodeTilerTopComponent.yWidth = max.y - min.y;
    return true;
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) Position(com.willwinder.universalgcodesender.model.Position) Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 27 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class ProbeServiceTest method testProbeServiceOutside.

@Test
public void testProbeServiceOutside() throws Exception {
    doReturn(true).when(backend).isIdle();
    ProbeService ps = new ProbeService(backend);
    ProbeParameters pc = new ProbeParameters(1, new Position(5, 5, 5, Units.MM), 10, 10, 0., 1, 1, 1, 100, 25, 5, Units.MM, G55);
    ps.performOutsideCornerProbe(pc);
    Position probeY = new Position(2.0, 2.0, 0, Units.MM);
    Position probeX = new Position(1.0, 1.0, 0, Units.MM);
    // Events to transition between states.
    ps.UGSEvent(new UGSEvent(probeY));
    ps.UGSEvent(new UGSEvent(probeY));
    ps.UGSEvent(new UGSEvent(probeX));
    ps.UGSEvent(new UGSEvent(probeX));
    ps.UGSEvent(new UGSEvent(UGSEvent.ControlState.COMM_IDLE));
    InOrder order = inOrder(backend);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X0.0Y0.0");
    // probe Y axis
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + pc.xSpacing);
    order.verify(backend, times(1)).probe("Y", pc.feedRate, pc.ySpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 Y" + retractDistance(pc.ySpacing));
    order.verify(backend, times(1)).probe("Y", pc.feedRateSlow, pc.ySpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y0.0");
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X0.0");
    // probe X axis
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y" + pc.ySpacing);
    order.verify(backend, times(1)).probe("X", pc.feedRate, pc.xSpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 X" + retractDistance(pc.ySpacing));
    order.verify(backend, times(1)).probe("X", pc.feedRateSlow, pc.xSpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X0.0");
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y0.0");
    // Verify the correct offset
    double radius = pc.probeDiameter / 2;
    double xDir = ((pc.xSpacing > 0) ? -1 : 1);
    double yDir = ((pc.ySpacing > 0) ? -1 : 1);
    double xProbeOffset = pc.startPosition.x - probeX.x + xDir * (radius + Math.abs(pc.xOffset));
    double yProbeOffset = pc.startPosition.y - probeY.y + yDir * (radius + Math.abs(pc.yOffset));
    order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X" + xProbeOffset + "Y" + yProbeOffset);
}
Also used : ProbeParameters(com.willwinder.ugs.platform.probe.ProbeService.ProbeParameters) InOrder(org.mockito.InOrder) Position(com.willwinder.universalgcodesender.model.Position) UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent) Test(org.junit.Test)

Example 28 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class ProbeServiceTest method testProbeServiceXYZ.

@Test
public void testProbeServiceXYZ() throws Exception {
    doReturn(true).when(backend).isIdle();
    ProbeService ps = new ProbeService(backend);
    ProbeParameters pc = new ProbeParameters(1, new Position(5, 5, 5, Units.MM), 10, 10, 0., 1, 1, 1, 100, 25, 5, Units.MM, G55);
    ps.performXYZProbe(pc);
    Position probeY = new Position(2.0, 2.0, 0, Units.MM);
    Position probeX = new Position(1.0, 1.0, 0, Units.MM);
    Position probeZ = new Position(0., 0., 3.0, Units.MM);
    // Events to transition between states.
    ps.UGSEvent(new UGSEvent(probeZ));
    ps.UGSEvent(new UGSEvent(probeZ));
    ps.UGSEvent(new UGSEvent(probeX));
    ps.UGSEvent(new UGSEvent(probeX));
    ps.UGSEvent(new UGSEvent(probeY));
    ps.UGSEvent(new UGSEvent(probeY));
    ps.UGSEvent(new UGSEvent(UGSEvent.ControlState.COMM_IDLE));
    InOrder order = inOrder(backend);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X0.0Y0.0Z0.0");
    // Probe Z axis
    order.verify(backend, times(1)).probe("Z", pc.feedRate, pc.zSpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 Z" + retractDistance(pc.zSpacing));
    order.verify(backend, times(1)).probe("Z", pc.feedRateSlow, pc.zSpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z0.0");
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + -pc.xSpacing);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z" + pc.zSpacing);
    // probe X axis
    order.verify(backend, times(1)).probe("X", pc.feedRate, pc.xSpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 X" + retractDistance(pc.ySpacing));
    order.verify(backend, times(1)).probe("X", pc.feedRateSlow, pc.xSpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + -pc.xSpacing);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Y" + -pc.ySpacing);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X" + pc.xSpacing);
    // probe Y axis
    order.verify(backend, times(1)).probe("Y", pc.feedRate, pc.ySpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G91 G21 G0 Y" + retractDistance(pc.ySpacing));
    order.verify(backend, times(1)).probe("Y", pc.feedRateSlow, pc.ySpacing, pc.units);
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 Z0.0");
    order.verify(backend, times(1)).sendGcodeCommand(true, "G90 G21 G0 X0.0 Y0.0");
    // Verify the correct offset
    double radius = pc.probeDiameter / 2;
    double xDir = ((pc.xSpacing > 0) ? -1 : 1);
    double yDir = ((pc.ySpacing > 0) ? -1 : 1);
    double xProbeOffset = pc.startPosition.x - probeX.x + xDir * (radius + Math.abs(pc.xOffset));
    double yProbeOffset = pc.startPosition.y - probeY.y + yDir * (radius + Math.abs(pc.yOffset));
    double zProbeOffset = pc.startPosition.z - probeZ.z;
    order.verify(backend, times(1)).sendGcodeCommand(true, "G10 L20 P2 X" + xProbeOffset + "Y" + yProbeOffset + "Z" + zProbeOffset);
}
Also used : ProbeParameters(com.willwinder.ugs.platform.probe.ProbeService.ProbeParameters) InOrder(org.mockito.InOrder) Position(com.willwinder.universalgcodesender.model.Position) UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent) Test(org.junit.Test)

Example 29 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class RendererInputHandler method updateBounds.

/**
 * Pass new bounds (after interpolating arcs) in case of weird arcs.
 */
private void updateBounds(Point3d min, Point3d max) {
    // Update bounds.
    FileStats fs = settings.getFileStats();
    fs.minCoordinate = new Position(min.x, min.y, min.z, Units.MM);
    fs.maxCoordinate = new Position(max.x, max.y, max.z, Units.MM);
    settings.setFileStats(fs);
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) FileStats(com.willwinder.universalgcodesender.utils.Settings.FileStats)

Example 30 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class AutoLevelerTopComponent method dataViewerActionPerformed.

// GEN-LAST:event_scanSurfaceButtonActionPerformed
private void dataViewerActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_dataViewerActionPerformed
    List<Map<String, Double>> probeData = new ArrayList<>();
    // Collect data from grid.
    if (scanner != null && scanner.getProbePositionGrid() != null) {
        for (Position[] row : scanner.getProbePositionGrid()) {
            for (Position p : row) {
                if (p != null) {
                    probeData.add(ImmutableMap.of("x", p.x, "y", p.y, "z", p.z));
                }
            }
        }
    }
    JTextArea ta = new JTextArea(15, 30);
    ta.setText(GSON.toJson(probeData));
    JOptionPane.showMessageDialog(null, new JScrollPane(ta));
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) Position(com.willwinder.universalgcodesender.model.Position) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Position (com.willwinder.universalgcodesender.model.Position)66 Test (org.junit.Test)33 GcodeState (com.willwinder.universalgcodesender.gcode.GcodeState)15 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)7 ControllerStatus (com.willwinder.universalgcodesender.listeners.ControllerStatus)6 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)6 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)5 Units (com.willwinder.universalgcodesender.model.UnitUtils.Units)5 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)4 Settings (com.willwinder.universalgcodesender.utils.Settings)4 ArrayList (java.util.ArrayList)4 ProbeParameters (com.willwinder.ugs.platform.probe.ProbeService.ProbeParameters)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)3 PlaneFormatter (com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)3 UGSEvent (com.willwinder.universalgcodesender.model.UGSEvent)3 AutoLevelSettings (com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings)3 SplitCommand (com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand)2 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)2 Code (com.willwinder.universalgcodesender.gcode.util.Code)2 PointSegment (com.willwinder.universalgcodesender.types.PointSegment)2