Search in sources :

Example 16 with PartialPosition

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

the class MirrorAction method getCenter.

private Position getCenter(File gcodeFile) throws IOException, GcodeParserException {
    List<LineSegment> lineSegments = parseGcodeLinesFromFile(gcodeFile);
    // We only care about carving motion, filter those commands out
    List<PartialPosition> pointList = lineSegments.parallelStream().filter(lineSegment -> !lineSegment.isFastTraverse()).flatMap(lineSegment -> {
        PartialPosition start = PartialPosition.from(lineSegment.getStart());
        PartialPosition end = PartialPosition.from(lineSegment.getEnd());
        return Stream.of(start, end);
    }).distinct().collect(Collectors.toList());
    return MathUtils.getCenter(pointList);
}
Also used : ActionID(org.openide.awt.ActionID) Position(com.willwinder.universalgcodesender.model.Position) ControllerStateEvent(com.willwinder.universalgcodesender.model.events.ControllerStateEvent) com.willwinder.universalgcodesender.utils(com.willwinder.universalgcodesender.utils) BackendAPI(com.willwinder.universalgcodesender.model.BackendAPI) ActionReference(org.openide.awt.ActionReference) UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent) UGSEventListener(com.willwinder.universalgcodesender.listeners.UGSEventListener) EditorActionRegistration(org.netbeans.api.editor.EditorActionRegistration) GcodeViewParse(com.willwinder.universalgcodesender.visualizer.GcodeViewParse) GcodeLanguageConfig(com.willwinder.ugs.nbp.editor.GcodeLanguageConfig) HelpCtx(org.openide.util.HelpCtx) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) CentralLookup(com.willwinder.ugs.nbp.lib.lookup.CentralLookup) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) MirrorProcessor(com.willwinder.universalgcodesender.gcode.processors.MirrorProcessor) Node(org.openide.nodes.Node) VisualizerUtils(com.willwinder.universalgcodesender.visualizer.VisualizerUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) GcodeDataObject(com.willwinder.ugs.nbp.editor.GcodeDataObject) LocalizingService(com.willwinder.ugs.nbp.lib.services.LocalizingService) File(java.io.File) FileStateEvent(com.willwinder.universalgcodesender.model.events.FileStateEvent) LoaderDialogHelper(com.willwinder.universalgcodesender.uielements.helpers.LoaderDialogHelper) CookieAction(org.openide.util.actions.CookieAction) java.awt(java.awt) ActionReferences(org.openide.awt.ActionReferences) List(java.util.List) Stream(java.util.stream.Stream) ActionRegistration(org.openide.awt.ActionRegistration) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment)

Example 17 with PartialPosition

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

the class SimplePocketTest method pocketShouldNotExceedTheGeometry.

@Test
public void pocketShouldNotExceedTheGeometry() {
    double toolRadius = 2.5;
    double geometrySize = 10d;
    double safeHeight = 1;
    double targetDepth = -10;
    int depthPerPass = 1;
    Rectangle rectangle = new Rectangle();
    rectangle.setSize(new Size(geometrySize, geometrySize));
    SimplePocket simplePocket = new SimplePocket(rectangle);
    simplePocket.setTargetDepth(targetDepth);
    simplePocket.setDepthPerPass(depthPerPass);
    simplePocket.setToolDiameter(toolRadius * 2);
    simplePocket.setStepOver(1);
    simplePocket.setSafeHeight(safeHeight);
    List<Segment> segmentList = simplePocket.toGcodePath().getSegments();
    Segment firstSegment = segmentList.get(0);
    assertEquals("The first segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
    assertFalse("The first segment should not move X", firstSegment.point.hasAxis(Axis.X));
    assertFalse("The first segment should not move Y", firstSegment.point.hasAxis(Axis.Y));
    Segment secondSegment = segmentList.get(1);
    assertEquals("The second segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
    assertEquals("The second segment should move to first X position", safeHeight, secondSegment.point.getAxis(Axis.X), toolRadius);
    assertEquals("The second segment should move to first Y position", safeHeight, secondSegment.point.getAxis(Axis.Y), toolRadius);
    // Make sure that we don't move outside the boundary of the geometry
    segmentList.stream().filter(segment -> segment.type == SegmentType.LINE || segment.type == SegmentType.POINT).forEach(segment -> {
        assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) >= toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) >= toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) <= geometrySize - toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) <= geometrySize - toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) < 0);
        assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) >= targetDepth);
    });
    List<Segment> drillOperations = segmentList.stream().filter(segment -> segment.type == SegmentType.POINT).collect(Collectors.toList());
    assertEquals("There should be a number of drill operations when making a pocket", Math.abs(targetDepth / depthPerPass), drillOperations.size(), 0.1);
    PartialPosition point = drillOperations.get(drillOperations.size() - 1).getPoint();
    assertEquals("Last operation should reach the target depth", targetDepth, point.getAxis(Axis.Z), 0.1);
}
Also used : Size(com.willwinder.ugs.nbp.designer.model.Size) Segment(com.willwinder.ugs.nbp.designer.io.gcode.path.Segment) Axis(com.willwinder.universalgcodesender.model.Axis) List(java.util.List) Rectangle(com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle) SegmentType(com.willwinder.ugs.nbp.designer.io.gcode.path.SegmentType) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Size(com.willwinder.ugs.nbp.designer.model.Size) Rectangle(com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle) Segment(com.willwinder.ugs.nbp.designer.io.gcode.path.Segment) Test(org.junit.Test)

Example 18 with PartialPosition

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

the class JogService method adjustManualLocationXY.

/**
 * Adjusts the XY axis location.
 * @param x direction.
 * @param y direction.
 */
public void adjustManualLocationXY(int x, int y) {
    try {
        double feedRate = getFeedRate();
        double stepSize = getStepSizeXY();
        Units preferredUnits = getUnits();
        Double dx = x == 0 ? null : x * stepSize;
        Double dy = y == 0 ? null : y * stepSize;
        backend.adjustManualLocation(new PartialPosition(dx, dy, null, preferredUnits), feedRate);
    } catch (Exception e) {
    // NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
    // DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 19 with PartialPosition

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

the class GrblControllerTest method testJogMachine.

/**
 * Test of jogMachine method, of class AbstractController.
 */
@Test
public void testJogMachine() throws Exception {
    System.out.println("jogMachine");
    GrblController instance = new GrblController(mgc);
    instance.setDistanceModeCode("G90");
    instance.setUnitsCode("G21");
    instance.openCommPort(getSettings().getConnectionDriver(), "foo", 2400);
    // Abstract controller should be used when grbl jog mode is disabled.
    instance.rawResponseHandler("Grbl 0.8c");
    instance.jogMachine(new PartialPosition(-10., null, 10., UnitUtils.Units.INCH), 11);
    assertEquals("G20G91G1X-10Z10F11", mgc.queuedStrings.get(2));
    assertEquals("G90 G21 ", mgc.queuedStrings.get(3));
    instance.jogMachine(new PartialPosition(null, 10., null, UnitUtils.Units.MM), 11);
    assertEquals("G21G91G1Y10F11", mgc.queuedStrings.get(4));
    assertEquals("G90 G21 ", mgc.queuedStrings.get(5));
    instance.rawResponseHandler("Grbl 1.1a");
    instance.jogMachine(new PartialPosition(-10., null, 10., UnitUtils.Units.INCH), 11);
    assertEquals("$J=G20G91X-10Z10F11", mgc.queuedStrings.get(8));
    instance.jogMachine(new PartialPosition(null, 10., null, UnitUtils.Units.MM), 11);
    assertEquals("$J=G21G91Y10F11", mgc.queuedStrings.get(9));
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition)

Example 20 with PartialPosition

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

the class G2CoreControllerTest method jogMachineToWhenUsingInchesShouldConvertCoordinates.

@Test
public void jogMachineToWhenUsingInchesShouldConvertCoordinates() throws Exception {
    // Given
    when(communicator.isConnected()).thenReturn(true);
    // Simulate that the machine is running in inches
    controller.getCurrentGcodeState().units = Code.G20;
    // When
    InOrder orderVerifier = inOrder(communicator);
    controller.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000);
    // Then
    orderVerifier.verify(communicator, times(1)).queueCommand(any(GcodeCommand.class));
    orderVerifier.verify(communicator).streamCommands();
    GcodeCommand command = queueCommandArgumentCaptor.getAllValues().get(0);
    assertEquals("G20G90G1X0.039Y0.079Z0.118F39.37", command.getCommandString());
    assertTrue(command.isGenerated());
    assertTrue(command.isTemporaryParserModalChange());
}
Also used : InOrder(org.mockito.InOrder) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test)

Aggregations

PartialPosition (com.willwinder.universalgcodesender.model.PartialPosition)36 Test (org.junit.Test)19 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)10 List (java.util.List)8 InOrder (org.mockito.InOrder)8 Position (com.willwinder.universalgcodesender.model.Position)7 Collectors (java.util.stream.Collectors)6 CentralLookup (com.willwinder.ugs.nbp.lib.lookup.CentralLookup)4 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)4 UGSEventListener (com.willwinder.universalgcodesender.listeners.UGSEventListener)4 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)4 UGSEvent (com.willwinder.universalgcodesender.model.UGSEvent)4 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)4 ControllerStateEvent (com.willwinder.universalgcodesender.model.events.ControllerStateEvent)4 FileStateEvent (com.willwinder.universalgcodesender.model.events.FileStateEvent)4 LoaderDialogHelper (com.willwinder.universalgcodesender.uielements.helpers.LoaderDialogHelper)4 com.willwinder.universalgcodesender.utils (com.willwinder.universalgcodesender.utils)4 GcodeViewParse (com.willwinder.universalgcodesender.visualizer.GcodeViewParse)4 LineSegment (com.willwinder.universalgcodesender.visualizer.LineSegment)4 VisualizerUtils (com.willwinder.universalgcodesender.visualizer.VisualizerUtils)4