Search in sources :

Example 36 with Position

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

the class GcodeViewParse method toObjRedux.

/**
 * The original (working) gcode to LineSegment collection code.
 * @param gcode commands to visualize.
 * @param arcSegmentLength length of line segments when expanding an arc.
 */
public List<LineSegment> toObjRedux(List<String> gcode, double arcSegmentLength) throws GcodeParserException {
    GcodeParser gp = getParser(arcSegmentLength);
    lines.clear();
    // Save the state
    Position start = new Position();
    for (String s : gcode) {
        List<String> commands = gp.preprocessCommand(s, gp.getCurrentState());
        for (String command : commands) {
            List<GcodeMeta> points = gp.addCommand(command);
            for (GcodeMeta meta : points) {
                if (meta.point != null) {
                    addLinesFromPointSegment(start, meta.point, arcSegmentLength, lines);
                    start.set(meta.point.point());
                }
            }
        }
    }
    return lines;
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser)

Example 37 with Position

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

the class GcodePreprocessorUtils method generatePointsAlongArcBDring.

/**
 * Generates the points along an arc including the start and end points.
 */
private static List<Position> generatePointsAlongArcBDring(final Position p1, final Position p2, final Position center, boolean isCw, double radius, double startAngle, double sweep, int numPoints, PlaneFormatter plane) {
    Position lineStart = new Position(p1);
    List<Position> segments = new ArrayList<>();
    double angle;
    // Calculate radius if necessary.
    if (radius == 0) {
        radius = Math.sqrt(Math.pow(plane.axis0(p1) - plane.axis1(center), 2.0) + Math.pow(plane.axis1(p1) - plane.axis1(center), 2.0));
    }
    double zIncrement = (plane.linear(p2) - plane.linear(p1)) / numPoints;
    for (int i = 0; i < numPoints; i++) {
        if (isCw) {
            angle = (startAngle - i * sweep / numPoints);
        } else {
            angle = (startAngle + i * sweep / numPoints);
        }
        if (angle >= Math.PI * 2) {
            angle = angle - Math.PI * 2;
        }
        // lineStart.x = Math.cos(angle) * radius + center.x;
        plane.setAxis0(lineStart, Math.cos(angle) * radius + plane.axis0(center));
        // lineStart.y = Math.sin(angle) * radius + center.y;
        plane.setAxis1(lineStart, Math.sin(angle) * radius + plane.axis1(center));
        // lineStart.z += zIncrement;
        plane.setLinear(lineStart, plane.linear(lineStart) + zIncrement);
        segments.add(new Position(lineStart));
    }
    segments.add(new Position(p2));
    return segments;
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) ArrayList(java.util.ArrayList)

Example 38 with Position

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

the class GrblControllerMockTests method testProbeResponse.

@Test
public void testProbeResponse() {
    GrblController gc = Mockito.spy(new GrblController());
    GrblFirmwareSettings firmwareSettings = Mockito.mock(GrblFirmwareSettings.class);
    Mockito.when(firmwareSettings.getReportingUnits()).thenReturn(Units.MM);
    doReturn(firmwareSettings).when(gc).getFirmwareSettings();
    gc.rawResponseListener("[PRB:-192.200,-202.000,-40.400:1]");
    ArgumentCaptor<Position> probeCaptor = ArgumentCaptor.forClass(Position.class);
    verify(gc, times(1)).dispatchProbeCoordinates(probeCaptor.capture());
    assertThat(probeCaptor.getValue(), is(new Position(-192.200, -202.000, -40.400, Units.MM)));
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) GrblFirmwareSettings(com.willwinder.universalgcodesender.firmware.GrblFirmwareSettings) Test(org.junit.Test)

Example 39 with Position

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

the class LineSplitterTest method testShortLineNoOp.

/**
 * Multiple commands on 1 line sent to the splitter should throw.
 */
@Test
public void testShortLineNoOp() throws Exception {
    System.out.println("testShortLineNoOp");
    LineSplitter instance = new LineSplitter(2);
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(0, 0, 0, MM);
    state.inAbsoluteMode = true;
    String command = "G20 G1X1Y1Z1";
    List<String> result = instance.processCommand(command, state);
    assertThat(result).containsExactly(command);
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 40 with Position

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

the class LineSplitterTest method testG1G0.

/**
 * The split line should use G1 or G0 depending on the original line.
 */
@Test
public void testG1G0() throws Exception {
    System.out.println("G1G0");
    List<String> expected;
    expected = Arrays.asList("G1X0Y0Z0", "G1X1Y0Z0");
    splitterHarness(1, new Position(-1, 0, 0, MM), "G1X1", expected);
    expected = Arrays.asList("G0X0Y0Z0", "G0X1Y0Z0");
    splitterHarness(1, new Position(-1, 0, 0, MM), "G0X1", expected);
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

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