use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class MirrorAction method getCenter.
private Position getCenter(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 -> {
PartialPosition start = PartialPosition.from(lineSegment.getStart());
PartialPosition end = PartialPosition.from(lineSegment.getEnd());
return Stream.of(start, end);
}).distinct().collect(Collectors.toList());
return MathUtils.getCenter(pointList);
}
use of com.willwinder.universalgcodesender.model.PartialPosition 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.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class JogService method adjustManualLocationXY.
/**
* Adjusts the XY axis location.
* @param x direction.
* @param y direction.
*/
public void adjustManualLocationXY(int x, int y) {
try {
double feedRate = getFeedRate();
double stepSize = getStepSizeXY();
Units preferredUnits = getUnits();
Double dx = x == 0 ? null : x * stepSize;
Double dy = y == 0 ? null : y * stepSize;
backend.adjustManualLocation(new PartialPosition(dx, dy, null, preferredUnits), feedRate);
} catch (Exception e) {
// NotifyDescriptor nd = new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
// DialogDisplayer.getDefault().notify(nd);
}
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class GrblControllerTest method testJogMachine.
/**
* Test of jogMachine method, of class AbstractController.
*/
@Test
public void testJogMachine() throws Exception {
System.out.println("jogMachine");
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.jogMachine(new PartialPosition(-10., null, 10., UnitUtils.Units.INCH), 11);
assertEquals("G20G91G1X-10Z10F11", mgc.queuedStrings.get(2));
assertEquals("G90 G21 ", mgc.queuedStrings.get(3));
instance.jogMachine(new PartialPosition(null, 10., null, UnitUtils.Units.MM), 11);
assertEquals("G21G91G1Y10F11", mgc.queuedStrings.get(4));
assertEquals("G90 G21 ", mgc.queuedStrings.get(5));
instance.rawResponseHandler("Grbl 1.1a");
instance.jogMachine(new PartialPosition(-10., null, 10., UnitUtils.Units.INCH), 11);
assertEquals("$J=G20G91X-10Z10F11", mgc.queuedStrings.get(8));
instance.jogMachine(new PartialPosition(null, 10., null, UnitUtils.Units.MM), 11);
assertEquals("$J=G21G91Y10F11", mgc.queuedStrings.get(9));
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class G2CoreControllerTest method jogMachineToWhenUsingInchesShouldConvertCoordinates.
@Test
public void jogMachineToWhenUsingInchesShouldConvertCoordinates() throws Exception {
// Given
when(communicator.isConnected()).thenReturn(true);
// Simulate that the machine is running in inches
controller.getCurrentGcodeState().units = Code.G20;
// When
InOrder orderVerifier = inOrder(communicator);
controller.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000);
// Then
orderVerifier.verify(communicator, times(1)).queueCommand(any(GcodeCommand.class));
orderVerifier.verify(communicator).streamCommands();
GcodeCommand command = queueCommandArgumentCaptor.getAllValues().get(0);
assertEquals("G20G90G1X0.039Y0.079Z0.118F39.37", command.getCommandString());
assertTrue(command.isGenerated());
assertTrue(command.isTemporaryParserModalChange());
}
Aggregations