Search in sources :

Example 1 with CodeHandler

use of com.neuronrobotics.replicator.driver.interpreter.CodeHandler in project java-bowler by NeuronRobotics.

the class ServoStockGCodeParser method addHandlers.

void addHandlers(GCodeInterpreter interp) {
    interp.setErrorHandler(new CodeHandler() {

        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            firePrinterStatusUpdate(new PrinterStatus(currentTransform, extrusion, currentTempreture, (int) next.getWord('P'), PrinterState.ERROR, next + " unhandled exception"));
        }
    });
    // Temperature control
    interp.addMHandler(104, new CodeHandler() {

        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentTempreture = next.getWord('S');
            device.setExtrusionTempreture(currentTempreture);
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    // TODO this code should wait until up to tempreture
    interp.addMHandler(109, new CodeHandler() {

        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentTempreture = next.getWord('S');
            device.setExtrusionTempreture(currentTempreture);
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    interp.setGHandler(0, new CodeHandler() {

        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentTransform = new TransformNR(next.getWord('X'), next.getWord('Y'), next.getWord('Z'), new RotationNR());
            extrusion = next.getWord('E');
            // zero seconds is a rapid
            device.setDesiredPrintLocetion(currentTransform, extrusion, 0);
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    interp.setGHandler(28, new CodeHandler() {

        // Move to origin
        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentTransform = new TransformNR(0, 0, 0, new RotationNR());
            // zero seconds is a rapid
            device.setDesiredPrintLocetion(currentTransform, extrusion, 0);
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    interp.setGHandler(92, new CodeHandler() {

        // Move to origin
        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            // clear the print queue before zeroing out extruder
            waitForEmptyPrintQueue();
            extrusion = next.getWord('E');
            device.zeroExtrusion(extrusion);
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    // set units to millimeters
    interp.setGHandler(21, new CodeHandler() {

        // Move to origin
        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    // use absolute coordinates
    interp.setGHandler(90, new CodeHandler() {

        // Move to origin
        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentLine = (int) next.getWord('P');
            firePrinterStatusUpdate(PrinterState.PRINTING);
        }
    });
    interp.setGHandler(1, new CodeHandler() {

        public void execute(GCodeLineData prev, GCodeLineData next) throws Exception {
            waitForClearToPrint();
            currentTransform = new TransformNR(next.getWord('X'), next.getWord('Y'), next.getWord('Z'), new RotationNR());
            TransformNR prevT = new TransformNR(prev.getWord('X'), prev.getWord('Y'), prev.getWord('Z'), new RotationNR());
            double seconds = (currentTransform.getOffsetVectorMagnitude(prevT) / next.getWord('F')) * 60.0;
            extrusion = next.getWord('E');
            int iter = 0;
            while (iter++ < 1000) {
                try {
                    device.setDesiredPrintLocetion(currentTransform, extrusion, seconds);
                    currentLine = (int) next.getWord('P');
                    firePrinterStatusUpdate(PrinterState.PRINTING);
                    return;
                } catch (RuntimeException ex) {
                    // keep trying
                    Thread.sleep(100);
                }
            }
        }
    });
}
Also used : CodeHandler(com.neuronrobotics.replicator.driver.interpreter.CodeHandler) RotationNR(com.neuronrobotics.sdk.addons.kinematics.math.RotationNR) GCodeLineData(com.neuronrobotics.replicator.driver.interpreter.GCodeLineData) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)

Aggregations

CodeHandler (com.neuronrobotics.replicator.driver.interpreter.CodeHandler)1 GCodeLineData (com.neuronrobotics.replicator.driver.interpreter.GCodeLineData)1 RotationNR (com.neuronrobotics.sdk.addons.kinematics.math.RotationNR)1 TransformNR (com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)1