use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class MathUtilsTest method orientationWithPointsInClockwiseOrder.
@Test
public void orientationWithPointsInClockwiseOrder() {
PartialPosition p1 = new PartialPosition(0d, 0d, UnitUtils.Units.MM);
PartialPosition p2 = new PartialPosition(1d, 1d, UnitUtils.Units.MM);
PartialPosition p3 = new PartialPosition(1d, 0d, UnitUtils.Units.MM);
int orientation = MathUtils.orientation(p1, p2, p3);
assertEquals(MathUtils.CLOCKWISE, orientation);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class TranslateToZeroAction method getLowerLeftCorner.
private Position getLowerLeftCorner(File gcodeFile) throws IOException, GcodeParserException {
List<LineSegment> lineSegments = parseGcodeLinesFromFile(gcodeFile);
// We only care about carving motion, filter those commands out
List<PartialPosition> pointList = lineSegments.parallelStream().filter(lineSegment -> !lineSegment.isFastTraverse()).flatMap(lineSegment -> {
// We map both the start and end points in MM
PartialPosition start = PartialPosition.from(lineSegment.getStart());
PartialPosition end = PartialPosition.from(lineSegment.getEnd());
return Stream.of(start, end);
}).distinct().collect(Collectors.toList());
return MathUtils.getLowerLeftCorner(pointList);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class AbstractToolPath method addSafeHeightSegment.
protected void addSafeHeightSegment(GcodePath gcodePath) {
PartialPosition safeHeightCoordinate = PartialPosition.from(Axis.Z, getSafeHeight(), UnitUtils.Units.MM);
gcodePath.addSegment(SegmentType.MOVE, safeHeightCoordinate);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class DrillCenterToolPath method toGcodePath.
@Override
public GcodePath toGcodePath() {
Point2D center = source.getCenter();
PartialPosition centerPosition = PartialPosition.builder().setX(center.getX()).setY(center.getY()).setUnits(UnitUtils.Units.MM).build();
GcodePath gcodePath = new GcodePath();
addSafeHeightSegmentTo(gcodePath, centerPosition);
double currentDepth = getStartDepth() - getDepthPerPass();
while (currentDepth < getTargetDepth()) {
currentDepth += getDepthPerPass();
if (currentDepth > getTargetDepth()) {
currentDepth = getTargetDepth();
}
final double depth = -currentDepth;
gcodePath.addSegment(SegmentType.POINT, PartialPosition.builder().copy(centerPosition).setZ(depth).build());
gcodePath.addSegment(SegmentType.POINT, PartialPosition.builder().copy(centerPosition).setZ(0d).build());
}
addSafeHeightSegment(gcodePath);
return gcodePath;
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class PocketToolPathTest method pocketShouldNotExceedTheGeometry.
@Test
public void pocketShouldNotExceedTheGeometry() {
double toolRadius = 2.5;
double geometrySize = 10d;
double safeHeight = 1;
double targetDepth = -10;
int depthPerPass = 1;
Rectangle rectangle = new Rectangle();
rectangle.setSize(new Size(geometrySize, geometrySize));
PocketToolPath simplePocket = new PocketToolPath(rectangle);
simplePocket.setTargetDepth(targetDepth);
simplePocket.setDepthPerPass(depthPerPass);
simplePocket.setToolDiameter(toolRadius * 2);
simplePocket.setStepOver(1);
simplePocket.setSafeHeight(safeHeight);
List<Segment> segmentList = simplePocket.toGcodePath().getSegments();
Segment firstSegment = segmentList.get(0);
assertEquals("The first segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
assertFalse("The first segment should not move X", firstSegment.point.hasAxis(Axis.X));
assertFalse("The first segment should not move Y", firstSegment.point.hasAxis(Axis.Y));
Segment secondSegment = segmentList.get(1);
assertEquals("The second segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
assertEquals("The second segment should move to first X position", safeHeight, secondSegment.point.getAxis(Axis.X), toolRadius);
assertEquals("The second segment should move to first Y position", safeHeight, secondSegment.point.getAxis(Axis.Y), toolRadius);
// Make sure that we don't move outside the boundary of the geometry
segmentList.stream().filter(segment -> segment.type == SegmentType.LINE || segment.type == SegmentType.POINT).forEach(segment -> {
assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) >= toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) >= toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) <= geometrySize - toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) <= geometrySize - toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) <= 0);
assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) >= targetDepth);
});
List<Segment> drillOperations = segmentList.stream().filter(segment -> segment.type == SegmentType.POINT).collect(Collectors.toList());
assertEquals("There should be a number of drill operations when making a pocket", Math.abs((targetDepth - depthPerPass) / depthPerPass), drillOperations.size(), 0.1);
PartialPosition point = drillOperations.get(drillOperations.size() - 1).getPoint();
assertEquals("Last operation should reach the target depth", targetDepth, point.getAxis(Axis.Z), 0.1);
}
Aggregations