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);
}
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);
}
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);
}
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));
}
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;
}
Aggregations