Search in sources :

Example 61 with Position

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);
}
Also used : ProbeParameters(com.willwinder.ugs.platform.probe.ProbeService.ProbeParameters) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 62 with Position

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();
    }
}
Also used : Position(com.willwinder.universalgcodesender.model.Position)

Example 63 with Position

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);
    }
}
Also used : Random(java.util.Random) Position(com.willwinder.universalgcodesender.model.Position) AutoLevelSettings(com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings) AutoLevelSettings(com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings) Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 64 with Position

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;
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) ArrayList(java.util.ArrayList) SplitCommand(com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) Code(com.willwinder.universalgcodesender.gcode.util.Code)

Example 65 with Position

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);
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) Point3d(javax.vecmath.Point3d)

Aggregations

Position (com.willwinder.universalgcodesender.model.Position)66 Test (org.junit.Test)33 GcodeState (com.willwinder.universalgcodesender.gcode.GcodeState)15 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)7 ControllerStatus (com.willwinder.universalgcodesender.listeners.ControllerStatus)6 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)6 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)5 Units (com.willwinder.universalgcodesender.model.UnitUtils.Units)5 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)4 Settings (com.willwinder.universalgcodesender.utils.Settings)4 ArrayList (java.util.ArrayList)4 ProbeParameters (com.willwinder.ugs.platform.probe.ProbeService.ProbeParameters)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)3 PlaneFormatter (com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)3 UGSEvent (com.willwinder.universalgcodesender.model.UGSEvent)3 AutoLevelSettings (com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings)3 SplitCommand (com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand)2 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)2 Code (com.willwinder.universalgcodesender.gcode.util.Code)2 PointSegment (com.willwinder.universalgcodesender.types.PointSegment)2