use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class ProbeServiceTest method testProbeServiceZ.
@Test
public void testProbeServiceZ() throws Exception {
doReturn(true).when(backend).isIdle();
ProbeParameters pc = new ProbeParameters(1, new Position(5, 5, 5, Units.MM), 10, 10, 10., 1, 1, 1, 100, 25, 5, Units.INCH, G54);
testZProbe(pc, pc.zSpacing < 0);
pc = new ProbeParameters(1, new Position(5, 5, 5, Units.MM), 10, 10, -10., 1, 1, 1, 100, 25, 5, Units.INCH, G54);
testZProbe(pc, pc.zSpacing < 0);
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class AutoLevelerTopComponent method UGSEvent.
@Override
public void UGSEvent(UGSEvent evt) {
if (evt.isProbeEvent()) {
if (!scanningSurface)
return;
Position probe = evt.getProbePosition();
Position offset = this.settings.getAutoLevelSettings().autoLevelProbeOffset;
if (probe.getUnits() == Units.UNKNOWN || offset.getUnits() == Units.UNKNOWN) {
System.out.println("Unknown units in autoleveler receiving probe.");
}
offset = offset.getPositionIn(probe.getUnits());
scanner.probeEvent(new Position(probe.x + offset.x, probe.y + offset.y, probe.z + offset.z, probe.getUnits()));
} else if (evt.isSettingChangeEvent()) {
updateSettings();
}
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class AutoLevelerTopComponent method generateTestDataButtonActionPerformed.
// GEN-LAST:event_useLoadedFileActionPerformed
private void generateTestDataButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_generateTestDataButtonActionPerformed
// Generate some random test data.
Random random = new Random();
Settings.AutoLevelSettings autoLevelerSettings = this.settings.getAutoLevelSettings();
for (Position p : scanner.getProbeStartPositions()) {
Position probe = new Position(p);
p.z = ((random.nextBoolean() ? -1 : 1) * random.nextFloat()) + getValue(this.zSurface);
scanner.probeEvent(p);
}
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class LineSplitter method processCommand.
@Override
public List<String> processCommand(String commandString, GcodeState state) throws GcodeParserException {
List<GcodeParser.GcodeMeta> commands = GcodeParser.processCommand(commandString, 0, state);
List<String> results = new ArrayList<>();
Code code = hasLine(commands);
if (code == null) {
return Collections.singletonList(commandString);
}
SplitCommand sc = GcodePreprocessorUtils.extractMotion(code, commandString);
if (sc.remainder.length() > 0) {
results.add(sc.remainder);
}
GcodeMeta command = Iterables.getLast(commands);
if (command == null || command.point == null) {
throw new GcodeParserException("Internal parser error: missing data.");
}
// line length
Position start = state.currentPoint;
Position end = command.point.point();
Position current = start;
double length = start.distance(end);
// Check if line needs splitting.
if (length > this.maxSegmentLength) {
int numSegments = (int) Math.ceil(length / this.maxSegmentLength);
double segmentLength = length / Math.ceil(length / this.maxSegmentLength);
// Create line segments, stop before the last one which uses the end point.
for (int i = 1; i < numSegments; i++) {
double k = 1 / (length / (i * segmentLength));
double newX = start.x + k * (end.x - start.x);
double newY = start.y + k * (end.y - start.y);
double newZ = start.z + k * (end.z - start.z);
Position next = new Position(newX, newY, newZ, start.getUnits());
results.add(GcodePreprocessorUtils.generateLineFromPoints(command.code, current, next, command.state.inAbsoluteMode, null));
current = next;
}
// Add the last line point.
results.add(GcodePreprocessorUtils.generateLineFromPoints(command.code, current, end, command.state.inAbsoluteMode, null));
} else {
return Collections.singletonList(commandString);
}
return results;
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class Stats method processCommand.
@Override
public List<String> processCommand(String command, GcodeState state) throws GcodeParserException {
Point3d c = state.currentPoint;
if (c != null) {
Position p = new Position(c.x, c.y, c.z, state.isMetric ? Units.MM : Units.INCH).getPositionIn(defaultUnits);
// Update min
min.x = Math.min(min.x, p.x);
min.y = Math.min(min.y, p.y);
min.z = Math.min(min.z, p.z);
// Update max
max.x = Math.max(max.x, p.x);
max.y = Math.max(max.y, p.y);
max.z = Math.max(max.z, p.z);
// Num commands
commandCount++;
}
return Collections.singletonList(command);
}
Aggregations