Search in sources :

Example 6 with GcodeMeta

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

the class GcodeParserTest method fWordOnly.

@Test
public void fWordOnly() throws Exception {
    List<GcodeMeta> metaList = GcodeParser.processCommand("F100", 0, new GcodeState(), true);
    GcodeMeta meta = Iterables.getOnlyElement(metaList);
    assertThat(meta.state.speed).isEqualTo(100.0);
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Test(org.junit.Test)

Example 7 with GcodeMeta

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

the class GcodeParserTest method sWordOnly.

@Test
public void sWordOnly() throws Exception {
    List<GcodeMeta> metaList = GcodeParser.processCommand("S100", 0, new GcodeState(), true);
    GcodeMeta meta = Iterables.getOnlyElement(metaList);
    assertThat(meta.state.spindleSpeed).isEqualTo(100.0);
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Test(org.junit.Test)

Example 8 with GcodeMeta

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

the class GcodeParserTest method stateInitialized.

@Test
public void stateInitialized() throws Exception {
    GcodeState state = new GcodeState();
    Assert.assertEquals(G0, state.currentMotionMode);
    List<GcodeMeta> metaList = GcodeParser.processCommand("X1", 0, new GcodeState());
    Assert.assertEquals(1, metaList.size());
    GcodeMeta meta = Iterables.getOnlyElement(metaList);
    Assert.assertEquals(G0, meta.code);
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Test(org.junit.Test)

Example 9 with GcodeMeta

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

the class GcodeParserTest method spaceInAxisWord.

@Test
public void spaceInAxisWord() throws Exception {
    List<GcodeMeta> metaList = GcodeParser.processCommand("G \t1 X-1Y  - 0.\t5Z\n1 .0", 0, new GcodeState());
    GcodeMeta meta = Iterables.getOnlyElement(metaList);
    assertThat(meta.code).isEqualTo(G1);
    assertThat(meta.state.currentPoint).isEqualTo(new Position(-1, -0.5, 1, MM));
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 10 with GcodeMeta

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

the class LineSplitter method processCommand.

@Override
public List<String> processCommand(String commandString, GcodeState state) throws GcodeParserException {
    List<GcodeParser.GcodeMeta> commands = GcodeParser.processCommand(commandString, 0, state);
    List<String> results = new ArrayList<>();
    Code code = hasLine(commands);
    if (code == null) {
        return Collections.singletonList(commandString);
    }
    SplitCommand sc = GcodePreprocessorUtils.extractMotion(code, commandString);
    if (sc.remainder.length() > 0) {
        results.add(sc.remainder);
    }
    GcodeMeta command = Iterables.getLast(commands);
    if (command == null || command.point == null) {
        throw new GcodeParserException("Internal parser error: missing data.");
    }
    // line length
    Position start = state.currentPoint;
    Position end = command.point.point();
    Position current = start;
    double length = start.distance(end);
    // Check if line needs splitting.
    if (length > this.maxSegmentLength) {
        int numSegments = (int) Math.ceil(length / this.maxSegmentLength);
        double segmentLength = length / Math.ceil(length / this.maxSegmentLength);
        // Create line segments, stop before the last one which uses the end point.
        for (int i = 1; i < numSegments; i++) {
            double k = 1 / (length / (i * segmentLength));
            double newX = start.x + k * (end.x - start.x);
            double newY = start.y + k * (end.y - start.y);
            double newZ = start.z + k * (end.z - start.z);
            Position next = new Position(newX, newY, newZ, start.getUnits());
            results.add(GcodePreprocessorUtils.generateLineFromPoints(command.code, current, next, command.state.inAbsoluteMode, null));
            current = next;
        }
        // Add the last line point.
        results.add(GcodePreprocessorUtils.generateLineFromPoints(command.code, current, end, command.state.inAbsoluteMode, null));
    } else {
        return Collections.singletonList(commandString);
    }
    return results;
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) ArrayList(java.util.ArrayList) SplitCommand(com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) Code(com.willwinder.universalgcodesender.gcode.util.Code)

Aggregations

GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)11 Position (com.willwinder.universalgcodesender.model.Position)7 Test (org.junit.Test)5 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)2 SplitCommand (com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand)2 Code (com.willwinder.universalgcodesender.gcode.util.Code)2 PointSegment (com.willwinder.universalgcodesender.types.PointSegment)2 ArrayList (java.util.ArrayList)2 PlaneFormatter (com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)1 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)1