Search in sources :

Example 1 with PointSegment

use of com.willwinder.universalgcodesender.types.PointSegment in project Universal-G-Code-Sender by winder.

the class GcodeParser method addProbePointSegment.

private static PointSegment addProbePointSegment(Position nextPoint, boolean fastTraverse, int line, GcodeState state) {
    PointSegment ps = addLinearPointSegment(nextPoint, fastTraverse, line, state);
    ps.setIsProbe(true);
    return ps;
}
Also used : PointSegment(com.willwinder.universalgcodesender.types.PointSegment)

Example 2 with PointSegment

use of com.willwinder.universalgcodesender.types.PointSegment in project Universal-G-Code-Sender by winder.

the class GcodeParser method addArcPointSegment.

/**
 * Create a PointSegment representing the arc command.
 */
private static PointSegment addArcPointSegment(Position nextPoint, boolean clockwise, List<String> args, int line, GcodeState state) {
    if (nextPoint == null) {
        return null;
    }
    PointSegment ps = new PointSegment(nextPoint, line);
    Position center = GcodePreprocessorUtils.updateCenterWithCommand(args, state.currentPoint, nextPoint, state.inAbsoluteIJKMode, clockwise, new PlaneFormatter(state.plane));
    double radius = GcodePreprocessorUtils.parseCoord(args, 'R');
    // Calculate radius if necessary.
    if (Double.isNaN(radius)) {
        radius = Math.sqrt(Math.pow(state.currentPoint.x - center.x, 2.0) + Math.pow(state.currentPoint.y - center.y, 2.0));
    }
    ps.setIsMetric(state.isMetric);
    ps.setArcCenter(center);
    ps.setIsArc(true);
    ps.setRadius(radius);
    ps.setIsClockwise(clockwise);
    ps.setPlaneState(state.plane);
    // Save off the endpoint.
    state.currentPoint = nextPoint;
    return ps;
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) PointSegment(com.willwinder.universalgcodesender.types.PointSegment) PlaneFormatter(com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)

Example 3 with PointSegment

use of com.willwinder.universalgcodesender.types.PointSegment in project Universal-G-Code-Sender by winder.

the class GcodeParserTest method testCommand.

private void testCommand(List<GcodeMeta> segments, int numResults, double speed, double x, double y, double z, boolean fastTraversal, boolean zMovement, boolean arc, boolean clockwise, boolean isMetric, int num) {
    int points = 0;
    for (GcodeMeta meta : segments) {
        if (meta.point != null) {
            points++;
            PointSegment ps = meta.point;
            assertEquals(ps.getSpeed(), speed, 0);
            assertEquals(x, ps.point().x, 0);
            assertEquals(y, ps.point().y, 0);
            assertEquals(z, ps.point().z, 0);
            assertEquals(fastTraversal, ps.isFastTraverse());
            assertEquals(zMovement, ps.isZMovement());
            assertEquals(arc, ps.isArc());
            if (arc) {
                assertEquals(clockwise, ps.isClockwise());
            }
            assertEquals(num, ps.getLineNumber());
            assertEquals(isMetric, ps.isMetric());
        }
    }
    assertEquals(numResults, points);
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) PointSegment(com.willwinder.universalgcodesender.types.PointSegment)

Example 4 with PointSegment

use of com.willwinder.universalgcodesender.types.PointSegment in project Universal-G-Code-Sender by winder.

the class GcodeParser method addLinearPointSegment.

/**
 * Create a PointSegment representing the linear command.
 */
private static PointSegment addLinearPointSegment(Position nextPoint, boolean fastTraverse, int line, GcodeState state) {
    if (nextPoint == null) {
        return null;
    }
    PointSegment ps = new PointSegment(nextPoint, line);
    boolean zOnly = false;
    // Check for z-only
    if ((state.currentPoint.x == nextPoint.x) && (state.currentPoint.y == nextPoint.y) && (state.currentPoint.z != nextPoint.z)) {
        zOnly = true;
    }
    ps.setIsMetric(state.isMetric);
    ps.setIsZMovement(zOnly);
    ps.setIsFastTraverse(fastTraverse);
    // Save off the endpoint.
    state.currentPoint = nextPoint;
    return ps;
}
Also used : PointSegment(com.willwinder.universalgcodesender.types.PointSegment)

Example 5 with PointSegment

use of com.willwinder.universalgcodesender.types.PointSegment in project Universal-G-Code-Sender by winder.

the class ArcExpander method processCommand.

@Override
public List<String> processCommand(String command, GcodeState state) throws GcodeParserException {
    if (state.currentPoint == null)
        throw new GcodeParserException(Localization.getString("parser.processor.arc.start-error"));
    List<String> results = new ArrayList<>();
    List<GcodeMeta> commands = GcodeParser.processCommand(command, 0, state);
    // If this is not an arc, there is nothing to do.
    Code c = hasArcCommand(commands);
    if (c == null) {
        return Collections.singletonList(command);
    }
    SplitCommand sc = GcodePreprocessorUtils.extractMotion(c, command);
    if (sc.remainder.length() > 0) {
        results.add(sc.remainder);
    }
    GcodeMeta arcMeta = Iterables.getLast(commands);
    PointSegment ps = arcMeta.point;
    Position start = state.currentPoint;
    Position end = arcMeta.point.point();
    List<Position> points = GcodePreprocessorUtils.generatePointsAlongArcBDring(start, end, ps.center(), ps.isClockwise(), ps.getRadius(), 0, this.length, new PlaneFormatter(ps.getPlaneState()));
    // That function returns the first and last points. Exclude the first
    // point because the previous gcode command ends there already.
    points.remove(0);
    if (convertToLines) {
        // Tack the speed onto the first line segment in case the arc also
        // changed the feed value.
        String feed = "F" + arcMeta.point.getSpeed();
        for (Position point : points) {
            results.add(GcodePreprocessorUtils.generateLineFromPoints(G1, start, point, state.inAbsoluteMode, df) + feed);
            start = point;
            feed = "";
        }
    } else {
        // TODO: Generate arc segments.
        throw new UnsupportedOperationException("I have not implemented this.");
    }
    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) Code(com.willwinder.universalgcodesender.gcode.util.Code) PointSegment(com.willwinder.universalgcodesender.types.PointSegment) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) PlaneFormatter(com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)

Aggregations

PointSegment (com.willwinder.universalgcodesender.types.PointSegment)5 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)2 PlaneFormatter (com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)2 Position (com.willwinder.universalgcodesender.model.Position)2 SplitCommand (com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.SplitCommand)1 Code (com.willwinder.universalgcodesender.gcode.util.Code)1 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)1 ArrayList (java.util.ArrayList)1