use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GcodeViewParse method addLinesFromPointSegment.
/**
* Turns a point segment into one or more LineSegment. Arcs are expanded.
* Keeps track of the minimum and maximum x/y/z locations.
*/
private List<LineSegment> addLinesFromPointSegment(final Position start, final PointSegment endSegment, double arcSegmentLength, List<LineSegment> ret) {
// For a line segment list ALL arcs must be converted to lines.
double minArcLength = 0;
LineSegment ls;
endSegment.convertToMetric();
Position end = new Position(endSegment.point());
// start is null for the first iteration.
if (start != null) {
// Expand arc for graphics.
if (endSegment.isArc()) {
List<Position> points = GcodePreprocessorUtils.generatePointsAlongArcBDring(start, end, endSegment.center(), endSegment.isClockwise(), endSegment.getRadius(), minArcLength, arcSegmentLength, new PlaneFormatter(endSegment.getPlaneState()));
// Create line segments from points.
if (points != null) {
Position startPoint = start;
for (Position nextPoint : points) {
ls = new LineSegment(startPoint, nextPoint, endSegment.getLineNumber());
ls.setIsArc(endSegment.isArc());
ls.setIsFastTraverse(endSegment.isFastTraverse());
ls.setIsZMovement(endSegment.isZMovement());
this.testExtremes(nextPoint);
ret.add(ls);
startPoint = nextPoint;
}
}
// Line
} else {
ls = new LineSegment(start, end, endSegment.getLineNumber());
ls.setIsArc(endSegment.isArc());
ls.setIsFastTraverse(endSegment.isFastTraverse());
ls.setIsZMovement(endSegment.isZMovement());
this.testExtremes(end);
ret.add(ls);
}
}
return ret;
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GrblUtilsTest method getStatusFromStringVersion1WithoutWorkCoordinateOffsetStatusString.
@Test
public void getStatusFromStringVersion1WithoutWorkCoordinateOffsetStatusString() {
String status = "<Idle|MPos:1.1,2.2,3.3|WPos:4.4,5.5,6.6|Ov:1,2,3|F:12345.6|FS:12345.7,65432.1|Pn:XYZPDHRS|A:SFMC>";
Capabilities version = new Capabilities();
version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
UnitUtils.Units unit = UnitUtils.Units.MM;
ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
assertEquals(new Position(1.1, 2.2, 3.3, UnitUtils.Units.MM), controllerStatus.getMachineCoord());
assertEquals(new Position(4.4, 5.5, 6.6, UnitUtils.Units.MM), controllerStatus.getWorkCoord());
assertEquals(new Position(0, 0, 0, UnitUtils.Units.MM), controllerStatus.getWorkCoordinateOffset());
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GrblUtilsTest method getStatusFromStringVersion1WithoutWorkCoordinateStatusString.
@Test
public void getStatusFromStringVersion1WithoutWorkCoordinateStatusString() {
String status = "<Idle|MPos:1.0,2.0,3.0|WCO:7.0,8.0,9.0|Ov:1,2,3|F:12345.6|FS:12345.7,65432.1|Pn:XYZPDHRS|A:SFMC>";
Capabilities version = new Capabilities();
version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
UnitUtils.Units unit = UnitUtils.Units.MM;
ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
assertEquals(new Position(1, 2, 3, UnitUtils.Units.MM), controllerStatus.getMachineCoord());
assertEquals(new Position(-6, -6, -6, UnitUtils.Units.MM), controllerStatus.getWorkCoord());
assertEquals(new Position(7, 8, 9, UnitUtils.Units.MM), controllerStatus.getWorkCoordinateOffset());
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GcodeParserTest method motionNoAxes.
@Test
public void motionNoAxes() throws Exception {
List<GcodeMeta> metaList = GcodeParser.processCommand("G3", 0, new GcodeState());
GcodeMeta meta = Iterables.getOnlyElement(metaList);
assertThat(meta.code).isEqualTo(G3);
assertThat(meta.state.currentPoint).isEqualTo(new Position(0, 0, 0, MM));
}
use of com.willwinder.universalgcodesender.model.Position 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);
}
}
Aggregations