Search in sources :

Example 1 with GcodeState

use of com.willwinder.universalgcodesender.gcode.GcodeState in project Universal-G-Code-Sender by winder.

the class ArcExpanderTest method expandArcG17.

@Test
public void expandArcG17() throws Exception {
    System.out.println("expandArcG17");
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(-1, 0, 0, MM);
    state.plane = XY;
    // ///////////////////////////////////////////////////////
    for (double segmentLength = 0.1; segmentLength < 1; segmentLength += 0.1) {
        ArcExpander instance = new ArcExpander(true, segmentLength);
        // Half circle clockwise, X-1 -> X1, Y0 -> Y1 -> Y0
        String command = "G2 Y0 X1 R1";
        List<String> result = instance.processCommand(command, state);
        assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
        verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(-1, 0, 0, MM), new Position(1, 1, 0, MM), state.plane);
        // Half circle counter-clockwise, X-1 -> X1, Y0 -> Y-1 -> Y0
        command = "G3 Y0 X1 R1";
        result = instance.processCommand(command, state);
        assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
        verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(-1, -1, 0, MM), new Position(1, 0, 0, MM), state.plane);
    }
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 2 with GcodeState

use of com.willwinder.universalgcodesender.gcode.GcodeState in project Universal-G-Code-Sender by winder.

the class ArcExpanderTest method arcExpandIgnoreNonArc.

@Test
public void arcExpandIgnoreNonArc() throws Exception {
    System.out.println("arcExpandIgnoreNonArc");
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(0, 0, 0, MM);
    state.plane = XY;
    ArcExpander instance = new ArcExpander(true, 1);
    boolean threwException = false;
    String command = "G17 G0 X12";
    List<String> result = instance.processCommand(command, state);
    assertThat(result.size()).isEqualTo(1);
    assertThat(result.get(0)).isEqualTo(command);
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 3 with GcodeState

use of com.willwinder.universalgcodesender.gcode.GcodeState in project Universal-G-Code-Sender by winder.

the class ArcExpanderTest method expandArcG19.

@Test
public void expandArcG19() throws Exception {
    System.out.println("expandArcG19");
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(0, -1, 0, MM);
    state.plane = YZ;
    // ///////////////////////////////////////////////////////
    for (double segmentLength = 0.1; segmentLength < 1; segmentLength += 0.1) {
        ArcExpander instance = new ArcExpander(true, segmentLength);
        // Half circle clockwise, Y-1 -> Y1, X0 -> X1 -> X0
        String command = "G2 Y1 X0 R1";
        List<String> result = instance.processCommand(command, state);
        assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
        verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(0, -1., 0, MM), new Position(0, 1, 1, MM), state.plane);
        // Half circle clockwise, Y-1 -> Y1, X0 -> X-1 -> X0
        command = "G3 Y1 X0 R1";
        result = instance.processCommand(command, state);
        assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
        verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(0, -1, -1, MM), new Position(0, 1, 0, MM), state.plane);
    }
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 4 with GcodeState

use of com.willwinder.universalgcodesender.gcode.GcodeState in project Universal-G-Code-Sender by winder.

the class LineSplitterTest method testModalReturnedFirst.

@Test
public void testModalReturnedFirst() throws Exception {
    System.out.println("testModalReturnedFirst");
    LineSplitter instance = new LineSplitter(1.5);
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(0, 0, 0, MM);
    state.inAbsoluteMode = true;
    String command = "G20 G1X2Y2Z0";
    List<String> result = instance.processCommand(command, state);
    assertThat(result).containsExactly("G20", "G1X1Y1Z0", "G1X2Y2Z0");
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 5 with GcodeState

use of com.willwinder.universalgcodesender.gcode.GcodeState in project Universal-G-Code-Sender by winder.

the class LineSplitterTest method splitterHarness.

private static void splitterHarness(double splitterLength, Position start, String command, List<String> expected) throws Exception {
    LineSplitter instance = new LineSplitter(splitterLength);
    GcodeState state = new GcodeState();
    state.currentPoint = start;
    state.inAbsoluteMode = true;
    List<String> result = instance.processCommand(command, state);
    assertEquals(expected, result);
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState)

Aggregations

GcodeState (com.willwinder.universalgcodesender.gcode.GcodeState)18 Position (com.willwinder.universalgcodesender.model.Position)15 Test (org.junit.Test)15 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)1 Before (org.junit.Before)1