Search in sources :

Example 51 with Position

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

the class GcodeParserTest method autoLevelerProcessorSet.

@Test
public void autoLevelerProcessorSet() throws Exception {
    System.out.println("autoLevelerProcessorSet");
    GcodeParser gcp = new GcodeParser();
    gcp.addCommandProcessor(new CommentProcessor());
    gcp.addCommandProcessor(new ArcExpander(true, 0.1));
    gcp.addCommandProcessor(new LineSplitter(1));
    Position[][] grid = { { new Position(-5, -5, 0, MM), new Position(-5, 35, 0, MM) }, { new Position(35, -5, 0, MM), new Position(35, 35, 0, MM) } };
    gcp.addCommandProcessor(new MeshLeveler(0, grid, Units.MM));
    Path output = Files.createTempFile("autoleveler_processor_set_test.nc", "");
    // Copy resource to temp file since my parser methods need it that way.
    URL file = this.getClass().getClassLoader().getResource("./gcode/circle_test.nc");
    File tempFile = File.createTempFile("temp", "file");
    IOUtils.copy(file.openStream(), FileUtils.openOutputStream(tempFile));
    GcodeParserUtils.processAndExport(gcp, tempFile, output.toFile());
    GcodeStreamReader reader = new GcodeStreamReader(output.toFile());
    file = this.getClass().getClassLoader().getResource("./gcode/circle_test.nc.processed");
    Files.lines(Paths.get(file.toURI())).forEach((t) -> {
        try {
            GcodeCommand c = reader.getNextCommand();
            if (c == null) {
                Assert.fail("Reached end of gcode reader before end of expected commands.");
            }
            Assert.assertEquals(c.getCommandString(), t);
        } catch (IOException ex) {
            Assert.fail("Unexpected exception.");
        }
    });
    assertEquals(1027, reader.getNumRows());
    output.toFile().delete();
}
Also used : Path(java.nio.file.Path) Position(com.willwinder.universalgcodesender.model.Position) LineSplitter(com.willwinder.universalgcodesender.gcode.processors.LineSplitter) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException) URL(java.net.URL) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) MeshLeveler(com.willwinder.universalgcodesender.gcode.processors.MeshLeveler) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) ArcExpander(com.willwinder.universalgcodesender.gcode.processors.ArcExpander) File(java.io.File) Test(org.junit.Test)

Example 52 with Position

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

the class GcodeParserTest method spaceInAxisWord.

@Test
public void spaceInAxisWord() throws Exception {
    List<GcodeMeta> metaList = GcodeParser.processCommand("G \t1 X-1Y  - 0.\t5Z\n1 .0", 0, new GcodeState());
    GcodeMeta meta = Iterables.getOnlyElement(metaList);
    assertThat(meta.code).isEqualTo(G1);
    assertThat(meta.state.currentPoint).isEqualTo(new Position(-1, -0.5, 1, MM));
}
Also used : GcodeMeta(com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 53 with Position

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

the class ArcExpanderTest method modalsReturnedFirst.

@Test
public void modalsReturnedFirst() throws Exception {
    System.out.println("arcExpandWithModals");
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(0, 0, 0, MM);
    state.plane = XY;
    ArcExpander instance = new ArcExpander(true, 1);
    List<String> result = instance.processCommand("G17 G20 G02 X5 Y0 R12 S1300", state);
    assertThat(result.get(0)).isEqualTo("G17G20S1300");
    assertThat(result).size().isGreaterThan(2);
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 54 with Position

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

the class ArcExpanderTest method expandArcG18.

@Test
public void expandArcG18() throws Exception {
    System.out.println("expandArcG18");
    GcodeState state = new GcodeState();
    state.currentPoint = new Position(0, 0, -1, MM);
    state.plane = ZX;
    // ///////////////////////////////////////////////////////
    for (double segmentLength = 0.1; segmentLength < 1; segmentLength += 0.1) {
        ArcExpander instance = new ArcExpander(true, segmentLength);
        // Half circle clockwise, Z-1 -> Z1, X0 -> X1 -> X0
        String command = "G2 Z1 X0 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(0, 0, -1, MM), new Position(1, 0, 1, MM), state.plane);
        // Half circle clockwise, Z-1 -> Z1, X0 -> X-1 -> X0
        command = "G3 Z1 X0 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, 0, -1, MM), new Position(0, 0, 1, MM), state.plane);
    }
}
Also used : GcodeState(com.willwinder.universalgcodesender.gcode.GcodeState) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 55 with Position

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

the class AutoLevelPreview method draw.

@Override
public void draw(GLAutoDrawable drawable, boolean idle, Point3d workCoord, Point3d objectMin, Point3d objectMax, double scaleFactor, Point3d mouseWorldCoordinates, Point3d rotation) {
    // Don't draw something invalid.
    if (positions == null || positions.isEmpty()) {
        return;
    }
    Position first = Iterables.getFirst(positions, null);
    Units unit = first.getUnits();
    double objectX = objectMax.x - objectMin.x;
    double objectY = objectMax.y - objectMin.y;
    double diameter = Math.max(objectX * 0.005, objectY * 0.005);
    double minx, miny, minz;
    double maxx, maxy, maxz;
    minx = maxx = first.x;
    miny = maxy = first.y;
    minz = maxz = first.z;
    GL2 gl = drawable.getGL().getGL2();
    gl.glPushMatrix();
    // Scale inch to mm if needed
    double scale = UnitUtils.scaleUnits(unit, Units.MM);
    if (unit != Units.MM) {
        gl.glScaled(scale, scale, scale);
    }
    // Balls indicating the probe start locations.
    gl.glColor4fv(new float[] { 0.1f, 0.1f, 0.1f, 1.0f }, 0);
    for (Position p : positions) {
        gl.glPushMatrix();
        gl.glTranslated(p.x, p.y, p.z);
        glut.glutSolidSphere(diameter / scale, 7, 7);
        // update min/max
        minx = Math.min(minx, p.x);
        maxx = Math.max(maxx, p.x);
        miny = Math.min(miny, p.y);
        maxz = Math.max(maxz, p.z);
        minz = Math.min(minz, p.z);
        maxy = Math.max(maxy, p.y);
        gl.glPopMatrix();
    }
    // Outline of probe area
    gl.glPushMatrix();
    gl.glTranslated((minx + maxx) / 2, (miny + maxy) / 2, (minz + maxz) / 2);
    gl.glScaled(maxx - minx, maxy - miny, maxz - minz);
    gl.glColor4fv(new float[] { 0.3f, 0, 0, 0.1f }, 0);
    glut.glutWireCube((float) 1.);
    gl.glPopMatrix();
    drawProbedSurface(gl);
    gl.glPopMatrix();
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) GL2(com.jogamp.opengl.GL2) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

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