Search in sources :

Example 66 with Position

use of com.willwinder.universalgcodesender.model.Position 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

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