use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class SimplePath method toGcodePath.
@Override
public GcodePath toGcodePath() {
Geometry geometry = ToolPathUtils.convertAreaToGeometry(new Area(source.getShape()), getGeometryFactory());
Geometry bufferedGeometry = geometry.buffer(offset);
List<Geometry> geometries = ToolPathUtils.toGeometryList(bufferedGeometry);
ArrayList<List<PartialPosition>> coordinateList = new ArrayList<>();
geometries.forEach(g -> {
List<PartialPosition> geometryCoordinates = ToolPathUtils.geometryToCoordinates(g);
double currentDepth = getStartDepth();
while (currentDepth < getTargetDepth()) {
currentDepth += getDepthPerPass();
if (currentDepth > getTargetDepth()) {
currentDepth = getTargetDepth();
}
final double depth = -currentDepth;
coordinateList.add(geometryCoordinates.stream().map(numericCoordinate -> PartialPosition.builder().copy(numericCoordinate).setZ(depth).build()).collect(Collectors.toList()));
}
});
return toGcodePath(coordinateList);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class AbstractToolPath method addSafeHeightSegmentTo.
protected void addSafeHeightSegmentTo(GcodePath gcodePath, PartialPosition coordinate) {
addSafeHeightSegment(gcodePath);
gcodePath.addSegment(SegmentType.MOVE, new PartialPosition(coordinate.getX(), coordinate.getY(), UnitUtils.Units.MM));
gcodePath.addSegment(SegmentType.MOVE, PartialPosition.from(Axis.Z, 0d, UnitUtils.Units.MM));
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class OutlineToolPath method toGcodePath.
@Override
public GcodePath toGcodePath() {
List<Geometry> geometries;
if (ToolPathUtils.isClosedGeometry(source.getShape())) {
Geometry geometry = ToolPathUtils.convertAreaToGeometry(new Area(source.getShape()), getGeometryFactory());
Geometry bufferedGeometry = geometry.buffer(offset);
geometries = ToolPathUtils.toGeometryList(bufferedGeometry);
} else {
geometries = ToolPathUtils.convertShapeToGeometry(source.getShape(), getGeometryFactory());
}
ArrayList<List<PartialPosition>> coordinateList = new ArrayList<>();
geometries.forEach(g -> {
List<PartialPosition> geometryCoordinates = ToolPathUtils.geometryToCoordinates(g);
double currentDepth = getStartDepth() - getDepthPerPass();
while (currentDepth < getTargetDepth()) {
currentDepth += getDepthPerPass();
if (currentDepth > getTargetDepth()) {
currentDepth = getTargetDepth();
}
final double depth = -currentDepth;
coordinateList.add(geometryCoordinates.stream().map(numericCoordinate -> PartialPosition.builder().copy(numericCoordinate).setZ(depth).build()).collect(Collectors.toList()));
}
});
return toGcodePath(coordinateList);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class OutlineAction method generateOutlineCommands.
public List<GcodeCommand> generateOutlineCommands(File gcodeFile) throws IOException, GcodeParserException {
List<LineSegment> gcodeLineList = parseGcodeLinesFromFile(gcodeFile);
// We only care about carving motion, filter those commands out
List<PartialPosition> pointList = gcodeLineList.parallelStream().filter(lineSegment -> !lineSegment.isFastTraverse()).flatMap(lineSegment -> {
// We map both the start and end points in MM
PartialPosition start = PartialPosition.fromXY(lineSegment.getStart().getPositionIn(UnitUtils.Units.MM));
PartialPosition end = PartialPosition.fromXY(lineSegment.getEnd().getPositionIn(UnitUtils.Units.MM));
return Stream.of(start, end);
}).distinct().collect(Collectors.toList());
UnitUtils.Units preferredUnits = backend.getSettings().getPreferredUnits();
double jogFeedRateInMM = backend.getSettings().getJogFeedRate() * UnitUtils.scaleUnits(preferredUnits, UnitUtils.Units.MM);
List<PartialPosition> outline = MathUtils.generateConvexHull(pointList);
return outline.stream().map(point -> new GcodeCommand(GcodeUtils.generateMoveToCommand(Code.G1.name(), point, jogFeedRateInMM))).collect(Collectors.toList());
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method testJogMachineTo.
/**
* Test of jogMachineTo method
*/
@Test
public void testJogMachineTo() throws Exception {
System.out.println("jogMachineTo");
GrblController instance = new GrblController(mgc);
instance.setDistanceModeCode("G90");
instance.setUnitsCode("G21");
instance.openCommPort(getSettings().getConnectionDriver(), "foo", 2400);
// Abstract controller should be used when grbl jog mode is disabled.
instance.rawResponseHandler("Grbl 0.8c");
instance.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 200);
assertEquals("G21G90G1X1Y2Z3F200", mgc.queuedStrings.get(2));
assertEquals("G90 G21 ", mgc.queuedStrings.get(3));
instance.jogMachineTo(new PartialPosition(1.0, 2.0, UnitUtils.Units.MM), 200);
assertEquals("G21G90G1X1Y2F200", mgc.queuedStrings.get(4));
assertEquals("G90 G21 ", mgc.queuedStrings.get(5));
instance.jogMachineTo(new PartialPosition(1.2345678, 2.0, UnitUtils.Units.MM), 200);
assertEquals("G21G90G1X1.235Y2F200", mgc.queuedStrings.get(6));
assertEquals("G90 G21 ", mgc.queuedStrings.get(7));
instance.jogMachineTo(new PartialPosition(1.0, 2.0, UnitUtils.Units.INCH), 200);
assertEquals("G20G90G1X1Y2F200", mgc.queuedStrings.get(8));
assertEquals("G90 G21 ", mgc.queuedStrings.get(9));
}
Aggregations