Exemplo n.º 1
0
 void Setup()
 {
     finished        = false;
     canvasClone     = Instantiate(canvas);
     mat.mainTexture = canvasClone;
     machineConfig   = FindObjectOfType <MachineConfig>();
     gCodeWriter     = FindObjectOfType <GCodeWriter>();
     dbugSettings    = FindObjectOfType <DbugSettings>();
     painter         = new BMapPainter(canvasClone, machineConfig.paper);
 }
Exemplo n.º 2
0
        public bool RunProcessor(IPreprocessor processor, String inputFile, String outputFile)
        {
            var reader = new GCodeReader(inputFile);
            var writer = new GCodeWriter(outputFile);

            try
            {
                return(processor.ProcessGCode(reader, writer, getPrinterDetails(), getJobDetails()));
            }
            finally
            {
                reader.Close();
                writer.Close();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            const string filename = "20x20x20.sl1";
            FileInfo     file     = new FileInfo(filename);

            var p = new Program();

            var configuration = p.Extract(filename);

            GCodeWriter gCodeWriter = new GCodeWriter(configuration.config);

            gCodeWriter.WriteHeader();
            gCodeWriter.StartGCode();

            var     layerHeight        = (decimal)gCodeWriter.PrusaPrintConfig.LayerHeight;
            decimal currentLayerHeight = 0.0m;
            decimal currentLayer       = 1m;

            foreach (var image in configuration.images)
            {
                decimal zlevel = (currentLayer * layerHeight);
                gCodeWriter.Write();

                gCodeWriter.Write(new Comment()
                {
                    Value = $"LAYER_START:{currentLayer-1}"
                });
                gCodeWriter.Write(new Comment()
                {
                    Value = $"currPos:{zlevel}"
                });
                gCodeWriter.Write(new M6054()
                {
                    Value = image.Name
                });
                gCodeWriter.Write(new G0()
                {
                    Z = 5.0m + zlevel, F = 65
                });
                gCodeWriter.Write(new G0()
                {
                    Z = zlevel, F = 150
                });
                gCodeWriter.Write(new G4()
                {
                    Value = 0
                });
                gCodeWriter.Write(new M106()
                {
                    Value = 255
                });
                gCodeWriter.Write(new G4()
                {
                    Value = (currentLayer <= gCodeWriter.PrusaPrintConfig.NumFade ? gCodeWriter.PrusaPrintConfig.ExpTimeFirst * 1000 : gCodeWriter.PrusaPrintConfig.ExpTime * 1000)
                });
                gCodeWriter.Write(new M106()
                {
                    Value = 0
                });
                gCodeWriter.Write();
                gCodeWriter.Write(new Comment()
                {
                    Value = "LAYER_END"
                });
                gCodeWriter.Write();

                currentLayerHeight += layerHeight;
                currentLayer++;
            }
            var gcode = gCodeWriter.ToString();

            var data     = p.RebuildZipFile(gcode, configuration.images);
            var fileName = file.Name + ".zip";

            File.WriteAllBytes(fileName, data);
        }
Exemplo n.º 4
0
        static void TranslateGCode(TextReader reader, TextWriter writer, decimal firstTowerZ, decimal deltaX, decimal deltaY, List <CurvePoint> curvePoints)
        {
            curvePoints.Sort(
                (left, right) => left.Z.CompareTo(right.Z));

            decimal z = decimal.MinValue;

            var uniqueZValues = new HashSet <decimal>();

            decimal lastE = decimal.MinValue;

            string lastSerialMessage = "";

            var gcodeWriter = new GCodeWriter(writer);

            int numberOfRetractions = 0;

            while (true)
            {
                string line = reader.ReadLine();

                if (line == null)
                {
                    break;
                }

                var command = new GCodeCommand(line);

                if ((command.Command == "G0") || (command.Command == "G1"))
                {
                    if (command.HasParameter('X'))
                    {
                        command.SetParameter('X', command.GetParameter('X') + deltaX);
                    }
                    if (command.HasParameter('Y'))
                    {
                        command.SetParameter('Y', command.GetParameter('Y') + deltaY);
                    }

                    if (command.HasParameter('Z'))
                    {
                        z = command.GetParameter('Z');

                        if (uniqueZValues.Add(z))
                        {
                            Console.Write('#');
                        }
                    }

                    if (z >= firstTowerZ)
                    {
                        if (command.HasParameter('E'))
                        {
                            decimal e = command.GetParameter('E');

                            if (e < lastE)
                            {
                                // Retraction!
                                numberOfRetractions++;

                                decimal retraction = GetRetractionForZ(z, curvePoints);

                                command.SetParameter('E', lastE - retraction);

                                string lcdScreenMessage = $"dE {retraction:0.000} at Z {z:#0.0}";
                                string serialMessage    = $"Retraction {retraction:0.00000} at Z {z:#0.0}";

                                gcodeWriter.WriteLine("M117 " + lcdScreenMessage);

                                if (serialMessage != lastSerialMessage)
                                {
                                    gcodeWriter.WriteLine("M118 " + serialMessage);

                                    lastSerialMessage = serialMessage;
                                }
                            }

                            lastE = e;
                        }
                    }
                }

                gcodeWriter.WriteLine(command);
            }

            gcodeWriter.WriteLine("G0 X0 Y0");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Output:");
            Console.WriteLine("- {0} characters", gcodeWriter.NumCharactersWritten);
            Console.WriteLine("- {0} lines", gcodeWriter.NumLines);
            Console.WriteLine("- {0} commands", gcodeWriter.NumCommands);
            Console.WriteLine("- {0} movement commands", gcodeWriter.NumMovementCommands);
            Console.WriteLine("- {0} unique Z values", uniqueZValues.Count);
            Console.WriteLine("- {0} retractions", numberOfRetractions);
        }