Search in sources :

Example 6 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class MeshLeveler method processCommand.

@Override
public List<String> processCommand(final String commandString, GcodeState state) throws GcodeParserException {
    List<GcodeMeta> commands = GcodeParser.processCommand(commandString, 0, state);
    // If there are no lines, return unmodified input.
    if (!hasJustLines(commands)) {
        return Collections.singletonList(commandString);
    }
    if (commands.size() > 1) {
        throw new GcodeParserException(Localization.getString("parser.processor.general.multiple-commands"));
    }
    GcodeMeta command = commands.get(0);
    if (command == null || command.point == null) {
        throw new GcodeParserException(ERROR_MISSING_POINT_DATA);
    }
    Position start = state.currentPoint;
    Position end = command.point.point();
    if (start.z != end.z) {
        this.lastZHeight = end.z;
    }
    // Get offset relative to the expected surface height.
    // Visualizer normalizes everything to MM but probe mesh might be INCH
    double probeScaleFactor = UnitUtils.scaleUnits(UnitUtils.Units.MM, this.unit);
    double zScaleFactor = UnitUtils.scaleUnits(UnitUtils.Units.MM, state.isMetric ? Units.MM : Units.INCH);
    double zPointOffset = surfaceHeightAt(end.x / zScaleFactor, end.y / zScaleFactor) - (this.materialSurfaceHeight / probeScaleFactor);
    zPointOffset *= zScaleFactor;
    // Update z coordinate.
    end.z = this.lastZHeight + zPointOffset;
    // end.z /= resultScaleFactor;
    String adjustedCommand = GcodePreprocessorUtils.generateLineFromPoints(command.code, start, end, command.state.inAbsoluteMode, null);
    return Collections.singletonList(adjustedCommand);
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException)

Example 7 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class MeshLeveler method surfaceHeightAt.

/**
 * Bilinear interpolation:
 * http://supercomputingblog.com/graphics/coding-bilinear-interpolation/
 */
protected double surfaceHeightAt(double x, double y) throws GcodeParserException {
    Position[][] q = findBoundingArea(x, y);
    Position Q11 = q[0][0];
    Position Q21 = q[1][0];
    Position Q12 = q[0][1];
    Position Q22 = q[1][1];
    /*
        // This check doesn't work properly because I chose to clamp bounds
        if (Q11.x > x || Q12.x > x || Q21.x < x || Q22.x < x ||
            Q12.y < y || Q22.y < y || Q11.y > y || Q21.y > y) {
            throw new GcodeParserException("Problem detected getting surface height. Please submit file to github for analysis.");
        }
        */
    double x1 = Q11.x;
    double x2 = Q21.x;
    double y1 = Q11.y;
    double y2 = Q12.y;
    double R1 = ((x2 - x) / (x2 - x1)) * Q11.z + ((x - x1) / (x2 - x1)) * Q21.z;
    double R2 = ((x2 - x) / (x2 - x1)) * Q12.z + ((x - x1) / (x2 - x1)) * Q22.z;
    return ((y2 - y) / (y2 - y1)) * R1 + ((y - y1) / (y2 - y1)) * R2;
}
Also used : Position(com.willwinder.universalgcodesender.model.Position)

Example 8 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class GcodeState method copy.

public GcodeState copy() {
    GcodeState ret = new GcodeState();
    ret.currentMotionMode = currentMotionMode;
    ret.plane = plane;
    ret.inAbsoluteMode = inAbsoluteMode;
    ret.distanceMode = distanceMode;
    ret.inAbsoluteIJKMode = inAbsoluteIJKMode;
    ret.arcDistanceMode = arcDistanceMode;
    ret.feedMode = feedMode;
    ret.isMetric = isMetric;
    ret.units = units;
    ret.speed = speed;
    ret.spindleSpeed = spindleSpeed;
    ret.offset = offset;
    if (currentPoint != null) {
        ret.currentPoint = new Position(currentPoint.x, currentPoint.y, currentPoint.z, UnitUtils.Units.getUnits(units));
    }
    ret.commandNumber = commandNumber;
    return ret;
}
Also used : Position(com.willwinder.universalgcodesender.model.Position)

Example 9 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class PointSegment method setArcCenter.

// Arc properties.
public void setArcCenter(final Position center) {
    if (this.arcProperties == null) {
        this.arcProperties = new ArcProperties();
    }
    this.arcProperties.center = new Position(center);
    this.setIsArc(true);
}
Also used : Position(com.willwinder.universalgcodesender.model.Position)

Example 10 with Position

use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.

the class GcodeViewParse method toObjFromReader.

/**
 * Almost the same as toObjRedux, convert gcode to a LineSegment collection.
 * I've tried refactoring this, but the function is so small that merging
 * toObjFromReader and toObjRedux adds more complexity than having these two
 * methods.
 *
 * @param gcode commands to visualize.
 * @param arcSegmentLength length of line segments when expanding an arc.
 */
public List<LineSegment> toObjFromReader(GcodeStreamReader reader, double arcSegmentLength) throws IOException, GcodeParserException {
    lines.clear();
    GcodeParser gp = getParser(arcSegmentLength);
    // Save the state
    Position start = new Position();
    while (reader.getNumRowsRemaining() > 0) {
        GcodeCommand commandObject = reader.getNextCommand();
        List<String> commands = gp.preprocessCommand(commandObject.getCommandString(), gp.getCurrentState());
        for (String command : commands) {
            List<GcodeMeta> points = gp.addCommand(command, commandObject.getCommandNumber());
            for (GcodeMeta meta : points) {
                if (meta.point != null) {
                    addLinesFromPointSegment(start, meta.point, arcSegmentLength, lines);
                    start.set(meta.point.point());
                }
            }
        }
    }
    return lines;
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

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