Ejemplo n.º 1
0
        public override void PageIsBecomingActive()
        {
            // This data is currently the offset from the probe to the extruder tip. We need to translate them
            // into bed offsets and store them.

            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);
            // The first point is the user assisted offset to the bed
            Vector3 userBedSample0 = probePositions[0].position;
            // The first point sample offset at the limit switch
            Vector3 probeOffset0 = probePositions[1].position; // this z should be 0

            // right side of printer
            Vector3 userBedSample1 = probePositions[2].position;
            Vector3 probeOffset1   = probePositions[3].position;

            // auto back probe
            Vector3 probeOffset2 = probePositions[4].position;

            levelingData.sampledPosition0 = userBedSample0 - paperWidth;
            levelingData.sampledPosition1 = userBedSample1 - paperWidth;
            levelingData.sampledPosition2 = probeOffset2 - probeOffset0 + userBedSample0 - paperWidth;

            levelingData.probeOffset0 = probeOffset0 - paperWidth;
            levelingData.probeOffset1 = probeOffset1 - paperWidth;

            ActivePrinterProfile.Instance.DoPrintLeveling = true;
            base.PageIsBecomingActive();
        }
		internal static PrintLevelingData Create(PrinterSettings printerProfile, string jsonData, string depricatedPositionsCsv3ByXYZ)
		{
			if (!string.IsNullOrEmpty(jsonData))
			{
				var deserialized = JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
				deserialized.printerProfile = printerProfile;

				return deserialized;
			}
			else if (!string.IsNullOrEmpty(depricatedPositionsCsv3ByXYZ))
			{
				var item = new PrintLevelingData(ActiveSliceSettings.Instance);
				item.printerProfile = printerProfile;
				item.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);

				return item;
			}
			else
			{
				return new PrintLevelingData(ActiveSliceSettings.Instance)
				{
					printerProfile = printerProfile
				};
			}
		}
Ejemplo n.º 3
0
        public override void PageIsBecomingActive()
        {
            // This data is currently the offset from the probe to the extruder tip. We need to translate them
            // into bed offsets and store them.

            // The first point is the user assisted offset to the bed
            Vector3 userBedSample0 = probePositions[0].position;
            // The first point sample offset at the limit switch
            Vector3 probeOffset0 = probePositions[1].position;             // this z should be 0

            // right side of printer
            Vector3 userBedSample1 = probePositions[2].position;
            Vector3 probeOffset1   = probePositions[3].position;

            // auto back probe
            Vector3 probeOffset2 = probePositions[4].position;

            Vector3 paperWidth = new Vector3(0, 0, ActiveSliceSettings.Instance.GetValue <double>("manual_probe_paper_width"));

            PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();

            levelingData.SampledPosition0 = userBedSample0 - paperWidth;
            levelingData.SampledPosition1 = userBedSample1 - paperWidth;
            levelingData.SampledPosition2 = probeOffset2 - probeOffset0 + userBedSample0 - paperWidth;

            levelingData.ProbeOffset0 = probeOffset0 - paperWidth;
            levelingData.ProbeOffset1 = probeOffset1 - paperWidth;

            // Invoke setter forcing persistence of leveling data
            ActiveSliceSettings.Instance.SetPrintLevelingData(levelingData);

            ActiveSliceSettings.Instance.DoPrintLeveling(true);
            base.PageIsBecomingActive();
        }
Ejemplo n.º 4
0
        private static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
        {
            // turn off print leveling
            ActiveSliceSettings.Instance.Helpers.DoPrintLeveling(false);
            // clear any data that we are going to be acquiring (sampled positions, after z home offset)
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();

            levelingData.SampledPositions.Clear();
            ActiveSliceSettings.Instance.SetValue(SettingsKey.baby_step_z_offset, "0");

            ApplicationController.Instance.ReloadAdvancedControlsPanel();

            LevelWizardBase printLevelWizardWindow;

            switch (levelingData.CurrentPrinterLevelingSystem)
            {
            case PrintLevelingData.LevelingSystem.Probe3Points:
                printLevelWizardWindow = new LevelWizard3Point(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                printLevelWizardWindow = new LevelWizard7PointRadial(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                printLevelWizardWindow = new LevelWizard13PointRadial(runningState);
                break;

            default:
                throw new NotImplementedException();
            }

            printLevelWizardWindow.ShowAsSystemWindow();
            return(printLevelWizardWindow);
        }
Ejemplo n.º 5
0
        public override Vector2 GetPrintLevelPositionToSample(int index, double radius)
        {
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();

            return(GetLevelingFunctions(numberOfRadialSamples, levelingData, ActiveSliceSettings.Instance.GetValue <Vector2>(SettingsKey.print_center))
                   .GetPrintLevelPositionToSample(index, radius));
        }
Ejemplo n.º 6
0
        internal static PrintLevelingData Create(SettingsProfile settingsProfile, string jsonData, string depricatedPositionsCsv3ByXYZ)
        {
            if (!string.IsNullOrEmpty(jsonData))
            {
                var deserialized = JsonConvert.DeserializeObject <PrintLevelingData>(jsonData);
                deserialized.settingsProfile = settingsProfile;

                return(deserialized);
            }
            else if (!string.IsNullOrEmpty(depricatedPositionsCsv3ByXYZ))
            {
                var item = new PrintLevelingData(ActiveSliceSettings.Instance);
                item.settingsProfile = settingsProfile;
                item.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);

                return(item);
            }
            else
            {
                return(new PrintLevelingData(ActiveSliceSettings.Instance)
                {
                    settingsProfile = settingsProfile
                });
            }
        }
Ejemplo n.º 7
0
        private static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
        {
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();

            LevelWizardBase printLevelWizardWindow;

            switch (levelingData.CurrentPrinterLevelingSystem)
            {
            case PrintLevelingData.LevelingSystem.Probe2Points:
                printLevelWizardWindow = new LevelWizard2Point(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe3Points:
                printLevelWizardWindow = new LevelWizard3Point(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                printLevelWizardWindow = new LevelWizard7PointRadial(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                printLevelWizardWindow = new LevelWizard13PointRadial(runningState);
                break;

            default:
                throw new NotImplementedException();
            }

            printLevelWizardWindow.ShowAsSystemWindow();
            return(printLevelWizardWindow);
        }
        private void Initialize()
        {
            printer.Settings.ForTools <double>(SettingsKey.baby_step_z_offset, (key, value, i) =>
            {
                // remember the current baby stepping values
                babySteppingValue[i] = value;
                // clear them while we measure the offsets
                printer.Settings.SetValue(key, "0");
            });

            // turn off print leveling
            printer.Connection.AllowLeveling = false;

            // clear any data that we are going to be acquiring (sampled positions, after z home offset)
            var levelingData = new PrintLevelingData()
            {
                LevelingSystem = printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution)
            };

            printer.Connection.QueueLine("T0");

            switch (levelingData.LevelingSystem)
            {
            case LevelingSystem.Probe3Points:
                LevelingPlan = new LevelWizard3Point(printer);
                break;

            case LevelingSystem.Probe7PointRadial:
                LevelingPlan = new LevelWizard7PointRadial(printer);
                break;

            case LevelingSystem.Probe13PointRadial:
                LevelingPlan = new LevelWizard13PointRadial(printer);
                break;

            case LevelingSystem.Probe100PointRadial:
                LevelingPlan = new LevelWizard100PointRadial(printer);
                break;

            case LevelingSystem.Probe3x3Mesh:
                LevelingPlan = new LevelWizardMesh(printer, 3, 3);
                break;

            case LevelingSystem.Probe5x5Mesh:
                LevelingPlan = new LevelWizardMesh(printer, 5, 5);
                break;

            case LevelingSystem.Probe10x10Mesh:
                LevelingPlan = new LevelWizardMesh(printer, 10, 10);
                break;

            case LevelingSystem.ProbeCustom:
                LevelingPlan = new LevelWizardCustom(printer);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 9
0
        public override Vector2 GetPrintLevelPositionToSample(int index, double radius)
        {
            Printer           activePrinter = PrinterConnectionAndCommunication.Instance.ActivePrinter;
            PrintLevelingData levelingData  = PrintLevelingData.GetForPrinter(activePrinter);

            return(GetLevelingFunctions(numberOfRadialSamples, levelingData, ActiveSliceSettings.Instance.BedCenter)
                   .GetPrintLevelPositionToSample(index, radius));
        }
		public RadialLevlingFunctions(int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)
        {
            this.LevelingData = levelingData;
            this.BedCenter = bedCenter;
            this.NumberOfRadialSamples = numberOfRadialSamples;

			PrinterConnectionAndCommunication.Instance.PositionRead.RegisterEvent(PrinterReportedPosition, ref unregisterEvents);
        }
Ejemplo n.º 11
0
        public RadialLevlingFunctions(int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)
        {
            this.LevelingData          = levelingData;
            this.BedCenter             = bedCenter;
            this.NumberOfRadialSamples = numberOfRadialSamples;

            PrinterConnectionAndCommunication.Instance.PositionRead.RegisterEvent(PrinterReportedPosition, ref unregisterEvents);
        }
Ejemplo n.º 12
0
        public void Leveling7PointsCorectInterpolation()
        {
			PrintLevelingData levelingData = new PrintLevelingData();

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			Vector2 currentEdgePoint = new Vector2(radius, 0);
			for (int i = 0; i < 6; i++)
			{
				levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
				currentEdgePoint.Rotate(MathHelper.Tau / 6);
			}

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			for (int curPoint = 0; curPoint < 6; curPoint++)
			{
				int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

				// test actual sample position
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				Vector3 outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);

				// test mid point between samples
				Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
				currentTestPoint = new Vector2(midPoint.x, midPoint.y);
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				Assert.AreEqual(outPosition.z, midPoint.z, .001);

				// test mid point between samples with offset
				Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
				currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 3), levelingData);
				Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);

				// test 1/2 angles (mid way between samples on radius)
				currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				// the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
				Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);

				// test 1/2 to center
				currentTestPoint = new Vector2(radius / 2, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				outPosition = LevelWizard7PointRadial.GetPositionWithZOffset(new Vector3(currentTestPoint, 0), levelingData);
				Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
			}
			
			Vector3 outPosition2 = LevelWizard7PointRadial.GetPositionWithZOffset(Vector3.Zero, levelingData);
			Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
		}
Ejemplo n.º 13
0
        private static void SetEquations()
        {
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

            // position 0 does not change as it is the distance from the switch trigger to the extruder tip.
            //levelingData.sampledPosition0 = levelingData.sampledPosition0;
            levelingData.sampledPosition1 = levelingData.sampledPosition0 + probeRead1;
            levelingData.sampledPosition2 = levelingData.sampledPosition0 + probeRead2;

            ActivePrinterProfile.Instance.DoPrintLeveling = true;
        }
Ejemplo n.º 14
0
        public override void PageIsBecomingActive()
        {
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

            levelingData.sampledPosition0 = probePositions[0].position - paperWidth;
            levelingData.sampledPosition1 = probePositions[1].position - paperWidth;
            levelingData.sampledPosition2 = probePositions[2].position - paperWidth;

            ActivePrinterProfile.Instance.DoPrintLeveling = true;
            base.PageIsBecomingActive();
        }
Ejemplo n.º 15
0
        private void Initialize()
        {
            // turn off print leveling
            printer.Connection.AllowLeveling = false;

            // clear any data that we are going to be acquiring (sampled positions, after z home offset)
            var levelingData = new PrintLevelingData()
            {
                LevelingSystem = printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution)
            };

            printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");
            printer.Settings.SetValue(SettingsKey.baby_step_z_offset_1, "0");

            printer.Connection.QueueLine("T0");

            switch (levelingData.LevelingSystem)
            {
            case LevelingSystem.Probe3Points:
                levelingPlan = new LevelWizard3Point(printer);
                break;

            case LevelingSystem.Probe7PointRadial:
                levelingPlan = new LevelWizard7PointRadial(printer);
                break;

            case LevelingSystem.Probe13PointRadial:
                levelingPlan = new LevelWizard13PointRadial(printer);
                break;

            case LevelingSystem.Probe100PointRadial:
                levelingPlan = new LevelWizard100PointRadial(printer);
                break;

            case LevelingSystem.Probe3x3Mesh:
                levelingPlan = new LevelWizardMesh(printer, 3, 3);
                break;

            case LevelingSystem.Probe5x5Mesh:
                levelingPlan = new LevelWizardMesh(printer, 5, 5);
                break;

            case LevelingSystem.Probe10x10Mesh:
                levelingPlan = new LevelWizardMesh(printer, 10, 10);
                break;

            case LevelingSystem.ProbeCustom:
                levelingPlan = new LevelWizardCustom(printer);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 16
0
        public override void PageIsBecomingActive()
        {
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);
            Vector3           paperWidth   = new Vector3(0, 0, ActiveSliceSettings.Instance.ProbePaperWidth);

            levelingData.SampledPosition0 = probePositions[0].position - paperWidth;
            levelingData.SampledPosition1 = probePositions[1].position - paperWidth;
            levelingData.SampledPosition2 = probePositions[2].position - paperWidth;

            ActivePrinterProfile.Instance.DoPrintLeveling = true;
            base.PageIsBecomingActive();
        }
Ejemplo n.º 17
0
        private static void SetEquations()
        {
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();

            // position 0 does not change as it is the distance from the switch trigger to the extruder tip.
            //levelingData.sampledPosition0 = levelingData.sampledPosition0;
            levelingData.SampledPosition1 = levelingData.SampledPosition0 + probeRead1;
            levelingData.SampledPosition2 = levelingData.SampledPosition0 + probeRead2;

            ActiveSliceSettings.Instance.SetPrintLevelingData(levelingData);
            ActiveSliceSettings.Instance.DoPrintLeveling(true);
        }
Ejemplo n.º 18
0
        public static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode)
        {
            var settings = ActiveSliceSettings.Instance;

            if (settings?.GetValue <bool>("print_leveling_enabled") == true &&
                (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 ")) &&
                lineBeingSent.Length > 2 &&
                lineBeingSent[2] == ' ')
            {
                PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();
                return(GetLevelingFunctions(numberOfRadialSamples, levelingData, ActiveSliceSettings.Instance.GetValue <Vector2>(SettingsKey.print_center))
                       .DoApplyLeveling(lineBeingSent, currentDestination, movementMode));
            }

            return(lineBeingSent);
        }
Ejemplo n.º 19
0
        public static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode)
        {
            Printer activePrinter = PrinterConnectionAndCommunication.Instance.ActivePrinter;

            if (activePrinter != null &&
                activePrinter.DoPrintLeveling &&
                (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 ")) &&
                lineBeingSent.Length > 2 &&
                lineBeingSent[2] == ' ')
            {
                PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(activePrinter);
                return(GetLevelingFunctions(numberOfRadialSamples, levelingData, ActiveSliceSettings.Instance.BedCenter)
                       .DoApplyLeveling(lineBeingSent, currentDestination, movementMode));
            }

            return(lineBeingSent);
        }
Ejemplo n.º 20
0
        public override void PageIsBecomingActive()
        {
            Vector3 paperWidth = new Vector3(0, 0, ActiveSliceSettings.Instance.GetValue <double>("manual_probe_paper_width"));

            PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();

            levelingData.SampledPosition0 = probePositions[0].position - paperWidth;
            levelingData.SampledPosition1 = probePositions[1].position - paperWidth;
            levelingData.SampledPosition2 = probePositions[2].position - paperWidth;

            // Invoke setter forcing persistence of leveling data
            ActiveSliceSettings.Instance.SetPrintLevelingData(levelingData);

            ActiveSliceSettings.Instance.DoPrintLeveling(true);

            base.PageIsBecomingActive();
        }
Ejemplo n.º 21
0
        public override void PageIsBecomingActive()
        {
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();

            Vector3 paperWidth = new Vector3(0, 0, ActiveSliceSettings.Instance.GetValue <double>("manual_probe_paper_width"));

            for (int i = 0; i < probePositions.Count; i++)
            {
                levelingData.SampledPositions.Add(probePositions[i].position - paperWidth);
            }

            // Invoke setter forcing persistence of leveling data
            ActiveSliceSettings.Instance.Helpers.SetPrintLevelingData(levelingData);

            ActiveSliceSettings.Instance.Helpers.DoPrintLeveling(true);
            base.PageIsBecomingActive();
        }
Ejemplo n.º 22
0
        public LevelingFunctions(PrinterSettings printerSettings, PrintLevelingData levelingData)
        {
            this.printerSettings  = printerSettings;
            this.SampledPositions = new List <Vector3>(levelingData.SampledPositions);

            bedSize = printerSettings.GetValue <Vector2>(SettingsKey.bed_size);

            // get the delaunay triangulation
            var zDictionary = new Dictionary <(double, double), double>();
            var vertices    = new List <DefaultVertex>();

            foreach (var sample in SampledPositions)
            {
                vertices.Add(new DefaultVertex()
                {
                    Position = new double[] { sample.X, sample.Y }                    //, sample.Z }
                });
                var key = (sample.X, sample.Y);
                if (!zDictionary.ContainsKey(key))
                {
                    zDictionary.Add(key, sample.Z);
                }
            }
            ;

            int extraXPosition = -50000;

            vertices.Add(new DefaultVertex()
            {
                Position = new double[] { extraXPosition, SampledPositions[0].Y }
            });

            var triangles = DelaunayTriangulation <DefaultVertex, DefaultTriangulationCell <DefaultVertex> > .Create(vertices, .001);

            var probeOffset = new Vector3(0, 0, printerSettings.GetValue <double>(SettingsKey.z_probe_z_offset));

            // make all the triangle planes for these triangles
            foreach (var triangle in triangles.Cells)
            {
                var p0 = triangle.Vertices[0].Position;
                var p1 = triangle.Vertices[1].Position;
                var p2 = triangle.Vertices[2].Position;
                if (p0[0] != extraXPosition && p1[0] != extraXPosition && p2[0] != extraXPosition)
                {
                    var v0 = new Vector3(p0[0], p0[1], zDictionary[(p0[0], p0[1])]);
Ejemplo n.º 23
0
        public override void PageIsBecomingActive()
        {
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();

            levelingData.SampledPositions.Clear();
            Vector3 paperWidth = new Vector3(0, 0, ActiveSliceSettings.Instance.ProbePaperWidth());

            for (int i = 0; i < probePositions.Length; i++)
            {
                levelingData.SampledPositions.Add(probePositions[i].position - paperWidth);
            }

            // Invoke setter forcing persistence of leveling data
            ActiveSliceSettings.Instance.SetPrintLevelingData(levelingData);

            ActiveSliceSettings.Instance.DoPrintLeveling(true);
            base.PageIsBecomingActive();
        }
Ejemplo n.º 24
0
        public override void PageIsBecomingActive()
        {
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

            levelingData.SampledPositions.Clear();
            Vector3 paperWidth = new Vector3(0, 0, ActiveSliceSettings.Instance.ProbePaperWidth);

            for (int i = 0; i < probePositions.Length; i++)
            {
                levelingData.SampledPositions.Add(probePositions[i].position - paperWidth);
            }

            levelingData.Commit();


            ActivePrinterProfile.Instance.DoPrintLeveling = true;
            base.PageIsBecomingActive();
        }
Ejemplo n.º 25
0
 private static void CreateFromJsonOrLegacy(string jsonData, string depricatedPositionsCsv3ByXYZ)
 {
     if (jsonData != null)
     {
         activelyLoading = true;
         instance        = (PrintLevelingData)Newtonsoft.Json.JsonConvert.DeserializeObject <PrintLevelingData>(jsonData);
         activelyLoading = false;
     }
     else if (depricatedPositionsCsv3ByXYZ != null)
     {
         instance = new PrintLevelingData();
         instance.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);
     }
     else
     {
         instance = new PrintLevelingData();
     }
 }
Ejemplo n.º 26
0
        public override void OnLoad(EventArgs args)
        {
            PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;

            levelingData.SampledPositions.Clear();

            for (int i = 0; i < probePositions.Count; i++)
            {
                levelingData.SampledPositions.Add(probePositions[i].Position);
            }

            levelingData.LevelingSystem = printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution);
            levelingData.CreationDate   = DateTime.Now;
            // record the temp the bed was when we measured it (or 0 if no heated bed)
            levelingData.BedTemperature = printer.Settings.GetValue <bool>(SettingsKey.has_heated_bed) ?
                                          printer.Settings.GetValue <double>(SettingsKey.bed_temperature)
                                : 0;
            levelingData.IssuedLevelingTempWarning = false;

            // Invoke setter forcing persistence of leveling data
            printer.Settings.Helpers.PrintLevelingData = levelingData;
            printer.Settings.ForTools <double>(SettingsKey.baby_step_z_offset, (key, value, i) =>
            {
                printer.Settings.SetValue(key, "0");
            });
            printer.Connection.AllowLeveling = true;
            printer.Settings.Helpers.DoPrintLeveling(true);

            // Make sure when the wizard is done we turn off the bed heating
            printer.Connection.TurnOffBedAndExtruders(TurnOff.AfterDelay);

            if (printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
            {
                printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
            }
            else if (!printer.Settings.GetValue <bool>(SettingsKey.has_z_probe))
            {
                // Lift the hotend off the bed - at the conclusion of the wizard, make sure we lift the heated nozzle off the bed
                printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().Z);
            }

            base.OnLoad(args);
        }
Ejemplo n.º 27
0
        public override void PageIsBecomingActive()
        {
            PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();

            levelingData.SampledPositions.Clear();

            for (int i = 0; i < probePositions.Count; i++)
            {
                levelingData.SampledPositions.Add(probePositions[i].position);
            }

            levelingData.LevelingSystem = printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution);
            levelingData.CreationDate   = DateTime.Now;
            // record the temp the bed was when we measured it (or 0 if no heated bed)
            levelingData.BedTemperature = printer.Settings.GetValue <bool>(SettingsKey.has_heated_bed) ?
                                          printer.Settings.GetValue <double>(SettingsKey.bed_temperature)
                                : 0;
            levelingData.IssuedLevelingTempWarning = false;

            // Invoke setter forcing persistence of leveling data
            printer.Settings.Helpers.SetPrintLevelingData(levelingData, true);
            PrintLevelingStream.AllowLeveling = true;
            printer.Settings.Helpers.DoPrintLeveling(true);

            if (printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max))
            {
                printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
            }

            // Make sure when the wizard is done we turn off the bed heating
            printer.Connection.TurnOffBedAndExtruders(TurnOff.AfterDelay);

            Closed += (s, e) =>
            {
                // give instruction about how to load filament if the user has not gotten them
                ApplicationController.Instance.RunAnyRequiredPrinterSetup(printer, theme);
            };


            base.PageIsBecomingActive();
        }
        private void SetupForValidation()
        {
            validationRunning = true;

            // make sure baby stepping is removed as this will be calibrated exactly (assuming it works)
            printer.Settings.ForTools <double>(SettingsKey.baby_step_z_offset, (key, value, i) =>
            {
                // remember the current baby stepping values
                babySteppingValue[i] = value;
                printer.Settings.SetValue(key, "0");
            });

            oldAllowLeveling = printer.Connection.AllowLeveling;
            // turn off print leveling
            printer.Connection.AllowLeveling = false;

            var levelingData = new PrintLevelingData()
            {
                LevelingSystem = printer.Settings.GetValue <LevelingSystem>(SettingsKey.print_leveling_solution)
            };
        }
Ejemplo n.º 29
0
		public void Leveling7PointsNeverGetsTooHigh()
		{
			StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
			MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

			var levelingData = new PrintLevelingData(ActiveSliceSettings.Instance);

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			levelingData.SampledPositions.Add(new Vector3(130.00, 0.00, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, 112.58, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, 112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(-130.00, 0.00, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, -112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, -112.58, 10));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 0));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			int totalPoints = 2000;
			for (int curPoint = 0; curPoint < totalPoints; curPoint++)
			{
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / totalPoints * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);

				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.IsTrue(outPosition.z <= 10);

				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				double outZ = 0;
				Assert.IsTrue(GCodeFile.GetFirstNumberAfter("Z", outPositionString, ref outZ));
				Assert.IsTrue(outZ <= 10);
			}
		}
Ejemplo n.º 30
0
        private static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
        {
            PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);

            LevelWizardBase printLevelWizardWindow;

            switch (levelingData.levelingSystem)
            {
            case PrintLevelingData.LevelingSystem.Probe2Points:
                printLevelWizardWindow = new LevelWizard2Point(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe3Points:
                printLevelWizardWindow = new LevelWizard3Point(runningState);
                break;

            default:
                throw new NotImplementedException();
            }

            printLevelWizardWindow.ShowAsSystemWindow();
            return(printLevelWizardWindow);
        }
Ejemplo n.º 31
0
		public void Leveling7PointsNeverGetsTooHeigh()
		{
			PrintLevelingData levelingData = new PrintLevelingData();

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			levelingData.SampledPositions.Add(new Vector3(130.00, 0.00, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, 112.58, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, 112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(-130.00, 0.00, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, -112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, -112.58, 10));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 0));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			int totalPoints = 2000;
			for (int curPoint = 0; curPoint < totalPoints; curPoint++)
			{
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / totalPoints * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);
				
				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.IsTrue(outPosition.z <= 10);
				
				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				double outZ = 0;
				Assert.IsTrue(GCodeFile.GetFirstNumberAfter("Z", outPositionString, ref outZ));
				Assert.IsTrue(outZ <= 10);
			}
		}
Ejemplo n.º 32
0
        private static LevelWizardBase CreateAndShowWizard(LevelWizardBase.RuningState runningState)
        {
            PrintLevelingData levelingData = ActiveSliceSettings.Instance.GetPrintLevelingData();

            LevelWizardBase printLevelWizardWindow;

            switch (levelingData.CurrentPrinterLevelingSystem)
            {
            case PrintLevelingData.LevelingSystem.Probe2Points:
                printLevelWizardWindow = new LevelWizard2Point(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe3Points:
                printLevelWizardWindow = new LevelWizard3Point(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe7PointRadial:
                printLevelWizardWindow = new LevelWizard7PointRadial(runningState);
                break;

            case PrintLevelingData.LevelingSystem.Probe13PointRadial:
                printLevelWizardWindow = new LevelWizard13PointRadial(runningState);
                break;

            default:
                throw new NotImplementedException();
            }

            printLevelWizardWindow.Closed += (sender, e) =>
            {
                ApplicationController.Instance.ReloadAll(null, null);
            };

            printLevelWizardWindow.ShowAsSystemWindow();
            return(printLevelWizardWindow);
        }
Ejemplo n.º 33
0
		private static void CreateFromJsonOrLegacy(string jsonData, string depricatedPositionsCsv3ByXYZ)
		{
			if (jsonData != null)
			{
				activelyLoading = true;
				instance = Newtonsoft.Json.JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
				activelyLoading = false;
			}
			else if (depricatedPositionsCsv3ByXYZ != null)
			{
				instance = new PrintLevelingData();
				instance.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);
			}
			else
			{
				instance = new PrintLevelingData();
			}
		}
Ejemplo n.º 34
0
		public PrintLevelingData GetPrintLevelingData()
		{
			if (printLevelingData == null)
			{
				printLevelingData = PrintLevelingData.Create(
					ActiveSliceSettings.Instance,
					printerSettings.GetValue(SettingsKey.print_leveling_data),
					printerSettings.GetValue("MatterControl.PrintLevelingProbePositions"));

				if (printLevelingData.SampledPositions.Count == 3)
				{
					PrintLevelingPlane.Instance.SetPrintLevelingEquation(
						printLevelingData.SampledPositions[0],
						printLevelingData.SampledPositions[1],
						printLevelingData.SampledPositions[2],
						ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.print_center));
				}
			}

			return printLevelingData;
		}
Ejemplo n.º 35
0
        public static RadialLevlingFunctions GetLevelingFunctions(int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)
        {
            if (currentLevelingFunctions == null ||
                currentLevelingFunctions.NumberOfRadialSamples != numberOfRadialSamples ||
                currentLevelingFunctions.BedCenter != bedCenter ||
                currentLevelingFunctions.LevelingData != levelingData)
            {
                if (currentLevelingFunctions != null)
                {
                    currentLevelingFunctions.Dispose();
                }

                currentLevelingFunctions = new RadialLevlingFunctions(numberOfRadialSamples, levelingData, bedCenter);
            }

            return(currentLevelingFunctions);
        }
 public RadialLevlingFunctions(int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)
 {
     this.LevelingData = levelingData;
     this.BedCenter = bedCenter;
     this.NumberOfRadialSamples = numberOfRadialSamples;
 }
        public static RadialLevlingFunctions GetLevelingFunctions(int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)
        {
            if (currentLevelingFunctions == null
                || currentLevelingFunctions.NumberOfRadialSamples != numberOfRadialSamples
                || currentLevelingFunctions.BedCenter != bedCenter
                || currentLevelingFunctions.LevelingData != levelingData)
            {
				if (currentLevelingFunctions != null)
				{
					currentLevelingFunctions.Dispose();
                }

                currentLevelingFunctions = new RadialLevlingFunctions(numberOfRadialSamples, levelingData, bedCenter);
            }

            return currentLevelingFunctions;
        }
Ejemplo n.º 38
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            var inverseScale = 1 / scalingFactor;

            var offset = Vector2.Zero;

            //graphics2D.PushTransform();

            // Reset to zero
            var existing = graphics2D.GetTransform();

            existing.translation(out double x, out double y);
            offset.X += x;
            offset.Y += y;

            // Center
            if (this.Width > this.Height)
            {
                offset.X += (this.Width / 2) - (bedBounds.Width * scalingFactor / 2);
            }
            else
            {
                offset.Y += (this.Height / 2) - (bedBounds.Height * scalingFactor / 2);
            }

            // Offset considering bed bounds
            offset.X -= bedBounds.Left * scalingFactor;
            offset.Y -= bedBounds.Bottom * scalingFactor;

            // Apply transform
            graphics2D.SetTransform(Affine.NewScaling(scalingFactor) * Affine.NewTranslation(offset));

            // Draw the bed
            this.RenderBed(graphics2D);

            // Build hotend path
            if (this.RenderProbePath)
            {
                this.RenderProbingPath(graphics2D);
            }

            if (this.RenderLevelingData)
            {
                if (currentLevelingFunctions == null)
                {
                    PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
                    currentLevelingFunctions = new LevelingFunctions(printer, levelingData);
                }

                var levelingTriangles = new VertexStorage();

                foreach (var region in currentLevelingFunctions.Regions)
                {
                    levelingTriangles.MoveTo(region.V0.X, region.V0.Y);

                    levelingTriangles.LineTo(region.V1.X, region.V1.Y);
                    levelingTriangles.LineTo(region.V2.X, region.V2.Y);
                    levelingTriangles.LineTo(region.V0.X, region.V0.Y);
                }

                graphics2D.Render(
                    new Stroke(levelingTriangles),
                    opaqueMinimumAccent);
            }

            // Render probe points
            int i = 0;

            foreach (var position in probePoints)
            {
                var center = new Vector2(position.X, position.Y);

                var circleColor = lightColor;

                if (this.SimplePoints)
                {
                    graphics2D.Render(
                        new Ellipse(center, 4 * inverseScale),
                        opaqueMinimumAccent);
                }
                else
                {
                    if (i < this.ActiveProbeIndex)
                    {
                        circleColor = opaqueMinimumAccent;
                    }
                    else if (i == this.ActiveProbeIndex)
                    {
                        circleColor = opaqueAccent;
                    }

                    graphics2D.Render(
                        new Ellipse(center, 8 * inverseScale),
                        circleColor);

                    graphics2D.DrawString(
                        $"{1 + i++}",
                        center.X,
                        center.Y,
                        justification: Agg.Font.Justification.Center,
                        baseline: Agg.Font.Baseline.BoundsCenter,
                        pointSize: theme.FontSize7 * inverseScale,
                        color: theme.TextColor);
                }
            }

            //graphics2D.PopTransform();

            base.OnDraw(graphics2D);
        }
		bool EditSamplePositionList(PrintLevelingData levelingData)
		{
			if (levelingData.CurrentPrinterLevelingSystem == PrintLevelingData.LevelingSystem.Probe7PointRadial
				|| levelingData.CurrentPrinterLevelingSystem == PrintLevelingData.LevelingSystem.Probe13PointRadial)
			{
				return true;
			}

			return false;
		}
		public static Vector3 GetPositionWithZOffset(Vector3 currentDestination, PrintLevelingData levelingData)
		{
			Vector2 destinationFromCenter = new Vector2(currentDestination) - ActiveSliceSettings.Instance.BedCenter;

			double angleToPoint = Math.Atan2(destinationFromCenter.y, destinationFromCenter.x);

			if (angleToPoint < 0)
			{
				angleToPoint += MathHelper.Tau;
			}

			double oneSegmentAngle = MathHelper.Tau / numberOfRadialSamples;
			int firstIndex = (int)(angleToPoint / oneSegmentAngle);
			int lastIndex = firstIndex + 1;
			if (lastIndex == numberOfRadialSamples)
			{
				lastIndex = 0;
			}

			Plane currentPlane = new Plane(levelingData.SampledPositions[firstIndex], levelingData.SampledPositions[lastIndex], levelingData.SampledPositions[numberOfRadialSamples]);

			double hitDistance = currentPlane.GetDistanceToIntersection(new Vector3(currentDestination.x, currentDestination.y, 0), Vector3.UnitZ);

			currentDestination.z += hitDistance;
			return currentDestination;
		}
Ejemplo n.º 41
0
		internal static PrintLevelingData Create(string jsonData, string depricatedPositionsCsv3ByXYZ)
		{
			if (!string.IsNullOrEmpty(jsonData))
			{
				return JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
			}
			else if (!string.IsNullOrEmpty(depricatedPositionsCsv3ByXYZ))
			{
				var item = new PrintLevelingData();
				item.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);
				return item;
			}
			else
			{
				return new PrintLevelingData();
			}
		}
Ejemplo n.º 42
0
        public void Leveling7PointsCorectInterpolation()
		{
			PrintLevelingData levelingData = new PrintLevelingData();

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			Vector2 currentEdgePoint = new Vector2(radius, 0);
			for (int i = 0; i < 6; i++)
			{
				levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
				currentEdgePoint.Rotate(MathHelper.Tau / 6);
			}

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			for (int curPoint = 0; curPoint < 6; curPoint++)
			{
				int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

				// test actual sample position
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);
				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);
				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test mid point between samples
				Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
				currentTestPoint = new Vector2(midPoint.x, midPoint.y);
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, midPoint.z, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test mid point between samples with offset
				Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
				currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
				destPosition = new Vector3(currentTestPoint, 3);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test 1/2 angles (mid way between samples on radius)
				currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				// the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
				Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test 1/2 to center
				currentTestPoint = new Vector2(radius / 2, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);
			}

			// prove that relative offsets work
			{
				Vector2 prevTestPoint = new Vector2(radius, 0);
				Vector3 prevDestPosition = new Vector3(prevTestPoint, 0);
				Vector3 prevOutPosition = levelingFunctions7Point.GetPositionWithZOffset(prevDestPosition);
				string prevOutPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(prevDestPosition), prevDestPosition, PrinterMachineInstruction.MovementTypes.Absolute);

				for (int curPoint = 1; curPoint < 6; curPoint++)
				{
					// test actual sample position
					Vector2 currentTestPoint = new Vector2(radius, 0);
					currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
					Vector3 destPosition = new Vector3(currentTestPoint, 0);
					Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);

					string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Relative);
					Vector3 delatFromPrevToCurrent = outPosition - prevOutPosition;
					Assert.AreEqual(GetGCodeString(delatFromPrevToCurrent), outPositionString);

					prevTestPoint = currentTestPoint;
					prevDestPosition = destPosition;
					prevOutPosition = outPosition;
				}
			}

			Vector3 outPosition2 = levelingFunctions7Point.GetPositionWithZOffset(Vector3.Zero);
			Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
		}
Ejemplo n.º 43
0
 public RadialLevlingFunctions(int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)
 {
     this.LevelingData          = levelingData;
     this.BedCenter             = bedCenter;
     this.NumberOfRadialSamples = numberOfRadialSamples;
 }
Ejemplo n.º 44
0
		public void SetPrintLevelingData(PrintLevelingData data)
		{
			printLevelingData = data;
			printerSettings.SetValue(SettingsKey.print_leveling_data, JsonConvert.SerializeObject(data));
		}
		private static Vector3 GetPositionWithZOffset(Vector3 currentDestination, PrintLevelingData levelingData)
		{
			double angleToPoint = Math.Atan2(currentDestination.y, currentDestination.x);

			if (angleToPoint < 0)
			{
				angleToPoint += MathHelper.Tau;
			}

			double ratioToRadius = Math.Min(1, Math.Max(0, new Vector3(currentDestination.x, currentDestination.y, 0).Length / levelingData.SampledPositions[0].x));

			double oneSegmentAngle = MathHelper.Tau / 6;
			int firstIndex = (int)(angleToPoint / oneSegmentAngle);
			int lastIndex = firstIndex + 1;
			if (lastIndex == 6)
			{
				lastIndex = 0;
			}

			double ratioToLast = Math.Min(1, Math.Max(0, (angleToPoint - firstIndex * oneSegmentAngle) / oneSegmentAngle));

			double firstZ = levelingData.SampledPositions[firstIndex].z;
			double lastZ = levelingData.SampledPositions[lastIndex].z;
			double centerZ = levelingData.SampledPositions[6].z;

			double zAtRadius = lastZ * ratioToLast + firstZ * (1-ratioToLast);

			double zBetweenCenterAndRadius = zAtRadius * ratioToRadius + centerZ * (1 - ratioToRadius);

			return new Vector3(currentDestination.x, currentDestination.y, currentDestination.z + zBetweenCenterAndRadius);
		}