Search in sources :

Example 1 with M30Processor

use of com.willwinder.universalgcodesender.gcode.processors.M30Processor in project Universal-G-Code-Sender by winder.

the class CommandProcessorLoader method getHelpForConfig.

/**
 * Helper to instantiate a processor by name and call the getHelp method.
 * @param pc
 * @return
 */
public static String getHelpForConfig(ProcessorConfig pc) {
    CommandProcessor p;
    try {
        switch(pc.name) {
            case "ArcExpander":
                double length = pc.args.get("segmentLengthMM").getAsDouble();
                p = new ArcExpander(true, length);
                break;
            case "CommandLengthProcessor":
                int commandLength = pc.args.get("commandLength").getAsInt();
                p = new CommandLengthProcessor(commandLength);
                break;
            case "CommentProcessor":
                p = new CommentProcessor();
                break;
            case "DecimalProcessor":
                int decimals = pc.args.get("decimals").getAsInt();
                p = new DecimalProcessor(decimals);
                break;
            case "FeedOverrideProcessor":
                double override = pc.args.get("speedOverridePercent").getAsDouble();
                p = new FeedOverrideProcessor(override);
                break;
            case "M30Processor":
                p = new M30Processor();
                break;
            case "PatternRemover":
                String pattern = pc.args.get("pattern").getAsString();
                p = new PatternRemover(pattern);
                break;
            case "WhitespaceProcessor":
                p = new WhitespaceProcessor();
                break;
            case "M3Dweller":
                int duration = pc.args.get("duration").getAsInt();
                p = new M3Dweller(duration);
                break;
            default:
                throw new IllegalArgumentException("Unknown processor: " + pc.name);
        }
        return p.getHelp();
    } catch (Exception e) {
        return Localization.getString("settings.processors.loadError") + ": " + Localization.getString(pc.name);
    }
}
Also used : DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) PatternRemover(com.willwinder.universalgcodesender.gcode.processors.PatternRemover) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) M3Dweller(com.willwinder.universalgcodesender.gcode.processors.M3Dweller) WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) CommandProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandProcessor) ArcExpander(com.willwinder.universalgcodesender.gcode.processors.ArcExpander) FeedOverrideProcessor(com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor)

Example 2 with M30Processor

use of com.willwinder.universalgcodesender.gcode.processors.M30Processor in project Universal-G-Code-Sender by winder.

the class GcodeParserTest method testPreprocessCommandFeedOverride.

@Test
public void testPreprocessCommandFeedOverride() throws Exception {
    System.out.println("preprocessCommandFeedOverride");
    // Tests:
    // '(comment)' is removed
    // '; Comment!' is removed
    // 'M30' is removed
    // Decimal truncated to 0.88889
    // Remove spaces
    String command = "(comment) G01 X0.888888888888888888 M30 F100; Comment!";
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    instance.addCommandProcessor(new FeedOverrideProcessor(0.));
    instance.addCommandProcessor(new DecimalProcessor(5));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    List<String> result = instance.preprocessCommand(command, instance.getCurrentState());
    assertEquals(1, result.size());
    assertEquals("G01X0.88889F100", result.get(0));
    instance.resetCommandProcessors();
    instance.addCommandProcessor(new CommentProcessor());
    instance.addCommandProcessor(new FeedOverrideProcessor(200.));
    instance.addCommandProcessor(new DecimalProcessor(5));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    result = instance.preprocessCommand(command, instance.getCurrentState());
    assertEquals(1, result.size());
    assertEquals("G01X0.88889F200.0", result.get(0));
}
Also used : WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) FeedOverrideProcessor(com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 3 with M30Processor

use of com.willwinder.universalgcodesender.gcode.processors.M30Processor in project Universal-G-Code-Sender by winder.

the class GcodeParserTest method testPreprocessCommandException.

@Test
public void testPreprocessCommandException() throws Exception {
    System.out.println("preprocessCommandException?!");
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    // Don't process decimals to make this test easier to create.
    instance.addCommandProcessor(new DecimalProcessor(0));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    // Shouldn't throw if exactly 50 characters long.
    final String command = "G01X0.88888888888888888888888888888888888888888888";
    instance.preprocessCommand(command, instance.getCurrentState());
    // Should throw an exception when it is 51 characters long.
    Assertions.assertThatThrownBy(() -> instance.preprocessCommand(command + "8", instance.getCurrentState())).isInstanceOf(GcodeParserException.class);
}
Also used : WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 4 with M30Processor

use of com.willwinder.universalgcodesender.gcode.processors.M30Processor in project Universal-G-Code-Sender by winder.

the class GcodeParserTest method testPreprocessCommandGood.

/**
 * Test of preprocessCommand method, of class GcodeParser.
 */
@Test
public void testPreprocessCommandGood() throws Exception {
    System.out.println("preprocessCommandGood");
    // Tests:
    // '(comment)' is removed
    // '; Comment!' is removed
    // 'M30' is removed
    // Decimal truncated to 0.88889
    // Remove spaces
    String command = "(comment) G01 X0.888888888888888888 M30; Comment!";
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    instance.addCommandProcessor(new DecimalProcessor(5));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    List<String> result = instance.preprocessCommand(command, instance.getCurrentState());
    assertEquals(1, result.size());
    assertEquals("G01X0.88889", result.get(0));
}
Also used : WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 5 with M30Processor

use of com.willwinder.universalgcodesender.gcode.processors.M30Processor in project Universal-G-Code-Sender by winder.

the class GcodeTilerTopComponent method generateOneTile.

private void generateOneTile(double offsetX, double offsetY, PrintWriter output) {
    String gcodeFile = backend.getGcodeFile().getAbsolutePath();
    UnitUtils.Units u = selectedUnit(this.units.getSelectedIndex());
    GcodeParser parser = new GcodeParser();
    parser.addCommandProcessor(new Translator(new Position(offsetX, offsetY, 0.0, u)));
    parser.addCommandProcessor(new M30Processor());
    output.println(GcodeUtils.unitCommand(u) + "G90");
    output.println("G0X" + offsetX + "Y" + offsetY);
    try {
        File file = new File(gcodeFile);
        try {
            try (GcodeStreamReader gsr = new GcodeStreamReader(file)) {
                while (gsr.getNumRowsRemaining() > 0) {
                    GcodeCommand next = gsr.getNextCommand();
                    applyTranslation(next.getCommandString(), parser, output);
                }
            }
        } catch (GcodeStreamReader.NotGcodeStreamFile e) {
            try (FileInputStream fstream = new FileInputStream(file);
                DataInputStream dis = new DataInputStream(fstream);
                BufferedReader fileStream = new BufferedReader(new InputStreamReader(dis))) {
                String line;
                while ((line = fileStream.readLine()) != null) {
                    applyTranslation(line, parser, output);
                }
            }
        }
    } catch (GcodeParserException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Position(com.willwinder.universalgcodesender.model.Position) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) Translator(com.willwinder.universalgcodesender.gcode.processors.Translator) BufferedReader(java.io.BufferedReader) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) File(java.io.File)

Aggregations

M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)6 CommandLengthProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor)5 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)5 DecimalProcessor (com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor)5 WhitespaceProcessor (com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor)5 FeedOverrideProcessor (com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor)3 Test (org.junit.Test)3 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)2 CommandProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandProcessor)2 M3Dweller (com.willwinder.universalgcodesender.gcode.processors.M3Dweller)2 PatternRemover (com.willwinder.universalgcodesender.gcode.processors.PatternRemover)2 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)1 Translator (com.willwinder.universalgcodesender.gcode.processors.Translator)1 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)1 Position (com.willwinder.universalgcodesender.model.Position)1 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)1 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)1 ProcessorConfig (com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig)1 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)1 BufferedReader (java.io.BufferedReader)1