Beispiel #1
0
        /// <summary>
        /// Generate G-code instructions for the segment.
        /// </summary>
        /// <param name="s">StringBuilder to store the G-code.</param>
        /// <param name="printer">Printer state.</param>
        public override void GenerateGCode(StringBuilder s, V2GState printer)
        {
            double MovementLength = printer.Position.DistanceTo(printer.PrintPointOnBase(this.PrintPosition));

            if (MovementLength > MovementThreshold)
            {
                if (printer.settings.IsVerbose)
                {
                    s.Append("\n(A. PrintMovement) (Printer has to move)");
                }
                printer.F = this.PrintPosition.Speed;
                printer.SetPosition(this.PrintPosition, s);

                // Move
                s.Append("\nG1");
                s.Append(" X" + Math.Round(printer.Position.X, 4));
                s.Append(" Y" + Math.Round(printer.Position.Y, 4));
                s.Append(" Z" + Math.Round(printer.Position.Z, 4));
                s.Append(" F" + Math.Round(printer.F, 4));
            }
            else
            {
                if (printer.settings.IsVerbose)
                {
                    s.Append("\n (A. PrintMovement) (Printer is already here)");
                }
            }
        }
Beispiel #2
0
 public void SetRelativePoint(V2GState printer)
 {
     this.p = printer.Position + this.p;
     if (this.p.Z <= 0.0)
     {
         this.p.Z = 0.05;
     }
 }
Beispiel #3
0
        public override void GenerateGCode(StringBuilder s, V2GState printer)
        {
            V2GPrintPosition prevP = printer.Position;

            printer.F = this.speed;
            printer.SetPosition(this.p);
            double length          = printer.Position.DistanceTo(prevP);
            double extrusionHeight = this.Height();

            if (printer.Position.Z < 0)
            {
                printer.Position.Z = 0;                         // todo: this safes inside the PrintState class
            }
            if (printer.Position.Z < 0.7 && this.AllowsGroundOverride)
            {
                if (this.thickness < 700)
                {
                    this.speed = 400;
                }
                extrusionHeight = 0.25;
            }

            // Locate Z in its place
            s.Append("\nG1");
            s.Append(" Z" + Math.Round((printer.Position.Z + extrusionHeight), 4));

            printer.EPerMM = this.EUnitIncrease();

            // Calculate E increase
            double EUnitIncrease = printer.EPerMM;
            double EIncrease     = EUnitIncrease * length;

            printer.E += EIncrease;

            // Extrude
            // - todo: check if coordinates are equal than previous ones
            s.Append("\nG1");
            s.Append(" X" + Math.Round(printer.Position.X, 4));
            s.Append(" Y" + Math.Round(printer.Position.Y, 4));
            s.Append(" Z" + Math.Round((printer.Position.Z + extrusionHeight), 4));
            s.Append(" E" + Math.Round(printer.E, 4));
            s.Append(" F" + Math.Round(printer.F, 4));
            if (printer.settings.IsVerbose)
            {
                s.Append(" (EUnitIncrease " + EUnitIncrease + ", thickness " + this.thickness + ", height " + extrusionHeight + ")");
            }
            if (printer.settings.IsVerbose)
            {
                s.Append(" (PrintSegment)");
            }
        }
Beispiel #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Variables
            List <V2GPrintable> printables = new List <V2GPrintable>();
            V2GSettings         settings   = new V2GSettings();

            // Get Data
            DA.GetDataList(0, printables);
            DA.GetData(1, ref settings);
            //if (!DA.GetData(1, ref settings))
            //{
            //   settings = new V2GSettings();
            // }

            // Stuff
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            // Create Printer and adjust settings
            V2GState printer = new V2GState();

            printer.SetSettings(settings);

            // Create Model
            V2GModel model = new V2GModel();

            // Append PrintPolylines
            foreach (V2GPrintable printable in printables)
            {
                if (printable is V2GPrintPolyline)
                {
                    model.AppendAsPath(printable as Voxel2GCodeCore.Geometry.V2GPrintPolyline);
                }
                else if (printable is V2GPrintPosition)
                {
                    /// TODO: implement model.AppendAsPath(V2GPrintPosition position) { }
                }
            }

            model.AppendAsRelativeMovement(new V2GPrintPosition(0, 0, 10.0), 0, 7200);

            // Generate GCode
            model.GenerateGCode(sb, printer);

            // Set Data
            DA.SetData(0, sb.ToString());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Printables"></param>
        /// <param name="Settings"></param>
        /// <param name="IsVerbose"></param>
        /// <returns name="GCode">Printable GCode</returns>

        public static string Printer(
            List <V2GPrintPolyline> Printables,
            [DefaultArgumentAttribute("Voxel2GCodeZeroTouch.GetUnsetValue()")] object Settings,
            [DefaultArgumentAttribute("Voxel2GCodeZeroTouch.GetUnsetValue()")] bool IsVerbose)
        {
            // Stuff
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            // Create State
            V2GState printer = new V2GState();

            if (IsSet(IsVerbose))
            {
                printer.settings.IsVerbose = (bool)IsVerbose;
            }
            if (IsSet(Settings))
            {
                printer.SetSettings((V2GSettings)Settings);
            }

            // Create Model
            V2GModel model = new V2GModel();

            printer.settings.StartPoint = new V2GPrintPosition(20, 20, 0);
            printer.settings.EndPoint   = printer.settings.StartPoint;

            // Append PrintPolylines
            foreach (var printable in Printables)
            {
                if (printable is V2GPrintPolyline)
                {
                    model.AppendAsPath(printable as V2GPrintPolyline);
                }

                // if (printable is PrintPoint) { }
                // if (printable is PrintSurface) { }
            }

            model.AppendAsRelativeMovement(new V2GPrintPosition(0, 0, 10.0), 0);

            // Generate GCode
            model.GenerateGCode(sb, printer);

            return(sb.ToString());
        }
Beispiel #6
0
        /// <summary>
        /// Generate G-code instructions for the segment.
        /// </summary>
        /// <param name="s">StringBuilder to store the G-code.</param>
        /// <param name="printer">Printer state.</param>
        public override void GenerateGCode(StringBuilder s, V2GState printer)
        {
            V2GPrintPosition prevPrinterPosition = printer.Position;
            bool             speedChanged        = false;

            if (printer.F != this.PrintPosition.Speed)
            {
                printer.F    = this.PrintPosition.Speed;
                speedChanged = true;
            }
            printer.SetPosition(this.PrintPosition, s);
            double length = printer.Position.DistanceTo(prevPrinterPosition);

            // Switch Extruder Head if Needed
            printer.SetHead(s, this.PrintPosition.Head);

            // Move to Start Point
            //s.Append("\nG1");
            //s.Append(" Z" + Math.Round(printer.Position.Z, 4));

            // Move and Extrude
            s.Append("\nG1");
            if (prevPrinterPosition.X != printer.Position.X)
            {
                s.Append(" X" + Math.Round(printer.Position.X, 4));
            }
            if (prevPrinterPosition.Y != printer.Position.Y)
            {
                s.Append(" Y" + Math.Round(printer.Position.Y, 4));
            }
            if (Math.Abs(prevPrinterPosition.Z - printer.Position.Z) > 0.0001)
            {
                s.Append(" Z" + Math.Round(printer.Position.Z, 4));
            }
            printer.IncreaseE(s, this.PrintPosition.MaterialAmount, length, this.PrintPosition.MixPercentage);
            if (speedChanged)
            {
                s.Append(" F" + Math.Round(printer.F, 4));
            }
        }
Beispiel #7
0
        public override void GenerateGCode(StringBuilder s, V2GState printer)
        {
            double MovementLength = printer.Position.DistanceTo(printer.PrintPointOnBase(this.p));

            if (MovementLength > 0.001)
            {
                if (this.IsRelative)
                {
                    this.SetRelativePoint(printer);
                }

                if (printer.settings.IsVerbose)
                {
                    s.Append("\n(A. PrintMovement) (Printer has to move)");
                }

                printer.F = this.speed;

                // Filament retract
                if (this.FilamentRetract > 0.0 && (MovementLength > 2.0 || ForceFilamentOperations))
                {
                    printer.E += -this.FilamentRetract;
                    s.Append("\nG1 E" + Math.Round(printer.E, 4));
                }

                // Add zDelta
                if (zDelta != 0)
                {
                    printer.Position.Z += zDelta;
                    s.Append("\nG1 Z" + Math.Round(printer.Position.Z, 4)); if (printer.settings.IsVerbose)
                    {
                        s.Append(" (B. PrintMovement) (move zDelta " + zDelta + ")");
                    }
                }

                // Move
                // todo: rollback and forth
                printer.SetPosition(this.p + new V2GPrintPosition(0, 0, zDelta));
                s.Append("\nG1");
                s.Append(" X" + Math.Round(printer.Position.X, 4));
                s.Append(" Y" + Math.Round(printer.Position.Y, 4));
                s.Append(" Z" + Math.Round(printer.Position.Z, 4));
                s.Append(" F" + Math.Round(printer.F, 4));

                if (printer.settings.IsVerbose)
                {
                    s.Append(" (C. PrintMovement) (move towards point with zDelta " + zDelta + ")");
                }

                // Substract zDelta
                if (zDelta != 0)
                {
                    printer.Position.Z -= zDelta;
                    if (printer.Position.Z < 0)
                    {
                        printer.Position.Z = 0.0;
                    }
                    s.Append("\nG1 Z" + Math.Round(printer.Position.Z, 4));
                    //if (printer.IsVerbose) s.Append(" (D. PrintMovement) (move zDelta " + zDelta + ")");
                }

                // Filament feed (while moving)

                if (this.FilamentFeed > 0.0 && (MovementLength > 2.0 || ForceFilamentOperations)) // todo: check if this makes PLA behavior worse (length restriction wasn't here, just testing for NinjaFlex not to go out of the extruder)
                {
                    if (zDelta == 0)
                    {
                        s.Append("\nG1");
                    }
                    printer.E += this.FilamentFeed;
                    s.Append(" E" + Math.Round(printer.E, 4));
                }
            }
            else
            {
                if (printer.settings.IsVerbose)
                {
                    s.Append("\n (A. PrintMovement) (Printer is already here)");
                }
            }
        }
Beispiel #8
0
 public virtual void GenerateGCode(StringBuilder s, V2GState printer)
 {
 }