Search in sources :

Example 11 with Position

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

the class GcodeViewParse method addLinesFromPointSegment.

/**
 * Turns a point segment into one or more LineSegment. Arcs are expanded.
 * Keeps track of the minimum and maximum x/y/z locations.
 */
private List<LineSegment> addLinesFromPointSegment(final Position start, final PointSegment endSegment, double arcSegmentLength, List<LineSegment> ret) {
    // For a line segment list ALL arcs must be converted to lines.
    double minArcLength = 0;
    LineSegment ls;
    endSegment.convertToMetric();
    Position end = new Position(endSegment.point());
    // start is null for the first iteration.
    if (start != null) {
        // Expand arc for graphics.
        if (endSegment.isArc()) {
            List<Position> points = GcodePreprocessorUtils.generatePointsAlongArcBDring(start, end, endSegment.center(), endSegment.isClockwise(), endSegment.getRadius(), minArcLength, arcSegmentLength, new PlaneFormatter(endSegment.getPlaneState()));
            // Create line segments from points.
            if (points != null) {
                Position startPoint = start;
                for (Position nextPoint : points) {
                    ls = new LineSegment(startPoint, nextPoint, endSegment.getLineNumber());
                    ls.setIsArc(endSegment.isArc());
                    ls.setIsFastTraverse(endSegment.isFastTraverse());
                    ls.setIsZMovement(endSegment.isZMovement());
                    this.testExtremes(nextPoint);
                    ret.add(ls);
                    startPoint = nextPoint;
                }
            }
        // Line
        } else {
            ls = new LineSegment(start, end, endSegment.getLineNumber());
            ls.setIsArc(endSegment.isArc());
            ls.setIsFastTraverse(endSegment.isFastTraverse());
            ls.setIsZMovement(endSegment.isZMovement());
            this.testExtremes(end);
            ret.add(ls);
        }
    }
    return ret;
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) PlaneFormatter(com.willwinder.universalgcodesender.gcode.util.PlaneFormatter)

Example 12 with Position

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

the class GrblUtilsTest method getStatusFromStringVersion1WithoutWorkCoordinateOffsetStatusString.

@Test
public void getStatusFromStringVersion1WithoutWorkCoordinateOffsetStatusString() {
    String status = "<Idle|MPos:1.1,2.2,3.3|WPos:4.4,5.5,6.6|Ov:1,2,3|F:12345.6|FS:12345.7,65432.1|Pn:XYZPDHRS|A:SFMC>";
    Capabilities version = new Capabilities();
    version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
    UnitUtils.Units unit = UnitUtils.Units.MM;
    ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
    assertEquals(new Position(1.1, 2.2, 3.3, UnitUtils.Units.MM), controllerStatus.getMachineCoord());
    assertEquals(new Position(4.4, 5.5, 6.6, UnitUtils.Units.MM), controllerStatus.getWorkCoord());
    assertEquals(new Position(0, 0, 0, UnitUtils.Units.MM), controllerStatus.getWorkCoordinateOffset());
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 13 with Position

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

the class GrblUtilsTest method getStatusFromStringVersion1WithoutWorkCoordinateStatusString.

@Test
public void getStatusFromStringVersion1WithoutWorkCoordinateStatusString() {
    String status = "<Idle|MPos:1.0,2.0,3.0|WCO:7.0,8.0,9.0|Ov:1,2,3|F:12345.6|FS:12345.7,65432.1|Pn:XYZPDHRS|A:SFMC>";
    Capabilities version = new Capabilities();
    version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
    UnitUtils.Units unit = UnitUtils.Units.MM;
    ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
    assertEquals(new Position(1, 2, 3, UnitUtils.Units.MM), controllerStatus.getMachineCoord());
    assertEquals(new Position(-6, -6, -6, UnitUtils.Units.MM), controllerStatus.getWorkCoord());
    assertEquals(new Position(7, 8, 9, UnitUtils.Units.MM), controllerStatus.getWorkCoordinateOffset());
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 14 with Position

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

the class GcodeParserTest method motionNoAxes.

@Test
public void motionNoAxes() throws Exception {
    List<GcodeMeta> metaList = GcodeParser.processCommand("G3", 0, new GcodeState());
    GcodeMeta meta = Iterables.getOnlyElement(metaList);
    assertThat(meta.code).isEqualTo(G3);
    assertThat(meta.state.currentPoint).isEqualTo(new Position(0, 0, 0, MM));
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 15 with Position

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

the class ArcExpanderTest method expandArcG17.

@Test
public void expandArcG17() throws Exception {
    System.out.println("expandArcG17");
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(-1, 0, 0, MM);
    state.plane = XY;
    // ///////////////////////////////////////////////////////
    for (double segmentLength = 0.1; segmentLength < 1; segmentLength += 0.1) {
        ArcExpander instance = new ArcExpander(true, segmentLength);
        // Half circle clockwise, X-1 -> X1, Y0 -> Y1 -> Y0
        String command = "G2 Y0 X1 R1";
        List<String> result = instance.processCommand(command, state);
        assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
        verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(-1, 0, 0, MM), new Position(1, 1, 0, MM), state.plane);
        // Half circle counter-clockwise, X-1 -> X1, Y0 -> Y-1 -> Y0
        command = "G3 Y0 X1 R1";
        result = instance.processCommand(command, state);
        assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
        verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(-1, -1, 0, MM), new Position(1, 0, 0, MM), state.plane);
    }
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

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