コード例 #1
0
        private void PrimeHotend(GCodeSketch gcodeSketch, RectangleDouble towerRect)
        {
            gcodeSketch.WriteRaw("; Priming");

            while (towerRect.Width > 4)
            {
                towerRect.Inflate(-nozzleWidth);
                gcodeSketch.DrawRectangle(towerRect);
            }
        }
コード例 #2
0
        private RectangleDouble CreatePerimeters(GCodeSketch gcodeSketch, RectangleDouble rect)
        {
            gcodeSketch.WriteRaw("; CreatePerimeters");
            for (var i = 0; i < 3; i++)
            {
                rect.Inflate(-nozzleWidth);
                gcodeSketch.DrawRectangle(rect);
            }

            return(rect);
        }
コード例 #3
0
        private static void PrintLineEnd(GCodeSketch turtle, bool drawGlpyphs, int i, Vector2 currentPos)
        {
            if (drawGlpyphs && CalibrationLine.Glyphs.TryGetValue(i, out IVertexSource vertexSource))
            {
                var flattened = new FlattenCurves(vertexSource);

                var verticies = flattened.Vertices();
                var firstItem = verticies.First();
                var position  = turtle.CurrentPosition;

                var scale = 0.32;

                if (firstItem.command != ShapePath.FlagsAndCommand.MoveTo)
                {
                    turtle.MoveTo((firstItem.position * scale) + currentPos);
                }

                bool closed = false;

                foreach (var item in verticies)
                {
                    switch (item.command)
                    {
                    case ShapePath.FlagsAndCommand.MoveTo:
                        turtle.MoveTo((item.position * scale) + currentPos);
                        break;

                    case ShapePath.FlagsAndCommand.LineTo:
                        turtle.LineTo((item.position * scale) + currentPos);
                        break;

                    case ShapePath.FlagsAndCommand.FlagClose:
                        turtle.LineTo((firstItem.position * scale) + currentPos);
                        closed = true;
                        break;
                    }
                }

                if (!closed)
                {
                    turtle.LineTo((firstItem.position * scale) + currentPos);
                }
            }
        }
コード例 #4
0
        public void BuildTemplate(GCodeSketch gcodeSketch, bool verticalLayout)
        {
            gcodeSketch.SetTool("T0");
            gcodeSketch.WriteRaw($"G1 Z0.2 F{firstLayerSpeed}");

            if (verticalLayout)
            {
                gcodeSketch.Transform = Affine.NewRotation(MathHelper.DegreesToRadians(90)) * Affine.NewTranslation(105, 45);
            }
            else
            {
                gcodeSketch.Transform = Affine.NewTranslation(75, 175);
            }

            var rect = new RectangleDouble(0, 0, 123, 30);

            var originalRect = rect;

            int towerSize = 10;

            gcodeSketch.Speed = firstLayerSpeed;

            double y1 = rect.Bottom;

            gcodeSketch.MoveTo(rect.Left, y1);

            var towerRect = new RectangleDouble(0, 0, towerSize, towerSize);

            towerRect.Offset(originalRect.Left - towerSize, originalRect.Bottom);

            // Prime
            this.PrimeHotend(gcodeSketch, towerRect);

            // Perimeters
            rect = this.CreatePerimeters(gcodeSketch, rect);

            double x, y2, y3;
            double sectionHeight = rect.Height / 2;
            bool   up            = true;
            var    step          = (rect.Width - 3) / 40;

            if (!this.DebugMode)
            {
                y1 = rect.YCenter + (nozzleWidth / 2);

                // Draw centerline
                gcodeSketch.MoveTo(rect.Left, y1);
                gcodeSketch.LineTo(rect.Right, y1);
                y1 += nozzleWidth;
                gcodeSketch.MoveTo(rect.Right, y1);
                gcodeSketch.LineTo(rect.Left, y1);

                y1 -= nozzleWidth / 2;

                x = rect.Left + 1.5;

                y2 = y1 - sectionHeight - (nozzleWidth * 1.5);
                y3 = y2 - 5;

                bool drawGlpyphs = false;

                // Draw calibration lines
                for (var i = 0; i <= 40; i++)
                {
                    gcodeSketch.MoveTo(x, up ? y1 : y2);

                    if ((i % 5 == 0))
                    {
                        gcodeSketch.LineTo(x, y3);

                        var currentPos = gcodeSketch.CurrentPosition;

                        gcodeSketch.Speed = 500;

                        PrintLineEnd(gcodeSketch, drawGlpyphs, i, currentPos);

                        gcodeSketch.Speed = 1800;

                        gcodeSketch.MoveTo(x, y3);
                        gcodeSketch.MoveTo(x, y2);
                    }

                    gcodeSketch.LineTo(x, up ? y2 : y1);

                    x = x + step;

                    up = !up;
                }
            }

            x  = rect.Left + 1.5;
            y1 = rect.Top + (nozzleWidth * .5);
            y2 = y1 - sectionHeight + (nozzleWidth * .5);

            gcodeSketch.SetTool("T1");

            gcodeSketch.MoveTo(rect.Left, rect.Top);

            gcodeSketch.PenDown();

            towerRect = new RectangleDouble(0, 0, towerSize, towerSize);
            towerRect.Offset(originalRect.Left - towerSize, originalRect.Top - towerSize);

            // Prime
            this.PrimeHotend(gcodeSketch, towerRect);

            if (this.DebugMode)
            {
                // Perimeters
                rect = this.CreatePerimeters(gcodeSketch, rect);
            }
            else
            {
                up = true;

                // Draw calibration lines
                for (var i = 0; i <= 40; i++)
                {
                    gcodeSketch.MoveTo(x + activeOffsets[i], up ? y1 : y2, retract: true);
                    gcodeSketch.LineTo(x + activeOffsets[i], up ? y2 : y1);

                    x = x + step;

                    up = !up;
                }
            }

            gcodeSketch.PenUp();
        }
コード例 #5
0
        public override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);

            // Replace with calibration template code
            //await templatePrinter.PrintTemplate(verticalLayout: true);
            //await templatePrinter.PrintTemplate(verticalLayout: false);

            Task.Run(async() =>
            {
                var sketch1 = new GCodeSketch(printer)
                {
                    Speed         = (int)(printer.Settings.GetValue <double>(SettingsKey.first_layer_speed) * 60),
                    RetractLength = printer.Settings.GetValue <double>(SettingsKey.retract_length),
                    RetractSpeed  = printer.Settings.GetValue <double>(SettingsKey.retract_speed) * 60,
                    RetractLift   = printer.Settings.GetValue <double>(SettingsKey.retract_lift),
                    TravelSpeed   = printer.Settings.GetValue <double>(SettingsKey.travel_speed) * 60,
                };

                var sketch2 = new GCodeSketch(printer)
                {
                    Speed         = sketch1.Speed,
                    RetractLength = sketch1.RetractLength,
                    RetractSpeed  = sketch1.RetractSpeed,
                    RetractLift   = sketch1.RetractLift,
                    TravelSpeed   = sketch1.TravelSpeed
                };

                //gcodeSketch.WriteRaw("G92 E0");
                sketch1.WriteRaw("; LAYER: 0");
                sketch1.WriteRaw("; LAYER_HEIGHT: 0.2");


                sketch1.SetTool("T0");
                sketch2.SetTool("T1");
                sketch1.PenUp();

                templatePrinter.BuildTemplate(sketch1, sketch2, verticalLayout: true);
                templatePrinter.BuildTemplate(sketch1, sketch2, verticalLayout: false);


                string outputPath = Path.Combine(
                    ApplicationDataStorage.Instance.GCodeOutputPath,
                    $"nozzle-offset-template-combined.gcode");

                File.WriteAllText(outputPath, sketch1.ToGCode() + "\r\n" + sketch2.ToGCode());

                // HACK: update state needed to be set before calling StartPrint
                printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;

                await printer.Connection.StartPrint(outputPath, allowRecovery: false);

                // Wait for print start
                while (!printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                // Wait for print finished
                while (printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                if (printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
                {
                    printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
                }
                else
                {
                    printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 20, printer.Settings.Helpers.ManualMovementSpeeds().Z);

                    printer.Connection.MoveAbsolute(PrinterConnection.Axis.Y,
                                                    printer.Bed.Bounds.Top,
                                                    printer.Settings.Helpers.ManualMovementSpeeds().Y);
                }
            });
        }
コード例 #6
0
        private static void PrintLineEnd(GCodeSketch turtle, bool drawGlyphs, int i, Vector2 currentPos, bool lift = false)
        {
            var originalSpeed = turtle.Speed;

            turtle.Speed = Math.Min(700, turtle.Speed);

            if (drawGlyphs && CalibrationLine.Glyphs.TryGetValue(i, out IVertexSource vertexSource))
            {
                turtle.WriteRaw("; LineEnd Marker");
                var flattened = new FlattenCurves(vertexSource);

                var verticies = flattened.Vertices();
                var firstItem = verticies.First();
                var position  = turtle.CurrentPosition;

                var scale = 0.3;

                if (firstItem.command != ShapePath.FlagsAndCommand.MoveTo)
                {
                    if (lift)
                    {
                        turtle.PenUp();
                    }

                    turtle.MoveTo((firstItem.position * scale) + currentPos);
                }

                bool closed = false;

                foreach (var item in verticies)
                {
                    switch (item.command)
                    {
                    case ShapePath.FlagsAndCommand.MoveTo:
                        if (lift)
                        {
                            turtle.PenUp();
                        }

                        turtle.MoveTo((item.position * scale) + currentPos);

                        if (lift)
                        {
                            turtle.PenDown();
                        }
                        break;

                    case ShapePath.FlagsAndCommand.LineTo:
                        turtle.LineTo((item.position * scale) + currentPos);
                        break;

                    case ShapePath.FlagsAndCommand.FlagClose:
                        turtle.LineTo((firstItem.position * scale) + currentPos);
                        closed = true;
                        break;
                    }
                }

                bool atStartingPosition = position.Equals(turtle.CurrentPosition, .1);

                if (!closed &&
                    !atStartingPosition)
                {
                    turtle.LineTo((firstItem.position * scale) + currentPos);
                    atStartingPosition = position.Equals(turtle.CurrentPosition, .1);
                }

                // Restore original speed
                turtle.Speed = originalSpeed;

                if (!atStartingPosition)
                {
                    // Return to original position
                    turtle.PenUp();
                    turtle.MoveTo(currentPos);
                    turtle.PenDown();
                }
            }
        }
コード例 #7
0
        public override void OnLoad(EventArgs args)
        {
            if (!this.HasBeenClosed)
            {
                this.NextButton.Enabled = true;
            }

            base.OnLoad(args);

            // Replace with calibration template code
            //await templatePrinter.PrintTemplate(verticalLayout: true);
            //await templatePrinter.PrintTemplate(verticalLayout: false);

            Task.Run(async() =>
            {
                var gcodeSketch = new GCodeSketch()
                {
                    Speed = (int)(printer.Settings.GetValue <double>(SettingsKey.first_layer_speed) * 60)
                };

                //gcodeSketch.WriteRaw("G92 E0");
                gcodeSketch.WriteRaw("; LAYER: 0");
                gcodeSketch.WriteRaw("; LAYER_HEIGHT: 0.2");

                templatePrinter.BuildTemplate(gcodeSketch, verticalLayout: true);
                templatePrinter.BuildTemplate(gcodeSketch, verticalLayout: false);

                string outputPath = Path.Combine(
                    ApplicationDataStorage.Instance.GCodeOutputPath,
                    $"nozzle-offset-template-combined.gcode");

                File.WriteAllText(outputPath, gcodeSketch.ToGCode());

                // HACK: update state needed to be set before calling StartPrint
                printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;

                await printer.Connection.StartPrint(outputPath);

                // Wait for print start
                while (!printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                // Wait for print finished
                while (printer.Connection.PrintIsActive)
                {
                    Thread.Sleep(500);
                }

                if (printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
                {
                    printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
                }
                else
                {
                    printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 20, printer.Settings.Helpers.ManualMovementSpeeds().Z);

                    printer.Connection.MoveAbsolute(PrinterConnection.Axis.Y,
                                                    printer.Bed.Bounds.Top,
                                                    printer.Settings.Helpers.ManualMovementSpeeds().Y);
                }
            });
        }