Search in sources :

Example 1 with Units

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

the class GrblController method handleStatusString.

// No longer a listener event
private void handleStatusString(final String string) {
    if (this.capabilities == null) {
        return;
    }
    ControlState before = getControlState();
    String beforeState = controllerStatus == null ? "" : controllerStatus.getState();
    controllerStatus = GrblUtils.getStatusFromStatusString(controllerStatus, string, capabilities, getFirmwareSettings().getReportingUnits());
    // Make UGS more responsive to the state being reported by GRBL.
    if (before != getControlState()) {
        this.dispatchStateChange(getControlState());
    }
    // GRBL 1.1 jog complete transition
    if (StringUtils.equals(beforeState, "Jog") && controllerStatus.getState().equals("Idle")) {
        this.comm.cancelSend();
    }
    // Set and restore the step mode when transitioning from CHECK mode to IDLE.
    if (before == COMM_CHECK && getControlState() != COMM_CHECK) {
        setSingleStepMode(temporaryCheckSingleStepMode);
    } else if (before != COMM_CHECK && getControlState() == COMM_CHECK) {
        temporaryCheckSingleStepMode = getSingleStepMode();
        setSingleStepMode(true);
    }
    // pausing.
    if (isCanceling) {
        if (attemptsRemaining > 0 && lastLocation != null) {
            attemptsRemaining--;
            // If the machine goes into idle, we no longer need to cancel.
            if (this.controllerStatus.getState().equals("Idle") || this.controllerStatus.getState().equalsIgnoreCase("Check")) {
                isCanceling = false;
                // Make sure the GUI gets updated
                this.dispatchStateChange(getControlState());
            } else // Otherwise check if the machine is Hold/Queue and stopped.
            if ((this.controllerStatus.getState().equals("Hold") || this.controllerStatus.getState().equals("Queue")) && lastLocation.equals(this.controllerStatus.getMachineCoord())) {
                try {
                    this.issueSoftReset();
                } catch (Exception e) {
                    this.errorMessageForConsole(e.getMessage() + "\n");
                }
                isCanceling = false;
            }
            if (isCanceling && attemptsRemaining == 0) {
                this.errorMessageForConsole(Localization.getString("grbl.exception.cancelReset") + "\n");
            }
        }
        lastLocation = new Position(this.controllerStatus.getMachineCoord());
    }
    // Save max Z location
    if (this.controllerStatus != null && this.getUnitsCode() != null && this.controllerStatus.getMachineCoord() != null) {
        Units u = this.getUnitsCode().equalsIgnoreCase("G21") ? Units.MM : Units.INCH;
        double zLocationMM = this.controllerStatus.getMachineCoord().z;
        if (u == Units.INCH)
            zLocationMM *= 26.4;
        if (zLocationMM > this.maxZLocationMM) {
            maxZLocationMM = zLocationMM;
        }
    }
    dispatchStatusString(controllerStatus);
}
Also used : ControlState(com.willwinder.universalgcodesender.model.UGSEvent.ControlState) Position(com.willwinder.universalgcodesender.model.Position) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 2 with Units

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

the class AutoLevelerTopComponent method scanSurfaceButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void scanSurfaceButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_scanSurfaceButtonActionPerformed
    if (scanner == null || scanner.getProbeStartPositions() == null || scanner.getProbeStartPositions().isEmpty()) {
        return;
    }
    scanningSurface = true;
    try {
        Units u = this.unitMM.isSelected() ? Units.MM : Units.INCH;
        AutoLevelSettings als = settings.getAutoLevelSettings();
        for (Position p : scanner.getProbeStartPositions()) {
            backend.sendGcodeCommand(true, String.format("G90 G21 G0 X%f Y%f Z%f", p.x, p.y, p.z));
            backend.probe("Z", als.probeSpeed, this.scanner.getProbeDistance(), u);
            backend.sendGcodeCommand(true, String.format("G90 G21 G0 Z%f", p.z));
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        scanningSurface = false;
    }
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) AutoLevelSettings(com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 3 with Units

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

the class AutoLevelerTopComponent method updateSettings.

private void updateSettings() {
    this.bulkChanges = true;
    // Only set units radio button the first time.
    if (!this.unitInch.isSelected() && !this.unitMM.isSelected()) {
        Units u = settings.getPreferredUnits();
        this.unitInch.setSelected(u == Units.INCH);
        this.unitMM.setSelected(u == Units.MM);
    }
    AutoLevelSettings als = settings.getAutoLevelSettings();
    this.stepResolution.setValue(als.stepResolution);
    this.zSurface.setValue(als.zSurface);
    this.bulkChanges = false;
    this.stateChanged(null);
}
Also used : AutoLevelSettings(com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 4 with Units

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

the class SurfaceScanner method update.

/**
 * Provides two points of the scanners bounding box and the number of points to sample in the X/Y directions.
 */
public void update(final Position corner1, final Position corner2, double resolution) {
    if (corner1.getUnits() != corner2.getUnits()) {
        throw new IllegalArgumentException("Provide same unit for both measures.");
    }
    if (resolution == 0)
        return;
    Units units = corner1.getUnits();
    double minx = Math.min(corner1.x, corner2.x);
    double maxx = Math.max(corner1.x, corner2.x);
    double miny = Math.min(corner1.y, corner2.y);
    double maxy = Math.max(corner1.y, corner2.y);
    double minz = Math.min(corner1.z, corner2.z);
    double maxz = Math.max(corner1.z, corner2.z);
    Position newMin = new Position(minx, miny, minz, units);
    Position newMax = new Position(maxx, maxy, maxz, units);
    // Make sure the position changed before resetting things.
    if (newMin.equals(this.minXYZ) && newMax.equals(this.maxXYZ) && this.resolution == resolution) {
        return;
    }
    this.minXYZ = newMin;
    this.maxXYZ = newMax;
    this.probeDistance = minz - maxz;
    this.resolution = resolution;
    this.xAxisPoints = (int) (Math.ceil((maxx - minx) / resolution)) + 1;
    this.yAxisPoints = (int) (Math.ceil((maxy - miny) / resolution)) + 1;
    this.probePositionGrid = new Position[this.xAxisPoints][this.yAxisPoints];
    // Calculate probe locations.
    ImmutableList.Builder<Position> probePositionBuilder = ImmutableList.builder();
    for (int x = 0; x < this.xAxisPoints; x++) {
        for (int y = 0; y < this.yAxisPoints; y++) {
            Position p = new Position(minx + Math.min(maxx - minx, x * resolution), miny + Math.min(maxy - miny, y * resolution), maxz, units);
            probePositionBuilder.add(p);
        }
    }
    this.probePositions = probePositionBuilder.build();
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) ImmutableList(com.google.common.collect.ImmutableList) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 5 with Units

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

Units (com.willwinder.universalgcodesender.model.UnitUtils.Units)7 Position (com.willwinder.universalgcodesender.model.Position)5 AutoLevelSettings (com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings)3 ImmutableList (com.google.common.collect.ImmutableList)1 GL2 (com.jogamp.opengl.GL2)1 ControlState (com.willwinder.universalgcodesender.model.UGSEvent.ControlState)1 Settings (com.willwinder.universalgcodesender.utils.Settings)1 FileStats (com.willwinder.universalgcodesender.utils.Settings.FileStats)1