use of com.willwinder.ugs.nbp.designer.io.gcode.path.Segment in project Universal-G-Code-Sender by winder.
the class SimpleGcodeRouter method runPath.
protected void runPath(Writer writer, List<Segment> segments) throws IOException {
boolean hasFeedRateSet = false;
// Convert path segments to G codes
for (Segment s : segments) {
// Write any label
if (StringUtils.isNotEmpty(s.getLabel())) {
writer.write(";" + s.getLabel() + "\n");
}
switch(s.type) {
// Seam are just markers.
case SEAM:
continue;
// Go to safe Z height, move over the target point and plunge down
case MOVE:
// The rapid over target point is skipped when we do multiple passes
// and the end point is the same as the starting point.
writer.write(SegmentType.MOVE.gcode);
writer.write(" ");
writer.write(s.point.getFormattedGCode());
writer.write("\n");
hasFeedRateSet = false;
break;
// Drill down using the plunge speed
case POINT:
writer.write(SegmentType.POINT.gcode);
writer.write(" ");
writer.write("F" + plungeSpeed + " ");
writer.write(s.point.getFormattedGCode());
writer.write("\n");
break;
// Motion at feed rate
case LINE:
case CWARC:
case CCWARC:
writer.write(s.type.gcode);
writer.write(' ');
if (!hasFeedRateSet) {
writer.write("F");
writer.write(String.valueOf(feedSpeed));
writer.write(' ');
hasFeedRateSet = true;
}
writer.write(s.point.getFormattedGCode());
writer.write("\n");
break;
default:
throw new RuntimeException("BUG! Unhandled segment type " + s.type);
}
}
}
use of com.willwinder.ugs.nbp.designer.io.gcode.path.Segment in project Universal-G-Code-Sender by winder.
the class SimplePocketTest 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));
SimplePocket simplePocket = new SimplePocket(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), 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);
}
use of com.willwinder.ugs.nbp.designer.io.gcode.path.Segment in project Universal-G-Code-Sender by winder.
the class SimpleGcodeRouter method getGcodePathFromCuttables.
private GcodePath getGcodePathFromCuttables(List<Cuttable> cuttables) {
GcodePath gcodePath = new GcodePath();
int index = 0;
for (Cuttable cuttable : cuttables) {
index++;
gcodePath.addSegment(new Segment(" " + cuttable.getName() + " - " + cuttable.getCutType().getName() + " (" + index + "/" + cuttables.size() + ")"));
switch(cuttable.getCutType()) {
case POCKET:
PocketToolPath simplePocket = new PocketToolPath(cuttable);
simplePocket.setStartDepth(cuttable.getStartDepth());
simplePocket.setTargetDepth(cuttable.getTargetDepth());
simplePocket.setToolDiameter(toolDiameter);
simplePocket.setDepthPerPass(depthPerPass);
simplePocket.setSafeHeight(safeHeight);
simplePocket.setStepOver(toolStepOver);
gcodePath.appendGcodePath(simplePocket.toGcodePath());
break;
case OUTSIDE_PATH:
OutlineToolPath simpleOutsidePath = new OutlineToolPath(cuttable);
simpleOutsidePath.setOffset(toolDiameter / 2d);
simpleOutsidePath.setStartDepth(cuttable.getStartDepth());
simpleOutsidePath.setTargetDepth(cuttable.getTargetDepth());
simpleOutsidePath.setToolDiameter(toolDiameter);
simpleOutsidePath.setDepthPerPass(depthPerPass);
simpleOutsidePath.setSafeHeight(safeHeight);
gcodePath.appendGcodePath(simpleOutsidePath.toGcodePath());
break;
case INSIDE_PATH:
OutlineToolPath simpleInsidePath = new OutlineToolPath(cuttable);
simpleInsidePath.setOffset(-toolDiameter / 2d);
simpleInsidePath.setStartDepth(cuttable.getStartDepth());
simpleInsidePath.setTargetDepth(cuttable.getTargetDepth());
simpleInsidePath.setToolDiameter(toolDiameter);
simpleInsidePath.setDepthPerPass(depthPerPass);
simpleInsidePath.setSafeHeight(safeHeight);
gcodePath.appendGcodePath(simpleInsidePath.toGcodePath());
break;
case ON_PATH:
OutlineToolPath simpleOnPath = new OutlineToolPath(cuttable);
simpleOnPath.setStartDepth(cuttable.getStartDepth());
simpleOnPath.setTargetDepth(cuttable.getTargetDepth());
simpleOnPath.setToolDiameter(toolDiameter);
simpleOnPath.setDepthPerPass(depthPerPass);
simpleOnPath.setSafeHeight(safeHeight);
gcodePath.appendGcodePath(simpleOnPath.toGcodePath());
break;
case CENTER_DRILL:
DrillCenterToolPath drillToolPath = new DrillCenterToolPath(cuttable);
drillToolPath.setStartDepth(cuttable.getStartDepth());
drillToolPath.setTargetDepth(cuttable.getTargetDepth());
drillToolPath.setToolDiameter(toolDiameter);
drillToolPath.setDepthPerPass(depthPerPass);
drillToolPath.setSafeHeight(safeHeight);
gcodePath.appendGcodePath(drillToolPath.toGcodePath());
break;
default:
}
}
return gcodePath;
}
use of com.willwinder.ugs.nbp.designer.io.gcode.path.Segment 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