use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GcodeViewParse method toObjRedux.
/**
* The original (working) gcode to LineSegment collection code.
* @param gcode commands to visualize.
* @param arcSegmentLength length of line segments when expanding an arc.
*/
public List<LineSegment> toObjRedux(List<String> gcode, double arcSegmentLength) throws GcodeParserException {
GcodeParser gp = getParser(arcSegmentLength);
lines.clear();
// Save the state
Position start = new Position();
for (String s : gcode) {
List<String> commands = gp.preprocessCommand(s, gp.getCurrentState());
for (String command : commands) {
List<GcodeMeta> points = gp.addCommand(command);
for (GcodeMeta meta : points) {
if (meta.point != null) {
addLinesFromPointSegment(start, meta.point, arcSegmentLength, lines);
start.set(meta.point.point());
}
}
}
}
return lines;
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GcodePreprocessorUtils method generatePointsAlongArcBDring.
/**
* Generates the points along an arc including the start and end points.
*/
private static List<Position> generatePointsAlongArcBDring(final Position p1, final Position p2, final Position center, boolean isCw, double radius, double startAngle, double sweep, int numPoints, PlaneFormatter plane) {
Position lineStart = new Position(p1);
List<Position> segments = new ArrayList<>();
double angle;
// Calculate radius if necessary.
if (radius == 0) {
radius = Math.sqrt(Math.pow(plane.axis0(p1) - plane.axis1(center), 2.0) + Math.pow(plane.axis1(p1) - plane.axis1(center), 2.0));
}
double zIncrement = (plane.linear(p2) - plane.linear(p1)) / numPoints;
for (int i = 0; i < numPoints; i++) {
if (isCw) {
angle = (startAngle - i * sweep / numPoints);
} else {
angle = (startAngle + i * sweep / numPoints);
}
if (angle >= Math.PI * 2) {
angle = angle - Math.PI * 2;
}
// lineStart.x = Math.cos(angle) * radius + center.x;
plane.setAxis0(lineStart, Math.cos(angle) * radius + plane.axis0(center));
// lineStart.y = Math.sin(angle) * radius + center.y;
plane.setAxis1(lineStart, Math.sin(angle) * radius + plane.axis1(center));
// lineStart.z += zIncrement;
plane.setLinear(lineStart, plane.linear(lineStart) + zIncrement);
segments.add(new Position(lineStart));
}
segments.add(new Position(p2));
return segments;
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GrblControllerMockTests method testProbeResponse.
@Test
public void testProbeResponse() {
GrblController gc = Mockito.spy(new GrblController());
GrblFirmwareSettings firmwareSettings = Mockito.mock(GrblFirmwareSettings.class);
Mockito.when(firmwareSettings.getReportingUnits()).thenReturn(Units.MM);
doReturn(firmwareSettings).when(gc).getFirmwareSettings();
gc.rawResponseListener("[PRB:-192.200,-202.000,-40.400:1]");
ArgumentCaptor<Position> probeCaptor = ArgumentCaptor.forClass(Position.class);
verify(gc, times(1)).dispatchProbeCoordinates(probeCaptor.capture());
assertThat(probeCaptor.getValue(), is(new Position(-192.200, -202.000, -40.400, Units.MM)));
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class LineSplitterTest method testShortLineNoOp.
/**
* Multiple commands on 1 line sent to the splitter should throw.
*/
@Test
public void testShortLineNoOp() throws Exception {
System.out.println("testShortLineNoOp");
LineSplitter instance = new LineSplitter(2);
GcodeState state = new GcodeState();
state.currentPoint = new Position(0, 0, 0, MM);
state.inAbsoluteMode = true;
String command = "G20 G1X1Y1Z1";
List<String> result = instance.processCommand(command, state);
assertThat(result).containsExactly(command);
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class LineSplitterTest method testG1G0.
/**
* The split line should use G1 or G0 depending on the original line.
*/
@Test
public void testG1G0() throws Exception {
System.out.println("G1G0");
List<String> expected;
expected = Arrays.asList("G1X0Y0Z0", "G1X1Y0Z0");
splitterHarness(1, new Position(-1, 0, 0, MM), "G1X1", expected);
expected = Arrays.asList("G0X0Y0Z0", "G0X1Y0Z0");
splitterHarness(1, new Position(-1, 0, 0, MM), "G0X1", expected);
}
Aggregations